-
zhangwei
2025-01-23 e5a77d6a551d13e4cf74624b31b0fa3e328b304d
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<template>
    <view class="full-page ">
        <view class="list">
            <up-form labelPosition="left" :model="state.publicJob" ref="formRef" labelWidth='140rpx'>
                <view class="content c-p-l-24 c-p-b-120">
                    <up-form-item label="部门" prop="departmentId" required :borderBottom='false' ref="item1">
                        <up-input v-model="state.publicJob.departmentName" border="none" placeholder="请点击选择部门"
                            readonly></up-input>
                    </up-form-item>
                    <up-form-item label="姓名" prop="name" required :borderBottom='false' ref="item1">
                        <up-input v-model="state.publicJob.name" border="none" placeholder="请填写姓名" readonly></up-input>
                    </up-form-item>
                    <up-form-item label="金额" prop="planMoney" required :borderBottom='false' ref="item1">
                        <up-input v-model="state.publicJob.planMoney" border="none" placeholder="请填写金额"
                            type="digit"></up-input>
                    </up-form-item>
                    <up-form-item label="科目" prop="rewardContent" required :borderBottom='false' ref="item1"
                        @click='openKemuPicker'>
                        <up-input v-model="state.publicJob.rewardContent" border="none" placeholder="请点击选择科目"
                            readonly></up-input>
                    </up-form-item>
                    <up-form-item label="摘要" prop="planContent" required :borderBottom='false' ref="item1">
                        <!-- <view class="c-p-b-20"> -->
                        <up-textarea v-model="state.publicJob.planContent" border="none" height='35'
                            placeholder="请填写摘要"></up-textarea>
                        <!-- </view> -->
                    </up-form-item>
                    <up-form-item label="发票" prop="houbufapiaoStatus" required :borderBottom='false' ref="item1">
                        <u-radio-group v-model="state.publicJob.houbufapiaoStatus" placement="row"
                            @change="checkboxChange">
                            <u-radio :customStyle="{marginBottom: '8px',marginRight:'8px'}" label="有发票" name="You"
                                usedAlone />
                            <u-radio :customStyle="{marginBottom: '8px',marginRight:'8px'}" label="后补发票"
                                name="HouBuFaPiao" usedAlone />
                            <u-radio :customStyle="{marginBottom: '8px'}" label="没发票" name="Wu" usedAlone />
                        </u-radio-group>
                    </up-form-item>
                    <up-form-item label="上传发票" prop="idCardFace" required
                        v-if='state.publicJob.houbufapiaoStatus=="You"'>
                        <tem-upload-file immediate :url="`${apiBaseUrl}/api/UpFile/UpdateFile`" ref="uploadF"
                            fileType='all' @success="success('Invoice',$event)" @error="errorInvoice"
                            @complete="completeInvoice('Invoice',$event)">
                        </tem-upload-file>
                    </up-form-item>
                    <up-form-item label="上传附件" prop="idCardFace">
                        <tem-upload-file immediate :url="`${apiBaseUrl}/api/UpFile/UpdateFile`" ref="uploadB"
                            fileType="all" @success="success('File',$event)" @error="errorInvoice"
                            @complete="completeInvoice('',$event)">
                        </tem-upload-file>
                    </up-form-item>
                </view>
            </up-form>
        </view>
        <view class="tabbtns">
            <view class="chuany-flex">
                <up-button type="primary" :text="'保存报销'" :loading='isLoading' :loadingText="'保存中'"
                    @click="saveOrder('Uncommitted')" v-if='state.publicJob.approvalStatus=="Uncommitted"'></up-button>
                <up-button color='#fece01' :text="state.publicJob.approvalStatus!=='Uncommitted'?'修改报销':'提交报销'" :loading='isLoading'
                    :loadingText="state.publicJob.approvalStatus!=='Uncommitted'?'修改中':'提交中'" @click="saveOrder('unApproval')"></up-button>
            </view>
 
        </view>
        <!-- <u-picker :show="pickerShow" :columns="departList" keyName="name" @cancel='openPicker'
            :defaultIndex='defaultIndex' @confirm='confirmPicker'></u-picker> -->
        <u-picker :show="kemuPicker" :columns="kemuList" keyName="subjectName" @cancel='openKemuPicker'
            :defaultIndex='defaultIndex' @confirm='confirmKemuPicker'></u-picker>
 
    </view>
</template>
 
