|  |  | 
 |  |  |    <view> | 
 |  |  |       <view class="container"> | 
 |  |  |          <uni-forms ref="baseForm" :modelValue="baseFormData"> | 
 |  |  |             <uni-forms-item label="客户名称" required name="name"> | 
 |  |  |             <!-- <uni-forms-item label="客户名称" required name="name"> | 
 |  |  |                <uni-easyinput v-model="baseFormData.name" placeholder="请输入客户名称" /> | 
 |  |  |             </uni-forms-item> --> | 
 |  |  | 				 | 
 |  |  |             <uni-forms-item label="客户名称" required name="name"> | 
 |  |  |                <view> | 
 |  |  |                   <uni-combox :candidates="names" placeholder="请输入客户名称" | 
 |  |  |                   v-model="baseFormData.name" @input="cstmrSearch()"></uni-combox> | 
 |  |  |                </view> | 
 |  |  |             </uni-forms-item> | 
 |  |  |             <uni-forms-item label="客户关系" name="rela" > | 
 |  |  |                <uni-easyinput v-model="baseFormData.rela" placeholder="请输入客户关系" /> | 
 |  |  |             </uni-forms-item> | 
 |  |  | 				 | 
 |  |  |             <uni-forms-item label="客户类别" required name="cstmrType"> | 
 |  |  |                <view @click="autoLoad('cstmrType','')"> | 
 |  |  |                   <uni-combox :candidates="cstmrTypes" placeholder="请选择客户类别" | 
 |  |  |                   v-model="baseFormData.cstmrType" @input="autoLoad('cstmrType',baseFormData.cstmrType)"></uni-combox> | 
 |  |  |                   v-model="baseFormData.cstmrType$" @input="autoLoad('cstmrType',baseFormData.cstmrType$)"></uni-combox> | 
 |  |  |                </view> | 
 |  |  |             </uni-forms-item> | 
 |  |  |             <uni-forms-item label="客户行业" required name="industry"> | 
 |  |  |                <view > | 
 |  |  |                   <uni-combox :candidates="industrys" placeholder="请选择客户行业" | 
 |  |  |                   v-model="baseFormData.industry"></uni-combox> | 
 |  |  |                </view> | 
 |  |  |             </uni-forms-item> | 
 |  |  | 				 | 
 |  |  |             <uni-forms-item label="产品类别" required name="productCategory"> | 
 |  |  |                <view> | 
 |  |  |                   <uni-combox :candidates="productCategorys" placeholder="请选择产品类别" | 
 |  |  |                   v-model="baseFormData.productCategory"></uni-combox> | 
 |  |  |                </view> | 
 |  |  |             </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 @change="areaChange" placeholder="请选择省市区" popup-title="请选择所在地区" :localdata="citysData" v-model="baseFormData.pcd"> | 
 |  |  |             <uni-forms-item label="省市区" required name="pcd"> | 
 |  |  |                <uni-data-picker preload @change="areaChange" placeholder="请选择省市区" popup-title="请选择所在地区" :localdata="citysData" v-model="baseFormData.pcd"> | 
 |  |  |                </uni-data-picker> | 
 |  |  |             </uni-forms-item> | 
 |  |  |             <uni-forms-item label="电话" required name="tel"> | 
 |  |  |                <uni-easyinput v-model="baseFormData.tel" placeholder="请输入客户电话" /> | 
 |  |  |             </uni-forms-item> | 
 |  |  |             <uni-forms-item label="详细地址" required name="addr"> | 
 |  |  |                <uni-easyinput v-model="baseFormData.addr" placeholder="请输入详细地址" /> | 
 |  |  |             </uni-forms-item> | 
 |  |  |             <uni-forms-item label="负责人" required name="director"> | 
 |  |  |                <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="电话" required name="tel"> | 
 |  |  |                <uni-easyinput v-model="baseFormData.tel" placeholder="请输入客户电话" /> | 
 |  |  |             </uni-forms-item> | 
 |  |  |             <uni-forms-item label="负责人"  name="director"> | 
 |  |  |                <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="remarks"> | 
 |  |  |                <uni-easyinput type="textarea" v-model="baseFormData.remarks" placeholder="请输入备注" /> | 
 |  |  |             </uni-forms-item> | 
 |  |  |          </uni-forms> | 
 |  |  |          <button type="primary" @click="addCstmr()">添加</button> | 
 |  |  |          <button type="primary" @click="modiCstmr()">修改</button> | 
 |  |  |       </view> | 
 |  |  |    </view> | 
 |  |  | </template> | 
 |  |  | 
 |  |  |    export default { | 
 |  |  |       data() { | 
 |  |  |          return { | 
 |  |  |             ide: 0, | 
 |  |  |             cstmrTypes: [], | 
 |  |  |             cstmrType: '', | 
 |  |  |             directors: [], | 
 |  |  |             director: '', | 
 |  |  |             cstmrTypeList: [], | 
 |  |  |             directorList: [], | 
 |  |  |             names: [], | 
 |  |  |             nameList: [], | 
 |  |  |             industrys: ['医药业','制造业','纺织业'], | 
 |  |  |             productCategorys: ['立体库(货架)','立体库(集成)','四向穿梭库/两向穿梭库','阁楼货架/钢平台','周转容器','平库'], | 
 |  |  |             baseFormData: { | 
 |  |  |                name: '', | 
 |  |  |                citysData: [], | 
 |  |  |                cstmrType: '', | 
 |  |  |                director: '', | 
 |  |  |                rela: '', | 
 |  |  |                remarks: '', | 
 |  |  | 					 | 
 |  |  |                industry: '', | 
 |  |  |                pcd$: '' | 
 |  |  |             }, | 
 |  |  |             rules: { | 
 |  |  |                name: { | 
 |  |  | 
 |  |  |                      errorMessage: '请选择客户类别', | 
 |  |  |                   }] | 
 |  |  |                }, | 
 |  |  |                industry: { | 
 |  |  |                   rules: [{ | 
 |  |  |                      required: true, | 
 |  |  |                      errorMessage: '请选择客户行业' | 
 |  |  |                   }] | 
 |  |  |                }, | 
 |  |  |                productCategory: { | 
 |  |  |                   rules: [{ | 
 |  |  |                      required: true, | 
 |  |  |                      errorMessage: '请选择产品类别' | 
 |  |  |                   }] | 
 |  |  |                }, | 
 |  |  |                type: { | 
 |  |  |                   rules: [{ | 
 |  |  |                      required: true, | 
 |  |  |                      errorMessage: '请选择区分', | 
 |  |  |                   }] | 
 |  |  |                }, | 
 |  |  |                citysData: { | 
 |  |  |                pcd: { | 
 |  |  |                   rules: [{ | 
 |  |  |                      required: true, | 
 |  |  |                      errorMessage: '请选择省市区', | 
 |  |  | 
 |  |  |                }, | 
 |  |  |                director: { | 
 |  |  |                   rules: [{ | 
 |  |  |                      required: true, | 
 |  |  |                      required: false, | 
 |  |  |                      errorMessage: '请输入负责人', | 
 |  |  |                   }] | 
 |  |  |                }, | 
 |  |  | 
 |  |  |          this.autoLoad('cstmrType','') | 
 |  |  |          this.autoLoad('user','') | 
 |  |  |       }, | 
 |  |  |       onLoad(option) { | 
 |  |  |          if (JSON.stringify(option) != "{}") { | 
 |  |  |             this.id = option.id | 
 |  |  |             this.init() | 
 |  |  |          } else { | 
 |  |  |             let _this = this | 
 |  |  |             const eventChannel = this.getOpenerEventChannel(); | 
 |  |  |             eventChannel.on('cstmr', function(data) { | 
 |  |  |                _this.id = data.data.id | 
 |  |  |                _this.init() | 
 |  |  |             }) | 
 |  |  |          } | 
 |  |  |       }, | 
 |  |  |       methods: { | 
 |  |  |          init() { | 
 |  |  |             let that = this | 
 |  |  |             uni.request({ | 
 |  |  |                url: that.baseUrl + '/cstmr/' + that.id +'/auth', | 
 |  |  |                header: {'token' : uni.getStorageSync('token')}, | 
 |  |  |                method: 'GET', | 
 |  |  |                success(res) { | 
 |  |  |                   res = res.data | 
 |  |  |                   for (let key in res.data) { | 
 |  |  |                      if (res.data[key] === null) { | 
 |  |  |                         res.data[key] = '' | 
 |  |  |                      } | 
 |  |  |                      if (key == 'pcd') { | 
 |  |  |                         that.citysDataTemp = res.data[key] | 
 |  |  |                         res.data[key] = res.data[key].split(',')[2] | 
 |  |  |                      } | 
 |  |  |                   } | 
 |  |  |                   that.ide = res.data.id | 
 |  |  |                   that.baseFormData = res.data | 
 |  |  |                } | 
 |  |  |             }) | 
 |  |  |          }, | 
 |  |  |          cstmrSearch() { | 
 |  |  |             this.names = [] | 
 |  |  |             let _this = this | 
 |  |  |             if(_this.baseFormData.name.length < 4) { | 
 |  |  |                return | 
 |  |  |             } | 
 |  |  |             uni.request({ | 
 |  |  |                url: `${_this.baseUrl}/cstmrSearch/auth`, | 
 |  |  |                header:{'token':uni.getStorageSync('token'),'content-type':'application/x-www-form-urlencoded',}, | 
 |  |  |                data: {condition: _this.baseFormData.name}, | 
 |  |  |                method: 'POST', | 
 |  |  |                success(res) { | 
 |  |  |                   res = res.data | 
 |  |  |                   if (res.code === 200 && res.data.length > 0) { | 
 |  |  |                      for(let element of res.data) { | 
 |  |  |                         _this.names.push(element.name) | 
 |  |  |                         _this.nameList.push(element) | 
 |  |  |                      } | 
 |  |  |                   } | 
 |  |  |                } | 
 |  |  |             }) | 
 |  |  | 				 | 
 |  |  |          }, | 
 |  |  |          bindPickerChange: function(e) { | 
 |  |  |             this.cstmrTypeIndex = e.detail.value | 
 |  |  |             this.baseFormData.cstmrType = this.cstmrTypes[e.detail.value].id | 
 |  |  | 
 |  |  |                } | 
 |  |  |             }) | 
 |  |  |          }, | 
 |  |  |          // 添加用户 | 
 |  |  |          addCstmr() { | 
 |  |  |          // 修改用户 | 
 |  |  |          modiCstmr() { | 
 |  |  |             let that = this | 
 |  |  |             var element; | 
 |  |  |             for (element of that.directorList) { | 
 |  |  |                if(element.value == that.baseFormData.director) { | 
 |  |  |                if(element.value == that.baseFormData.director$) { | 
 |  |  |                   that.baseFormData.director = element.id | 
 |  |  |                } | 
 |  |  |             } | 
 |  |  |             for (element of that.cstmrTypeList) { | 
 |  |  |                if(element.value == that.baseFormData.cstmrType) { | 
 |  |  |                if(element.value == that.baseFormData.cstmrType$) { | 
 |  |  |                   that.baseFormData.cstmrType = element.id | 
 |  |  |                } | 
 |  |  |             } | 
 |  |  | 
 |  |  |                   res.remarks = '' | 
 |  |  |                } | 
 |  |  |                res.pcd = this.citysDataTemp | 
 |  |  |                res['id'] = this.ide | 
 |  |  |                uni.request({ | 
 |  |  |                   url: that.baseUrl + '/cstmr/add/auth', | 
 |  |  |                   url: that.baseUrl + '/cstmr/update/auth', | 
 |  |  |                   header:{ | 
 |  |  |                      'token':uni.getStorageSync('token'), | 
 |  |  |                      'content-type':'application/x-www-form-urlencoded', | 
 |  |  | 
 |  |  |                   success(result) { | 
 |  |  |                      var res = result.data | 
 |  |  |                      if (res.code === 200) { | 
 |  |  |                         uni.navigateBack() | 
 |  |  |                         uni.navigateBack({delta:2}) | 
 |  |  |                      } else if (res.code === 403) { | 
 |  |  |                         uni.showToast({title: res.msg, icon: "none", position: 'top'}) | 
 |  |  |                         setTimeout(() => { | 
 |  |  | 
 |  |  |       background-color: #fff; | 
 |  |  |       /* background-color: aqua; */ | 
 |  |  |    } | 
 |  |  | </style> | 
 |  |  | </style> |