#
whycq
2022-12-16 5c8dfb28feefe9a2f58ff52d4aeaaa303ad40a29
#
1个文件已修改
142 ■■■■ 已修改文件
pages/business/cstmr/addCsmtr.vue 142 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/business/cstmr/addCsmtr.vue
@@ -5,39 +5,20 @@
                <uni-forms-item label="客户名称" required name="name">
                    <uni-easyinput v-model="baseFormData.name" placeholder="请输入客户名称" />
                </uni-forms-item>
                <uni-forms-item label="客户关系" >
                <uni-forms-item label="客户关系" name="rela" >
                    <uni-easyinput v-model="baseFormData.rela" placeholder="请输入客户关系" />
                </uni-forms-item>
                <uni-forms-item label="客户类别" required name="cstmrType">
                    <view class="uni-list">
                        <view class="uni-list-cell">
                            <view class="uni-list-cell-db" >
                                <picker style="border: 1px solid #e5e5e5;height: 80rpx;border-radius: 4px;line-height: 80rpx;padding-left: 10px;font-size: 14px;" @change="bindPickerChange" :value="cstmrTypeIndex" :range="cstmrTypes" range-key="value">
                                    <view class="uni-input">{{cstmrTypes[cstmrTypeIndex].value}}</view>
                                </picker>
                            </view>
                        </view>
                    <view @click="autoLoad('cstmrType','')">
                        <uni-combox :candidates="cstmrTypes" placeholder="请选择客户类别"
                        v-model="baseFormData.cstmrType" @input="autoLoad('cstmrType',baseFormData.cstmrType)"></uni-combox>
                    </view>
                    <!-- <uni-combox :candidates="cstmrTypes" placeholder="请选择客户类别"
                    v-model="baseFormData.cstmrType" @input="autoLoad('cstmrType',baseFormData.cstmrType)"></uni-combox> -->
                    <!-- <uni-easyinput v-model="baseFormData.cstmrType" placeholder="请输入客户类别" /> -->
                </uni-forms-item>
                <uni-forms-item label="区分" required name="type">
                    <uni-data-checkbox v-model="baseFormData.type" :localdata="type$" />
                </uni-forms-item>
                <uni-forms-item label="省市区" required name="citysData">
                    <uni-data-picker placeholder="请选择省市区" popup-title="请选择所在地区" :localdata="citysData" v-model="baseFormData.userArea">
                    <uni-data-picker @change="areaChange" placeholder="请选择省市区" popup-title="请选择所在地区" :localdata="citysData" v-model="baseFormData.userArea">
                    </uni-data-picker>
                </uni-forms-item>
                <uni-forms-item label="电话" required name="tel">
@@ -47,14 +28,15 @@
                    <uni-easyinput v-model="baseFormData.addr" placeholder="请输入详细地址" />
                </uni-forms-item>
                <uni-forms-item label="负责人" required name="director">
                    <uni-combox :candidates="directors" placeholder="请选择负责人"
                    v-model="baseFormData.director" @input="autoLoad('user',baseFormData.director)"></uni-combox>
                    <!-- <uni-easyinput v-model="baseFormData.director" placeholder="请输入负责人" /> -->
                    <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="客户联系人" required name="contacts">
                    <uni-easyinput v-model="baseFormData.contacts" placeholder="请输入客户联系人" />
                </uni-forms-item>
                <uni-forms-item label="备注">
                <uni-forms-item label="备注" name="remarks">
                    <uni-easyinput type="textarea" v-model="baseFormData.remarks" placeholder="请输入备注" />
                </uni-forms-item>
            </uni-forms>
