audit-advanced-import.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div>
  3. <slot></slot>
  4. <a-button v-if="vIf" :class="classStyle" @click="showImportPanel">
  5. {{ Title }}
  6. </a-button>
  7. <a-modal
  8. :title="Title"
  9. :visible="modalImport.visible"
  10. :width="width"
  11. destroy-on-close
  12. :mask-closable="false"
  13. @cancel="handleCancel"
  14. >
  15. <slot name="modalimport">
  16. <a-form>
  17. <!-- 前置按钮插槽 -->
  18. <slot name="beforeimport"></slot>
  19. <a-form-item>
  20. <sd-attachment
  21. :max="1"
  22. :group-id="groupId"
  23. accept=".xls,.xlsx,.zip"
  24. @change="fnchangefile"
  25. >
  26. </sd-attachment>
  27. </a-form-item>
  28. <a-form-item style="text-align: center"></a-form-item>
  29. <!-- 后置按钮插槽 -->
  30. <slot name="afterimport"></slot>
  31. <a-form-item>
  32. <span v-if="Message !== ''" style="padding: 0 15px">
  33. {{ Message }}
  34. </span>
  35. <br v-if="Message !== '' && mblink && !hasattach" />
  36. <a-button v-if="!templategroupId && mblink" type="link" @click="fnDownloadTemplate">
  37. 导入模板.xls
  38. </a-button>
  39. <sd-attachment
  40. v-if="templategroupId && mblink && !hasattach"
  41. :group-id="templategroupId"
  42. read-only
  43. />
  44. <a-button
  45. v-if="templategroupId && mblink && !hasattach"
  46. style="padding-left: 0;"
  47. icon="sd-download"
  48. type="link"
  49. @click="fnDownloadFile"
  50. >
  51. 下载模板
  52. </a-button>
  53. </a-form-item>
  54. </a-form>
  55. </slot>
  56. <template slot="footer">
  57. <span :class="[$style.footerbtnsxm]"
  58. ><a-button :class="$style.buttonStyle" @click="handleCancel">取消</a-button></span
  59. >
  60. <span :class="[$style.footerbtnsxm]"
  61. ><a-button type="primary" :class="$style.buttonStyle" @click="importfromfile"
  62. >确定</a-button
  63. ></span
  64. >
  65. </template>
  66. </a-modal>
  67. <a-modal
  68. v-model="isErrorInfo"
  69. title="错误信息"
  70. :width="700"
  71. @ok="isErrorInfo = false"
  72. @cancel="isErrorInfo = false"
  73. >
  74. <!-- <table>
  75. <tr v-for="(item, index) in errorInfo" :key="index"
  76. ><td>{{ item }}</td></tr
  77. >
  78. </table> -->
  79. <a-descriptions bordered :class="$style.advancedimport">
  80. <a-descriptions-item :label="null">
  81. <p v-for="(item, index) in errorInfo" :key="index">{{ item }}</p>
  82. </a-descriptions-item>
  83. </a-descriptions>
  84. <!-- {{ errorInfo }} -->
  85. <!-- <a-descriptions-item v-for="(item, index) in errorInfo" :key="index" bordered>
  86. <a-descriptions-item label="">
  87. </a-descriptions-item>
  88. <p>{{ item }}</p
  89. ><br /> -->
  90. <!-- </a-descriptions-item> -->
  91. </a-modal>
  92. </div>
  93. </template>
  94. <script>
  95. import axios from '@/common/services/axios-instance'
  96. import { Message } from 'ant-design-vue'
  97. import AuditAdvancedImportService from './audit-advanced-import-service'
  98. import components from './_import-components/audit-advanced-import-import'
  99. import download from '@/common/services/download'
  100. export default {
  101. name: 'AuditAdvancedImport',
  102. metaInfo: {
  103. title: 'AuditAdvancedImport',
  104. },
  105. components,
  106. props: {
  107. classStyle: {
  108. type: Array,
  109. default: null,
  110. },
  111. /**
  112. * 判断导入按钮 显示条件,为true 则显示
  113. */
  114. vIf: {
  115. Type: Boolean,
  116. defalt: false,
  117. },
  118. /**
  119. * 导入弹出框大小设定,默认650
  120. */
  121. width: {
  122. Type: Number,
  123. defalt: 650,
  124. },
  125. /**
  126. * 文字说明提示
  127. */
  128. Message: {
  129. type: String,
  130. default: '',
  131. },
  132. /**
  133. * 标题
  134. */
  135. Title: {
  136. type: String,
  137. default: '导入',
  138. },
  139. /**
  140. * 导入具体方法
  141. */
  142. ImportFun: {
  143. type: Function,
  144. default: null,
  145. },
  146. /**
  147. * 显示模板样例
  148. */
  149. mblink: {
  150. type: Boolean,
  151. default: true,
  152. },
  153. /**
  154. * 配置表id
  155. */
  156. configId: {
  157. type: String,
  158. default: '',
  159. },
  160. /**
  161. * 父分类ID
  162. */
  163. relevantColumn: {
  164. type: Number,
  165. default: null,
  166. },
  167. /**
  168. * 刷新表名
  169. */
  170. tableId: {
  171. type: String,
  172. default: '',
  173. },
  174. /**
  175. * 样例接口参数
  176. */
  177. templateparam: {
  178. type: Array,
  179. default: null,
  180. },
  181. },
  182. data() {
  183. return {
  184. modalImport: {
  185. title: '导入',
  186. visible: false,
  187. },
  188. errorInfo: [],
  189. isErrorInfo: false,
  190. groupId: Math.round(Math.random() * 100000000000000000).toString(),
  191. templategroupId: null,
  192. templatepath: null,
  193. hasattach: false,
  194. }
  195. },
  196. mounted() {
  197. this.getTemplate(this.configId)
  198. this.hasattach = false
  199. },
  200. created() {
  201. this.hasattach = false
  202. },
  203. methods: {
  204. showImportPanel() {
  205. this.modalImport.visible = true
  206. this.groupId = Math.round(Math.random() * 100000000000000000).toString()
  207. },
  208. handleCancel() {
  209. this.modalImport.visible = false
  210. this.hasattach = false
  211. this.$emit('importHandleCancel') // 调用取消回调函数
  212. },
  213. importfromfile(data) {
  214. if (!this.hasattach) {
  215. Message.warn('请先上传附件')
  216. return
  217. }
  218. this.$emit('changeSpinning', false) // 修改Spinning显示状态
  219. let params = {
  220. groupId: this.groupId,
  221. configId: this.configId,
  222. relevantColumn: this.relevantColumn,
  223. }
  224. if (this.ImportFun !== null) {
  225. params = this.ImportFun(params)
  226. }
  227. AuditAdvancedImportService.Import(params)
  228. .then((res) => {
  229. this.$emit('changeSpinning', true) // 修改Spinning显示状态
  230. if (res.data.flag === false) {
  231. Message.error('导入数据失败!')
  232. this.isErrorInfo = true
  233. this.errorInfo = res.data.data
  234. console.log(this.errorInfo)
  235. return false
  236. } else {
  237. Message.success('导入成功!')
  238. this.$emit('importfromfileAfter') // 调用导入成功回调函数
  239. if (this.$parent.$parent.$refs[`${this.tableId}`]) {
  240. this.$parent.$parent.$refs[`${this.tableId}`].refresh()
  241. }
  242. }
  243. })
  244. .catch((err) => {
  245. this.$emit('changeSpinning', true) // 修改Spinning显示状态
  246. // Message.error(err)
  247. if (err.response.data.message === '字段被审计单位:auditedUnit不能为空') {
  248. Message.error('被审计单位名称填写错误,请核对后导入')
  249. } else {
  250. Message.error(err)
  251. }
  252. })
  253. this.modalImport.visible = false
  254. this.hasattach = false
  255. },
  256. fnDownloadTemplate() {
  257. AuditAdvancedImportService.downloadTemplateExcel(this.templatepath, this.templateparam).then(
  258. (res) => {
  259. const url = URL.createObjectURL(res.data)
  260. const fname = '导入模板.xls'
  261. download(url, fname)
  262. }
  263. )
  264. },
  265. getTemplate(configId) {
  266. AuditAdvancedImportService.getTemplate(configId).then((res) => {
  267. this.templategroupId = res.data.groupId
  268. this.templatepath = res.data.templateUrl
  269. })
  270. },
  271. fnDownloadFile() {
  272. return axios
  273. .get('api/framework/v1/attachment-extend/attachments-info/' + this.templategroupId)
  274. .then((res) => {
  275. const code = res.data[0]?.code
  276. if (code) {
  277. const fname = res.data[0].name
  278. const url = `${location.origin}${location.pathname}api/framework/v1/task-form-process/download-attachments/${code}`
  279. download(url, fname)
  280. }
  281. })
  282. },
  283. fnchangefile(attach) {
  284. if (attach.length > 0) {
  285. this.hasattach = true
  286. } else {
  287. this.hasattach = false
  288. }
  289. },
  290. },
  291. }
  292. </script>
  293. <style module lang="scss">
  294. @use '@/common/design' as *;
  295. .footerbtnsxm {
  296. padding: 0 5px;
  297. }
  298. :global(.ant-upload.ant-upload-drag .ant-upload) {
  299. padding: 0 0;
  300. }
  301. :global(.ant-form-item) {
  302. margin: 0 0;
  303. }
  304. .advancedimport {
  305. :global(.ant-descriptions-item-no-label) {
  306. display: none;
  307. }
  308. }
  309. </style>