list.vue 12 KB

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