importGuideModal.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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>1) 导入的Excel文件中必须包含名为“产品编码”、“成本价”、“数量”、“仓库”、“仓位”的列,且名称必须相同,其它列可自定义,不影响数据导入</li>
  19. <li>2) 如果导入的产品已经存在,则不会导入该行</li>
  20. <li>
  21. <a :href="filePath" id="importGuide-tpl" style="margin: 5px 0 0;display: block;">
  22. <a-icon type="download" style="padding-right: 5px;" />下载导入模板
  23. </a>
  24. </li>
  25. </ul>
  26. </div>
  27. <div class="explain-item">
  28. <div class="explain-tit">
  29. <span>2</span>上传数据文件
  30. </div>
  31. <p>目前支持的文件类型*.xls,*.xlsx.</p>
  32. <div style="overflow: hidden;padding-left: 23px;">
  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="attach"
  39. :action="attachAction"
  40. :uploadParams="uploadParams"
  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 :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. },
  84. data () {
  85. return {
  86. isShow: this.openModal, // 是否打开弹框
  87. openImportModal: false, // 导入
  88. attachAction: process.env.VUE_APP_API_BASE_URL + '/sparePartsPur/detail/import',
  89. paramsData: null,
  90. uploadParams: { // 上传参数
  91. savePathType: 'local',
  92. sparePartsPurchaseSn: this.params.sparePartsPurchaseSn
  93. },
  94. filePath: location.protocol + '//' + location.host + '/templ/散件入库产品导入模板.xlsx' // 模板地址
  95. }
  96. },
  97. methods: {
  98. // 清空数据
  99. resetSearchForm () {
  100. this.$refs.importUpload.setFileList() // 清空导入文件
  101. this.paramsData = null // 清空上传数据
  102. },
  103. // 下一步
  104. handlerNextStep () {
  105. if (this.paramsData) {
  106. this.openImportModal = true
  107. } else {
  108. this.$message.warning('添加文件后再进行下一步操作!')
  109. }
  110. },
  111. // 上传文件 change
  112. changeImport (file) {
  113. // console.log(file, JSON.parse(file))
  114. if (file && JSON.parse(file).length > 0) {
  115. this.paramsData = Object.assign({}, JSON.parse(file)[0] || null, this.params)
  116. } else {
  117. this.paramsData = null
  118. }
  119. },
  120. // 导入
  121. hanldeOk (obj) {
  122. if (obj && obj.length > 0) {
  123. this.$emit('ok', obj)
  124. this.isShow = false
  125. }
  126. },
  127. // 关闭
  128. handleClose () {
  129. this.openImportModal = false
  130. this.isShow = false
  131. }
  132. },
  133. watch: {
  134. // 父页面传过来的弹框状态
  135. openModal (newValue, oldValue) {
  136. this.isShow = newValue
  137. },
  138. // 重定义的弹框状态
  139. isShow (newValue, oldValue) {
  140. if (!newValue) {
  141. this.$emit('close')
  142. this.resetSearchForm()
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="less" scoped>
  149. .importGuide-modal{
  150. .importGuide-con{
  151. .explain-con{
  152. .explain-item{
  153. margin-bottom: 10px;
  154. .explain-tit{
  155. font-weight: bold;
  156. span{
  157. display: inline-block;
  158. width: 18px;
  159. height: 18px;
  160. line-height: 16px;
  161. text-align: center;
  162. margin-right: 5px;
  163. border-radius: 50%;
  164. border: 1px solid rgba(0, 0, 0, 0.3);
  165. }
  166. }
  167. p{
  168. margin: 8px 0;
  169. padding-left: 23px;
  170. }
  171. ul{
  172. list-style: none;
  173. padding: 0;
  174. padding-left: 23px;
  175. margin: 0;
  176. li{
  177. line-height: 26px;
  178. }
  179. }
  180. }
  181. #importGuide-attachList{
  182. width: 100%;
  183. }
  184. }
  185. .btn-con{
  186. margin: 10px 0 20px;
  187. text-align: center;
  188. .button-cancel{
  189. font-size: 12px;
  190. }
  191. }
  192. }
  193. }
  194. </style>