index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div class="white" :class="{ 'pa-3': !$attrs.panorama }">
  3. <m-search v-if="!$attrs.panorama" :items="searchItems" v-model="searchValues" class="mb-3" @search="onSearch"></m-search>
  4. <m-table
  5. :cardTitle="cardTitle || undefined"
  6. v-loading="loading"
  7. row-key="id"
  8. :items="items"
  9. :headers="headers"
  10. :page-size="pageInfo.size"
  11. :page-current="pageInfo.current"
  12. :total="total"
  13. :default-sort="{ prop: 'sort', order: 'ascending' }"
  14. @page-change="pageChange"
  15. >
  16. <template #card-tools v-if="!$attrs.panorama">
  17. <m-button type="orange" size="small" icon="el-icon-plus" @click="onAdd">新增</m-button>
  18. <el-upload class="el-button pa-0" action="#" :show-file-list="false" :http-request="onImport">
  19. <m-button type="orange" size="small" icon="el-icon-upload2" :loading="importLoading">上传</m-button>
  20. </el-upload>
  21. <m-button type="orange" size="small" icon="el-icon-download" @click="onExport" :loading="exportLoading">导出</m-button>
  22. <m-button type="orange" size="small" icon="el-icon-download" @click="onDownload" :loading="downloadLoading">下载模板</m-button>
  23. <m-button type="orange" size="small" icon="el-icon-setting" @click="onChange">变更记录</m-button>
  24. </template>
  25. <template #actions="{ row }" v-if="!$attrs.panorama">
  26. <m-button text type="primary" @click="onEdit(row)">编辑</m-button>
  27. <m-button text type="danger" @click="onDelete(row)">删除</m-button>
  28. </template>
  29. </m-table>
  30. <RosterEdit ref="rosterEditRef" :title="title" @refresh="init"></RosterEdit>
  31. <RosterVersion ref="rosterVersionRefs"></RosterVersion>
  32. </div>
  33. </template>
  34. <script>
  35. import { downloadFile } from '@/utils'
  36. import RosterEdit from './rosterEdit.vue'
  37. import RosterVersion from './rosterVersion.vue'
  38. import {
  39. getRosterList,
  40. deleteRoster,
  41. uploadRoster,
  42. exportRoster,
  43. downloadRosterTemplate
  44. } from '@/api/system'
  45. import { mapGetters } from 'vuex'
  46. export default {
  47. name: 'sys-roster',
  48. components: { RosterEdit, RosterVersion },
  49. data () {
  50. return {
  51. importLoading: false,
  52. exportLoading: false,
  53. downloadLoading: false,
  54. title: '',
  55. loading: false,
  56. searchValues: {
  57. employeeName: null
  58. },
  59. itemData: {},
  60. items: [],
  61. orders: [],
  62. pageInfo: {
  63. size: 10,
  64. current: 1
  65. },
  66. total: 0,
  67. cardTitle: null // 用于全景视图显示
  68. }
  69. },
  70. computed: {
  71. ...mapGetters(['organizationTree']),
  72. searchItems () {
  73. return [
  74. {
  75. label: '员工名称',
  76. options: {
  77. placeholder: '请输入员工名称'
  78. },
  79. prop: 'employeeName',
  80. type: 'input'
  81. },
  82. {
  83. label: '部门名称',
  84. options: {
  85. filterable: true,
  86. clearable: true,
  87. placeholder: '请选择部门',
  88. options: this.organizationTree,
  89. showAllLevels: false,
  90. props: {
  91. emitPath: false,
  92. value: 'organizationNo',
  93. label: 'organizationName',
  94. children: 'child'
  95. }
  96. },
  97. prop: 'organizationNo',
  98. type: 'cascader'
  99. }
  100. ]
  101. },
  102. headers () {
  103. const header = [
  104. // { text: '一级机构', align: 'start', value: 'secondLevelBranch' },
  105. { label: '上级机构', prop: 'parentOrganizationName' },
  106. { label: '部门', prop: 'deptName' },
  107. { label: '员工名称', prop: 'employeeName' },
  108. { label: '人员类别', prop: 'personnelCategory' },
  109. { label: '岗位名称', prop: 'postName' },
  110. { label: '岗位序列', prop: 'positionSequence' },
  111. { label: '岗位类别', prop: 'positionCategory' },
  112. { label: '职务层级', prop: 'jobLevel' },
  113. { label: '通行证号', prop: 'passes' },
  114. { label: '工行时间', prop: 'tradeUnionsTimeText' },
  115. { label: '薪酬档次', align: 'center', prop: 'salaryCategory' },
  116. { label: '薪酬级别', align: 'center', prop: 'salaryLevel' }
  117. ]
  118. if (!this.$attrs.panorama) {
  119. header.push({ label: '操作', prop: 'actions' })
  120. }
  121. return header
  122. }
  123. },
  124. created () {
  125. // 全景视图终止自动调用
  126. if (this.$attrs.panorama) {
  127. return
  128. }
  129. this.init()
  130. },
  131. methods: {
  132. // 执行全景初始化操作
  133. onInitPanorama (organizationNo, employeeNo, title) {
  134. this.cardTitle = title
  135. this.panorama = { organizationNo, employeeNo }
  136. if (employeeNo) {
  137. this.searchValues = {
  138. personnelCode: employeeNo
  139. }
  140. } else {
  141. this.searchValues = {
  142. organizationNo: organizationNo
  143. }
  144. }
  145. this.init()
  146. },
  147. async init () {
  148. this.loading = true
  149. const query = {}
  150. if (this.$attrs.panorama) {
  151. if (this.searchValues.personnelCode) {
  152. query.entity = {
  153. personnelCode: this.searchValues.personnelCode
  154. }
  155. }
  156. if (this.searchValues.organizationNo) {
  157. Object.assign(query, {
  158. organizationNo: this.searchValues.organizationNo
  159. })
  160. }
  161. } else {
  162. Object.assign(query, {
  163. entity: this.searchValues
  164. })
  165. }
  166. try {
  167. const { data } = await getRosterList({
  168. page: { ...this.pageInfo, orders: this.orders },
  169. ...query
  170. })
  171. this.items = data.records.map(e => {
  172. const date = new Date(e.tradeUnionsTime)
  173. // 获取年、月、日
  174. const year = date.getFullYear()
  175. const month = String(date.getMonth() + 1).padStart(2, '0') // 月份从0开始,所以要加1
  176. const day = String(date.getDate()).padStart(2, '0')
  177. return {
  178. ...e,
  179. tradeUnionsTimeText: `${year}年${month}月${day}日`
  180. }
  181. })
  182. this.total = data.total
  183. } catch (error) {
  184. this.$message.error(error)
  185. } finally {
  186. this.loading = false
  187. }
  188. },
  189. onSearch () {
  190. this.pageInfo.current = 1
  191. this.init()
  192. },
  193. onAdd () {
  194. this.title = '新增员工'
  195. this.$refs.rosterEditRef.open()
  196. },
  197. onEdit (item) {
  198. this.title = '编辑员工'
  199. this.$refs.rosterEditRef.open(item)
  200. },
  201. onDelete (item) {
  202. this.$confirm('确定删除该员工吗?', '提示').then(async () => {
  203. try {
  204. await deleteRoster({ personnelCode: item.personnelCode, employeeName: item.employeeName })
  205. this.init()
  206. this.$message.success('删除成功')
  207. } catch (error) {
  208. this.$message.error(error)
  209. }
  210. }).catch(() => {})
  211. },
  212. async onImport (response) {
  213. this.importLoading = true
  214. const formData = new FormData()
  215. formData.append('file', response.file)
  216. try {
  217. await uploadRoster(formData)
  218. this.$message.success('导入成功')
  219. this.init()
  220. } catch (error) {
  221. this.$message.error(error)
  222. } finally {
  223. this.importLoading = false
  224. }
  225. },
  226. async onExport () {
  227. this.exportLoading = true
  228. try {
  229. const { data, name } = await exportRoster()
  230. downloadFile(data, name)
  231. } catch (error) {
  232. this.$message.error(error)
  233. } finally {
  234. this.exportLoading = false
  235. }
  236. },
  237. async onDownload () {
  238. this.downloadLoading = true
  239. try {
  240. const { data, name } = await downloadRosterTemplate()
  241. downloadFile(data, name)
  242. } catch (error) {
  243. this.$message.error(error)
  244. } finally {
  245. this.downloadLoading = false
  246. }
  247. },
  248. pageChange (index) {
  249. this.pageInfo.current = index
  250. this.init()
  251. },
  252. onChange () {
  253. this.$refs.rosterVersionRefs.open(this.headers.slice(0, -1))
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. </style>