importExcel.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div>
  3. <import-table
  4. :visible="showImportTable"
  5. title="导入签到人员"
  6. @close="() => (showImportTable = false)"
  7. @action-event="handleImport"
  8. />
  9. </div>
  10. </template>
  11. <script>
  12. import IbpsImport from '@/plugins/import'
  13. export default {
  14. name: 'importData',
  15. props: {
  16. params: {
  17. type: Object,
  18. default: () => {
  19. return {}
  20. }
  21. },
  22. },
  23. components: { ImportTable: () => import('@/business/platform/form/formrender/dynamic-form/components/import-table') },
  24. data() {
  25. return {
  26. showImportTable: true,
  27. userList: [],
  28. }
  29. },
  30. mounted() {
  31. this.$common.request('query', {
  32. key: 'hqsyyhsj',
  33. params: [null]
  34. }).then(res => {
  35. this.userList = res.variables.data
  36. })
  37. },
  38. methods: {
  39. async handleImport(file, options) {
  40. this.loading = false
  41. IbpsImport.xlsx(file, options).then(async ({ header, results }) => {
  42. const keys = this.getKeys(this.getColumns())
  43. const list = []
  44. results.forEach((item) => {
  45. const obj = {}
  46. Object.keys(item).forEach((key) => {
  47. if (keys[key]) {
  48. obj[keys[key]] = item[key]
  49. }
  50. })
  51. list.push(obj)
  52. })
  53. // const keysValue = Object.values(keys)
  54. // const isError = list.some((item) => keysValue.some((key) => !item[key]))
  55. // if (isError || !list.length) {
  56. // return this.$message.warning(
  57. // '导出模板中的每一项都需填写,请检查您的数据!'
  58. // )
  59. // }
  60. // const dateRegex = /^(\d{4})[-/](\d{2})(?:[-/](\d{2}))?$/
  61. // const isDateError = list.some((item) => {
  62. // return !dateRegex.test(item.qian_dao_shi_jian)
  63. // })
  64. // if (isDateError) {
  65. // return this.$message.warning(
  66. // '有效期格式支持【2026-01】、【2026/01】、【2026-01-01】、【2026/01/01】,请检查您的数据!'
  67. // )
  68. // }
  69. const userMap = new Map();
  70. this.userList.forEach(user => {
  71. const key = `${user.NAME_}|${user.jian_ding_zi_ge_z}`;
  72. userMap.set(key, user.ID_);
  73. });
  74. list.forEach(item => {
  75. item.qian_dao_shi_jian = item.qian_dao_shi_jian.replace(/\//g, '-')
  76. item.guan_lian_id_ = this.params.guan_lian_id_
  77. item.qian_dao_lei_xing = '导入'
  78. item.ye_wu_biao_ming_ = 't_lhrypxjlb'
  79. const key = `${item.xingMing}|${item.gongHao}`;
  80. if (userMap.has(key)) {
  81. item.ren_yuan_id_ = userMap.get(key);
  82. } else {
  83. item.ren_yuan_id_ = null;
  84. }
  85. delete item.xingMing;
  86. delete item.gongHao;
  87. });
  88. let newList = list.filter((item) => item.ren_yuan_id_)
  89. let addList = newList.filter(item => !this.params.isSigned.includes(item.ren_yuan_id_))
  90. const addParams = {
  91. tableName: 't_qdxxb',
  92. paramWhere: addList
  93. }
  94. if(addList && addList.length > 0){
  95. const { variables: { cont } } = await this.$common.request('add', addParams)
  96. let allIds = [...(this.params.addPeople.split(',')), ...addList.map(item => item.ren_yuan_id_)]
  97. let uniqueIds = [...new Set(allIds.filter(id => id != null && id !== ''))];
  98. this.$emit('action-event', 'import', uniqueIds.join(','))
  99. }
  100. console.log('list', list)
  101. this.$message.success('导入成功!')
  102. this.showImportTable = false
  103. })
  104. },
  105. getColumns() {
  106. return [
  107. { label: '签到日期', field_name: 'qian_dao_shi_jian', name: 'qian_dao_shi_jian' },
  108. {
  109. label: '姓名',
  110. field_name: 'xingMing',
  111. name: 'xingMing'
  112. },
  113. { label: '工号', field_name: 'gongHao', name: 'gongHao' },
  114. ]
  115. },
  116. getKeys(data) {
  117. return Array.isArray(data)
  118. ? data.reduce((acc, item) => ({ ...acc, [item.label]: item.name }), {})
  119. : {}
  120. },
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. .qrcode-dialog {
  126. .qrCode {
  127. display: flex;
  128. justify-content: center;
  129. margin: 5% 0;
  130. }
  131. .qrCode > img {
  132. width: 50%;
  133. }
  134. }
  135. </style>