schangxiang@126.com
2024-09-09 a19d2fd7d9f52f7daa15b32d434cb86fa7ffb30b
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<template>
    <default-header-page-layout ref="page" :title="type=='add'?'新增班组':'编辑班组'">
        <view class="page-frame">
            <u-form :model="form" :rules="rules" ref="uForm" label-width="65" labelAlign="right">
 
                <!-- <u-form-item required label="班组名称:" prop="shiftName">
                    <u-input placeholder="请输入班组名称" v-model="form.shiftName"></u-input>
                </u-form-item> -->
 
                <!-- <u-form-item required label="班组名称">
                    <view class="input-box" @click="shiftTypeShow=true">
                        {{form.shiftTypeName}}
                        <u-icon @click.native.stop="clearValue('shiftTypeName',$event)" v-if="form.shiftTypeName"
                            color="#dadbde" size="25" name="close-circle"
                            style="position: absolute;top:6rpx;right:10rpx;"></u-icon>
                        <view v-show="!Boolean(form.shiftTypeName)" style="font-size:20rpx;color:rgb(192, 196, 204)">
                            请选择班组名称
                        </view>
                    </view>
                </u-form-item>
                <view v-show="form.shiftTypeName!=undefined&&!Boolean(form.shiftTypeName)"
                    style="font-size:23rpx;color:#f56c6c;margin:-10rpx 0 -10rpx 130rpx;">
                    班组类型不能为空
                </view> -->
 
                <u-form-item required label="班组名称:" prop="shiftName">
                    <u-input :readonly="true" :disabled="type=='edit'" placeholder="请选择班组名称" v-model="form.shiftName" @click.native="shiftTypeShow=true"></u-input>
                </u-form-item>
 
                <u-form-item required label="开始时间:" prop="shiftStartTime">
                    <u-input :readonly="true" placeholder="请选择开始时间" v-model="form.shiftStartTime"
                        @click.native="showTimePicker('start')"></u-input>
                </u-form-item>
 
                <!--项目完成时所有选择器的input加上 :readonly="true" -->
                <u-form-item required label="结束时间:" prop="shiftEndTime">
                    <u-input :readonly="true" placeholder="请选择结束时间" v-model="form.shiftEndTime"
                        @click.native="showTimePicker('end')"></u-input>
                </u-form-item>
 
                <u-form-item required label="是否隔日:" prop="isNextDay">
                    <u-input :readonly="true" placeholder="请选择是否隔日" v-model="form.isNextDay" @click.native="dayShow=true"></u-input>
                </u-form-item>
 
                <u-form-item label="班组长:">
                    <u-textarea :placeholderStyle="{fontSize:45+'rpx',color:'rgb(192, 196, 204)'}"
                        v-model="form.shiftRemark" placeholder="请输入班组长"></u-textarea>
                </u-form-item>
            </u-form>
 
            <!-- 班制选择器 -->
            <u-picker closeOnClickOverlay :show="shiftTypeShow" :columns="shiftTypeList" keyName="name"
                @confirm="shiftTypeConfirm" @cancel="shiftTypeShow=false" @close="shiftTypeShow=false"></u-picker>
 
            <!-- 时间选择器 -->
            <u-datetime-picker closeOnClickOverlay :show="timeShow" @confirm="timeConfirm" mode="time"
                @close="timeShow=false" @cancel="timeShow=false"></u-datetime-picker>
 
            <!-- 是否隔日选择器 -->
            <u-picker closeOnClickOverlay :show="dayShow" :columns="dayList" keyName="name" @confirm="dayConfirm"
                @cancel="dayShow=false" @close="dayShow=false"></u-picker>
            <!-- 班组长选择器 -->
            <!-- <u-picker closeOnClickOverlay :show="userShow" :columns="userList" keyName="name" @confirm="userConfirm"
                @cancel="userShow=false" @close="userShow=false"></u-picker> -->
 
            <!-- :custom-style="{backgroundColor:'#F18201',color:'#fff',marginTop:10+'px'}" -->
            <u-button @click="submit" size="large" type="primary" style="margin-top: 10rpx;">提交</u-button>
        </view>
    </default-header-page-layout>
</template>
 
