importGuideModal.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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) 请先下载导入模板,模板中已标示出必填项</li>
  19. <li>2) 产品编码具有唯一性,{{ guideType=='1'?'系统中已存在的无法导入':(guideType=='2'?'下线导入':'上线导入')+',必须是系统中已存在的产品编码' }}</li>
  20. <li v-if="guideType=='1'">3) 产品品牌、产品分类、单位、包装数单位、出库仓库、退货仓库,必须是系统中已经存在的值,否则无法导入</li>
  21. <li v-if="guideType=='2'||guideType=='3'"><a :href="guideType=='3' ? fileOnlinPath : filePath" style="margin: 5px 0 0 15px;display: block;">
  22. <a-icon type="download" style="padding-right: 5px;" />下载导入模板
  23. </a></li>
  24. </ul>
  25. <a-button
  26. v-if="guideType=='1'"
  27. id="importGuide-export"
  28. type="link"
  29. icon="download"
  30. style="padding: 0 0 0 23px;"
  31. :loading="exportLoading"
  32. @click="handleExport">下载导入模板</a-button>
  33. </div>
  34. <div class="explain-item">
  35. <div class="explain-tit">
  36. <span>2</span>上传数据文件
  37. </div>
  38. <p>目前支持的文件类型*.xls,*.xlsx.</p>
  39. <div style="overflow: hidden;padding-left: 23px;">
  40. <Upload
  41. id="importGuide-attachList"
  42. ref="importUpload"
  43. :maxNums="1"
  44. fileType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
  45. :uploadType="guideType=='3' ? 'attach' : 'import'"
  46. :action="guideType=='3' ? attachOnlinAction : attachAction"
  47. :uploadParams="uploadParams"
  48. upText="添加文件"
  49. @remove="resetSearchForm"
  50. @change="changeImport"></Upload>
  51. </div>
  52. </div>
  53. </div>
  54. <!-- 按钮 -->
  55. <div class="btn-con">
  56. <a-button
  57. type="primary"
  58. id="importGuide-nextStep"
  59. size="large"
  60. class="button-primary"
  61. @click="handlerNextStep"
  62. style="padding: 0 60px;">下一步</a-button>
  63. <a-button
  64. id="importGuide-cancel"
  65. size="large"
  66. class="button-cancel"
  67. @click="isShow=false"
  68. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  69. </div>
  70. </div>
  71. <!-- 导入 -->
  72. <chooseImportModal :openModal="openImportModal" :paramsData="paramsData" @close="handleClose" @ok="hanldeOk" />
  73. <offlineImportModal :openModal="openOfflineImportModal" :paramsData="paramsData" @close="handleClose" @ok="hanldeOk" />
  74. <onlineImportModal :openModal="openOnlineImportModal" :paramsData="paramsData" @close="handleClose" @ok="hanldeOk" />
  75. </a-modal>
  76. </template>
  77. <script>
  78. import { commonMixin } from '@/utils/mixin'
  79. // 组件
  80. import ChooseImportModal from './chooseImportModal.vue'
  81. import offlineImportModal from './offlineImportModal.vue'
  82. import onlineImportModal from './onlineImportModal.vue'
  83. import { Upload } from '@/components'
  84. export default {
  85. name: 'SalesImportGuideModal',
  86. mixins: [commonMixin],
  87. components: { ChooseImportModal, offlineImportModal, onlineImportModal, Upload },
  88. props: {
  89. openModal: { // 弹框显示状态
  90. type: Boolean,
  91. default: false
  92. },
  93. guideType: {// 产品导入类型 1 新增产品导入 2下线产品导入
  94. type: String,
  95. default: ''
  96. }
  97. },
  98. data () {
  99. return {
  100. isShow: this.openModal, // 是否打开弹框
  101. openImportModal: false, // 打开新增产品导入弹框
  102. openOfflineImportModal: false, // 打开下线产品导入弹框
  103. openOnlineImportModal: false, // 打开下线产品导入弹框
  104. attachAction: process.env.VUE_APP_API_BASE_URL + '/upload', // 上传地址
  105. attachOnlinAction: process.env.VUE_APP_API_BASE_URL + '/product/importOnline',
  106. paramsData: null, // 导入参数
  107. uploadParams: {// 上传参数
  108. savePathType: 'local'
  109. },
  110. exportLoading: false, // 导出按钮加载状态
  111. filePath: location.protocol + '//' + location.host + '/templ/批量下线导入模板.xlsx', // 模板地址
  112. fileOnlinPath: location.protocol + '//' + location.host + '/templ/批量上线导入模板.xlsx'
  113. }
  114. },
  115. methods: {
  116. // 清空数据
  117. resetSearchForm () {
  118. this.$refs.importUpload.setFileList() // 清空导入文件
  119. this.paramsData = null // 清空上传数据
  120. },
  121. // 下一步
  122. handlerNextStep () {
  123. const _this = this
  124. if (_this.paramsData) {
  125. if (_this.guideType == 1) {
  126. _this.openImportModal = true
  127. } else if (_this.guideType == 2) {
  128. _this.openOfflineImportModal = true
  129. } else {
  130. _this.openOnlineImportModal = true
  131. }
  132. } else {
  133. _this.$message.warning('添加文件后再进行下一步操作!')
  134. }
  135. },
  136. // 上传文件 change
  137. changeImport (file) {
  138. if (file && this.guideType != 3) {
  139. this.paramsData = {
  140. path: file
  141. }
  142. } else {
  143. if (file && JSON.parse(file).length > 0) {
  144. this.paramsData = Object.assign({}, JSON.parse(file)[0] || null)
  145. } else {
  146. this.paramsData = null
  147. }
  148. }
  149. },
  150. // 导入
  151. hanldeOk (obj) {
  152. if (obj) {
  153. this.$emit('ok', obj)
  154. this.isShow = false
  155. }
  156. },
  157. // 关闭
  158. handleClose () {
  159. this.openImportModal = false
  160. this.openOfflineImportModal = false
  161. this.openOnlineImportModal = false
  162. this.isShow = false
  163. },
  164. // 下载模板
  165. handleExport () {
  166. this.exportLoading = true
  167. setTimeout(() => {
  168. this.exportLoading = false
  169. }, 1000)
  170. const link = document.createElement('a')
  171. link.style.display = 'none'
  172. link.href = location.protocol + '//' + location.host + '/templ/产品批量导入模板.xlsx'
  173. link.setAttribute('download', '产品批量导入模板' + '.xlsx')
  174. document.body.appendChild(link)
  175. link.click()
  176. document.body.removeChild(link)
  177. }
  178. },
  179. watch: {
  180. // 父页面传过来的弹框状态
  181. openModal (newValue, oldValue) {
  182. this.isShow = newValue
  183. },
  184. // 重定义的弹框状态
  185. isShow (newValue, oldValue) {
  186. if (!newValue) {
  187. this.$emit('close')
  188. this.paramsData = null
  189. this.$refs.importUpload.setFileList('')
  190. }
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="less" scoped>
  196. .importGuide-modal{
  197. .importGuide-con{
  198. .explain-con{
  199. .explain-item{
  200. margin-bottom: 10px;
  201. .explain-tit{
  202. font-weight: bold;
  203. span{
  204. display: inline-block;
  205. width: 18px;
  206. height: 18px;
  207. line-height: 16px;
  208. text-align: center;
  209. margin-right: 5px;
  210. border-radius: 50%;
  211. border: 1px solid rgba(0, 0, 0, 0.3);
  212. }
  213. }
  214. p{
  215. margin: 8px 0;
  216. padding-left: 23px;
  217. }
  218. ul{
  219. list-style: none;
  220. padding: 0;
  221. padding-left: 23px;
  222. margin: 0;
  223. li{
  224. line-height: 26px;
  225. }
  226. }
  227. }
  228. #importGuide-attachList{
  229. width: 100%;
  230. }
  231. }
  232. .btn-con{
  233. margin: 10px 0 20px;
  234. text-align: center;
  235. .button-cancel{
  236. font-size: 12px;
  237. }
  238. }
  239. }
  240. }
  241. </style>