From a598d935a61fea27312fc57becd80e23bf09f788 Mon Sep 17 00:00:00 2001 From: “dzb” <2632970487@qq.com> Date: 星期五, 21 十月 2022 18:04:19 +0800 Subject: [PATCH] 修改bug --- src/views/operate/fivepack/shop/components/createUser/index.vue | 152 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 105 insertions(+), 47 deletions(-) diff --git a/src/views/operate/fivepack/shop/components/createUser/index.vue b/src/views/operate/fivepack/shop/components/createUser/index.vue index 5860e28..0e5b88d 100644 --- a/src/views/operate/fivepack/shop/components/createUser/index.vue +++ b/src/views/operate/fivepack/shop/components/createUser/index.vue @@ -6,8 +6,11 @@ label-position="right"> <!-- 搴楅摵绫诲瀷 --> <el-form-item class="optionItem" label="搴楅摵绫诲瀷:" prop="storetype"> - <el-select v-model="store.storetype" placeholder="閫夋嫨搴楅摵/闂ㄥ簵绫诲瀷"> - <el-option v-for="item in shopTypeList" :key="item.name" :label="item.name" :value="item.value"> + <el-select v-model="store.storetype" placeholder="璇烽�夋嫨搴楅摵绫诲瀷"> + <el-option value="1"> + <el-tree ref="tree" :check-strictly="true" :data="shopTypeList" :props="defaultProps" + show-checkbox @check-change="handleCheck" default-expand-all node-key="id"> + </el-tree> </el-option> </el-select> </el-form-item> @@ -39,12 +42,13 @@ <footer> <div class="optionBtn"> <el-button class="btn reset" @click="handleBack">鍙栨秷</el-button> - <el-button type="primary" class="btn submit" @click="handleUser">纭畾</el-button> + <el-button type="primary" class="btn submit" @click="handleStore">纭畾</el-button> </div> </footer> </div> </template> <script> +import { getCodeList } from '@/utils/helper' export default { data() { const validateNickname = (rule, value, callback) => { @@ -75,7 +79,7 @@ const rep = /(^1[3|4|5|7|8|9]\d{9}$)|(^09\d{8}$)/ if (!rep.test(value)) { callback("璇疯緭鍏ユ纭殑鎵嬫満鍙风爜"); - }else{ + } else { callback(); } } @@ -90,7 +94,7 @@ const validateType = (rule, value, callback) => { if (!value) { callback(new Error('闂ㄥ簵绫诲瀷涓嶈兘涓虹┖')); - } else { + } else { callback(); } }; @@ -115,9 +119,9 @@ owner: [ { required: true, trigger: "blur", validator: validateNickname }, ], - storetype:[ + storetype: [ { - required:true,trigger:'change', validator:validateType, + required: true, trigger: 'change', validator: validateType, } ], idcardinfo: [ @@ -139,62 +143,116 @@ shopTypeList: [ { name: '绫诲瀷1', value: 1 }, { name: '绫诲瀷2', value: 2 } ], + defaultProps: { + children: 'children', + label: 'name', + disabled: (data, node) => { + if (node.level === 1 && node.childNodes.length !== 0) { + return !data.leaf + } + } + }, + selectOrg: { + orgsid: [] + }, } }, created() { - this.getCodeList(); + this.getShopTypeList(); }, methods: { - handleUser() { + handleStore() { const { store } = this; - console.log('in'); - this.$refs.user.validate((valid)=>{ + this.$refs.user.validate((valid) => { console.log(valid); - if(valid){ + if (valid) { this.$axios({ - method:'post', - url:'sccg/store/storeinfo/add', - data:{ - contact:store.contact, - idcardinfo:'511025184612310215', - owner:store.owner, - storeaddr:store.storeaddr, - storename:store.storename, + method: 'post', + url: 'sccg/store/storeinfo/add', + data: { + contact: store.contact, + idcardinfo: '511025184612310215', + owner: store.owner, + storeaddr: store.storeaddr, + storename: store.storename, } }) - .then(res=>{ - console.log(res); - if(res.code===200){ - this.$message({ - type:'success', - message:'娣诲姞鎴愬姛', - }) - this.$emit('sendDialog',{flag:false}); - }else{ - this.$message({ - type:'error', - message:res.message, - }) - } - }) - }else{ + .then(res => { + console.log(res); + if (res.code === 200) { + this.$message({ + type: 'success', + message: '娣诲姞鎴愬姛', + }) + this.$emit('sendDialog', { flag: false }); + } else { + this.$message({ + type: 'error', + message: res.message, + }) + } + }) + } else { return false; } }) }, - handleBack(){ - this.$emit('sendDialog',{flag:false}) + handleBack() { + this.$emit('sendDialog', { flag: false }) }, // 鑾峰彇瀛楀吀 - getCodeList(){ - this.$axios({ - method:'get', - url:'sccg/dict/queryByCode?code='+"03" - }) - .then(res=>{ - console.log(res); - }) - } + async getShopTypeList() { + let arr = await getCodeList('16'); + this.shopTypeList = this.createShopTypeTree(arr); + }, + // 鍒涘缓鍟嗛摵绫诲瀷鏍� + createShopTypeTree(arr) { + if (arr.length && arr.length !== 0) { + // 鑾峰彇椤剁骇鑿滃崟 + let treeRoot = arr.filter(item => { + return item.parentId === 0 + }) + console.log(treeRoot); + // 娣诲姞child + treeRoot.forEach(item => { + item.children = [] + arr.forEach(child => { + if (child.parentId === item.id) { + item.children.push(child) + } + }) + }) + return treeRoot; + } + }, + handleCheck(data, checked) { + this.store.storetype = data.name; + // 鑾峰彇褰撳墠閫夋嫨鐨刬d鍦ㄦ暟缁勪腑鐨勭储寮� + const indexs = this.selectOrg.orgsid.indexOf(data.id) + // 濡傛灉涓嶅瓨鍦ㄦ暟缁勪腑锛屽苟涓旀暟缁勪腑宸茬粡鏈変竴涓猧d骞朵笖checked涓簍rue鐨勬椂鍊欙紝浠h〃涓嶈兘鍐嶆閫夋嫨銆� + if (indexs < 0 && this.selectOrg.orgsid.length === 1 && checked) { + this.$message({ + message: '鍙兘閫夋嫨涓�涓儴闂紒', + type: 'warning', + showClose: true + }) + // 璁剧疆宸查�夋嫨鐨勮妭鐐逛负false 寰堥噸瑕� + this.$refs.tree.setChecked(data, false) + } else if (this.selectOrg.orgsid.length === 0 && checked) { + // 鍙戠幇鏁扮粍涓虹┖ 骞朵笖鏄凡閫夋嫨 + // 闃叉鏁扮粍鏈夊�硷紝棣栧厛娓呯┖锛屽啀push + this.selectOrg.orgsid = [] + this.selectOrg.orgsid.push(data.id) + } else if ( + indexs >= 0 && + this.selectOrg.orgsid.length === 1 && + !checked + ) { + // 鍐嶆鐩存帴杩涜璧嬪�间负绌烘搷浣� + this.selectOrg.orgsid = [] + this.store.storetype = '' + } + }, }, props: ['sendDialog'] } -- Gitblit v1.8.0