| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <template>
- <view class="common-page">
- <u-form :model="form" :rules="rules" ref="formRef" labelWidth="90px" errorType="toast" :labelStyle="labelStyle">
- <u-form-item label="重量(千克)" prop="weight" required>
- <u-input :placeholderStyle="placeholderStyle" :customStyle="customStyle" v-model="form.weight" placeholder="请输入数值" clearable />
- </u-form-item>
- <u-form-item label="ISBN" prop="isbn" required>
- <u-input :placeholderStyle="placeholderStyle" :customStyle="customStyle" v-model="form.isbn" placeholder="请输入编码" clearable />
- </u-form-item>
- </u-form>
- <view class="fixed-bottom">
- <u-button size="large" type="warning" text="扫码" @click="handleScan" />
- <u-button size="large" type="success" text="提交" v-permission="'app:entry:bookWeight:confirm'" @click="submitForm" />
- </view>
- </view>
- </template>
- <script setup>
- import { ref, onUnmounted } from 'vue';
- import { onLoad, onShow } from '@dcloudio/uni-app'
- const customStyle = {
- height: '100rpx',
- fontSize: '32rpx'
- }
- const labelStyle = {
- fontSize: '32rpx'
- }
- const placeholderStyle = ref("fontSize: 32rpx")
- const form = ref({
- weight: '',
- isbn: ''
- });
- const rules = {
- weight: [{
- required: true,
- message: '请输入重量',
- trigger: 'blur'
- },
- {
- type: 'number',
- message: '重量必须是数字',
- trigger: 'blur'
- }
- ],
- isbn: [{
- required: true,
- message: '请输入ISBN',
- trigger: 'blur'
- }]
- };
- function handleScan() {
- uni.scanCode({
- success: (res) => {
- form.value.isbn = res.result
- }
- })
- }
- const formRef = ref(null);
- const submitForm = () => {
- formRef.value.validate().then((valid) => {
- if (valid) {
- // 提交表单
- uni.$u.http.post('/app/weighChangeLog/add', form.value).then(res => {
- if (res.code == 200) {
- uni.$u.toast('修改成功');
- form.value.isbn = ''
- form.value.weight = ''
- } else {
- uni.$u.toast(res.msg);
- }
- })
- }
- });
- };
- // #ifdef APP-PLUS
- const { unregister } = uni.$u.useEventListener((e) => {
- form.value.isbn = e.barcode
- });
- // #endif
- onUnmounted(() => {
- // #ifdef APP-PLUS
- unregister();
- // #endif
- });
- </script>
|