edit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <template>
  2. <el-dialog :title="title" :visible.sync="dialogVisible" :close-on-click-modal="false" :close-on-press-escape="false" append-to-body class="bpmn-agent-dialog" width="80%" top="10vh" @open="getFormData" @close="closeDialog">
  3. <el-form ref="agentForm" v-loading="dialogLoading" :element-loading-text="$t('common.loading')" :model="bpmAgent" :rules="rules" :label-width="formLabelWidth" @submit.native.prevent>
  4. <el-image style="width: 400px; height: 500px; margin-left: 100px" :src="url" :preview-src-list="srcList"> </el-image>
  5. <el-form-item label="标题:" prop="title">
  6. <el-input v-if="!readonly" v-model="bpmAgent.title" />
  7. <span v-else>{{ bpmAgent.title }}</span>
  8. </el-form-item>
  9. <el-row>
  10. <el-col :span="12" col>
  11. <el-form-item label="代理类型:" prop="agentType">
  12. <el-radio-group v-if="!readonly" v-model="bpmAgent.agentType">
  13. <el-radio v-for="option in agentTypeOptions" :key="option.value" :label="option.value">{{ option.label }}</el-radio>
  14. </el-radio-group>
  15. <el-tag v-else :type="bpmAgent.agentType | optionsFilter(agentTypeOptions, 'type')">{{ bpmAgent.agentType | optionsFilter(agentTypeOptions, 'label') }}</el-tag>
  16. </el-form-item>
  17. </el-col>
  18. <el-col :span="12" col>
  19. <el-form-item label="是否启用:" prop="isEnabled">
  20. <el-switch v-if="!readonly" v-model="bpmAgent.isEnabled" active-value="enabled" inactive-value="disabled" />
  21. <el-tag v-else :type="bpmAgent.isEnabled | optionsFilter(statusOptions, 'type')">{{ bpmAgent.isEnabled | optionsFilter(statusOptions, 'label') }}</el-tag>
  22. </el-form-item>
  23. </el-col>
  24. </el-row>
  25. <el-form-item label="委托人:" prop="delegatorId">
  26. <ibps-employee-selector v-if="!readonly" v-model="bpmAgent.delegatorId" :customPartyTypeOptions="customPartyTypeOptions" @callback="callbackDelegatorrInfo" />
  27. <span v-else>{{ bpmAgent.delegatorName }}</span>
  28. </el-form-item>
  29. <el-row>
  30. <el-col :span="12" col>
  31. <el-form-item label="生效时间:" prop="effectiveTime">
  32. <el-date-picker v-if="!readonly" v-model="bpmAgent.effectiveTime" type="date" value-format="yyyy-MM-dd" style="width:100%;" />
  33. <span v-else>{{ bpmAgent.effectiveTime }}</span>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="12" col>
  37. <el-form-item label="失效时间:" prop="expiryTime">
  38. <el-date-picker v-if="!readonly" v-model="bpmAgent.expiryTime" type="date" value-format="yyyy-MM-dd" style="width:100%;" />
  39. <span v-else>{{ bpmAgent.expiryTime }}</span>
  40. </el-form-item>
  41. </el-col>
  42. </el-row>
  43. <!-- 全部代理 || 部分代理 -->
  44. <el-form-item v-if="bpmAgent.agentType === 'all' || bpmAgent.agentType === 'part'" label="代理人:" prop="agenterId">
  45. <ibps-employee-selector v-if="!readonly" v-model="bpmAgent.agenterId" :customPartyTypeOptions="customPartyTypeOptions" @callback="callbackAgenterInfo" />
  46. <span v-else>{{ bpmAgent.agenterName }}</span>
  47. </el-form-item>
  48. <div v-if="bpmAgent.agentType === 'part'">
  49. <el-form-item label="流程定义">
  50. <div v-if="!readonly" class="dialog-right">
  51. <bpm-definition-selector button multiple @callback="updateDefine" />
  52. <el-button class="ibps-icon-remove ibps-ml-10" type="danger" @click="handleAllDelete(multipleSelection)">删除</el-button>
  53. </div>
  54. </el-form-item>
  55. <el-form-item v-loading="rowLoading" label-width="20px" :element-loading-text="$t('common.loading')">
  56. <el-table ref="multipleTable" border :data="bpmAgent.bpmAgentDefPoList" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
  57. <el-table-column v-if="!readonly" type="selection" width="45" />
  58. <el-table-column label="流程名称">
  59. <template slot-scope="scope">{{ scope.row.procDefName ? scope.row.procDefName : scope.row.name }}</template>
  60. </el-table-column>
  61. <el-table-column v-if="!readonly" label="操作" width="55">
  62. <template slot-scope="scope">
  63. <el-button type="danger" icon="el-icon-delete" circle @click="handleDelete(scope.$index, scope.row)" />
  64. </template>
  65. </el-table-column>
  66. </el-table>
  67. </el-form-item>
  68. </div>
  69. <!-- 条件代理 -->
  70. <div v-if="bpmAgent.agentType === 'condition'">
  71. <el-form-item label="流程名称:">
  72. <bpm-definition-selector v-model="bpmAgent.procDefId" :disabled="readonly" />
  73. </el-form-item>
  74. <el-form-item label="流程代理条件">
  75. <div v-if="!readonly" class="dialog-right">
  76. <el-button class="ibps-icon-add" type="primary" @click="openConditionDialog">添加</el-button>
  77. <el-button class="ibps-icon-remove ibps-ml-5" type="danger">删除</el-button>
  78. </div>
  79. </el-form-item>
  80. <el-form-item v-loading="rowLoading" label-width="20px" :element-loading-text="$t('common.loading')">
  81. <el-table ref="multipleTable" :data="bpmAgent.bpmAgentConditionPoList" tooltip-effect="dark" style="width: 100%" @selection-change="handleConditionChange">
  82. <el-table-column type="selection" width="55" />
  83. <el-table-column label="代理人">
  84. <template slot-scope="scope">{{ scope.row.agenterName }}</template>
  85. </el-table-column>
  86. <el-table-column label="条件名称">
  87. <template slot-scope="scope">{{ scope.row.name }}</template>
  88. </el-table-column>
  89. <el-table-column prop="address" label="管理" width="100px" show-overflow-tooltip>
  90. <el-button type="primary" icon="el-icon-edit" circle @click="handleEdit(scope.$index, scope.row)" />
  91. <el-button type="danger" icon="el-icon-delete" circle @click="handleRemove(scope.$index, scope.row)" />
  92. </el-table-column>
  93. </el-table>
  94. </el-form-item>
  95. </div>
  96. </el-form>
  97. <div slot="footer" class="el-dialog--center">
  98. <ibps-toolbar :actions="toolbars" @action-event="handleActionEvent" />
  99. </div>
  100. <!-- 添加规则弹窗 -->
  101. <condition :def-id="bpmAgent.procDefId" :visible="conditionDialogVisible" @callback="callbackBpmAgentConditionPoList" @close="(visible) => (conditionDialogVisible = visible)" />
  102. </el-dialog>
  103. </template>
  104. <script>
  105. import { save, get } from '@/api/platform/bpmn/bpmAgent'
  106. import { agentTypeOptions, statusOptions } from './constants'
  107. import ActionUtils from '@/utils/action'
  108. import IbpsEmployeeSelector from '@/business/platform/org/employee/selector'
  109. import BpmDefinitionSelector from '@/business/platform/bpmn/definition/selector'
  110. import curdPost from '@/business/platform/form/utils/custom/joinCURD.js'
  111. import Condition from './condition'
  112. import { setTimeout } from 'timers'
  113. export default {
  114. components: {
  115. IbpsEmployeeSelector,
  116. BpmDefinitionSelector,
  117. Condition
  118. },
  119. props: {
  120. visible: {
  121. type: Boolean,
  122. default: false
  123. },
  124. readonly: {
  125. type: Boolean,
  126. default: false
  127. },
  128. id: String,
  129. title: String
  130. },
  131. data() {
  132. return {
  133. formName: 'agentForm',
  134. formLabelWidth: '120px',
  135. dialogVisible: this.visible,
  136. conditionDialogVisible: false, // 条件规则界面
  137. dialogLoading: false,
  138. rowLoading: false,
  139. statusOptions: statusOptions,
  140. agentTypeOptions: agentTypeOptions,
  141. defaultForm: {},
  142. multipleSelection: [],
  143. conditionSelection: [],
  144. bpmAgent: {
  145. title: '',
  146. procDefId: '',
  147. procDefKey: '',
  148. delegatorId: this.$store.getters.userId,
  149. delegatorName: this.$store.getters.name,
  150. effectiveTime: '',
  151. expiryTime: '',
  152. agenterId: '',
  153. agenterName: '',
  154. agentType: 'all',
  155. isEnabled: 'enabled',
  156. bpmAgentDefPoList: [],
  157. bpmAgentConditionPoList: []
  158. },
  159. rules: {
  160. title: [
  161. { required: true, message: this.$t('validate.required') },
  162. { min: 1, max: 64, message: '长度不能超过64个字符', trigger: 'blur' }
  163. ],
  164. delegatorId: [{ required: true, message: this.$t('validate.required') }],
  165. agenterId: [{ required: true, message: this.$t('validate.required') }],
  166. effectiveTime: [{ required: true, message: this.$t('validate.required') }],
  167. expiryTime: [{ required: true, message: this.$t('validate.required') }]
  168. },
  169. toolbars: [
  170. {
  171. key: 'save',
  172. hidden: () => {
  173. return this.readonly
  174. }
  175. },
  176. { key: 'cancel' }
  177. ],
  178. url: '',
  179. srcList: [],
  180. customPartyTypeOptions: [{
  181. label: "岗位",
  182. value: "position"
  183. }]
  184. }
  185. },
  186. computed: {
  187. formId() {
  188. return this.id
  189. }
  190. },
  191. watch: {
  192. visible: {
  193. handler: function (val, oldVal) {
  194. this.dialogVisible = this.visible
  195. },
  196. immediate: true
  197. }
  198. },
  199. created() {
  200. this.defaultForm = JSON.parse(JSON.stringify(this.bpmAgent))
  201. this.getImage()
  202. },
  203. mounted() {
  204. this.$nextTick(() => {
  205. if (this.$refs.multipleTable) {
  206. this.$refs.multipleTable.doLayout()
  207. }
  208. })
  209. },
  210. methods: {
  211. handleEdit() {
  212. this.rowLoading = true
  213. setTimeout(() => {
  214. this.rowLoading = false
  215. // TODO:
  216. })
  217. },
  218. handleRemove() {
  219. this.rowLoading = true
  220. setTimeout(() => {
  221. this.rowLoading = false
  222. // TODO:
  223. })
  224. },
  225. callbackBpmAgentConditionPoList(data) {
  226. console.log(data)
  227. },
  228. handleDelete(index, arr) {
  229. this.rowLoading = true
  230. setTimeout(() => {
  231. if (arr !== []) {
  232. this.bpmAgent.bpmAgentDefPoList.splice(index, 1)
  233. } else {
  234. arr.forEach((i) => {
  235. this.bpmAgent.bpmAgentDefPoList.forEach((l) => {
  236. if (i.procDefKey === l.procDefKey) {
  237. this.bpmAgent.bpmAgentDefPoList.splice(l, 1)
  238. }
  239. })
  240. })
  241. }
  242. this.rowLoading = false
  243. })
  244. },
  245. handleAllDelete(arr) {
  246. this.rowLoading = true
  247. setTimeout(() => {
  248. if (!this.$utils.isEmpty(arr)) {
  249. arr.forEach((i) => {
  250. this.bpmAgent.bpmAgentDefPoList.forEach((l) => {
  251. if (i.procDefKey === l.procDefKey) {
  252. this.bpmAgent.bpmAgentDefPoList.splice(l, 1)
  253. }
  254. })
  255. })
  256. }
  257. this.rowLoading = false
  258. })
  259. },
  260. handleSelectionChange(val) {
  261. this.multipleSelection = val
  262. },
  263. handleConditionChange(val) {
  264. this.conditionSelection = val
  265. },
  266. handleActionEvent({ key }) {
  267. switch (key) {
  268. case 'save':
  269. this.handleSave()
  270. break
  271. case 'cancel':
  272. this.closeDialog()
  273. break
  274. default:
  275. break
  276. }
  277. },
  278. // 保存数据
  279. handleSave() {
  280. this.$refs[this.formName].validate((valid) => {
  281. if (valid) {
  282. this.saveData()
  283. } else {
  284. ActionUtils.saveErrorMessage()
  285. }
  286. })
  287. },
  288. // 提交保存数据
  289. saveData() {
  290. const data = JSON.parse(JSON.stringify(this.bpmAgent))
  291. data.effectiveTime = new Date(this.bpmAgent.effectiveTime).getTime() || ''
  292. data.expiryTime = new Date(this.bpmAgent.expiryTime).getTime() || ''
  293. // 检测生效时间日期是否发布日期在之前。
  294. if (data.effectiveTime > data.expiryTime) {
  295. ActionUtils.error('生效时间与失效时间范围不合法!')
  296. return
  297. }
  298. if (this.$utils.isEmpty(this.bpmAgent.bpmAgentDefPoList) && this.bpmAgent.agentType === 'part') {
  299. ActionUtils.error('流程定义数据不能为空!')
  300. return
  301. }
  302. save(this.bpmAgent)
  303. .then((response) => {
  304. this.$emit('callback', this)
  305. ActionUtils.saveSuccessMessage(response.message, (rtn) => {
  306. if (this.$utils.isEmpty(this.formId)) {
  307. this.$refs[this.formName].resetFields()
  308. }
  309. if (rtn) {
  310. this.closeDialog()
  311. }
  312. })
  313. })
  314. .catch((err) => {
  315. console.error(err)
  316. })
  317. },
  318. // 关闭当前窗口
  319. closeDialog() {
  320. this.$emit('close', false)
  321. this.$refs[this.formName].resetFields()
  322. },
  323. /**
  324. * 表单验证
  325. */
  326. formValidate() {
  327. if (this.readonly) return
  328. this.$nextTick(() => {
  329. this.$refs[this.formName].validate(() => {})
  330. })
  331. },
  332. /**
  333. * 获取表单数据
  334. */
  335. getFormData() {
  336. if (this.$utils.isEmpty(this.formId)) {
  337. // 重置表单
  338. this.bpmAgent = JSON.parse(JSON.stringify(this.defaultForm))
  339. this.formValidate()
  340. return
  341. }
  342. this.dialogLoading = true
  343. get({
  344. id: this.formId
  345. })
  346. .then((response) => {
  347. this.bpmAgent = response.data
  348. console.log(this.bpmAgent)
  349. this.formValidate()
  350. this.dialogLoading = false
  351. })
  352. .catch(() => {
  353. this.dialogLoading = false
  354. })
  355. },
  356. addDef() {
  357. alert('打开流程选择器')
  358. },
  359. callbackDelegatorrInfo(data) {
  360. this.bpmAgent.delegatorName = data.name
  361. },
  362. callbackAgenterInfo(data) {
  363. this.bpmAgent.agenterName = data.name
  364. },
  365. updateDefine(data) {
  366. this.rowLoading = true
  367. const arr = data.map((item) => {
  368. return {
  369. id: '',
  370. agentId: '',
  371. procDefKey: item.defKey,
  372. nodeId: '',
  373. name: item.name
  374. }
  375. })
  376. setTimeout(() => {
  377. if (this.$utils.isEmpty(this.bpmAgent.bpmAgentDefPoList)) {
  378. this.bpmAgent.bpmAgentDefPoList = arr
  379. } else {
  380. this.bpmAgent.bpmAgentDefPoList = this.bpmAgent.bpmAgentDefPoList.concat(arr)
  381. }
  382. this.rowLoading = false
  383. })
  384. },
  385. openConditionDialog() {
  386. if (this.$utils.isEmpty(this.bpmAgent.procDefId)) {
  387. ActionUtils.warning('请选择流程!!')
  388. return
  389. }
  390. this.conditionDialogVisible = true
  391. },
  392. getImage() {
  393. let sql = `select * from t_dlpz order by create_time_ desc LIMIT 1`
  394. curdPost('sql', sql).then((res) => {
  395. if (res.state == 200) {
  396. let datas = res.variables.data
  397. let image = JSON.parse(datas[0].tu_pian_)
  398. let id = image[0].id
  399. this.getUrl(id)
  400. }
  401. })
  402. },
  403. getUrl(id) {
  404. let sql1 = `select nei_rong_ from t_ipcc where id_ = '1'`
  405. let sql2 = `select FILE_PATH_ from ibps_file_attachment where ID_ = '${id}'`
  406. Promise.all([curdPost('sql', sql1), curdPost('sql', sql2)]).then(([res1, res2]) => {
  407. if (res1.state == 200 && res2.state == 200) {
  408. let datas1 = res1.variables.data
  409. let datas2 = res2.variables.data
  410. let ip = datas1[0].nei_rong_
  411. let image = datas2[0].FILE_PATH_
  412. this.url = ip + '/' + image
  413. this.srcList[0] = this.url
  414. }
  415. })
  416. }
  417. }
  418. }
  419. </script>
  420. <style lang="scss">
  421. .bpmn-agent-dialog {
  422. .el-dialog__body {
  423. height: calc(70vh - 110px) !important;
  424. }
  425. .dialog-right {
  426. float: right;
  427. div {
  428. display: inline-block;
  429. }
  430. }
  431. }
  432. </style>
  433. <style scoped>
  434. .imageListClass {
  435. display: flex;
  436. justify-content: center;
  437. }
  438. </style>