list.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <a-card size="small" :bordered="false" class="inventoryWarningList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="产品编码">
  10. <a-input id="inventoryWarningList-productCode" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="原厂编码">
  15. <a-input id="inventoryWarningList-productOrigCode" v-model.trim="queryParam.productOrigCode" allowClear placeholder="请输入原厂编码"/>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="产品名称">
  20. <a-input id="inventoryWarningList-productName" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  21. </a-form-item>
  22. </a-col>
  23. <template v-if="advanced">
  24. <a-col :md="6" :sm="24">
  25. <a-form-model-item label="产品品牌">
  26. <ProductBrand id="inventoryWarningList-productBrandSn" placeholder="请选择产品品牌" v-model="queryParam.productBrandSn"></ProductBrand>
  27. </a-form-model-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-model-item label="产品分类">
  31. <ProductType id="inventoryWarningList-productType" placeholder="请选择产品分类" :isDealer="true" @change="changeProductType" v-model="productType"></ProductType>
  32. </a-form-model-item>
  33. </a-col>
  34. <a-col :md="6" :sm="24">
  35. <a-form-item label="预警提示">
  36. <v-select
  37. v-model="queryParam.stockState"
  38. ref="stockState"
  39. id="inventoryWarningList-stockState"
  40. code="STOCK_WARN_TIP"
  41. placeholder="请选择预警提示"
  42. allowClear
  43. ></v-select>
  44. </a-form-item>
  45. </a-col>
  46. </template>
  47. <a-col :md="6" :sm="24">
  48. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="inventoryWarningList-refresh">查询</a-button>
  49. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="inventoryWarningList-reset">重置</a-button>
  50. <a-button
  51. type="primary"
  52. style="margin-left: 5px"
  53. @click="handleExport"
  54. :disabled="disabled"
  55. :loading="exportLoading"
  56. class="button-warning"
  57. id="inventoryWarningList-export-btn">导出</a-button>
  58. <a @click="advanced=!advanced" style="margin-left: 5px">
  59. {{ advanced ? '收起' : '展开' }}
  60. <a-icon :type="advanced ? 'up' : 'down'"/>
  61. </a>
  62. </a-col>
  63. </a-row>
  64. </a-form>
  65. <!-- 操作按钮 -->
  66. <div class="table-operator">
  67. <a-button type="primary" v-if="$hasPermissions('B_inventoryWarningBatchSave')" id="inventoryWarningList-update" @click="handleupdate">批量更新</a-button>
  68. <a-button
  69. type="primary"
  70. style="margin-left: 5px"
  71. class="button-warning"
  72. @click="openGuideModal=true"
  73. v-if="$hasPermissions('B_inventoryWarningProductImport')"
  74. id="inventoryWarningList-import-btn">导入产品</a-button>
  75. <span style="margin-left: 5px" v-if="$hasPermissions('B_inventoryWarningBatchSave')">
  76. <template v-if="rowSelectionInfo&&rowSelectionInfo.selectedRowKeys.length>0">{{ `已选 ${rowSelectionInfo.selectedRowKeys.length} 项` }}</template>
  77. </span>
  78. </div>
  79. </div>
  80. <!-- 列表 -->
  81. <s-table
  82. class="sTable fixPagination"
  83. ref="table"
  84. :style="{ height: tableHeight+68.5+'px' }"
  85. size="small"
  86. :rowKey="(record) => record.id"
  87. :row-selection="$hasPermissions('B_inventoryWarningBatchSave') ? { columnWidth: 40 } : null"
  88. @rowSelection="rowSelectionFun"
  89. :columns="columns"
  90. :data="loadData"
  91. :scroll="{ x: 1330, y: tableHeight }"
  92. :defaultLoadData="false"
  93. bordered>
  94. <!-- 产品分类 -->
  95. <template slot="productType" slot-scope="text, record">
  96. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  97. <span v-else>--</span>
  98. </template>
  99. <!-- 实时库存数 -->
  100. <template slot="stockQty" slot-scope="text, record">
  101. {{ record.currentStockQty + record.freezeQty }}
  102. <span v-if="record.freezeQty">(冻结{{ record.freezeQty }})</span>
  103. </template>
  104. <!-- 预警提示 -->
  105. <template slot="stockState" slot-scope="text, record">
  106. <span v-if="record.stockStateDictValue" :class="[record.stockState=='OVERFLOW'?'yellow':record.stockState=='NOT_ENOUGH'?'red':record.stockState=='LACK'?'blue':record.stockState=='NORMAL'?'green':'']">{{ record.stockStateDictValue }}</span>
  107. <span v-else>--</span>
  108. </template>
  109. <!-- 在途数 -->
  110. <!-- <template slot="inTransit" slot-scope="text, record" >
  111. <div>
  112. <a-input-number
  113. id="inventoryWarningList-inTransit"
  114. size="small"
  115. v-model="record.inTransit"
  116. :precision="0"
  117. :min="0"
  118. :max="999999"
  119. style="width: 100%;"
  120. @change="numChange(record)"
  121. placeholder="请输入在途数" />
  122. </div>
  123. </template> -->
  124. <!-- 最大库存数 -->
  125. <template slot="upperLimit" slot-scope="text, record" >
  126. <div>
  127. <a-input-number
  128. id="inventoryWarningList-upperLimit"
  129. size="small"
  130. v-model="record.upperLimit"
  131. :precision="0"
  132. :min="0"
  133. :max="999999"
  134. style="width: 100%;"
  135. @change="numChange(record)"
  136. placeholder="请输入最大库存数" />
  137. </div>
  138. </template>
  139. <!-- 最小库存数 -->
  140. <template slot="lowerLimit" slot-scope="text, record" >
  141. <div>
  142. <a-input-number
  143. id="inventoryWarningList-lowerLimit"
  144. size="small"
  145. v-model="record.lowerLimit"
  146. :precision="0"
  147. :min="0"
  148. :max="record.upperLimit"
  149. style="width: 100%;"
  150. @change="numChange(record)"
  151. placeholder="请输入最小库存数" />
  152. </div>
  153. </template>
  154. <!-- 操作 -->
  155. <template slot="action" slot-scope="text, record">
  156. <a-button
  157. type="link"
  158. v-if="$hasPermissions('B_inventoryWarningSave')"
  159. size="small"
  160. class="button-primary"
  161. @click="handleSave(record)"
  162. id="inventoryWarningList-add-btn">保存</a-button>
  163. <a-button type="link" v-if="record.dealerProduct.sysFlag==1&&record.dealerProduct.onlineFalg==1&&$hasPermissions('M_shoppingCart')" @click="addShopCar(record)">加入购物车</a-button>
  164. <span v-if="!$hasPermissions('B_inventoryWarningSave')">--</span>
  165. </template>
  166. </s-table>
  167. </a-spin>
  168. <!-- 导入产品 -->
  169. <importGuideModal :openModal="openGuideModal" @close="openGuideModal=false" @ok="resetSearchForm" />
  170. <!-- 设置采购数量 -->
  171. <set-purchase-qty ref="setPurchaseQty" :openModal="openPurchaseModal" @close="openPurchaseModal=false" v-drag></set-purchase-qty>
  172. </a-card>
  173. </template>
  174. <script>
  175. import { commonMixin } from '@/utils/mixin'
  176. import { STable, VSelect } from '@/components'
  177. import { stockWarnList, stockWarnSaveBatch, stockWarnExport } from '@/api/stockWarn'
  178. import { purchaseCartExistProduct } from '@/api/purchaseCart'
  179. import { downloadExcel } from '@/libs/JGPrint.js'
  180. import ProductType from '../../common/productType.js'
  181. import ProductBrand from '../../common/productBrand.js'
  182. import importGuideModal from './importGuideModal.vue'
  183. import setPurchaseQty from '@/views/inventoryManagement/inventoryQuery/setPurchaseQty.vue'
  184. export default {
  185. name: 'InventoryWarningList',
  186. components: { STable, VSelect, ProductType, ProductBrand, importGuideModal, setPurchaseQty },
  187. mixins: [commonMixin],
  188. data () {
  189. return {
  190. spinning: false,
  191. openGuideModal: false,
  192. openPurchaseModal: false,
  193. advanced: true, // 高级搜索 展开/关闭
  194. tableHeight: 0,
  195. queryParam: { // 查询条件
  196. productCode: '',
  197. productName: '',
  198. productOrigCode: '', // 原厂编码
  199. productBrandSn: undefined,
  200. productTypeSn1: undefined,
  201. productTypeSn2: undefined,
  202. productTypeSn3: undefined,
  203. stockState: undefined
  204. },
  205. exportLoading: false, // 导出loading
  206. disabled: false, // 查询、重置按钮是否可操作
  207. productBrandList: [], // 产品品牌下拉数据
  208. productTypeList: [], // 产品类别下拉数据
  209. productType: [],
  210. columns: [
  211. { title: '序号', dataIndex: 'no', width: 50, align: 'center', fixed: 'left' },
  212. { title: '产品编码', dataIndex: 'productCode', width: 120, align: 'center', customRender: function (text) { return text || '--' }, fixed: 'left' },
  213. { title: '产品名称', dataIndex: 'productName', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  214. { title: '原厂编码', dataIndex: 'productOrigCode', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  215. { title: '产品品牌', dataIndex: 'brandName', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  216. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 120, align: 'center' },
  217. { title: '在途数(个)', dataIndex: 'inTransit', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  218. { title: '总库存数(个)', dataIndex: 'currentStockQty', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  219. { title: '最大库存数(个)', scopedSlots: { customRender: 'upperLimit' }, width: 100, align: 'center' },
  220. { title: '最小库存数(个)', scopedSlots: { customRender: 'lowerLimit' }, width: 100, align: 'center' },
  221. { title: '差异数量', dataIndex: 'differenceNum', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  222. { title: '预警提示', scopedSlots: { customRender: 'stockState' }, width: 100, align: 'center' },
  223. { title: <div><a-tooltip placement='top' title='注意:购物车仅限添加箭冠已上线产品。'><a-icon type="question-circle" /></a-tooltip>&nbsp;操作</div>, scopedSlots: { customRender: 'action' }, width: 160, align: 'center', fixed: 'right' }
  224. ],
  225. // 加载数据方法 必须为 Promise 对象
  226. loadData: parameter => {
  227. this.disabled = true
  228. this.spinning = true
  229. return stockWarnList(Object.assign(parameter, this.queryParam)).then(res => {
  230. let data
  231. if (res.status == 200) {
  232. data = res.data
  233. const no = (data.pageNo - 1) * data.pageSize
  234. for (var i = 0; i < data.list.length; i++) {
  235. data.list[i].no = no + i + 1
  236. if (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys) { // 处理切换页码后 上页已选已输数据保留
  237. const ind = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.indexOf(data.list[i].id)
  238. if (ind >= 0) {
  239. data.list[i].inTransit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].inTransit
  240. data.list[i].upperLimit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].upperLimit
  241. data.list[i].lowerLimit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].lowerLimit
  242. }
  243. }
  244. }
  245. this.disabled = false
  246. }
  247. this.spinning = false
  248. return data
  249. })
  250. },
  251. loading: false,
  252. rowSelectionInfo: null
  253. }
  254. },
  255. methods: {
  256. // 加入购物车
  257. addShopCar (row) {
  258. this.spinning = true
  259. purchaseCartExistProduct({
  260. productSn: row.productSn
  261. }).then(res => {
  262. if (res.status == 200) {
  263. if (res.data) {
  264. this.$message.info('此产品已添加到购物车!')
  265. } else {
  266. this.$refs.setPurchaseQty.setData(row)
  267. this.openPurchaseModal = true
  268. }
  269. }
  270. this.spinning = false
  271. })
  272. },
  273. // 表格选中项
  274. rowSelectionFun (obj) {
  275. this.rowSelectionInfo = obj || null
  276. },
  277. numChange (row) {
  278. if (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys) { // 处理切换页码后 上页已选已输数据保留
  279. const ind = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.indexOf(row.id)
  280. if (ind >= 0) {
  281. this.rowSelectionInfo.selectedRows[ind].inTransit = row.inTransit
  282. this.rowSelectionInfo.selectedRows[ind].upperLimit = row.upperLimit
  283. this.rowSelectionInfo.selectedRows[ind].lowerLimit = row.lowerLimit
  284. }
  285. }
  286. },
  287. // 导出
  288. handleExport () {
  289. const _this = this
  290. _this.exportLoading = true
  291. stockWarnExport(_this.queryParam).then(res => {
  292. downloadExcel(res, '库存预警')
  293. _this.exportLoading = false
  294. })
  295. },
  296. // 保存
  297. handleSave (row, isBatch) {
  298. const params = []
  299. if (isBatch) { // 批量更新
  300. const dataInd = []
  301. this.rowSelectionInfo && this.rowSelectionInfo.selectedRows.map((item, index) => {
  302. if ((!item.inTransit && item.inTransit != 0) || (!item.upperLimit && item.upperLimit != 0) || (!item.lowerLimit && item.lowerLimit != 0)) {
  303. dataInd.push(item.no)
  304. }
  305. params.push({
  306. id: item.id,
  307. inTransit: item.inTransit,
  308. upperLimit: item.upperLimit,
  309. lowerLimit: item.lowerLimit
  310. })
  311. })
  312. if (dataInd.length > 0) {
  313. let str = ''
  314. dataInd.map(item => {
  315. str += item + '、'
  316. })
  317. str = str.substr(0, str.length - 1)
  318. this.$message.warning('请完善第' + str + '行数据后再提交')
  319. return
  320. }
  321. } else { // 单个保存
  322. if (!row.inTransit && row.inTransit != 0) {
  323. this.$message.warning('请输入在途数')
  324. return
  325. }
  326. if (!row.upperLimit && row.upperLimit != 0) {
  327. this.$message.warning('请输入最大库存数')
  328. return
  329. }
  330. if (!row.lowerLimit && row.lowerLimit != 0) {
  331. this.$message.warning('请输入最小库存数')
  332. return
  333. }
  334. params.push({
  335. id: row.id,
  336. inTransit: row.inTransit,
  337. upperLimit: row.upperLimit,
  338. lowerLimit: row.lowerLimit
  339. })
  340. }
  341. this.spinning = true
  342. stockWarnSaveBatch(params).then(res => {
  343. if (res.status == 200) {
  344. this.$message.success(res.message)
  345. this.$refs.table.refresh()
  346. this.$refs.table.clearSelected() // 清空表格选中项
  347. this.spinning = false
  348. } else {
  349. this.spinning = false
  350. }
  351. })
  352. },
  353. // 重置
  354. resetSearchForm () {
  355. this.queryParam.productCode = ''
  356. this.queryParam.productName = ''
  357. this.queryParam.productOrigCode = ''
  358. this.queryParam.productBrandSn = undefined
  359. this.queryParam.productTypeSn1 = undefined
  360. this.queryParam.productTypeSn2 = undefined
  361. this.queryParam.productTypeSn3 = undefined
  362. this.queryParam.stockState = undefined
  363. this.productType = []
  364. this.$refs.table.refresh(true)
  365. },
  366. // 批量更新
  367. handleupdate () {
  368. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  369. this.$message.warning('请在列表勾选后再进行批量操作!')
  370. return
  371. }
  372. const _this = this
  373. this.$confirm({
  374. title: '提示',
  375. content: '确定提交批量更新的内容吗?',
  376. centered: true,
  377. onOk () {
  378. _this.handleSave('', 'batch')
  379. }
  380. })
  381. },
  382. // 产品分类 change
  383. changeProductType (val, opt) {
  384. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  385. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  386. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  387. },
  388. pageInit () {
  389. const _this = this
  390. this.$nextTick(() => { // 页面渲染完成后的回调
  391. _this.setTableH()
  392. })
  393. },
  394. setTableH () {
  395. const tableSearchH = this.$refs.tableSearch.offsetHeight
  396. this.tableHeight = window.innerHeight - tableSearchH - 180
  397. }
  398. },
  399. watch: {
  400. advanced (newValue, oldValue) {
  401. const _this = this
  402. this.$nextTick(() => { // 页面渲染完成后的回调
  403. _this.setTableH()
  404. })
  405. },
  406. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  407. this.setTableH()
  408. }
  409. },
  410. mounted () {
  411. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  412. this.pageInit()
  413. this.resetSearchForm()
  414. }
  415. },
  416. activated () {
  417. // 如果是新页签打开,则重置当前页面
  418. if (this.$store.state.app.isNewTab) {
  419. this.pageInit()
  420. this.resetSearchForm()
  421. }
  422. },
  423. beforeRouteEnter (to, from, next) {
  424. next(vm => {})
  425. }
  426. }
  427. </script>
  428. <style lang="less">
  429. .inventoryWarningList-wrap{
  430. .green{
  431. color: #19be6b;
  432. }
  433. .red{
  434. color: #ed1c24;
  435. }
  436. .yellow{
  437. color: #ff9900;
  438. }
  439. .blue{
  440. color: #2db7f5;
  441. }
  442. }
  443. </style>