<template>
|
<div class="app-container">
|
<!--工具栏-->
|
<div class="head-container">
|
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
<div>
|
<el-button
|
slot="right"
|
size="mini"
|
type="primary"
|
icon="el-icon-edit"
|
class="filter-item"
|
:loading="refreshWecomVacationTypeLoading"
|
@click="refreshWecomVacationType()"
|
>
|
更新企微请假类型
|
</el-button>
|
|
<el-popover
|
slot="right"
|
placement="bottom-start"
|
width="400"
|
trigger="click"
|
title="更新申请审核站点"
|
@show="showEditApprovalSite()"
|
@hide="hideEditApprovalSite()"
|
>
|
<el-form ref="form" :model="approvalSiteParam.form" :rules="rules" size="small" label-width="80px">
|
<el-form-item label="审核站点">
|
<el-radio-group v-model="approvalSiteParam.form.approvalSite">
|
<el-radio-button label="system">系统</el-radio-button>
|
<el-radio-button label="wecom">企微</el-radio-button>
|
</el-radio-group>
|
</el-form-item>
|
</el-form>
|
<div class="popover-footer">
|
<el-button :loading="approvalSiteParam.loading" type="primary" @click="doEditApprovalSite">确认</el-button>
|
</div>
|
|
<el-button
|
slot="reference"
|
size="mini"
|
type="warning"
|
icon="el-icon-edit"
|
class="filter-item"
|
>
|
更新申请审核站点
|
</el-button>
|
</el-popover>
|
</div>
|
<!--表单组件-->
|
<el-dialog :close-on-click-modal="false" :before-close="cancelBind" :visible.sync="bindParam.visible" :title="bindParam.title" width="600px">
|
<div class="query-container">
|
<el-input v-model="bindParam.queryTemplateId" placeholder="请输入模版ID查询" style="width: 300px;" />
|
<span>
|
<el-button icon="el-icon-search" type="primary" size="mini" @click="toQueryTemplate">查新</el-button>
|
<el-button icon="el-icon-search" type="primary" size="mini" @click="toQueryTemplate(false)">查旧</el-button>
|
<el-button icon="el-icon-refresh-right" type="warning" size="mini" @click="resetTemplate">重置</el-button>
|
</span>
|
</div>
|
|
<el-divider />
|
|
<el-form ref="form" :model="bindParam.data" :rules="rules" size="small" label-width="180px">
|
<el-form-item label="模板ID">
|
<el-input v-model="bindParam.data.templateId" disabled style="width: 370px;" />
|
</el-form-item>
|
|
<el-form-item label="模版名称">
|
<el-input v-model="bindParam.data.templateName" disabled style="width: 370px;" />
|
</el-form-item>
|
|
<el-form-item
|
v-for="control in bindParam.currentTemplateData.templateControls"
|
:key="control.id"
|
:label="`${control.titleTextZh || control.titleTextEn}(${control.controlParamName})`"
|
:prop="`${control.id}`"
|
:rules="[{
|
required: control.contentRequire == 1, message: `${control.titleTextZh || control.titleTextEn}(${control.controlParamName})不能为空`, trigger: 'change'
|
}]"
|
>
|
<el-select v-model="bindParam.data[`${control.id}`]" filterable clearable :placeholder="`请选择${control.titleTextZh || control.titleTextEn}(${control.controlParamName})`" style="width: 370px;">
|
<el-option v-for="item in bindParam.tableData.fieldNames" :key="control.id + control.controlId + '_' + item.propName" :label="`${item.label}(${item.propName})`" :value="item.propName" />
|
</el-select>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="text" @click="cancelBind">取消</el-button>
|
<el-button :loading="bindParam.loading" type="primary" @click="doBind">确认</el-button>
|
</div>
|
</el-dialog>
|
|
<!--表格渲染-->
|
<el-table ref="table" v-loading="queryLoading" :data="tableInfoData" size="small" style="width: 100%;">
|
<el-table-column type="selection" width="55" />
|
<el-table-column prop="name" label="绑定类型" />
|
<el-table-column prop="fieldTable" label="绑定表名" />
|
<el-table-column v-if="checkPer(['admin','templateControlField:edit'])" label="操作" width="150px" align="center">
|
<template slot-scope="scope">
|
<el-button v-permission="permission.edit" size="mini" type="primary" icon="el-icon-edit" @click="toBind(scope.row)" />
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import { bind, queryByTable, editWecomVacationType, editApprovalSite } from '@/api/template/templateControlField'
|
import { queryTemplate } from '@/api/template/template'
|
import constant from '@utils/constant'
|
import Vue from 'vue'
|
|
export default {
|
name: 'TemplateBind',
|
data() {
|
return {
|
// 绑定审批表信息
|
tableInfoData: [],
|
queryLoading: false,
|
bindParam: {
|
loading: false,
|
visible: false,
|
title: '审批模板绑定',
|
queryTemplateId: null,
|
// 选中表数据
|
tableData: null,
|
// 当前模板信息
|
currentTemplateData: {},
|
// 当前控件绑定信息
|
currentTemplateControlFieldData: [],
|
// 原始模板信息
|
originTemplateData: {},
|
// 原始控件绑定信息
|
originTemplateControlFieldData: [],
|
// 绑定表单数据
|
data: {}
|
},
|
// 更新企微请假类型Loading
|
refreshWecomVacationTypeLoading: false,
|
// 更新申请审核站点参数
|
approvalSiteParam: {
|
form: {
|
approvalSite: null
|
},
|
loading: false
|
},
|
// 申请审核站点: system-系统审批,wecom-企业微信审批。默认为system
|
approvalSite: 'system',
|
permission: {
|
add: ['admin', 'templateControlField:add'],
|
edit: ['admin', 'templateControlField:edit'],
|
del: ['admin', 'templateControlField:del']
|
},
|
rules: {}
|
}
|
},
|
dicts: [constant.WECOM_BIND_LEAVE, constant.WECOM_BIND_GOOUT, constant.WECOM_BIND_TRAVEL, constant.WECOM_BIND_OVERTIME, constant.WECOM_BIND_REPLACEMENT, constant.WECOM_BIND_REIMBURSE, constant.WECOM_BIND_PRE_TRAVEL, constant.APPROVAL_SITE_TYPE],
|
created() {
|
const that = this
|
that.queryLoading = true
|
that.$on('dictReady', () => {
|
const dictData = { ...that.dict }
|
// 请假字段绑定信息制作
|
const leaveTableDate = { name: '请假', fieldTable: constant.WECOM_BIND_LEAVE, fieldNames: [] }
|
dictData[constant.WECOM_BIND_LEAVE].forEach(leave => {
|
leaveTableDate.fieldNames.push({ label: leave.label, propName: leave.value })
|
return leave
|
})
|
// 外出字段绑定信息制作
|
const goOutTableDate = { name: '外出', fieldTable: constant.WECOM_BIND_GOOUT, fieldNames: [] }
|
dictData[constant.WECOM_BIND_GOOUT].forEach(goOut => {
|
goOutTableDate.fieldNames.push({ label: goOut.label, propName: goOut.value })
|
})
|
// 出差字段绑定信息制作
|
const travelTableDate = { name: '出差', fieldTable: constant.WECOM_BIND_TRAVEL, fieldNames: [] }
|
dictData[constant.WECOM_BIND_TRAVEL].forEach(travel => {
|
travelTableDate.fieldNames.push({ label: travel.label, propName: travel.value })
|
})
|
// 换休字段绑定信息制作
|
const overtimeTableDate = { name: '换休', fieldTable: constant.WECOM_BIND_OVERTIME, fieldNames: [] }
|
dictData[constant.WECOM_BIND_OVERTIME].forEach(overtime => {
|
overtimeTableDate.fieldNames.push({ label: overtime.label, propName: overtime.value })
|
})
|
// 补卡字段绑定信息制作
|
const replacementTableDate = { name: '补卡', fieldTable: constant.WECOM_BIND_REPLACEMENT, fieldNames: [] }
|
dictData[constant.WECOM_BIND_REPLACEMENT].forEach(replacement => {
|
replacementTableDate.fieldNames.push({ label: replacement.label, propName: replacement.value })
|
})
|
// 报销字段绑定信息制作
|
const reimburseTableDate = { name: '报销', fieldTable: constant.WECOM_BIND_REIMBURSE, fieldNames: [] }
|
dictData[constant.WECOM_BIND_REIMBURSE].forEach(reimburse => {
|
reimburseTableDate.fieldNames.push({ label: reimburse.label, propName: reimburse.value })
|
})
|
// 事前出差字段绑定信息制作
|
const preTravelTableDate = { name: '事前出差', fieldTable: constant.WECOM_BIND_PRE_TRAVEL, fieldNames: [] }
|
dictData[constant.WECOM_BIND_PRE_TRAVEL].forEach(preTravel => {
|
preTravelTableDate.fieldNames.push({ label: preTravel.label, propName: preTravel.value })
|
})
|
|
// 填充数据
|
that.tableInfoData.push(leaveTableDate, goOutTableDate, travelTableDate, overtimeTableDate, replacementTableDate, reimburseTableDate, preTravelTableDate)
|
that.queryLoading = false
|
|
// 判断申请审核站点
|
const filterData = dictData[constant.APPROVAL_SITE_TYPE].filter(item => item.value.toLowerCase() === 'wecom')
|
if (filterData.length > 0) {
|
that.approvalSite = 'wecom'
|
}
|
})
|
},
|
methods: {
|
// 更新企微请假类型
|
refreshWecomVacationType() {
|
const that = this
|
that.refreshWecomVacationTypeLoading = true
|
editWecomVacationType().then(() => {
|
that.$message({
|
message: '企微请假类型更新成功',
|
type: 'success',
|
duration: 1500
|
})
|
that.refreshWecomVacationTypeLoading = false
|
}).catch(() => {
|
that.refreshWecomVacationTypeLoading = false
|
})
|
},
|
|
// 执行绑定
|
toBind(data) {
|
const that = this
|
|
// 显示模版绑定弹窗
|
that.bindParam.visible = true
|
// 显示模版绑定Loading
|
that.bindParam.loading = true
|
// 绑定数据赋值
|
that.bindParam.tableData = data
|
|
// 查询模版绑定信息
|
queryByTable({ fieldTable: data.fieldTable }).then(res => {
|
if (res) {
|
// 源数据赋值
|
that.bindParam.originTemplateData = res.template || {}
|
that.bindParam.currentTemplateData = res.template || {}
|
that.bindParam.originTemplateControlFieldData = res.templateControlField || []
|
that.bindParam.currentTemplateControlFieldData = res.templateControlField || []
|
if (res.template) {
|
Vue.set(that.bindParam.data, 'templateId', res.template.templateId)
|
Vue.set(that.bindParam.data, 'templateName', res.template.templateNameZh || res.template.templateNameEn)
|
}
|
res.templateControlField.forEach(i => {
|
Vue.set(that.bindParam.data, `${i.controlId}`, i.fieldName || null)
|
})
|
}
|
|
// 关闭模版绑定Loading
|
that.bindParam.loading = false
|
}).catch(() => {
|
// 关闭模版绑定Loading
|
that.bindParam.loading = false
|
})
|
},
|
|
// 执行绑定
|
doBind() {
|
const that = this
|
that.$refs.form.validate((valid) => {
|
if (!valid) {
|
return
|
}
|
const finalData = []
|
that.bindParam.currentTemplateData.templateControls.forEach(i => {
|
const item = {}
|
item.templateId = that.bindParam.currentTemplateData.id
|
item.controlId = i.id
|
item.fieldTable = that.bindParam.tableData.fieldTable
|
item.fieldName = that.bindParam.data[`${i.id}`] || null
|
finalData.push(item)
|
})
|
|
bind(finalData).then(() => {
|
that.cancelBind()
|
})
|
})
|
},
|
|
// 获取模版信息
|
toQueryTemplate(update = true) {
|
const that = this
|
if (that.bindParam.queryTemplateId === null || that.bindParam.queryTemplateId === '') {
|
return
|
}
|
queryTemplate({ templateId: that.bindParam.queryTemplateId, queryNew: (!!update) }).then(res => {
|
that.bindParam.currentTemplateData = res
|
that.bindParam.currentTemplateControlFieldData = []
|
that.bindParam.data = {
|
templateId: res.templateId,
|
templateName: res.templateNameZh || res.templateNameEn
|
}
|
})
|
},
|
|
// 重置模版信息
|
resetTemplate() {
|
const that = this
|
that.bindParam.currentTemplateData = { ...that.bindParam.originTemplateData }
|
that.bindParam.currentTemplateControlFieldData = { ...that.bindParam.originTemplateControlFieldData }
|
if (that.bindParam.originTemplateData.templateId) {
|
that.bindParam.data['templateId'] = that.bindParam.originTemplateData.templateId
|
that.bindParam.data['templateName'] = that.bindParam.originTemplateData.templateNameZh || that.bindParam.originTemplateData.templateNameEn
|
} else {
|
that.bindParam.data['templateId'] = null
|
that.bindParam.data['templateName'] = null
|
}
|
that.bindParam.originTemplateControlFieldData.forEach(i => {
|
that.bindParam.data[`${i.controlId}`] = i.fieldName
|
})
|
},
|
|
// 清空模板绑定数据
|
clearTemplateBindData() {
|
const that = this
|
that.bindParam.currentTemplateData = {}
|
that.bindParam.currentTemplateControlFieldData = []
|
that.bindParam.originTemplateData = {}
|
that.bindParam.originTemplateControlFieldData = []
|
that.bindParam.queryTemplateId = null
|
that.bindParam.tableData = null
|
that.bindParam.data = {}
|
},
|
|
// 取消模版绑定
|
cancelBind() {
|
const that = this
|
that.bindParam.visible = false
|
that.bindParam.loading = false
|
that.clearTemplateBindData()
|
},
|
|
// 开启更新申请审核站点弹窗
|
showEditApprovalSite() {
|
const that = this
|
that.$set(that.approvalSiteParam.form, 'approvalSite', that.approvalSite)
|
},
|
|
// 隐藏更新申请审核站点弹窗
|
hideEditApprovalSite() {
|
const that = this
|
that.$set(that.approvalSiteParam.form, 'approvalSite', null)
|
},
|
|
// 执行更新申请审核站点
|
doEditApprovalSite() {
|
const that = this
|
const approvalSite = that.approvalSiteParam.form.approvalSite
|
that.approvalSiteParam.loading = true
|
editApprovalSite({ approvalSite: approvalSite }).then(() => {
|
that.$message({
|
message: '申请审核站点更新成功',
|
type: 'success',
|
duration: 1500
|
})
|
that.$set(that, 'approvalSite', approvalSite)
|
that.approvalSiteParam.loading = false
|
}).catch(() => {
|
that.approvalSiteParam.loading = false
|
})
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.query-container {
|
display: flex;
|
flex-direction: row;
|
justify-content: center;
|
align-items: center;
|
gap: 10px;
|
}
|
.popover-footer {
|
display: flex;
|
justify-content: end;
|
}
|
</style>
|