list.vue 10 KB

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