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