diff --git a/frontend/src/views/system/dept/form copy.vue b/frontend/src/views/system/dept/form copy.vue deleted file mode 100644 index 63967d4..0000000 --- a/frontend/src/views/system/dept/form copy.vue +++ /dev/null @@ -1,263 +0,0 @@ - - - diff --git a/frontend/src/views/system/dept/form.vue b/frontend/src/views/system/dept/form.vue index 4a13c2c..7bc5040 100644 --- a/frontend/src/views/system/dept/form.vue +++ b/frontend/src/views/system/dept/form.vue @@ -1,26 +1,244 @@ - + created() { + if (this.$router.currentRoute.params && this.$router.currentRoute.params.deptId) { + var row = this.$router.currentRoute.params + this.edit(row) + } else { + this.create() + } + this.setLoyoutInfo() + }, + mounted() { + this.bindKey() + }, + destroyed() { + this.unBindKey() + }, + methods: { + entryKey(event) { + var keyCode = event.keyCode + if (keyCode === 13) { + this.save() + } + }, + bindKey() { + document.addEventListener('keypress', this.entryKey) + }, + unBindKey() { + document.removeEventListener('keypress', this.entryKey) + }, + executeAxios(url, type, data, callBack) { + var param = { + url: url, + type: type, + data: data, + callBack: callBack + } + execute(param) + .then(function(res) { + if (param.callBack) { + param.callBack(res) + } + }) + .catch(function(e) { + if (param.error) { + param.error(e) + } + }) + }, + setLoyoutInfo() { + this.$emit('on-plugin-layout', { + header: this.formType === 'add' ? this.$t('organization.create') : this.$t('organization.modify'), + backName: 'system-dept' + }) + }, + create() { + this.formType = 'add' + this.form = Object.assign({}, this.defaultForm) + }, + edit(row) { + this.formType = 'modify' + this.form = Object.assign({}, row) + this.initDeptTree() + }, + initDeptTree() { + var _this = this + this.executeAxios('/plugin/dept/nodesByDeptId/' + (this.form.pid || 0), 'post', {}, function(res) { + var results = res.data.map(function(node) { + if (node.hasChildren && !node.children) { + node.children = null + } + return node + }) + _this.depts = results + }) + }, + // 获取弹窗内部门数据 + loadDepts(_ref) { + var action = _ref.action + var parentNode = _ref.parentNode + var callback = _ref.callback + + if (action === 'LOAD_ROOT_OPTIONS' && !this.form.pid) { + var _self = this + this.executeAxios('/plugin/dept/nodesByDeptId/' + 0, 'post', {}, function(res) { + var results = res.data.map(function(node) { + if (node.hasChildren && !node.children) { + node.children = null + } + return node + }) + _self.depts = _self.excludeSelf(results) + callback() + }) + } + + if (action === 'LOAD_CHILDREN_OPTIONS') { + var _self2 = this + this.executeAxios('/plugin/dept/childNodes/' + parentNode.id, 'post', {}, function(res) { + var kids = res.data.map(function(obj) { + return _self2.normalizer(obj) + }) + + parentNode.children = _self2.excludeSelf(kids) + callback() + }) + } + }, + normalizer(node) { + if (node.hasChildren) { + node.children = null + } + return { + id: node.deptId, + label: node.name, + children: node.children + } + }, + topChange(value) { + if (!value) { + this.form.pid = null + this.depts = null + this.pLabel = this.$t('dept.root_org') + } + }, + reset() { + if (this.formType !== 'add') { + var row = this.$router.currentRoute.params + this.edit(row) + } else { + this.$refs.deptForm.resetFields() + } + }, + save() { + var _this2 = this + + this.$refs.deptForm.validate(function(valid) { + if (valid) { + var url = _this2.formType === 'add' ? '/plugin/dept/create' : '/plugin/dept/update' + _this2.executeAxios(url, 'post', _this2.form, function(res) { + if (res.data && res.data === -2) { + var msg = _this2.pLabel + _this2.$t('dept.name_exist_pre') + _this2.form.name + _this2.$t('dept.name_exist_suf') + _this2.$warning(msg) + return + } + _this2.$success(_this2.$t('commons.save_success')) + _this2.backToList() + }) + } else { + return false + } + }) + }, + backToList() { + this.$router.push({ name: 'system-dept' }) + }, + excludeSelf(nodes) { + var _this3 = this + + if (this.formType !== 'modify') return nodes + nodes.forEach(function(node) { + return node.id === _this3.form.deptId && (node.isDisabled = true) + }) + return nodes + }, + nodeChange(node, instanceId) { + if (node.label) { + this.pLabel = node.label + } + // console.log(node) + console.log(instanceId) + } + } +} + diff --git a/frontend/src/views/system/dept/index.vue b/frontend/src/views/system/dept/index.vue index 6d9db43..9fd5073 100644 --- a/frontend/src/views/system/dept/index.vue +++ b/frontend/src/views/system/dept/index.vue @@ -1,26 +1,443 @@ diff --git a/frontend/src/views/system/dept/index2.vue b/frontend/src/views/system/dept/index2.vue deleted file mode 100644 index 3b96c36..0000000 --- a/frontend/src/views/system/dept/index2.vue +++ /dev/null @@ -1,423 +0,0 @@ - - - - -