list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <a-card size="small" :bordered="false" class="bulkImportList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <div ref="tableSearch" class="table-page-search-wrapper">
  5. <Upload
  6. id="bulkImportList-attachList"
  7. ref="importUpload"
  8. :maxNums="1"
  9. fileType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
  10. uploadType="attach"
  11. :action="attachAction"
  12. :uploadParams="uploadParams"
  13. upText="选择导入文件"
  14. @remove="resetSearchForm"
  15. @change="changeImport"></Upload>
  16. <a :href="filePath" style="margin: 5px 0 0 15px;display: block;float: left;">
  17. <a-icon type="download" style="padding-right: 5px;" />下载导入模板
  18. </a>
  19. </div>
  20. <div class="importGuide-con">
  21. <div class="explain-con">
  22. <div class="explain-item">
  23. <div class="explain-tit">导入文件说明</div>
  24. <ul>
  25. <li>1) 导入的EXCEL文件中必须包含名为"供应商"、"产品品牌"、"产品编码"、"原厂编码"、"产品名称"、"产品一级分类"、"产品二级分类"、"产品三级分类"、"仓库"、"仓位"、"入库数量"、"成本价"、"售价";列顺序可忽略、行顺序可忽略。其中"供应商"、"产品品牌"、"产品编码"、"产品名称"、"仓库"、"仓位"、"入库数量"、"成本价"、"售价"内容不能为空。</li>
  26. <li>2) 红色底白字为错误项,对应错误原因列显示错误信息,存在错误项时不能导入,请取消修改后重新上传操作。</li>
  27. <li>3) 供应商/产品品牌为必填项且不能包含箭冠、箭牌、冠牌等文字,产品名称为必填项。</li>
  28. <li>4) 支持上传文件格式:.xls、.xlsx。</li>
  29. </ul>
  30. </div>
  31. </div>
  32. </div>
  33. <!-- 列表 -->
  34. <s-table
  35. class="sTable fixPagination"
  36. ref="table"
  37. :style="{ height: tableHeight+84.5+'px' }"
  38. size="small"
  39. :rowClassName="(record, index) => record.isError==1 ? 'redBg-row':''"
  40. :rowKey="(record) => record.id"
  41. :columns="columns"
  42. :data="loadData"
  43. :scroll="{ x: 1680, y: tableHeight }"
  44. :defaultLoadData="false"
  45. bordered>
  46. </s-table>
  47. <div class="btn-con" v-if="uploadData && uploadData.stockImportSn">
  48. <a-button
  49. id="productInfoList-batchAudit"
  50. type="primary"
  51. class="button-warning"
  52. @click="handleConfirm"
  53. style="margin: 0 15px;">确认导入</a-button>
  54. <a-button
  55. id="productInfoList-batchLaunch"
  56. type="primary"
  57. class="button-primary"
  58. @click="handleCancel"
  59. style="margin: 0 15px;">取消导入</a-button>
  60. <a-button
  61. id="productInfoList-batchDownline"
  62. type="primary"
  63. class="button-grey"
  64. @click="handleExportError"
  65. style="margin: 0 15px;">导出错误项</a-button>
  66. </div>
  67. </a-spin>
  68. </a-card>
  69. </template>
  70. <script>
  71. import { STable, Upload } from '@/components'
  72. import { stockImportList, stockImportFinish, stockImportCancel, stockImportExportError } from '@/api/stockImport'
  73. import moment from 'moment'
  74. export default {
  75. components: { STable, Upload },
  76. data () {
  77. return {
  78. spinning: false,
  79. exportLoading: false, // 导出loading
  80. tableHeight: 0,
  81. queryParam: {}, // 查询参数
  82. // 表头
  83. columns: [
  84. { title: '序号', dataIndex: 'no', width: 50, align: 'center' },
  85. { title: '产品编码', dataIndex: 'productCode', align: 'center', customRender: function (text) { return text || '--' } },
  86. { title: '原厂编码', dataIndex: 'productOrigCode', align: 'center', customRender: function (text) { return text || '--' } },
  87. { title: '产品品牌', dataIndex: 'productBrandName', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  88. { title: '供应商', dataIndex: 'supplierName', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  89. { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' } },
  90. { title: '产品一级分类', dataIndex: 'productTypeName1', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  91. { title: '产品二级分类', dataIndex: 'productTypeName2', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  92. { title: '产品三级分类', dataIndex: 'productTypeName3', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  93. { title: '仓库', dataIndex: 'warehouseName', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  94. { title: '仓位', dataIndex: 'warehouseLocationName', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  95. { title: '入库数量', dataIndex: 'putQty', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  96. { title: '成本价', dataIndex: 'cost', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  97. { title: '售价', dataIndex: 'terminalPrice', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  98. { title: '错误原因', dataIndex: 'errorMsg', width: 150, align: 'center', customRender: function (text) { return text || '--' } }
  99. ],
  100. // 加载数据方法 必须为 Promise 对象
  101. loadData: parameter => {
  102. this.spinning = true
  103. return stockImportList(Object.assign(parameter, { stockImportSn: this.uploadData && this.uploadData.stockImportSn })).then(res => {
  104. const data = res.data
  105. const no = (data.pageNo - 1) * data.pageSize
  106. for (var i = 0; i < data.list.length; i++) {
  107. data.list[i].no = no + i + 1
  108. }
  109. this.spinning = false
  110. return data
  111. })
  112. },
  113. attachAction: process.env.VUE_APP_API_BASE_URL + '/stockImport/importForSpareParts',
  114. uploadParams: {
  115. savePathType: 'local'
  116. },
  117. uploadData: null,
  118. filePath: 'https://jianguan-images.oss-cn-beijing.aliyuncs.com/template/ShangHuProductImports.xlsx'
  119. }
  120. },
  121. methods: {
  122. // 上传文件 change
  123. changeImport (file) {
  124. if (file && JSON.parse(file).length > 0) {
  125. this.uploadData = JSON.parse(file)[0] || null
  126. if (this.uploadData && this.uploadData.stockImportSn) {
  127. this.$refs.table.refresh(true)
  128. }
  129. } else {
  130. this.uploadData = null
  131. }
  132. },
  133. resetSearchForm () {
  134. this.$refs.table.clearTable() // 清空列表数据
  135. this.$refs.importUpload.setFileList() // 清空导入文件
  136. this.uploadData = null // 清空上传数据
  137. },
  138. // 确认导入
  139. handleConfirm () {
  140. const _this = this
  141. this.$confirm({
  142. title: '提示',
  143. content: '您是否确认导入产品信息?',
  144. centered: true,
  145. onOk () {
  146. _this.spinning = true
  147. stockImportFinish({ stockImportSn: _this.uploadData && _this.uploadData.stockImportSn }).then(res => {
  148. if (res.status == 200) {
  149. _this.$message.success(res.message)
  150. _this.resetSearchForm()
  151. _this.spinning = false
  152. } else {
  153. _this.spinning = false
  154. }
  155. })
  156. }
  157. })
  158. },
  159. // 取消导入
  160. handleCancel () {
  161. const _this = this
  162. this.$confirm({
  163. title: '提示',
  164. content: '您确认取消导入产品的信息?',
  165. centered: true,
  166. onOk () {
  167. _this.spinning = true
  168. stockImportCancel({ stockImportSn: _this.uploadData && _this.uploadData.stockImportSn }).then(res => {
  169. if (res.status == 200) {
  170. _this.$message.success(res.message)
  171. _this.resetSearchForm()
  172. _this.spinning = false
  173. } else {
  174. _this.spinning = false
  175. }
  176. })
  177. }
  178. })
  179. },
  180. // 下载模板
  181. handleExport () {},
  182. // 导出错误项
  183. handleExportError () {
  184. const _this = this
  185. _this.spinning = true
  186. stockImportExportError({ stockImportSn: _this.uploadData && _this.uploadData.stockImportSn }).then(res => {
  187. _this.spinning = false
  188. if (res.type == 'application/json') {
  189. var reader = new FileReader()
  190. reader.addEventListener('loadend', function () {
  191. const obj = JSON.parse(reader.result)
  192. _this.$notification.error({
  193. message: '提示',
  194. description: obj.message
  195. })
  196. })
  197. reader.readAsText(res)
  198. } else {
  199. this.download(res)
  200. }
  201. })
  202. },
  203. download (data) {
  204. if (!data) { return }
  205. const url = window.URL.createObjectURL(new Blob([data]))
  206. const link = document.createElement('a')
  207. link.style.display = 'none'
  208. link.href = url
  209. const fname = '散件导入错误项' + moment('YYYY_MMDD')
  210. link.setAttribute('download', fname + '.xlsx')
  211. document.body.appendChild(link)
  212. link.click()
  213. },
  214. setTableH () {
  215. const tableSearchH = this.$refs.tableSearch.offsetHeight
  216. this.tableHeight = window.innerHeight - tableSearchH - 400
  217. }
  218. },
  219. mounted () {
  220. const _this = this
  221. this.$nextTick(() => { // 页面渲染完成后的回调
  222. _this.setTableH()
  223. })
  224. },
  225. watch: {
  226. advanced (newValue, oldValue) {
  227. const _this = this
  228. setTimeout(() => {
  229. _this.setTableH()
  230. }, 400)
  231. }
  232. },
  233. activated () {
  234. // 如果是新页签打开,则重置当前页面
  235. if (this.$store.state.app.isNewTab) {
  236. this.resetSearchForm()
  237. }
  238. },
  239. beforeRouteEnter (to, from, next) {
  240. next(vm => {})
  241. }
  242. }
  243. </script>
  244. <style lang="less">
  245. .bulkImportList-wrap{
  246. .table-page-search-wrapper{
  247. overflow: hidden;
  248. .upload-file{
  249. height: auto;
  250. margin-bottom: 10px;
  251. .ant-btn{
  252. background-color: #f30;
  253. border-color: #f30;
  254. margin: 0 5px;
  255. font-size: 12px;
  256. color: #fff;
  257. }
  258. }
  259. }
  260. .importGuide-con{
  261. .explain-con{
  262. .explain-item{
  263. margin-bottom: 10px;
  264. .explain-tit{
  265. font-weight: bold;
  266. span{
  267. display: inline-block;
  268. width: 18px;
  269. height: 18px;
  270. line-height: 16px;
  271. text-align: center;
  272. margin-right: 5px;
  273. border-radius: 50%;
  274. border: 1px solid rgba(0, 0, 0, 0.3);
  275. }
  276. }
  277. p{
  278. margin: 8px 0;
  279. padding-left: 23px;
  280. }
  281. ul{
  282. list-style: none;
  283. padding: 0;
  284. padding-left: 23px;
  285. margin: 0;
  286. li{
  287. line-height: 26px;
  288. font-size: 12px;
  289. }
  290. }
  291. }
  292. }
  293. }
  294. .redBg-row{
  295. background-color: #F39494;
  296. }
  297. .btn-con{
  298. text-align: center;
  299. }
  300. }
  301. </style>