adjust.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <div class="main-container">
  3. <ibps-crud
  4. ref="crud"
  5. :display-field="title"
  6. :height="height"
  7. :data="listData"
  8. :toolbars="listConfig.toolbars"
  9. :search-form="listConfig.searchForm"
  10. :pk-key="pkKey"
  11. :columns="listConfig.columns"
  12. :row-handle="listConfig.rowHandle"
  13. :pagination="pagination"
  14. :loading="loading"
  15. @action-event="handleAction"
  16. @sort-change="handleSortChange"
  17. @pagination-change="handlePaginationChange"
  18. @row-dblclick="handleRowDblclick"
  19. >
  20. <template slot="dateRange" slot-scope="scope">
  21. <span>{{ `${scope.row.startDate} 至 ${scope.row.endDate}` }}</span>
  22. </template>
  23. <template slot="partys" slot-scope="scope">
  24. <span v-for="party in scope.row.partys" :key="party.value">
  25. <span v-if="party.value !== scope.row.createBy" :class="getTagClass(party)" class="el-tag el-tag--small el-tag--light" style="margin-left: 5px;">{{ party.label }}</span>
  26. </span>
  27. </template>
  28. </ibps-crud>
  29. <adjust-edit
  30. v-if="showAdjustEdit"
  31. :visible.sync="showAdjustEdit"
  32. :params="params"
  33. :readonly="readonly"
  34. @refresh="loadData"
  35. @close="() => showAdjustEdit = false"
  36. />
  37. </div>
  38. </template>
  39. <script>
  40. import { queryAdjustment, removeAdjustment, sendMessage, saveAdjustment } from '@/api/business/schedule'
  41. import { stateType } from '@/views/constants/schedule'
  42. import ActionUtils from '@/utils/action'
  43. import FixHeight from '@/mixins/height'
  44. export default {
  45. components: {
  46. AdjustEdit: () => import('./components/adjust-edit')
  47. },
  48. mixins: [FixHeight],
  49. data () {
  50. const { userList = [] } = this.$store.getters || {}
  51. const userOption = userList.map(item => ({ label: item.userName, value: item.userId }))
  52. return {
  53. userOption,
  54. stateType,
  55. title: '调班申请记录',
  56. pkKey: 'id', // 主键 如果主键不是pk需要传主键
  57. loading: true,
  58. height: document.clientHeight,
  59. listData: [],
  60. pagination: {},
  61. sorts: {},
  62. showAdjustEdit: false,
  63. readonly: false,
  64. params: {},
  65. listConfig: {
  66. toolbars: [
  67. { key: 'search', icon: 'ibps-icon-search', label: '查询', type: 'primary', hidden: false },
  68. { key: 'create', icon: 'ibps-icon-plus', label: '申请', type: 'success', hidden: false },
  69. { key: 'remove', icon: 'ibps-icon-close', label: '删除', type: 'danger', hidden: !this.isRoleFilter() }
  70. ],
  71. searchForm: {
  72. labelWidth: 80,
  73. itemWidth: 180,
  74. forms: [
  75. { prop: 'Q^reason_^SL', label: '调班原因' },
  76. { prop: 'Q^status^S', label: '状态', fieldType: 'select', options: stateType },
  77. { prop: ['Q^create_time_^DL', 'Q^create_time_^DG'], label: '申请时间', fieldType: 'daterange', itemWidth: 200 }
  78. ]
  79. },
  80. // 表格字段配置
  81. columns: [
  82. { prop: 'createBy', label: '申请人', tags: userOption, width: 100 },
  83. { prop: 'createTime', label: '申请时间', dateFormat: 'yyyy-MM-dd HH:mm', sortable: 'custom', width: 140 },
  84. { prop: 'partys', label: '审核人', fieldType: 'slot', slotName: 'partys', minWidth: 120 },
  85. { prop: 'executor', label: '审批人', tags: userOption, dataType: 'stringArray', separator: ',', minWidth: 120 },
  86. { prop: 'executeDate', label: '审批时间', dateFormat: 'yyyy-MM-dd HH:mm', sortable: 'custom', width: 140 },
  87. { prop: 'reason', label: '调班原因', width: 150 },
  88. { prop: 'status', label: '状态', tags: stateType, width: 100 },
  89. { prop: 'overview', label: '概览', minWidth: 200 }
  90. ],
  91. rowHandle: {
  92. effect: 'default',
  93. // effect: 'display',
  94. actions: [
  95. { key: 'edit', label: '编辑', type: 'primary', icon: 'ibps-icon-edit', hidden: function (row) { return row.status !== '已暂存' && row.status !== '已取消' } },
  96. { key: 'cancel', label: '取消', type: 'danger', icon: 'ibps-icon-cancel', hidden: function (row) { return !(row.status === '待审核' && row.createBy === this.$store.getters.userId) } },
  97. { key: 'edit', label: '再次申请', type: 'primary', icon: 'ibps-icon-edit', hidden: function (row) { return row.status !== '已拒绝' } },
  98. { key: 'detail', label: '详情', type: 'primary', icon: 'ibps-icon-list-alt' }
  99. ]
  100. }
  101. }
  102. }
  103. },
  104. created () {
  105. this.loadData()
  106. },
  107. methods: {
  108. // 加载数据
  109. loadData () {
  110. this.loading = true
  111. queryAdjustment(this.getSearchFormData()).then(res => {
  112. ActionUtils.handleListData(this, res.data)
  113. // 处理审核人数据
  114. res.data.dataResult.forEach((el) => {
  115. el.partys = this.getPartysList(el.adjustmentDetailPoList)
  116. })
  117. this.loading = false
  118. }).catch(() => {
  119. this.loading = false
  120. })
  121. },
  122. /**
  123. * 判断当前用户是否为超级管理员和高权限角色
  124. */
  125. isRoleFilter () {
  126. const highRoles = this.$store.getters.userInfo.highRoles || [] // 高权限角色
  127. const userRole = this.$store.getters.userInfo.role || [] // 用户权限角色
  128. let isHighRole = false
  129. userRole.forEach(el => {
  130. const roleAlias = el.alias
  131. if (highRoles.includes(roleAlias)) {
  132. isHighRole = true
  133. }
  134. })
  135. return (this.$store.getters.isSuper || isHighRole)
  136. },
  137. /**
  138. * 获取格式化参数
  139. */
  140. getSearchFormData () {
  141. const paramjson = this.$refs['crud'] ? this.$refs['crud'].getSearcFormData() : {}
  142. if (this.isRoleFilter()) { // 超级管理员和高权限角色不做申请人过滤
  143. } else {
  144. const { userId } = this.$store.getters || ''
  145. if (userId) {
  146. paramjson['Q^create_By_^S'] = userId
  147. }
  148. }
  149. const { first, second } = this.$store.getters.level || {}
  150. paramjson['Q^di_dian_^S'] = (second || first)
  151. return ActionUtils.formatParams(
  152. // this.$refs['crud'] ? this.$refs['crud'].getSearcFormData() : {},
  153. paramjson,
  154. this.pagination,
  155. this.sorts
  156. )
  157. },
  158. /**
  159. * 处理审核人数据
  160. */
  161. getPartysList (poList) {
  162. const self = this
  163. const result = poList.reduce((acc, currentItem) => {
  164. const existing = acc.find(item => item.value === currentItem.party)
  165. if (!existing) {
  166. acc.push({
  167. value: currentItem.party,
  168. status: currentItem.status,
  169. label: (self.userOption.filter(o => o.value === currentItem.party))[0].label,
  170. type: 'success'
  171. })
  172. }
  173. return acc
  174. }, [])
  175. return result
  176. },
  177. /**
  178. * 处理审核人样式
  179. */
  180. getTagClass (party) {
  181. switch (party.status) {
  182. case '已通过':
  183. return 'el-tag--success'
  184. case '已拒绝':
  185. return 'el-tag--danger'
  186. case '待审核':
  187. return 'el-tag--primary'
  188. default:
  189. return 'el-tag--primary'
  190. }
  191. },
  192. /**
  193. * 处理分页事件
  194. */
  195. handlePaginationChange (page) {
  196. ActionUtils.setPagination(this.pagination, page)
  197. this.loadData()
  198. },
  199. /**
  200. * 处理排序
  201. */
  202. handleSortChange (sort) {
  203. ActionUtils.setSorts(this.sorts, sort)
  204. this.loadData()
  205. },
  206. /**
  207. * 查询
  208. */
  209. search () {
  210. this.loadData()
  211. },
  212. /**
  213. * 处理按钮事件
  214. */
  215. handleAction (command, position, selection, data) {
  216. switch (command) {
  217. case 'search':
  218. ActionUtils.setFirstPagination(this.pagination)
  219. this.search()
  220. break
  221. case 'create':
  222. this.handleEdit(command, {})
  223. break
  224. case 'edit':
  225. this.handleEdit(command, data)
  226. break
  227. case 'cancel':
  228. this.handleCancel(data)
  229. break
  230. case 'detail':
  231. this.handleEdit(command, data)
  232. break
  233. case 'remove':
  234. ActionUtils.removeRecord(selection).then((ids) => {
  235. this.handleRemove(ids)
  236. }).catch(() => {})
  237. break
  238. default:
  239. break
  240. }
  241. },
  242. /**
  243. * 处理编辑
  244. */
  245. async handleEdit (key, { id, scheduleId }) {
  246. this.params = {
  247. id,
  248. scheduleId,
  249. action: key === 'detail' ? 'view' : 'edit'
  250. }
  251. this.readonly = key === 'detail'
  252. this.showAdjustEdit = true
  253. },
  254. /**
  255. * 处理取消
  256. */
  257. async handleCancel (data) {
  258. data.status = '已取消'
  259. // 改为通用接口
  260. const tableName = 't_adjustment'
  261. const updateParams = {
  262. tableName,
  263. updList: [
  264. {
  265. where: {
  266. id_: data.id
  267. },
  268. param: {
  269. status: data.status
  270. }
  271. }]
  272. }
  273. this.$common.request('update', updateParams).then(async () => {
  274. const sonTableName = 't_adjustment_detail'
  275. const sonUpdateParams = {
  276. tableName: sonTableName,
  277. updList: [
  278. {
  279. where: {
  280. parent_id_: data.id
  281. },
  282. param: {
  283. status_: data.status
  284. }
  285. }]
  286. }
  287. // 更新子表
  288. this.$common.request('update', sonUpdateParams).then(() => {
  289. ActionUtils.successMessage()
  290. this.search()
  291. // 告知审核人该单已取消(除非是自己的排版变更取消)
  292. if (data.dbType !== 'paiban') {
  293. data.adjustmentDetailPoList.forEach((el) => { // 遍历子表提取审核人字段
  294. sendMessage(data, el.party)
  295. })
  296. }
  297. }).catch((e) => { console.error(e) })
  298. }).catch((e) => { console.error(e) })
  299. },
  300. /**
  301. * 处理删除
  302. */
  303. handleRemove (ids) {
  304. // return this.$message.warning('避免误删测试数据,联系开发删除')
  305. removeAdjustment({ ids }).then(() => {
  306. ActionUtils.removeSuccessMessage()
  307. this.search()
  308. }).catch(() => {})
  309. },
  310. handleRowDblclick (row) {
  311. // this.handleEdit(row, 'detail')
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss">
  317. </style>