MrShi
2025-07-02 39ae52b3f65e2bba3b6570adb51e791cb3befff7
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
<template>
    <view class="box">
        <view class="box_list">
            <u--form
                labelPosition="top"
                :model="model"
                :rules="rules"
                labelWidth="160"
                ref="uForm"
            >
                <u-form-item
                    label="姓名:"
                    prop="name"
                    borderBottom
                >
                    <u--input v-model="model.name" border="none" placeholder="请输入"></u--input>
                </u-form-item>
                <u-form-item
                    label="身份证号:"
                    prop="idCard"
                    borderBottom
                >
                    <view style="idth: 100%; position: relative;">
                        <u--input v-model="model.idCard" maxlength="18" border="none" placeholder="请输入"></u--input>
                        <button style="position: absolute; top: 0; right: 0; font-size: 22rpx;" @click="test">识别身份证</button>
                    </view>
                </u-form-item>
                <u-form-item
                    label="派遣单位:"
                    prop="pqId"
                    borderBottom
                    @click="show = true"
                >
                    <u--input
                        v-model="model.pqName"
                        disabled
                        disabledColor="#ffffff"
                        placeholder="请选择"
                        border="none"
                    ></u--input>
                    <u-icon
                        slot="right"
                        name="arrow-right"
                    ></u-icon>
                </u-form-item>
                <u-form-item
                    label="所属工种:"
                    prop="gzId"
                    borderBottom
                    @click="show1 = true"
                >
                    <u--input
                        v-model="model.gzName"
                        disabled
                        disabledColor="#ffffff"
                        placeholder="请选择"
                        border="none"
                    ></u--input>
                    <u-icon
                        slot="right"
                        name="arrow-right"
                    ></u-icon>
                </u-form-item>
                <u-form-item
                    label="备注:"
                    prop="remark"
                    borderBottom
                >
                    <u--input v-model="model.remark" border="none" placeholder="请输入"></u--input>
                </u-form-item>
            </u--form>
        </view>
        <view class="box_footer">
            <u-button type="primary" shape="circle" color="#437CB3" text="确认添加" @click="submit"></u-button>
        </view>
        <!-- 派遣单位 -->
        <u-picker :show="show" :columns="columns" confirmColor="#437CB3" keyName="label" @cancel="show = false" @confirm="confirm"></u-picker>
        <!-- 工种 -->
        <u-picker :show="show1" :columns="columns1" confirmColor="#437CB3" keyName="label" @cancel="show1 = false" @confirm="confirm1"></u-picker>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                show: false,
                show1: false,
                solutionId: null,
                columns: [],
                columns1: [],
                duSolutionId: '',
                model: {
                    name: '',
                    remark:'',
                    idCard: '',
                    gzId: '',
                    gzName: '',
                    pqId: '',
                    pqName: ''
                },
                rules: {
                    'name': {
                        type: 'string',
                        required: true,
                        message: '请填写姓名',
                        trigger: ['blur', 'change']
                    },
                    'idCard': {
                        type: 'string',
                        required: true,
                        message: '请填写身份证号',
                        trigger: ['blur', 'change']
                    }
                }
            };
        },
        onLoad(options) {
            this.solutionId = options.solutionId
            this.getDispatchingUnit()
        },
        methods: {
            test() {
                var that = this;
                // 选择图片
                wx.chooseImage({
                    count: 1,
                    success: async function(res) {
                        try {
                            uni.showLoading({ title: '识别中' });
                            const invokeRes = await wx.serviceMarket.invokeService({
                                service: 'wx79ac3de8be320b71',
                                api: 'OcrAllInOne',
                                data: {
                                    // 用 CDN 方法标记要上传并转换成 HTTP URL 的文件
                                    img_url: new wx.serviceMarket.CDN({
                                        type: 'filePath',
                                        filePath: res.tempFilePaths[0],
                                    }),
                                    data_type: 3,
                                    ocr_type: 1
                                },
                            })
                            that.model.idCard = invokeRes.data.idcard_res.id.text
                            that.model.name = invokeRes.data.idcard_res.name.text
                            uni.hideLoading();
                        } catch (err) {
                            wx.showModal({ title: 'fail', content: err })
                            uni.hideLoading();
                        }
                    },
                    fail: function(res) {},
                    complete: function(res) {},
                })
            },
            // 派遣单位
            getDispatchingUnit() {
                this.$u.api.findListByDTO({
                    solutionId: this.solutionId
                }).then(res => {
                    if (res.code === 200) {
                        let arr = res.data.map(item => {
                            return {
                                label: item.name,
                                duSolutionId: item.duSolutionId,
                                id: item.id
                            }
                        })
                        this.columns.push(arr)
                    }
                })
            },
            // 工种
            getGZ() {
                this.$u.api.worktypeFindListByDTO({
                    id: this.duSolutionId,
                    queryType: 1
                }).then(res => {
                    if (res.code === 200) {
                        let arr = res.data.map(item => {
                            return {
                                label: item.name,
                                id: item.id
                            }
                        })
                        this.columns1 = [arr]
                    }
                })
            },
            confirm(e) {
                this.model.pqId = e.value[0].id
                this.model.pqName = e.value[0].label
                this.duSolutionId = e.value[0].duSolutionId
                this.model.gzId = ''
                this.model.gzName = ''
                this.model.remark=''
                this.getGZ()
                this.show = false
            },
            confirm1(e) {
                this.model.gzId = e.value[0].id
                this.model.gzName = e.value[0].label
                this.show1 = false
            },
            submit() {
                this.$refs.uForm.validate().then(res => {
                    uni.$emit('add', { model: this.model })
                    uni.navigateBack({ delta: 1 });
                }).catch(errors => {
                    
                })
            }
        }
    }
</script>
<style>
    page {
        background-color: #f7f7f7;
    }
</style>
<style lang="scss" scoped>
    .box {
        width: 100vw;
        height: 100vh;
        padding: 20rpx 30rpx;
        box-sizing: border-box;
        .box_list {
            width: 100%;
            height: calc(100vh - 158rpx - env(safe-area-inset-bottom));
            background: #FFFFFF;
            border-radius: 16rpx;
            padding: 32rpx 30rpx;
            box-sizing: border-box;
        }
        .box_footer {
            width: 100%;
            margin-top: 40rpx;
            height: 88rpx;
        }
    }
</style>