importGuideModal.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <a-modal
  3. centered
  4. class="importGuide-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="导入"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="750">
  11. <div class="importGuide-con">
  12. <div class="explain-con">
  13. <div class="explain-item">
  14. <div class="explain-tit">
  15. <span>1</span>准备导入
  16. </div>
  17. <ul>
  18. <li>1) 导入的Excel文件中必须包含名为“供应商名称“、“产品编码”、“成本”的列,且名称必须与系统相同</li>
  19. <li>2) 除了“供应商名称“、“产品编码”、“成本”三列,其他列可自定义,不影响数据导入</li>
  20. <li>3) 如果导入的供应商名称、产品已经存在,未创建之间的关联,则允许导入,同时系统创建关联;若已建立之间的关联,则允许导入,成本按照更新处理,若不存在,则需先完善供应商和产品</li>
  21. </ul>
  22. <a-button type="link" icon="download" style="padding: 0 0 0 23px;" :loading="exportLoading" @click="handleExport">下载导入模板</a-button>
  23. </div>
  24. <div class="explain-item">
  25. <div class="explain-tit">
  26. <span>2</span>上传数据文件
  27. </div>
  28. <p>目前支持的文件类型*.xls,*.xlsx.</p>
  29. <div style="overflow: hidden;padding-left: 23px;">
  30. <Upload
  31. id="importGuide-attachList"
  32. ref="importUpload"
  33. :maxNums="1"
  34. fileType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
  35. uploadType="import"
  36. :action="attachAction"
  37. :uploadParams="uploadParams"
  38. upText="添加文件"
  39. @change="changeImport"></Upload>
  40. </div>
  41. </div>
  42. </div>
  43. <!-- 按钮 -->
  44. <div class="btn-con">
  45. <a-button
  46. type="primary"
  47. id="importGuide-nextStep"
  48. size="large"
  49. class="button-primary"
  50. @click="handlerNextStep"
  51. style="padding: 0 60px;">下一步</a-button>
  52. <a-button
  53. id="importGuide-cancel"
  54. size="large"
  55. class="button-cancel"
  56. @click="isShow=false"
  57. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  58. </div>
  59. </div>
  60. <!-- 导入 -->
  61. <chooseImportModal :openModal="openImportModal" :paramsData="paramsData" @close="handleClose" @ok="hanldeOk" />
  62. </a-modal>
  63. </template>
  64. <script>
  65. import ChooseImportModal from './chooseImportModal.vue'
  66. import { Upload } from '@/components'
  67. import { supplierProductNewDownloadExcel } from '@/api/supplier'
  68. export default {
  69. name: 'ImportGuideModal',
  70. components: { ChooseImportModal, Upload },
  71. props: {
  72. openModal: { // 弹框显示状态
  73. type: Boolean,
  74. default: false
  75. },
  76. params: {
  77. type: Object,
  78. default: null
  79. }
  80. },
  81. data () {
  82. return {
  83. isShow: this.openModal, // 是否打开弹框
  84. openImportModal: false, // 导入
  85. attachAction: process.env.VUE_APP_API_BASE_URL + '/upload',
  86. paramsData: null,
  87. uploadParams: {
  88. savePathType: 'local'
  89. },
  90. exportLoading: false
  91. }
  92. },
  93. methods: {
  94. // 下一步
  95. handlerNextStep () {
  96. if (this.paramsData) {
  97. this.openImportModal = true
  98. } else {
  99. this.$message.warning('添加文件后再进行下一步操作!')
  100. }
  101. },
  102. // 上传文件 change
  103. changeImport (file) {
  104. if (file) {
  105. this.paramsData = {
  106. path: file
  107. }
  108. }
  109. },
  110. // 导入
  111. hanldeOk (obj) {
  112. if (obj && obj.length > 0) {
  113. this.$emit('ok', obj)
  114. this.isShow = false
  115. }
  116. },
  117. // 关闭
  118. handleClose () {
  119. this.openImportModal = false
  120. this.isShow = false
  121. },
  122. // 导出
  123. handleExport () {
  124. const _this = this
  125. _this.spinning = true
  126. _this.exportLoading = true
  127. supplierProductNewDownloadExcel({}).then(res => {
  128. _this.spinning = false
  129. _this.exportLoading = false
  130. if (res.type == 'application/json') {
  131. var reader = new FileReader()
  132. reader.addEventListener('loadend', function () {
  133. const obj = JSON.parse(reader.result)
  134. _this.$notification.error({
  135. message: '提示',
  136. description: obj.message
  137. })
  138. })
  139. reader.readAsText(res)
  140. } else {
  141. this.download(res)
  142. }
  143. })
  144. },
  145. download (data) {
  146. if (!data) { return }
  147. const url = window.URL.createObjectURL(new Blob([data]))
  148. const link = document.createElement('a')
  149. link.style.display = 'none'
  150. link.href = url
  151. const fname = '关联产品导入模板'
  152. link.setAttribute('download', fname + '.xlsx')
  153. document.body.appendChild(link)
  154. link.click()
  155. }
  156. },
  157. watch: {
  158. // 父页面传过来的弹框状态
  159. openModal (newValue, oldValue) {
  160. this.isShow = newValue
  161. },
  162. // 重定义的弹框状态
  163. isShow (newValue, oldValue) {
  164. if (!newValue) {
  165. this.$emit('close')
  166. this.paramsData = null
  167. this.$refs.importUpload.setFileList('')
  168. }
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="less" scoped>
  174. .importGuide-modal{
  175. .importGuide-con{
  176. .explain-con{
  177. .explain-item{
  178. margin-bottom: 10px;
  179. .explain-tit{
  180. font-weight: bold;
  181. span{
  182. display: inline-block;
  183. width: 18px;
  184. height: 18px;
  185. line-height: 16px;
  186. text-align: center;
  187. margin-right: 5px;
  188. border-radius: 50%;
  189. border: 1px solid rgba(0, 0, 0, 0.3);
  190. }
  191. }
  192. p{
  193. margin: 8px 0;
  194. padding-left: 23px;
  195. }
  196. ul{
  197. list-style: none;
  198. padding: 0;
  199. padding-left: 23px;
  200. margin: 0;
  201. li{
  202. line-height: 26px;
  203. }
  204. }
  205. }
  206. #importGuide-attachList{
  207. width: 100%;
  208. }
  209. }
  210. .btn-con{
  211. margin: 10px 0 20px;
  212. text-align: center;
  213. .button-cancel{
  214. font-size: 12px;
  215. }
  216. }
  217. }
  218. }
  219. </style>