index.vue 6.1 KB

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