<script setup>
    import {
        apiBaseUrl
    } from '@/common/setting/constVarsHelper.js';
    import {
        ref,
        reactive,
        getCurrentInstance,
        onMounted,
        computed
    } from 'vue';
    import {
        onLoad,
        onShow,
        onReady,
        onHide
    } from "@dcloudio/uni-app";
    const {
        $upload,
        $api,
        $util,
        $db
    } = getCurrentInstance().appContext.config.globalProperties
    import {
        useStore
    } from 'vuex'
    const store = useStore()
    let departList = ref()
    let kemuList = ref()
    let defaultIndex = ref([0])
    let planId = ref('')
    let state = reactive({
        publicJob: {
            departmentId: '', //部门Id
            departmentName: '',
            name: '', //姓名
            rewardResult: '', //科目id
            rewardContent: '', //科目名称
            planMoney: '', //金额
            planContent: '', //摘要
            houbufapiaoStatus: 'You', //有无发票
            workPlanAttachments: [], //附件&发票
            approvalStatus:'Uncommitted'
        },
    })
    onLoad((options) => {
        let data = $db.get('userInfo').userCompany
        planId.value = options.planId
        if (!planId.value) {
            state.publicJob.departmentId = $db.get('userInfo').oaPermissions.departId
            state.publicJob.departmentName = $db.get('userInfo').oaPermissions.departmentName
            state.publicJob.name = $db.get('userInfo').oaPermissions.name
        }
        // $api.GetDepartLstt().then(res => {
        //     departList = [res.data]
        //     let index = res.data.findIndex(item => {
        //         return item.keyid == planId.value ? state.publicJob.departmentId : oaPermissions.departId
        //     })
        //     defaultIndex = [index]
        // })
        $api.getKeMuList().then(res => {
            kemuList = [res.data]
            let obj = kemuList[0].find(item => {
                return item.subjectName == '差旅费'
            })
            state.publicJob.rewardResult = String(obj.keyid)
            state.publicJob.rewardContent = obj.subjectName
            dataPlan(planId.value)
        })
    })
    let rules = {
        name: {
            required: true,
            message: '姓名不能为空',
            trigger: ['blur', 'change']
        },
        departId: {
            required: true,
            message: '部门不能为空',
            trigger: ['blur', 'change']
        },
        planMoney: {
            required: true,
            message: '金额不能为空',
            trigger: ['blur', 'change']
        },
        planContent: {
            required: true,
            message: '摘要不能为空',
            trigger: ['blur', 'change']
        },
        rewardContent: {
            required: true,
            message: '科目不能为空',
            trigger: ['blur', 'change']
        }
    }
    const formRef = ref(null);
    onReady(() => {
        formRef.value.setRules(rules);
    })
    onShow(() => {
        console.log('Show-------------', state.publicJob);
    })
    onMounted(() => {
        formRef.value.setRules(rules);
        console.log(formRef.value, 'formRef'); // 访问子组件Demo中的属性
 
    });
    let oaPermissions = computed(() => store.getters.userInfo.oaPermissions || {})
    let dateType = ref()
    let minDate = $util.formatDate(new Date())
    let sDate = $util.formatDate(new Date(), null, 1)
    let eDate = '结束日期'
    let workDate = ref('')
    let workTime = ref('8:00至18:00')
    let datePickerShow = ref(false)
    let pickerShow = ref(false)
    let kemuPicker = ref(false)
    let isLoading = ref(false)
    let editItem = null
    let uploadF = ref()
    let uploadB = ref()
 
    const changStyle = (val) => {
        state.publicJob.workerType = val
        if (val == 0) {
            state.publicJob.zixinganpai = false
        }
    }
    const dataPlan = (planId) => {
        if (planId) {
            $api.workerGetPlanInfo(planId).then(res => {
                state.publicJob = {
                    keyid: res.data.keyid,
                    departmentId: res.data.departId, //部门Id
                    departmentName: $db.get('userInfo').oaPermissions.departmentName,
                    name: res.data.planPeople, //姓名
                    rewardResult: res.data.rewardResult, //科目id
                    rewardContent: res.data.rewardContent, //科目名称
                    planMoney: String(res.data.planMoney), //金额
                    planContent: res.data.planContent, //摘要
                    houbufapiaoStatus: res.data.houbufapiaoStatus, //有无发票
                    workPlanAttachments: res.data.workPlanAttachments ,//附件&发票
                    approvalStatus:res.data.approvalStatus
                }
                state.publicJob.workPlanAttachments.forEach(item => {
                    if (item.attachmentType == 1) {
                        uploadF.value.urls.push(item.planAttachment)
                        uploadF.value.status.push('success')
                    } else {
                        uploadB.value.urls.push(item.planAttachment)
                        uploadB.value.status.push('success')
                    }
                })
                let index = kemuList[0].findIndex(item => {
                    return item.keyid == state.publicJob.rewardResult
                })
                defaultIndex = [index]
                console.log(state.publicJob);
            })
 
            // state.publicJob = reactive(editItem)
            // $db.del('editItem')
        }
    }
    const confirmPicker = (arr) => {
        state.publicJob.departmentId = arr.value[0].keyid
        state.publicJob.departmentName = arr.value[0].name
        openPicker()
    }
    const confirmKemuPicker = (arr) => {
        state.publicJob.rewardResult = String(arr.value[0].keyid)
        state.publicJob.rewardContent = arr.value[0].subjectName
        openKemuPicker()
    }
    const clickTime = (type) => {
        dateType.value = type
        datePickerShow.value = !datePickerShow.value
    }
    const cancel = () => {
        datePickerShow.value = !datePickerShow.value
    }
    const openPicker = () => {
        pickerShow.value = !pickerShow.value
    }
    const openKemuPicker = () => {
        kemuPicker.value = !kemuPicker.value
    }
    const checkboxChange = () => {
 
    }
    const saveOrder = (val) => {
        if (state.publicJob.houbufapiaoStatus == "You") {
            let index = state.publicJob.workPlanAttachments.findIndex(item => {
                return item.attachmentType == 1
            })
            if (index == -1) {
                $util.showToast({
                    title: "选择有发票时,必须上传发票!",
                })
                return
            }
 
        }
        formRef.value.validate().then(res => {
            isLoading.value = true
            let functionOrder = null
            if (planId.value) {
                functionOrder = $api.EditOder
            } else {
                functionOrder = $api.CreatOder
            }
            val ? state.publicJob.approvalStatus = val : ''
            functionOrder(state.publicJob).then(res => {
                if (res.code == 1) {
                    $util.showToast({
                        title: state.publicJob.approvalStatus=='Uncommitted' ? '保存成功!' : "提交成功!",
                        icon: "success"
                    })
                    // if (editItem) {
                    //     uni.navigateBack()
                    // } else if (val == 'continue') {
                    state.publicJob = {
                        departmentId: $db.get('userInfo').oaPermissions.departId, //部门Id
                        departmentName: $db.get('userInfo').oaPermissions.departmentName,
                        name: $db.get('userInfo').oaPermissions.name, //姓名
                        rewardResult: '', //科目id
                        rewardContent: '', //科目名称
                        planMoney: '', //金额
                        planContent: '', //摘要
                        houbufapiaoStatus: 'You', //有无发票
                        workPlanAttachments: [], //附件&发票
                        approvalStatus:'Uncommitted',
                    }
                    uploadB.value.urls = []
                    uploadB.value.status = []
                    uploadF.value.urls = []
                    uploadF.value.status = []
                    // } else {
                    //     uni.redirectTo({
                    //         url: '/pages/reimbursement/myreim'
                    //     })
                    // }
                    
                } else {
                    $util.showToast({
                        title: res.error
                    })
                }
                isLoading.value = false
            })
        })
    }
    //选择图片或上传完成时触发
    const completeInvoice = (val, e) => {
        if (e.action == 'delete') {
            // 删除处理
            state.publicJob.workPlanAttachments = state.publicJob.workPlanAttachments.filter(item => {
                return item.attachmentType == (val == "Invoice" ? 2 : 1)
            })
            e.urls.forEach(item => {
                let obj = {}
                obj.attachmentType = val == "Invoice" ? 1 : 2
                obj.planAttachment = item //发票
                state.publicJob.workPlanAttachments.push(obj)
            })
            return
        }
        // $util.pathToBase64(e.urls[0]).then(res => {
        //     idCardFaceBase64.value = res
        //     console.log(idCardFaceBase64, idCardFaceBase64.value);
        // })
    }
    const errorInvoice = (e) => {
        console.log(e, '--------------');
    }
    //上传成功时触发
    const success = (text, e) => {
        let obj = {}
        //e.res 为服务器返回数据
        //上传成功回调,处理服务器返回数据【此处根据实际返回数据进行处理】
        let res = JSON.parse(e.res.data.replace(/\ufeff/g, "") || "{}")
        if (res.code == 1) {
            if (res.data && text == 'Invoice') {
                obj.attachmentType = 1
                obj.planAttachment = res.data //发票
                uploadF.value.urls.push(res.data)
                uploadF.value.urls = uploadF.value.urls.filter(item => {
                    return item.indexOf('https') !== -1
                })
                uploadF.value.status.push('success')
                uploadF.value.status.length = uploadF.value.urls.length
            } else {
                obj.attachmentType = 2
                obj.planAttachment = res.data //附件
                uploadB.value.urls.push(res.data)
                uploadB.value.urls = uploadB.value.urls.filter(item => {
                    return item.indexOf('https') !== -1
                })
                uploadB.value.status.push('success')
                uploadB.value.status.length = uploadB.value.urls.length
            }
            state.publicJob.workPlanAttachments.push(obj)
            console.log(state.publicJob.workPlanAttachments);
        } else {
            uni.$u.toast(res.error)
            if (text == 'Invoice') {
                uploadF.value.deleteImage()
            } else {
                uploadB.value.deleteImage()
            }
        }
 
    }
</script>
 
<style>
    .list {}
 
    .u-button {
        width: 280rpx !important;
        margin: 0;
    }
 
    .content {
        width: 100%;
        box-sizing: border-box;
        background-color: #fff;
    }
 
    .u-textarea {
        padding: 0 !important;
    }
 
    .u-form-item__body {
        padding: 5px 0 !important;
    }
</style>