#
whycq
2023-11-03 68d1f5718be1061c3bb54098f9753910d58c00c3
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
<template>
    <view>
        <view class="container">
            <uni-forms ref="baseForm" :modelValue="baseFormData">
                <uni-forms-item label="跟踪项目名称" required name="name">
                    <uni-easyinput v-model="baseFormData.name" placeholder="请输入跟踪项目名称" />
                </uni-forms-item>
                <uni-forms-item label="甲方单位" required name="cstmrId">
                    <view @click="autoLoad('cstmr','')">
                        <uni-combox :candidates="cstmrs" placeholder="请选择甲方单位" v-model="baseFormData.cstmrId"
                            @input="autoLoad('cstmr',baseFormData.cstmrId)"></uni-combox>
                    </view>
                </uni-forms-item>
                <uni-forms-item label="所属公司" required name="company">
                    <view @click="autoLoad('company','')">
                        <uni-combox :candidates="companies" placeholder="请选所属公司" v-model="baseFormData.company"
                            @input="autoLoad('company',baseFormData.company)"></uni-combox>
                    </view>
                </uni-forms-item>
                <uni-forms-item label="预算金额(万元)" name="money" required>
                    <uni-easyinput v-model="baseFormData.money" placeholder="请输入预算金额(万元)" />
                </uni-forms-item>
                <uni-forms-item label="预计成交率" name="transactionRate" required>
                    <view>
                        <uni-combox :candidates="transactionRates" placeholder="请选择预计成交率" 
                        v-model="baseFormData.transactionRate" ></uni-combox>
                    </view>
                </uni-forms-item>
                <uni-forms-item label="负责人" name="director" required>
                    <view @click="autoLoad('user','')">
                        <uni-combox :candidates="directors" placeholder="请选择负责人" v-model="baseFormData.director"
                            @input="autoLoad('user',baseFormData.director)"></uni-combox>
                    </view>
                </uni-forms-item>
                <uni-forms-item label="产品类型" name="orderProductTypeId" required>
                    <view @click="autoLoad('orderProductType','')">
                        <uni-combox :candidates="orderProductTypeIds" placeholder="请选择产品类型" 
                        v-model="baseFormData.orderProductTypeId"
                            @input="autoLoad('orderProductType',baseFormData.orderProductTypeId)"></uni-combox>
                    </view>
                </uni-forms-item>
                <uni-forms-item label="省市区" name="citysData" required>
                    <uni-data-picker @change="areaChange" placeholder="请选择省市区" popup-title="请选择所在地区"
                        :localdata="citysData" v-model="baseFormData.pcd">
                    </uni-data-picker>
                </uni-forms-item>
                <uni-forms-item label="项目地址" name="addr">
                    <uni-easyinput v-model="baseFormData.addr" placeholder="请输入项目地址" />
                </uni-forms-item>
                <uni-forms-item label="心得体会" name="memoExperience">
                    <uni-easyinput type="textarea" v-model="baseFormData.memoExperience" placeholder="请输入心得体会" />
                </uni-forms-item>
                <uni-forms-item label="备注" name="remarks">
                    <uni-easyinput type="textarea" v-model="baseFormData.remarks" placeholder="请输入备注" />
                </uni-forms-item>
            </uni-forms>
            <button type="primary" @click="addOrder()">添加</button>
        </view>
    </view>
</template>
 