@@ -71,18 +53,28 @@
                baseUrl: '',
                cstmrTypes: [],
                cstmrType: '',
                cstmrTypeIndex: 0,
                directors: [],
                director: '',
                cstmrTypeList: [],
                directorList: [],
                baseFormData: {
                    citysData: [],
                    cstmrType: '',
                    director: '',
                    rela: '',
                    remarks: '',
                },
                rules: {
                    name: {
                        rules: [{
                            required: true,
                            errorMessage: '请填写客户名称',
                        }]
                    },
                    rela: {
                        rules: [{
                            required: false,
                            errorMessage: '请填写客户名称',
                        }]
                    },
@@ -127,6 +119,12 @@
                            required: true,
                            errorMessage: '请输入客户联系人',
                        }]
                    },
                    remarks: {
                        rules: [{
                            required: false,
                            errorMessage: '请输入客户联系人',
                        }]
                    }
                },
                // 单选数据源
@@ -138,14 +136,13 @@
                    value: 2
                }],
                citysData: [],
                userArea: '',
                cstmrList: [],
                citysDataTemp: ''
            }
        },
        onReady() {
                // 需要在onReady中设置规则
                this.$refs.baseForm.setRules(this.rules)
            },
        mounted() {
            // 获取省市区
@@ -153,18 +150,20 @@
            this.baseUrl = uni.getStorageSync('baseUrl')
            this.autoLoad('cstmrType','')
            this.autoLoad('user','')
            // this.getCstmrType()
            // this.getUser()
        },
        methods: {
            bindPickerChange: function(e) {
                console.log(e);
                console.log('picker发送选择改变,携带值为:' + e.detail.value)
                console.log(this.cstmrTypes[e.detail.value].id);
                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.cstmrTypes = []
                that.directors = []
                that.directorList = []
                var a = that.baseUrl + '/' + type + 'Query/auth'
                uni.request({
                    url: that.baseUrl + '/' + type + 'Query' +'/auth',
@@ -173,18 +172,19 @@
                    method: 'GET',
                    success(result) {
                        var res = result.data
                        console.log(res);
                        if (res.code === 200) {
                            var element;
                            if (type == 'cstmrType') {
                                for(element of res.data) {
                                    that.cstmrTypes.push(element)
                                    that.cstmrTypes.push(element.value)
                                    that.cstmrTypeList.push(element)
                                }
                                return
                            }
                            if (type == 'user') {
                                for(element of res.data) {
                                    that.directors.push(element.value)
                                    that.directorList.push(element)
                                }
                                return
                            }
@@ -195,41 +195,45 @@
            },
            // 添加用户
            addCstmr() {
                let that = this
                uni.request({
                    // url: that.baseUrl + '/cstmr/add/auth',
                    url: "http://localhost:9528" + '/cstmr/add/auth',
                    header:{
                        'token':uni.getStorageSync('token'),
                        // 'content-type':'application/json',
                        },
                    data: {
                        addr: "滨江路35号",
                        contacts: "程燕",
                        cstmrType: 1,
                        cstmrType$: "第一类",
                        director: "19",
                        director$: "超级管理员",
                        id: "",
                        name: "测试2",
                        pcd:"14000,140100,140105",
                        rela: "",
                        remarks: "",
                        tel: "15987462587",
                        type: "1"
                    },
                    method: 'POST',
                    success(result) {
                        var res = result.data
                        console.log(res);
                var element;
                for (element of that.directorList) {
                    if(element.value == that.baseFormData.director) {
                        that.baseFormData.director = element.id
                    }
                })
                return
                }
                for (element of that.cstmrTypeList) {
                    if(element.value == that.baseFormData.cstmrType) {
                        that.baseFormData.cstmrType = element.id
                    }
                }
                this.$refs.baseForm.validate().then(res=>{
                    if (res.rela == undefined) {
                        res.rela = ''
                    }
                    if(res.remarks == undefined) {
                        res.remarks = ''
                    }
                    res.citysData = this.citysDataTemp
                    console.log(res);
                    uni.request({
                        url: that.baseUrl + '/cstmr/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.back
                            }
                            console.log(res);
                        }
                    })
                }).catch(err =>{
                    console.log(err);
                })
            }
        }