| | |
| | | <template> |
| | | <div class="createUser"> |
| | | <div class="createUser" v-if="showFlag"> |
| | | <main> |
| | | <div class="mainContent"> |
| | | <el-form ref="user" label-width="140px" autoComplete="on" :model="store" :rules="createUserRules" |
| | | 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-form-item class="optionItem" label="店铺类型:" prop="type"> |
| | | <el-select v-model="store.type" placeholder="请选择店铺类型"> |
| | | <el-option value="1"> |
| | | <el-tree ref="tree" :check-strictly="true" :data="shopTypeList" :props="defaultProps" |
| | | show-checkbox @check-change="handleCheck" :default-checked-keys="[selectOrg.orgsid[0]]" default-expand-all node-key="id"> |
| | | </el-tree> |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | |
| | | </el-form-item> |
| | | <!-- 店铺描述 --> |
| | | <el-form-item class="optionItem" label="店铺描述:" prop="storeDesc"> |
| | | <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" maxlength="300" show-word-limit |
| | | <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" maxlength="300" show-word-limit |
| | | v-model="store.storeDesc" placeholder="输入店铺描述"></el-input> |
| | | <!-- <el-input type="textarea" v-model="user.storedesc" placeholder="输入部门描述"></el-input> --> |
| | | </el-form-item> |
| | |
| | | </div> |
| | | </template> |
| | | <script> |
| | | import { getCodeList } from '@/utils/helper' |
| | | export default { |
| | | data() { |
| | | const validateNickname = (rule, value, callback) => { |
| | |
| | | const rep = /(^1[3|4|5|7|8|9]\d{9}$)|(^09\d{8}$)/ |
| | | if (!rep.test(value)) { |
| | | callback("请输入正确的手机号码"); |
| | | }else{ |
| | | } else { |
| | | callback(); |
| | | } |
| | | } |
| | |
| | | const validateType = (rule, value, callback) => { |
| | | if (!value) { |
| | | callback(new Error('门店类型不能为空')); |
| | | } else { |
| | | } else { |
| | | callback(); |
| | | } |
| | | }; |
| | |
| | | owner: [ |
| | | { required: true, trigger: "blur", validator: validateNickname }, |
| | | ], |
| | | storetype:[ |
| | | storetype: [ |
| | | { |
| | | required:true,trigger:'change', validator:validateType, |
| | | required: true, trigger: 'change', validator: validateType, |
| | | } |
| | | ], |
| | | idcardinfo: [ |
| | |
| | | ], |
| | | }, |
| | | shopTypeList: [ |
| | | { name: '类型1', value: 1 }, { name: '类型2', value: 2 } |
| | | |
| | | ], |
| | | defaultProps: { |
| | | children: 'children', |
| | | label: 'name', |
| | | }, |
| | | selectOrg: { |
| | | orgsid: [] |
| | | }, |
| | | showFlag:false |
| | | } |
| | | }, |
| | | created() { |
| | | const {userInfo} = this; |
| | | console.log(userInfo) |
| | | const { userInfo } = this; |
| | | // console.log(userInfo) |
| | | this.store = userInfo |
| | | this.getShopTypeList(); |
| | | // console.log(this.store) |
| | | }, |
| | | methods: { |
| | | // 获取字典 |
| | | async getShopTypeList() { |
| | | let arr = await getCodeList('16'); |
| | | this.selectOrg.orgsid[0] = this.store.type |
| | | console.log(this.selectOrg.orgsid) |
| | | arr.forEach(item=>{ |
| | | item.id === this.store.type ? this.store.type = item.name : '暂无分类' |
| | | }) |
| | | this.showFlag = true |
| | | 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) { |
| | | // console.log(data) |
| | | this.store.type = data.name; |
| | | // 获取当前选择的id在数组中的索引 |
| | | const indexs = this.selectOrg.orgsid.indexOf(data.id) |
| | | // 如果不存在数组中,并且数组中已经有一个id并且checked为true的时候,代表不能再次选择。 |
| | | 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 = '' |
| | | } |
| | | }, |
| | | handleUser() { |
| | | const { store } = this; |
| | | this.$refs.user.validate((valid)=>{ |
| | | this.$refs.user.validate((valid) => { |
| | | console.log(valid); |
| | | if(valid){ |
| | | if (valid) { |
| | | this.$axios({ |
| | | method:'put', |
| | | url:'sccg/store/storeinfo/update', |
| | | data:{ |
| | | contact:store.contact, |
| | | idcardinfo:store.idCardInfo, |
| | | owner:store.owner, |
| | | storeAddress:store.storeAddress, |
| | | storeName:store.storeName, |
| | | id:store.id, |
| | | storePhoto:store.storePhoto, |
| | | storeScore:store.storeScore, |
| | | method: 'put', |
| | | url: 'sccg/store/storeinfo/update', |
| | | data: { |
| | | contact: store.contact, |
| | | idcardinfo: store.idCardInfo, |
| | | owner: store.owner, |
| | | storeAddress: store.storeAddress, |
| | | storeName: store.storeName, |
| | | id: store.id, |
| | | storePhoto: store.storePhoto, |
| | | storeScore: store.storeScore, |
| | | type:this.selectOrg.orgsid[0] |
| | | } |
| | | }) |
| | | .then(res=>{ |
| | | console.log(res); |
| | | if(res.code===200){ |
| | | this.$message({ |
| | | type:'success', |
| | | message:'修改成功', |
| | | }) |
| | | this.$emit('changeDialog',{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('changeDialog', { flag: false }); |
| | | } else { |
| | | this.$message({ |
| | | type: 'error', |
| | | message: res.message, |
| | | }) |
| | | } |
| | | }) |
| | | } else { |
| | | return false; |
| | | } |
| | | }) |
| | | }, |
| | | handleBack(){ |
| | | this.$emit('changeDialog',{flag:false}) |
| | | handleBack() { |
| | | this.$emit('changeDialog', { flag: false }) |
| | | } |
| | | }, |
| | | props: ['userInfo','changeDialog'] |
| | | props: ['userInfo', 'changeDialog'] |
| | | } |
| | | </script> |
| | | <style lang="scss" scoped> |