|
@@ -0,0 +1,208 @@
|
|
|
+<template>
|
|
|
+ <m-dialog ref="dialog" :title="title" v-bind="$attrs" v-on="$listeners" @sure="onSure">
|
|
|
+ <m-form ref="form" :items="formItems" label-width="180px" v-model="values" v-loading="loading">
|
|
|
+ <template #organizationName>
|
|
|
+ <el-dropdown trigger="click">
|
|
|
+ <el-input v-model="values.organizationName" readonly placeholder="请选择职务所属机构"></el-input>
|
|
|
+ <el-dropdown-menu slot="dropdown">
|
|
|
+ <div class="treeBox">
|
|
|
+ <el-tree
|
|
|
+ :data="treeItems"
|
|
|
+ node-key="uuid"
|
|
|
+ show-checkbox
|
|
|
+ :highlight-current="true"
|
|
|
+ :expand-on-click-node="false"
|
|
|
+ :default-expanded-keys="expandRowKeys"
|
|
|
+ :default-checked-keys="defaultCheckedKeys"
|
|
|
+ :props="{ label: 'organizationName', children: 'child' }"
|
|
|
+ @check="onCheck"
|
|
|
+ ></el-tree>
|
|
|
+ </div>
|
|
|
+ </el-dropdown-menu>
|
|
|
+ </el-dropdown>
|
|
|
+ </template>
|
|
|
+ </m-form>
|
|
|
+ </m-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { organizationDrill, getOrganizationTree } from '@/api/system'
|
|
|
+import {
|
|
|
+ saveWelfareCategory
|
|
|
+} from '@/api/salary'
|
|
|
+export default {
|
|
|
+ name: 'welfare-type-edit',
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ loading: false,
|
|
|
+ headers: [
|
|
|
+ { label: '职务名称', prop: 'organizationName' },
|
|
|
+ { label: '应用部门', prop: 'tag' }
|
|
|
+ ],
|
|
|
+ title: '',
|
|
|
+ values: {},
|
|
|
+ choose: [],
|
|
|
+ defaultCheckedKeys: [],
|
|
|
+ items: [],
|
|
|
+ treeItems: [],
|
|
|
+ expandRowKeys: []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ formItems () {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ label: '福利类型名称',
|
|
|
+ prop: 'title',
|
|
|
+ type: 'input',
|
|
|
+ options: {
|
|
|
+ placeholder: '请输入福利类型名称'
|
|
|
+ },
|
|
|
+ rules: [
|
|
|
+ { required: true, message: '请输入福利类型名称', trigger: 'blur' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '职务名称',
|
|
|
+ prop: 'postName',
|
|
|
+ type: 'select',
|
|
|
+ options: {
|
|
|
+ items: this.items,
|
|
|
+ labelText: 'organizationName',
|
|
|
+ labelValue: 'organizationName'
|
|
|
+ },
|
|
|
+ rules: [
|
|
|
+ { required: true, message: '请选择职务', trigger: 'change' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '机构',
|
|
|
+ prop: 'organizationName',
|
|
|
+ rules: [
|
|
|
+ { required: true, message: '请选择机构', trigger: 'change' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '描述',
|
|
|
+ prop: 'tag',
|
|
|
+ type: 'input',
|
|
|
+ options: {
|
|
|
+ type: 'textarea',
|
|
|
+ placeholder: '请输入描述'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ async open (item) {
|
|
|
+ this.loading = true
|
|
|
+ this.$refs.dialog.open()
|
|
|
+ await this.getData()
|
|
|
+ await this.getOrganizationTree()
|
|
|
+ this.loading = false
|
|
|
+ if (!item) {
|
|
|
+ this.title = '新增福利类型'
|
|
|
+ this.values = {
|
|
|
+ title: null,
|
|
|
+ tag: null,
|
|
|
+ postName: null,
|
|
|
+ organizationName: null
|
|
|
+ }
|
|
|
+ this.defaultCheckedKeys = []
|
|
|
+ } else {
|
|
|
+ this.title = '编辑福利类型'
|
|
|
+ this.values = {
|
|
|
+ subsidyPersonnelCategoryId: item.subsidyPersonnelCategoryId,
|
|
|
+ title: item.title,
|
|
|
+ tag: item.tag,
|
|
|
+ postName: item.subsidyPersonnelCategoryItems[0]?.postName ?? null,
|
|
|
+ organizationName: this.onShow(item.subsidyPersonnelCategoryItems.length)
|
|
|
+ }
|
|
|
+ this.choose = item.subsidyPersonnelCategoryItems
|
|
|
+ this.defaultCheckedKeys = this.onGetUUID(item.subsidyPersonnelCategoryItems, this.treeItems)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onSure () {
|
|
|
+ this.$refs.form.validate(async valid => {
|
|
|
+ if (!valid) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ await saveWelfareCategory({
|
|
|
+ subsidyPersonnelCategory: {
|
|
|
+ subsidyPersonnelCategoryId: this.values.subsidyPersonnelCategoryId,
|
|
|
+ title: this.values.title,
|
|
|
+ tag: this.values.tag
|
|
|
+ },
|
|
|
+ subsidyPersonnelCategoryItems: this.choose.map(e => {
|
|
|
+ return {
|
|
|
+ postName: this.values.postName,
|
|
|
+ organizationName: e.organizationName,
|
|
|
+ level: e.level
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.$message.success('保存成功')
|
|
|
+ this.$refs.dialog.close()
|
|
|
+ this.$emit('refresh')
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async getOrganizationTree () {
|
|
|
+ try {
|
|
|
+ const { data } = await getOrganizationTree()
|
|
|
+ this.expandRowKeys = [data.uuid]
|
|
|
+ this.treeItems = [data]
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async getData () {
|
|
|
+ try {
|
|
|
+ const { data } = await organizationDrill({ resDataType: 1 })
|
|
|
+ this.items = data.map(e => {
|
|
|
+ return {
|
|
|
+ ...e,
|
|
|
+ value: null
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onGetUUID (arr, items, content = []) {
|
|
|
+ items.forEach(e => {
|
|
|
+ if (e.child && e.child.length) {
|
|
|
+ content.push(...this.onGetUUID(arr, e.child, content))
|
|
|
+ }
|
|
|
+ const item = arr.find(_e => _e.level === e.level && _e.organizationName === e.organizationName)
|
|
|
+ if (item) {
|
|
|
+ content.push(e.uuid)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return content
|
|
|
+ },
|
|
|
+ onShow (val) {
|
|
|
+ if (!val) {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ return `已选 ${val} 个机构`
|
|
|
+ },
|
|
|
+ onCheck (data, event) {
|
|
|
+ this.choose = event.checkedNodes
|
|
|
+ this.values.organizationName = this.onShow(this.choose.length)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.treeBox {
|
|
|
+ width: 250px;
|
|
|
+ max-height: 400px;
|
|
|
+ overflow: auto;
|
|
|
+}
|
|
|
+</style>
|