list.vue 10 KB

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