<script>
    import test from '../../../static/js/citys-data.js'
    import user from '@/pages/api/user/user.js'
    export default {
        data() {
            return {
                cstmrTypes: [],
                cstmrType: '',
                companies: [],
                directors: [],
                director: '',
                cstmrs: [],
                cstmr: '',
                cstmrTypeList: [],
                cstmrList: [],
                directorList: [],
                companyList: [],
                orderProductTypeIds: [],
                orderProductTypeList: [],
                baseFormData: {
                    citysData: [],
                    cstmrType: '',
                    company: '',
                    director: '',
                    rela: '',
                    remarks: '',
                    transactionRate: '',
                    cstmrId: '',
                    addr: '',
                    money: ''
                },
                transactionRates: ['30%','40%','50%','60%','70%','80%','90%','100%'],
                rules: {
                    name: {
                        rules: [{
                            required: true,
                            errorMessage: '请输入跟踪项目名称',
                        }]
                    },
                    cstmrId: {
                        rules: [{
                            required: true,
                            errorMessage: '请选择甲方单位',
                        }]
                    },
                    company: {
                        rules: [{
                            required: true,
                            errorMessage: '请选所属公司',
                        }]
                    },
                    money: {
                        rules: [{
                            required: true,
                            errorMessage: '请输入预算金额',
                        }]
                    },
                    transactionRate: {
                        rules: [{
                            required: true,
                            errorMessage: '请选择预计成交率',
                        }]
                    },
                    director: {
                        rules: [{
                            required: true,
                            errorMessage: '请选择负责人',
                        }]
                    },
                    orderProductTypeId: {
                        rules: [{
                            required: true,
                            errorMessage: '请选择产品类型',
                        }]
                    },
                    citysData: {
                        rules: [{
                            required: true,
                            errorMessage: '请选择所在地区',
                        }]
                    }
                },
                // 单选数据源
                type$: [{
                    text: '内销',
                    value: 1
                }, {
                    text: '外销',
                    value: 2
                }],
                citysData: [],
                citysDataTemp: ''
            }
        },
        onReady() {
            // 需要在onReady中设置规则
            this.$refs.baseForm.setRules(this.rules)
        },
        onShow() {
            // 获取省市区
            this.citysData = test.citysData
            this.getDetail()
        },
        methods: {
            async getDetail() {
                let res = await user.getDetail()
                if (res.code === 200) {
                    this.baseFormData.director = res.data.username
                    res.data['value'] = res.data.username
                    this.directors.push(res.data.username)
                    this.directorList.push(res.data)
                } 
            },
            bindPickerChange: function(e) {
                this.cstmrTypeIndex = e.detail.value
                this.baseFormData.cstmrType = this.cstmrTypes[e.detail.value].id
            },
            areaChange(e) {
                this.citysDataTemp = e.detail.value[0].value + ',' + e.detail.value[1].value + ',' + e.detail.value[2]
                    .value
            },
            autoLoad(type, condition) {
                let that = this
                that.companies = []
                that.directors = []
                that.cstmrs = []
                that.orderProductTypeIds = []
                var a = that.baseUrl + '/' + type + 'Query/auth'
                uni.request({
                    url: that.baseUrl + '/' + type + 'Query' + '/auth',
                    header: {
                        'token': uni.getStorageSync('token')
                    },
                    data: {
                        condition: condition
                    },
                    method: 'GET',
                    success(result) {
                        var res = result.data
                        if (res.code === 200) {
                            var element;
                            if (type == 'user') {
                                for (element of res.data) {
                                    that.directors.push(element.value)
                                    that.directorList.push(element)
                                }
                                return
                            }
                            if (type == 'company') {
                                for (element of res.data) {
                                    that.companies.push(element.name)
                                    that.listAuth(type)
                                    that.companyList.push(element)
                                }
                                return
                            }
                            if (type == 'cstmr') {
                                for (element of res.data) {
                                    that.cstmrs.push(element.value)
                                    that.cstmrList.push(element)
                                }
                                return
                            }
                            if (type == 'orderProductType') {
                                for (element of res.data) {
                                    that.orderProductTypeIds.push(element.value)
                                    that.orderProductTypeList.push(element)
                                }
                                return
                            }
                        }
 
                    }
                })
            },
            listAuth(type) {
 
            },
            // 添加跟踪项目
            addOrder() {
                let that = this
                var element;
                // 所属公司
                for (element of that.companyList) {
                    if (element.name == that.baseFormData.company) {
                        that.baseFormData.company = element.id
                    }
                }
                for (element of that.cstmrList) {
                    if (element.value == that.baseFormData.cstmrId) {
                        that.baseFormData.cstmrId = element.id
                    }
                }
                for (element of that.directorList) {
                    console.log(that.directorList);
                    console.log(that.baseFormData.director);
                    if (element.value == that.baseFormData.director) {
                        that.baseFormData.director = element.id
                    }
                }
                for (element of that.orderProductTypeList) {
                    if (element.value == that.baseFormData.orderProductTypeId) {
                        that.baseFormData.orderProductTypeId = element.id
                    }
                }
                that.baseFormData.transactionRate = Number(that.baseFormData.transactionRate.split('%')[0])
                this.$refs.baseForm.validate().then(res => {
                    if (res.addr == undefined) {
                        res.addr = ''
                    }
                    if (res.money == undefined) {
                        res.money = ''
                    }
                    if (res.remarks == undefined) {
                        res.remarks = ''
                    }
                    res.pcd = this.citysDataTemp
                    uni.request({
                        url: that.baseUrl + '/order/add/auth',
                        header: {
                            'token': uni.getStorageSync('token'),
                            'content-type': 'application/x-www-form-urlencoded',
                        },
                        data: res,
                        method: 'POST',
                        success(result) {
                            var res = result.data
                            if (res.code === 200) {
                                uni.navigateBack()
                            } else if (res.code === 403) {
                                uni.showToast({
                                    title: res.msg,
                                    icon: "none",
                                    position: 'top'
                                })
                                setTimeout(() => {
                                    uni.reLaunch({
                                        url: '../../login/login'
                                    });
                                }, 1000);
                            } else {
                                uni.showToast({
                                    title: res.msg,
                                    icon: "none",
                                    position: 'top'
                                })
                            }
                        }
                    })
                }).catch(err => {})
            }
        }
 
    }
</script>
 
<style>
    .container {
        min-height: 50rpx;
        padding: 15px;
        background-color: #fff;
        /* background-color: aqua; */
    }
</style>