| | |
| | | <span>{{row.name}}</span> |
| | | <el-button :size="size" text icon="el-icon-setting" type="primary" placeholder="修改" @click="showEdit(row)"></el-button> |
| | | <el-button :size="size" text icon="el-icon-delete" type="primary" @click="showDel(row)" placeholder="删除"></el-button> |
| | | <el-button :size="size" text icon="el-icon-document-add" type="primary" @click="showAdd(row)" placeholder="新增子级"></el-button> |
| | | <el-button :size="size" text v-if="row.nodeType < 70" icon="el-icon-document-add" type="primary" @click="showAdd(row)" placeholder="新增子级"></el-button> |
| | | </template> |
| | | </avue-crud> |
| | | <el-dialog :title="modalTitle" append-to-body v-model="modalBox"> |
| | |
| | | }, |
| | | { |
| | | label: '设备(机床)', |
| | | prop: 'abc', |
| | | hide: true |
| | | prop: 'abc' |
| | | }, |
| | | { |
| | | label: '节点名称', |
| | | prop: 'name', |
| | | hide: true |
| | | prop: 'name' |
| | | }, |
| | | { |
| | | label: '节点描述', |
| | |
| | | { |
| | | label: '全路径', |
| | | prop: 'abc', |
| | | hide: true, |
| | | span: 24 |
| | | }, |
| | | { |
| | | label: '备注', |
| | | prop: 'remark', |
| | | type: "textarea", |
| | | hide: true, |
| | | span: 24 |
| | | } |
| | | ] |
| | |
| | | }, |
| | | methods: { |
| | | rowDel(row, index, done) { |
| | | console.log(done); |
| | | done(row); |
| | | }, |
| | | rowSave (row, done) { |
| | | console.log(done,1111); |
| | | done(row); |
| | | }, |
| | | rowUpdate (row, index, done) { |
| | | console.log(done,222); |
| | | done(row); |
| | | }, |
| | | showEdit(row,done) { |
| | | this.modalTitle = "修改"; |
| | | this.modalBox = true; |
| | | return; |
| | | this.modalForm = row; |
| | | }, |
| | | showDel(row) { |
| | | //调用接口 |
| | |
| | | ); |
| | | }, |
| | | showAdd (row) { //新增子节点 |
| | | if(row.nodeType == 70) { |
| | | return; |
| | | } |
| | | this.modalTitle = "新增子节点"; |
| | | this.selectedColumn.nodeType = String(Number(row.nodeType) + 10); |
| | | this.selectedColumn.parentId = row.id; |
| | |
| | | this.modalForm = this.selectedColumn; |
| | | this.modalBox = true; |
| | | }, |
| | | modalSubmit(row) { //新增子节点保存 |
| | | modalSubmit(row,done) { //新增子节点保存/修改 |
| | | if(this.modalTitle == "修改") { |
| | | var url = "/blade-mdm/program/node/update"; |
| | | }else { |
| | | var url = "/blade-mdm/program/node/save"; |
| | | } |
| | | //调用接口 |
| | | this.loading = true; |
| | | axios({ |
| | | url: '/blade-mdm/program/node/save', |
| | | url, |
| | | method: 'post', |
| | | data: this.modalForm, |
| | | }).then( |
| | | res => { |
| | | //this.$refs.crud.rowSave(this.modalForm); |
| | | this.onLoad(); |
| | | this.$refs.crud.refreshTable(); |
| | | this.$message.success('操作成功'); |
| | | this.modalBox = false; |
| | | // 修改,更新本地数据 |
| | | if (this.modalTitle === "修改") { |
| | | this.updateLocalTreeNode(this.modalForm); |
| | | } |
| | | this.loading = false; |
| | | done(row); |
| | | // 如果是新增操作,可能需要重新加载数据 |
| | | // this.$refs.crud.refresh(); |
| | | // this.$refs.crud.refreshTable(); |
| | | } |
| | | ); |
| | | }, |
| | | updateLocalTreeNode(nodeData) { |
| | | const updateNode = (nodes) => { |
| | | for (let i = 0; i < nodes.length; i++) { |
| | | if (nodes[i].id === nodeData.id) { |
| | | // 更新节点数据 |
| | | Object.assign(nodes[i], nodeData); |
| | | return true; |
| | | } |
| | | if (Array.isArray(nodes[i].children) && nodes[i].children.length > 0) { |
| | | if (updateNode(nodes[i].children)) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | }; |
| | | updateNode(this.data); |
| | | }, |
| | | modalCancel() { |
| | | this.modalBox = false; |
| | | }, |
| | | treeLoad (tree, treeNode, resolve) { |
| | | // setTimeout(() => { |
| | | // this.parentId += 1; |
| | | // var hasChildren = true; |
| | | // if(this.parentId == 6) { |
| | | // this.$message.error("到头了"); |
| | | // hasChildren = false; |
| | | // } |
| | | // resolve([{ |
| | | // id: this.parentId, |
| | | // parentId: this.parentId, |
| | | // date: '2016-05-01', |
| | | // name: '王小虎', |
| | | // address: '新增', |
| | | // hasChildren: hasChildren |
| | | // }]); |
| | | // console.log(tree,111) |
| | | // }, 100); |
| | | this.loading = true; |
| | | var obj = {parentId: tree.id} |
| | | axios({ |