<script>
    import DefaultHeaderPageLayout from '@/components/DefaultHeaderPageLayout.vue'
    import moment from 'moment'
    import {editShiftInfo,addShiftInfo} from '@/api/shift/index.js'
    // import {
    //     getUserList
    // } from '@/api/common/index.js'
    export default {
        name: 'createShift',
        components: {
            DefaultHeaderPageLayout
        },
        data() {
            return {
                type: '',
                form: {
                    shiftName: '',
                    shiftStartTime: '',
                    shiftEndTime: '',
                    isNextDay: null,
                    shiftRemark: ''
                },
                rules: {
                    shiftName: [{
                        required: true,
                        message: '班组名称不能为空',
                        trigger: ['change', 'blur']
                    }],
                    shiftStartTime: [{
                        required: true,
                        message: '开始时间不能为空',
                        trigger: ['change']
                    }],
                    shiftEndTime: [{
                        required: true,
                        message: '结束时间不能为空',
                        trigger: ['change']
                    }],
                    isNextDay: [{
                        required: true,
                        message: '是否隔日不能为空',
                        trigger: ['change']
                    }],
                },
                // 班组类型
                shiftTypeShow: false,
                shiftTypeList: [
                    [{
                            name: '白班'
                        },
                        {
 
                            name: '晚班'
                        }
                    ]
                ],
                // 时间
                timeShow: false,
                timeType: '', //区分是开始时间选择器还说结束时间选择器
                // 班组长
                dayShow: false,
                dayList: [
                    [{
                        code: true,
                        name: '是'
                    }, {
                        code: false,
                        name: '否'
                    }]
                ]
            }
        },
 
        created() {
            // this.getUserList()
        },
        methods: {
            // 班组确认
            shiftTypeConfirm(e) {
                const {
                    value
                } = e
                if (!value) {
                    return this.shiftTypeShow = false
                }
                this.form.shiftName = value[0].name
                this.shiftTypeShow = false
            },
 
            // 显示时间选择器
            showTimePicker(type) {
                this.timeShow = true
                this.timeType = type
 
            },
 
 
 
            // 时间确认
            timeConfirm({
                value
            }) {
                if (!value) {
                    return this.timeShow = false
                }
                if (this.timeType == 'start') {
                    this.form.shiftStartTime = value
                } else {
                    this.form.shiftEndTime = value
                }
 
                this.timeShow = false
 
            },
 
            // 是否隔日确认
            dayConfirm({
                value
            }) {
                if (!value) {
                    return this.dayShow = false
                }
                this.form.isNextDay = value[0].name
 
                this.dayShow = false
            },
 
            // 获取人员列表
            // async getUserList() {
            //     try {
            //         const {
            //             data
            //         } = await getUserList()
            //         this.userList = [data]
            //     } catch (error) {
            //         console.log(error)
            //     }
            // },
 
            // 显示班组长选择器
            // showUser() {
            //     uni.hideKeyboard()
            //     this.userShow = true
            // },
 
            // userConfirm(e) {
            //     const {
            //         value
            //     } = e
            //     if (!value) {
            //         return this.userShow = false
            //     }
            //     this.form.shiftTeamLeaderId = value[0].id
            //     this.form.shiftTeamLeaderName = value[0].name
 
            //     this.userShow = false
            // },
 
            async submit() {
                let form ={...this.form}
                form.isNextDay=form.isNextDay=='是'?true:false
                console.log(form);
                if(this.type=='add') {
                    try{
                        await addShiftInfo(form)
                        this.$modal('新增成功', () => {
                            this.toShiftIndex()
                        })
                    }catch(e){
                        //TODO handle the exception
                        console.log(e);
                    }
                }else{
                    try{
                        await editShiftInfo(form)
                        this.$modal('编辑成功', () => {
                            this.toShiftIndex()
                        })
                    }catch(e){
                        //TODO handle the exception
                        console.log(e);
                    }
                }
                
            },
            toShiftIndex(){
                uni.navigateTo({
                    url: `/pages/shift/index`,
                    success: () => {
                        this.form = {
                            shiftName: '',
                            shiftStartTime: '',
                            shiftEndTime: '',
                            isNextDay: null,
                            shiftRemark: ''
                        }
                    }
                });
            },
        },
        
        // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
        onReady() {
            this.$refs.uForm.setRules(this.rules);
        },
        onLoad(item) {
            this.type = item.type
            if (this.type == 'edit') {
                this.form = {
                    id:item.id,
                    shiftName: item.shiftName,
                    shiftStartTime:moment(moment(item.shiftStartTime,'HH:mm')).format('HH:mm'),
                    shiftEndTime: moment(moment(item.shiftEndTime,'HH:mm')).format('HH:mm'),
                    isNextDay: item.isNextDay?'是':'否',
                    shiftRemark: item.shiftRemark
                }
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    ::v-deep .page-frame {
        width: 90%;
        height: auto;
        background-color: #fff;
        margin: 20px auto;
        padding: 20px 20px;
 
        .u-form-item {
            &__body {
                &__left {
                    &__content {
                        &__label {
                            font-size: 25px !important;
                        }
                    }
                }
 
                &__right {
                    &__message {
                        font-size: 25px !important;
                    }
                }
            }
        }
 
        uni-input {
            font-size: 22px !important;
        }
    }
 
    ::v-deep .u-tag__text--large {
        font-size: 20rpx;
    }
 
    .input-box {
        height: 30rpx;
        position: relative;
        line-height: 30rpx;
        border-radius: 4rpx;
        padding: 6rpx 9rpx;
        border: 0.5rpx solid #dadbde;
        width: 100%;
        font-size: 21.5rpx;
        color: #303133;
    }
 
    .disbaled {
        background-color: #eee;
    }
</style>