book-weight.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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="提交" v-permission="'app:entry:bookWeight:confirm'" @click="submitForm" />
  14. </view>
  15. </view>
  16. </template>
  17. <script setup>
  18. import { ref, onUnmounted } from 'vue';
  19. import { onLoad, onShow } 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. // #ifdef APP-PLUS
  75. const { unregister } = uni.$u.useEventListener((e) => {
  76. form.value.isbn = e.barcode
  77. });
  78. // #endif
  79. onUnmounted(() => {
  80. // #ifdef APP-PLUS
  81. unregister();
  82. // #endif
  83. });
  84. </script>