“dzb”
2022-10-21 a598d935a61fea27312fc57becd80e23bf09f788
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) => {
@@ -139,15 +143,26 @@
            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)=>{
                console.log(valid);
                if(valid){
@@ -186,15 +201,58 @@
            this.$emit('sendDialog',{flag:false})
        },
        // 获取字典
        getCodeList(){
            this.$axios({
                method:'get',
                url:'sccg/dict/queryByCode?code='+"03"
        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
            })
            .then(res=>{
                console.log(res);
            })
                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;
            // 获取当前选择的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 = ''
            }
        },
    },
    props: ['sendDialog']
}