book-weight.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view class="common-page">
  3. <u-form :model="form" :rules="rules" ref="formRef" labelWidth="90px" errorType="toast" :labelStyle="labelStyle">
  4. <u-form-item label="重量(克)" prop="weight" required>
  5. <u-input :placeholderStyle="placeholderStyle" :customStyle="customStyle" v-model="form.weight" placeholder="请输入数值" clearable />
  6. </u-form-item>
  7. <u-form-item label="ISBN" prop="isbn" required>
  8. <u-input :placeholderStyle="placeholderStyle" :customStyle="customStyle" v-model="form.isbn" placeholder="请输入编码" clearable />
  9. </u-form-item>
  10. </u-form>
  11. <view class="fixed-bottom">
  12. <u-button size="large" type="warning" text="扫码" @click="handleScan" />
  13. <u-button size="large" type="success" text="提交" @click="submitForm" />
  14. </view>
  15. </view>
  16. </template>
  17. <script setup>
  18. import { ref } from 'vue';
  19. import { onLoad } from '@dcloudio/uni-app'
  20. const customStyle = {
  21. height: '100rpx',
  22. fontSize: '32rpx'
  23. }
  24. const labelStyle = {
  25. fontSize: '32rpx'
  26. }
  27. const placeholderStyle = ref("fontSize: 32rpx")
  28. const form = ref({
  29. weight: '',
  30. isbn: ''
  31. });
  32. const rules = {
  33. weight: [{
  34. required: true,
  35. message: '请输入重量',
  36. trigger: 'blur'
  37. },
  38. {
  39. type: 'number',
  40. message: '重量必须是数字',
  41. trigger: 'blur'
  42. }
  43. ],
  44. isbn: [{
  45. required: true,
  46. message: '请输入ISBN',
  47. trigger: 'blur'
  48. }]
  49. };
  50. function handleScan() {
  51. uni.scanCode({
  52. success: (res) => {
  53. form.value.isbn = res.result
  54. }
  55. })
  56. }
  57. const formRef = ref(null);
  58. const submitForm = () => {
  59. formRef.value.validate().then((valid) => {
  60. if (valid) {
  61. // 提交表单
  62. uni.$u.http.post('/app/weighChangeLog/add', form.value).then(res => {
  63. if (res.code == 200) {
  64. uni.$u.toast('修改成功');
  65. form.value.isbn = ''
  66. form.value.weight = ''
  67. } else {
  68. uni.$u.toast(res.msg);
  69. }
  70. })
  71. }
  72. });
  73. };
  74. onLoad(() => {
  75. // #ifdef APP-PLUS
  76. uni.$u.useGlobalEvent((e) => {
  77. form.value.isbn = e.barcode
  78. })
  79. // #endif
  80. })
  81. </script>