index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div>
  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" @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" :loading="importLoading">上传</m-button>
  8. </el-upload>
  9. <m-button type="primary" icon="el-icon-download" @click="onExport" :loading="exportLoading">导出</m-button>
  10. <m-button type="primary" icon="el-icon-download" @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. importLoading: false,
  48. exportLoading: false,
  49. downloadLoading: false,
  50. title: '',
  51. searchItems: [
  52. {
  53. label: '员工名称',
  54. option: {
  55. placeholder: '请输入员工名称'
  56. },
  57. prop: 'employeeName',
  58. type: 'input'
  59. },
  60. {
  61. label: '机构名称',
  62. option: {
  63. placeholder: '请输入机构名称'
  64. },
  65. prop: 'organizationName',
  66. type: 'input'
  67. }
  68. ],
  69. loading: false,
  70. searchValues: {
  71. employeeName: null
  72. },
  73. headers: [
  74. // { text: '一级机构', align: 'start', value: 'secondLevelBranch' },
  75. { label: '上级机构', prop: 'parentOrganizationName' },
  76. { label: '部门', prop: 'deptName' },
  77. { label: '员工名称', prop: 'employeeName' },
  78. { label: '人员类别', prop: 'personnelCategory' },
  79. { label: '岗位名称', prop: 'postName' },
  80. { label: '岗位序列', prop: 'positionSequence' },
  81. { label: '岗位类别', prop: 'positionCategory' },
  82. { label: '职务层级', prop: 'jobLevel' },
  83. { label: '通行证号', prop: 'passes' },
  84. { label: '工行时间', prop: 'tradeUnionsTimeText' },
  85. { label: '薪酬档次', align: 'center', prop: 'salaryCategory' },
  86. { label: '薪酬级别', align: 'center', prop: 'salaryLevel' },
  87. { label: '操作', prop: 'actions' }
  88. ],
  89. itemData: {},
  90. items: [],
  91. orders: [],
  92. pageInfo: {
  93. size: 10,
  94. current: 1
  95. },
  96. total: 0
  97. }
  98. },
  99. created () {
  100. this.init()
  101. },
  102. methods: {
  103. async init () {
  104. this.loading = true
  105. try {
  106. const { data } = await getRosterList({
  107. page: { ...this.pageInfo, orders: this.orders },
  108. entity: {
  109. ...this.searchValues
  110. }
  111. })
  112. this.items = data.records.map(e => {
  113. const date = new Date(e.tradeUnionsTime)
  114. // 获取年、月、日
  115. const year = date.getFullYear()
  116. const month = String(date.getMonth() + 1).padStart(2, '0') // 月份从0开始,所以要加1
  117. const day = String(date.getDate()).padStart(2, '0')
  118. return {
  119. ...e,
  120. tradeUnionsTimeText: `${year}${month}${day}`
  121. }
  122. })
  123. this.total = data.total
  124. } catch (error) {
  125. this.$message.error(error)
  126. } finally {
  127. this.loading = false
  128. }
  129. },
  130. onSearch () {
  131. this.pageInfo.current = 1
  132. this.init()
  133. },
  134. onAdd () {
  135. this.title = '新增员工'
  136. this.$refs.rosterEditRef.open()
  137. },
  138. onEdit (item) {
  139. this.title = '编辑员工'
  140. this.$refs.rosterEditRef.open(item)
  141. },
  142. onDelete (item) {
  143. this.$confirm('确定删除该员工吗?', '提示', {
  144. confirmButtonText: '确定',
  145. cancelButtonText: '取消',
  146. type: 'warning'
  147. }).then(async () => {
  148. try {
  149. await deleteRoster({ personnelCode: item.personnelCode })
  150. this.init()
  151. this.$message.success('删除成功')
  152. } catch (error) {
  153. this.$message.error(error)
  154. }
  155. }).catch(() => {})
  156. },
  157. async onImport (response) {
  158. this.importLoading = true
  159. const formData = new FormData()
  160. formData.append('file', response.file)
  161. try {
  162. await uploadRoster(formData)
  163. this.$message.success('导入成功')
  164. this.init()
  165. } catch (error) {
  166. this.$message.error(error)
  167. } finally {
  168. this.importLoading = false
  169. }
  170. },
  171. async onExport () {
  172. this.exportLoading = true
  173. try {
  174. const { data, name } = await exportRoster()
  175. downloadFile(data, name)
  176. } catch (error) {
  177. this.$message.error(error)
  178. } finally {
  179. this.exportLoading = false
  180. }
  181. },
  182. async onDownload () {
  183. this.downloadLoading = true
  184. try {
  185. const { data, name } = await downloadRosterTemplate()
  186. downloadFile(data, name)
  187. } catch (error) {
  188. this.$message.error(error)
  189. } finally {
  190. this.downloadLoading = false
  191. }
  192. },
  193. pageChange (index) {
  194. this.pageInfo.current = index
  195. this.init()
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. </style>