importGuideModal.vue 6.8 KB

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