importGuideModal.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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="800">
  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 v-if="goodFlag==='1'">1) 导入的Excel文件中必须包含名为“产品编码”的列,“产品编码”必填</li>
  19. <li v-else>1) 导入的Excel文件中必须包含名为“产品编码”、“省级特价”、“市级特价”和“特约特价”的列,都为必填</li>
  20. <li>2) 如果导入的产品已经存在,则不会导入该行</li>
  21. <li>
  22. <a :href="filePath" style="margin: 5px 0 0;display: block;">
  23. <a-icon type="download" style="padding-right: 5px;" />下载导入模板
  24. </a>
  25. </li>
  26. </ul>
  27. </div>
  28. <div class="explain-item">
  29. <div class="explain-tit">
  30. <span>2</span>上传数据文件
  31. </div>
  32. <p>目前支持的文件类型*.xls,*.xlsx.</p>
  33. <div style="overflow: hidden;padding-left: 23px;">
  34. <Upload
  35. id="importGuide-attachList"
  36. ref="importUpload"
  37. :maxNums="1"
  38. fileType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
  39. uploadType="attach"
  40. :action="goodFlag==='1'?attachAction:attachAction1"
  41. upText="选择导入文件"
  42. @remove="resetSearchForm"
  43. @change="changeImport"></Upload>
  44. </div>
  45. </div>
  46. </div>
  47. <!-- 按钮 -->
  48. <div class="btn-con">
  49. <a-button
  50. type="primary"
  51. id="importGuide-nextStep"
  52. size="large"
  53. class="button-primary"
  54. @click="handlerNextStep"
  55. style="padding: 0 60px;">下一步</a-button>
  56. <a-button
  57. id="importGuide-cancel"
  58. size="large"
  59. class="button-cancel"
  60. @click="isShow=false"
  61. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  62. </div>
  63. </div>
  64. <!-- 导入 -->
  65. <chooseImportModal ref="chooseImportBox" :openModal="openImportModal" :paramsData="paramsData" @close="handleClose" @ok="hanldeOk" />
  66. </a-modal>
  67. </template>
  68. <script>
  69. import ChooseImportModal from './chooseImportModal.vue'
  70. import { Upload } from '@/components'
  71. export default {
  72. name: 'ImportGuideModal',
  73. components: { ChooseImportModal, Upload },
  74. props: {
  75. openModal: { // 弹框显示状态
  76. type: Boolean,
  77. default: false
  78. },
  79. params: {
  80. type: Object,
  81. default: null
  82. },
  83. goodFlag: {
  84. type: [String, Number],
  85. default: '0'
  86. }
  87. },
  88. data () {
  89. return {
  90. isShow: this.openModal, // 是否打开弹框
  91. openImportModal: false, // 导入
  92. attachAction: process.env.VUE_APP_API_BASE_URL + '/promotion/importNormalProduct', // 导入门槛、正价、促销产品
  93. attachAction1: process.env.VUE_APP_API_BASE_URL + '/promotion/importSpecialProduct', // 导入特价产品
  94. paramsData: null,
  95. filePath: ''
  96. }
  97. },
  98. methods: {
  99. // 清空数据
  100. resetSearchForm () {
  101. this.$refs.importUpload.setFileList() // 清空导入文件
  102. this.paramsData = null // 清空上传数据
  103. },
  104. // 下一步
  105. handlerNextStep () {
  106. if (this.paramsData) {
  107. this.openImportModal = true
  108. this.$refs.chooseImportBox.setFlag(this.goodFlag)
  109. } else {
  110. this.$message.warning('添加文件后再进行下一步操作!')
  111. }
  112. },
  113. // 上传文件 change
  114. changeImport (file) {
  115. if (file && JSON.parse(file).length > 0) {
  116. this.paramsData = Object.assign({}, JSON.parse(file)[0] || null, this.params)
  117. } else {
  118. this.paramsData = null
  119. }
  120. },
  121. // 导入
  122. hanldeOk (obj) {
  123. if (obj && obj.length > 0) {
  124. this.$emit('ok', obj)
  125. this.isShow = false
  126. }
  127. },
  128. // 关闭
  129. handleClose () {
  130. this.openImportModal = false
  131. this.isShow = false
  132. }
  133. },
  134. watch: {
  135. // 父页面传过来的弹框状态
  136. openModal (newValue, oldValue) {
  137. this.isShow = newValue
  138. },
  139. // 重定义的弹框状态
  140. isShow (newValue, oldValue) {
  141. if (!newValue) {
  142. this.$emit('close')
  143. this.resetSearchForm()
  144. } else {
  145. this.filePath = location.protocol + '//' + location.host + (this.goodFlag === '1' ? '/templ/促销规则导入产品.xlsx' : '/templ/促销规则导入特价产品.xlsx')
  146. }
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="less" scoped>
  152. .importGuide-modal{
  153. .importGuide-con{
  154. .explain-con{
  155. .explain-item{
  156. margin-bottom: 10px;
  157. .explain-tit{
  158. font-weight: bold;
  159. span{
  160. display: inline-block;
  161. width: 18px;
  162. height: 18px;
  163. line-height: 16px;
  164. text-align: center;
  165. margin-right: 5px;
  166. border-radius: 50%;
  167. border: 1px solid rgba(0, 0, 0, 0.3);
  168. }
  169. }
  170. p{
  171. margin: 8px 0;
  172. padding-left: 23px;
  173. }
  174. ul{
  175. list-style: none;
  176. padding: 0;
  177. padding-left: 23px;
  178. margin: 0;
  179. li{
  180. line-height: 26px;
  181. }
  182. }
  183. }
  184. #importGuide-attachList{
  185. width: 100%;
  186. }
  187. }
  188. .btn-con{
  189. margin: 10px 0 20px;
  190. text-align: center;
  191. .button-cancel{
  192. font-size: 12px;
  193. }
  194. }
  195. }
  196. }
  197. </style>