set.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="intelligentReplenishmentSet-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="intelligentReplenishmentSet-back">
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="intelligentReplenishmentSet-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. </template>
  9. </a-page-header>
  10. <a-card size="small" :bordered="false" class="intelligentReplenishmentSet-cont">
  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. <p>所有允许导入的数据字段请参考模板,数据字段不符合规则,整条不予以导入。</p>
  18. <ul>
  19. <li>1) 下载导入模板得到的excel中,是目前系统中全部的产品信息,请修改变化的字段(该行的其他字段保持不变),并删除没有变化的行</li>
  20. <li>2) “产品编码”字段为必填项</li>
  21. <li>3) “订货周期”字段只能输入正整数,如果没有订货周期,保持为空即可</li>
  22. <li>4) “是否淘汰”字段,如果确定淘汰,则输入“是”,如果不淘汰,则不需要输入,保持为空即可</li>
  23. <li>5) “淘汰描述”字段,只有当是否淘汰为“是”时,才能录入淘汰描述,否则,淘汰描述只能保持为空</li>
  24. </ul>
  25. <a-button type="link" icon="download" style="padding: 0 0 0 23px;" :loading="exportLoading" @click="handleExport">下载导入模板</a-button>
  26. </div>
  27. <div class="explain-item">
  28. <div class="explain-tit">
  29. <span>2</span>上传数据文件
  30. </div>
  31. <p>目前支持的文件类型*.xls,*.xlsx.</p>
  32. <p>
  33. <Upload
  34. id="importGuide-attachList"
  35. ref="importUpload"
  36. :maxNums="1"
  37. fileType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
  38. uploadType="import"
  39. :action="attachAction"
  40. :uploadParams="uploadParams"
  41. @remove="resetForm"
  42. upText="添加文件"
  43. @change="changeImport"></Upload>
  44. </p>
  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="handleBack"
  61. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  62. </div>
  63. </div>
  64. </a-card>
  65. </a-spin>
  66. </div>
  67. </template>
  68. <script>
  69. import { commonMixin } from '@/utils/mixin'
  70. import moment from 'moment'
  71. import VueCookies from 'vue-cookies'
  72. import { Upload } from '@/components'
  73. import { predictProductInfoExport } from '@/api/predict'
  74. import debounce from 'lodash/debounce'
  75. export default {
  76. name: 'IntelligentReplenishmentSet',
  77. mixins: [commonMixin],
  78. components: { Upload },
  79. data () {
  80. this.handleExport = debounce(this.handleExport, 2200)
  81. return {
  82. spinning: false,
  83. filePath: 'javascript:;',
  84. attachAction: process.env.VUE_APP_API_BASE_URL + '/upload',
  85. paramsData: null,
  86. uploadParams: {
  87. savePathType: 'local'
  88. },
  89. exportLoading: false
  90. }
  91. },
  92. methods: {
  93. // 返回
  94. handleBack () {
  95. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/list`, query: { closeLastOldTab: true } })
  96. },
  97. // 下一步
  98. handlerNextStep () {
  99. if (this.paramsData) {
  100. this.$router.push({ path: `/inventoryManagement/intelligentReplenishment/import` })
  101. } else {
  102. this.$message.warning('添加文件后再进行下一步操作!')
  103. }
  104. },
  105. // 上传文件 change
  106. changeImport (file) {
  107. this.paramsData = file
  108. VueCookies.set('REPLENISHMENT_PATH', JSON.stringify(file))
  109. },
  110. // 导出
  111. handleExport () {
  112. const _this = this
  113. _this.spinning = true
  114. _this.exportLoading = true
  115. predictProductInfoExport({}).then(res => {
  116. _this.spinning = false
  117. _this.exportLoading = false
  118. if (res.type == 'application/json') {
  119. var reader = new FileReader()
  120. reader.addEventListener('loadend', function () {
  121. const obj = JSON.parse(reader.result)
  122. _this.$notification.error({
  123. message: '提示',
  124. description: obj.message
  125. })
  126. })
  127. reader.readAsText(res)
  128. } else {
  129. this.download(res)
  130. }
  131. })
  132. },
  133. download (data) {
  134. if (!data) { return }
  135. const url = window.URL.createObjectURL(new Blob([data]))
  136. const link = document.createElement('a')
  137. link.style.display = 'none'
  138. link.href = url
  139. const a = moment().format('YYYYMMDDHHmmss')
  140. const fname = '智能补货_模板_' + a
  141. link.setAttribute('download', fname + '.xlsx')
  142. document.body.appendChild(link)
  143. link.click()
  144. },
  145. resetForm () {
  146. this.$refs.importUpload.setFileList() // 清空导入文件
  147. this.paramsData = null // 清空上传数据
  148. VueCookies.set('REPLENISHMENT_PATH', '')
  149. }
  150. },
  151. mounted () {
  152. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  153. this.resetForm()
  154. }
  155. },
  156. activated () {
  157. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  158. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  159. this.resetForm()
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="less">
  165. .intelligentReplenishmentSet-wrap{
  166. .intelligentReplenishmentSet-back{
  167. margin-bottom: 10px;
  168. }
  169. .importGuide-con{
  170. width: 900px;
  171. margin: 30px auto 50px;
  172. line-height: 30px;
  173. .explain-con{
  174. .explain-item{
  175. margin-bottom: 40px;
  176. .explain-tit{
  177. font-weight: bold;
  178. span{
  179. display: inline-block;
  180. width: 18px;
  181. height: 18px;
  182. line-height: 16px;
  183. text-align: center;
  184. margin-right: 5px;
  185. border-radius: 50%;
  186. border: 1px solid rgba(0, 0, 0, 0.3);
  187. }
  188. }
  189. p{
  190. margin: 8px 0;
  191. padding-left: 23px;
  192. }
  193. ul{
  194. list-style: none;
  195. padding: 0;
  196. padding-left: 23px;
  197. margin: 0;
  198. li{
  199. line-height: 26px;
  200. }
  201. }
  202. }
  203. }
  204. .btn-con{
  205. margin: 80px 0 20px;
  206. .button-cancel{
  207. font-size: 12px;
  208. }
  209. }
  210. }
  211. }
  212. </style>