|  |  |  | 
|---|
|  |  |  | <el-input v-model="form.name" placeholder="请输入名称" v-trim/> | 
|---|
|  |  |  | </el-form-item> | 
|---|
|  |  |  | <el-form-item label="选择父级" prop="parentId"> | 
|---|
|  |  |  | <el-cascader  v-model="form.categoryList" :options="categorys" @change="handleChangeCategory" :show-all-levels="false" | 
|---|
|  |  |  | <treeselect | 
|---|
|  |  |  | v-model="form.parentId" | 
|---|
|  |  |  | placeholder="请选择" | 
|---|
|  |  |  | :options="categorys" | 
|---|
|  |  |  | :normalizer="normalizeOptions" | 
|---|
|  |  |  | :default-expand-level="1" | 
|---|
|  |  |  | noChildrenText="没有子选项" | 
|---|
|  |  |  | noOptionsText="没有可选项" | 
|---|
|  |  |  | noResultsText="没有匹配的结果" | 
|---|
|  |  |  | @select="node => treeHandleSelect(node)" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | <!--        <el-cascader  v-model="form.categoryList" :options="categorys" @change="handleChangeCategory" :show-all-levels="false" | 
|---|
|  |  |  | clearable filterable :props="categoryprops"  > | 
|---|
|  |  |  | <template slot-scope="{ node, data }"> | 
|---|
|  |  |  | <span>{{ data.name }}</span> <!-- 自定义显示内容 --> | 
|---|
|  |  |  | <span>{{ data.name }}</span> <!– 自定义显示内容 –> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  | </el-cascader> | 
|---|
|  |  |  | </el-cascader>--> | 
|---|
|  |  |  | </el-form-item> | 
|---|
|  |  |  | <el-form-item label="排序码" prop="sortnum"> | 
|---|
|  |  |  | <el-input v-model="form.sortnum" placeholder="请输入排序码(升序)" v-trim/> | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | methods: { | 
|---|
|  |  |  | normalizeOptions (node) { | 
|---|
|  |  |  | if (node.childList && !node.childList.length) { | 
|---|
|  |  |  | // 去掉children=[]的children属性 | 
|---|
|  |  |  | delete node.childList | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return { | 
|---|
|  |  |  | id: node.id, | 
|---|
|  |  |  | label: node.name, | 
|---|
|  |  |  | children: node.childList | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | treeHandleSelect (node) { | 
|---|
|  |  |  | if (this.form.id != null && node.id && this.form.id === node.id) { | 
|---|
|  |  |  | this.$tip.error('对不起,父级不能设置为自身!') | 
|---|
|  |  |  | this.form.parentId = null | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | handleChangeCategory (value) { | 
|---|
|  |  |  | this.form.parentId = null | 
|---|
|  |  |  | if (this.form.categoryList && this.form.categoryList.length >= 1) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return data | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | open (title, target, categorys, categoryType, parentIdPath) { | 
|---|
|  |  |  | open (title, target, categorys, categoryType, parentId) { | 
|---|
|  |  |  | this.title = title | 
|---|
|  |  |  | this.categorys = categorys || [] | 
|---|
|  |  |  | this.categorys = this.getTreeData(this.categorys) | 
|---|
|  |  |  | console.log(this.categorys) | 
|---|
|  |  |  | this.categorys = JSON.parse(JSON.stringify(categorys||[])); | 
|---|
|  |  |  | console.log(parentId) | 
|---|
|  |  |  | this.visible = true | 
|---|
|  |  |  | this.form = { | 
|---|
|  |  |  | id: null, | 
|---|
|  |  |  | 
|---|
|  |  |  | categoryList: [], | 
|---|
|  |  |  | sortnum: null, | 
|---|
|  |  |  | remark: '', | 
|---|
|  |  |  | parentId: null | 
|---|
|  |  |  | parentId: parentId | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.form.type = categoryType | 
|---|
|  |  |  | // 新建 | 
|---|
|  |  |  | 
|---|
|  |  |  | this.$nextTick(() => { | 
|---|
|  |  |  | this.$refs.form.resetFields() | 
|---|
|  |  |  | this.form[this.configData['field.id']] = null | 
|---|
|  |  |  | this.form.categoryList = [] | 
|---|
|  |  |  | if (parentIdPath && parentIdPath != null) { | 
|---|
|  |  |  | // this.form.categoryList = [] | 
|---|
|  |  |  | /*if (parentIdPath && parentIdPath != null) { | 
|---|
|  |  |  | var array = parentIdPath.split('/') | 
|---|
|  |  |  | array.forEach(item => { | 
|---|
|  |  |  | if (item && item != null && item !== '') { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | that.handleChangeCategory() | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | for (const key in this.form) { | 
|---|
|  |  |  | this.form[key] = target[key] | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.form.categoryList = [] | 
|---|
|  |  |  | /*this.form.categoryList = [] | 
|---|
|  |  |  | if (target.parentId && target.idParentPath) { | 
|---|
|  |  |  | var array = target.idParentPath.split('/') | 
|---|
|  |  |  | array.forEach(item => { | 
|---|
|  |  |  | 
|---|
|  |  |  | that.form.categoryList.push(parseInt(item)) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|