YYC
2023-04-14 db1dc3add7bc47c98da408c2e05de28591100bfb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<template>
    <view class="content">
        <view class="u-demo-block" style="width: 100%;">
            <view class="u-demo-block__content" style="margin: 0 50rpx;">
                <!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
                <u--form  labelPosition="left" :model="model1"  ref="form1">
 
                    <u-form-item  label="库区名称:" labelWidth="100" borderBottom ref="item1">
                        {{deptName}}
                    </u-form-item>
 
                    <u-form-item label="司机姓名:" labelWidth="100" required prop="userName" borderBottom ref="item1">
                        <u--input v-model="model1.userName" border="none" placeholder="姓名,只能为中文"></u--input>
                    </u-form-item>
                    <u-form-item label="司机手机号:" labelWidth="100" prop="phone" borderBottom ref="item1">
                        <u--input v-model="model1.phone" border="none" placeholder="请输入手机号"></u--input>
                    </u-form-item>
 
                    <u-form-item label="业务类型:" labelWidth="100" required prop="bizType" borderBottom ref="item1">
                        <u-radio-group v-model="model1.bizType">
                            <u-radio :customStyle="{marginRight: '16px'}" v-for="(item, index) in bizTypeList"
                                :key="index" :label="item.name" :name="item.type">
                            </u-radio>
                        </u-radio-group>
                    </u-form-item>
 
                    <u-form-item label="司机身份证号:" labelWidth="100" required prop="userId" borderBottom ref="item1">
                        <u--input v-model="model1.userId" border="none" placeholder="请输入身份证号"></u--input>
                    </u-form-item>
                    <u-form-item label="车牌号:" labelWidth="100" required prop="plateNum" borderBottom ref="item1">
                        <u--input v-model="model1.plateNum" border="none" placeholder="请输入车牌号"></u--input>
                    </u-form-item>
                    <u-form-item label="预约日期:" labelWidth="100" required prop="dataTime" borderBottom
                        @click="showdataTime = true; hideKeyboard()" ref="item1">
                        <u--input v-model="model1.dataTime" placeholder="请选择预约日期" border="none" disabled disabledColor="#efeff4"></u--input>
                        <u-icon slot="right" name="arrow-right"></u-icon>
                    </u-form-item>
 
                    
 
 
                </u--form>
                
                    <view style="margin: 0 20%;">
                        <u-button type="primary" text="提交" :customStyle="customStyle1"  @click="submit"></u-button>
                    </view>
                    <view style="margin: 0 20%;">
                        <u-button type="error" text="重置" :customStyle="customStyle2" @click="reset"></u-button>
                    </view>
                <view class="m1">
                    <u-checkbox-group>
                        <u-checkbox shape="circle" size="18" :checked="isChecked" @change="changeChecked">
                        </u-checkbox>
                        <label>请阅读并同意</label>
                        <a @click="goPrivacy">《智慧粮库协议》</a>
                    </u-checkbox-group>
                </view>
                
                <u-datetime-picker :show="showdataTime" :value="dataTime" mode="date" closeOnClickOverlay
                    @confirm="dataTimeConfirm" @cancel="dataTimeClose" @close="dataTimeClose"></u-datetime-picker>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                value: '',
                isChecked:false,
                showCalendar: false,
                showdataTime: false,
                model1: {
                    deptId: '',
                    bizType: '',
                    userName: '',
                    dataTime: '',
                    phone: '',
                    plateNum:'',
                    userId: '',
                    openid: ''
                },
                formStyle:{
                    width:'650rpx'
                },
                customStyle1:{
                    marginTop:'50px'
                },
                customStyle2:{
                    marginTop:'10px'
                },
                deptName: '',
                dataTime: Number(new Date().setTime(new Date().getTime() + 24 * 60 * 60 * 1000)),
                rules: {
                    userName: [{
                        type: 'string',
                        required: true,
                        message: '请填写姓名',
                        trigger: ['blur', 'change'],
                    }, {
                        // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
                        validator: (rule, value, callback) => {
                            // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
                            return uni.$u.test.chinese(value);
                        },
                        message: "姓名必须为中文",
                        // 触发器可以同时用blur和change,二者之间用英文逗号隔开
                        trigger: ["change", "blur"],
                    }],
                    dataTime: {
                        type: 'string',
                        required: true,
                        message: '请选择日期',
                        trigger: ['change']
                    },
                    plateNum: {
                        // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
                        validator: (rule, value, callback) => {
                            // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
                            return uni.$u.test.carNo(value);
                        },
                        message: "车牌号错误",
                        // 触发器可以同时用blur和change,二者之间用英文逗号隔开
                        trigger: ["change", "blur"],
                    },
                    bizType: {
                        type: 'string',
                        required: true,
                        message: '请选择业务类型',
                        trigger: ['change']
                    },
                    userId: {
                        // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
                        validator: (rule, value, callback) => {
                            // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
                            return uni.$u.test.idCard(value);
                        },
                        message: "身份证号格式错误",
                        // 触发器可以同时用blur和change,二者之间用英文逗号隔开
                        trigger: ["change", "blur"],
                    },
                },
                bizTypeList: [{
                        type: 'OUT',
                        name: '出库预约',
                        disabled: false
                    },
                    {
                        type: 'IN',
                        name: '入库预约',
                        disabled: false
                    }
                ],
            }
        },
        onReady() {
            // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
            this.$refs.form1.setRules(this.rules)
        },
        mounted() {
 
        },
        onLoad: function(option) {
            var info = JSON.parse(uni.getStorageSync('dept') || '[]');
            this.model1.deptId = info.deptId
            this.deptName = info.deptName
            this.model1.openid = info.openid
        },
        methods: {
 
            dataTimeClose() {
                this.showdataTime = false
                this.$refs.form1.validateField('dataTime')
            },
            dataTimeConfirm(e) {
                this.showdataTime = false
                this.model1.dataTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
                this.$refs.form1.validateField('dataTime')
            },
            submit() {
                if(this.isChecked){
                    // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
                    this.$refs.form1.validate().then(res => {
                        uni.request({
                            url: 'https://app.fzzygf.com/igds-wx/gateway',
                            data: {
                                interfaceId:'2007',
                                data:this.model1
                            },
                            method:'POST',
                            header:{
                                'Content-Type':'application/json'
                            },
                            success: (res) => {
                                
                                if (res.data.code == "0000") {
                                    uni.$u.toast(res.data.msg)
                                    this.reset()
                                    console.log(JSON.stringify(res))
                                } else{
                                    uni.$u.toast(res.data.msg)
                                }
                            },
                            fail: (errors) => {
                                uni.$u.toast(res.data.msg)
                            }
                        
                        })
                    console.log(JSON.stringify(this.model1))
                    }).catch(errors => {
                        uni.$u.toast('校验失败')
                    })
                    
                }else{
                    uni.$u.toast('请阅读并同意协议!')
                }
            },
            //重置输入的内容
            reset() {
                const validateList = ['userName', 'phone', 'userId', 'dataTime','plateNum','bizType']
                this.$refs.form1.resetFields()
                this.$refs.form1.clearValidate()
                setTimeout(() => {
                    this.$refs.form1.clearValidate(validateList)
                    // 或者使用 this.$refs.form1.clearValidate()
                }, 10)
                this.model1.userName=''
                this.model1.phone=''
                this.model1.plateNum=''
                this.model1.userId=''
                this.model1.dataTime=''
                this.model1.bizType=''
 
            },
            hideKeyboard() {
                uni.hideKeyboard()
            },
            // 复选框的点击事件
            changeChecked() {
                this.isChecked = !this.isChecked;
                console.log(this.isChecked)
            },
            goPrivacy(){
                uni.navigateTo({
                    url: '/pages/privacy/privacy'
                })
            }
        }
 
    }
</script>
 
<style lang="scss">
    .content {
        padding-top: 30rpx;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        .m1{
            position: absolute;
            bottom: -200rpx;
            transform: translateX(50%);
            font-size: 20rpx;
            white-space: nowrap;
        }
    }
</style>