index.vue 6.8 KB

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