list.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <a-card size="small" :bordered="false" class="inventoryWarningList-wrap">
  3. <!-- 搜索条件 -->
  4. <div class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="pageInit(1)">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="产品编码">
  9. <a-input id="inventoryWarningList-productCode" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="原厂编码">
  14. <a-input id="inventoryWarningList-productOrigCode" v-model.trim="queryParam.productOrigCode" allowClear placeholder="请输入原厂编码"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="6" :sm="24">
  18. <a-form-item label="产品名称">
  19. <a-input id="inventoryWarningList-productName" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  20. </a-form-item>
  21. </a-col>
  22. <template v-if="advanced">
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="产品品牌">
  25. <a-select
  26. placeholder="请选择产品品牌"
  27. id="inventoryWarningList-productBrandSn"
  28. allowClear
  29. v-model="queryParam.productBrandSn"
  30. :showSearch="true"
  31. option-filter-prop="children"
  32. :filter-option="filterOption">
  33. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  34. </a-select>
  35. </a-form-item>
  36. </a-col>
  37. <a-col :md="6" :sm="24">
  38. <a-form-item label="产品分类">
  39. <a-cascader
  40. @change="changeProductType"
  41. change-on-select
  42. v-model="productType"
  43. expand-trigger="hover"
  44. :options="productTypeList"
  45. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  46. id="inventoryWarningList-productType"
  47. placeholder="请选择产品分类"
  48. allowClear />
  49. </a-form-item>
  50. </a-col>
  51. <a-col :md="6" :sm="24">
  52. <a-form-item label="预警提示">
  53. <v-select
  54. v-model="queryParam.warnTip"
  55. ref="warnTip"
  56. id="inventoryWarningList-warnTip"
  57. code="STOCK_WARN_TIP"
  58. placeholder="请选择预警提示"
  59. allowClear
  60. ></v-select>
  61. </a-form-item>
  62. </a-col>
  63. </template>
  64. <a-col :md="6" :sm="24">
  65. <a-button type="primary" @click="pageInit(1)" :disabled="disabled" id="inventoryWarningList-refresh">查询</a-button>
  66. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="inventoryWarningList-reset">重置</a-button>
  67. <a-button
  68. style="margin-left: 8px"
  69. type="danger"
  70. @click="handleExport"
  71. :disabled="disabled"
  72. :loading="exportLoading"
  73. id="inventoryWarningList-export">导出</a-button>
  74. <a @click="advanced=!advanced" style="margin-left: 8px">
  75. {{ advanced ? '收起' : '展开' }}
  76. <a-icon :type="advanced ? 'up' : 'down'"/>
  77. </a>
  78. </a-col>
  79. </a-row>
  80. </a-form>
  81. </div>
  82. <!-- 操作按钮 -->
  83. <div class="table-operator">
  84. <a-button id="inventoryWarningList-update" type="primary" @click="handleupdate">批量更新</a-button>
  85. </div>
  86. <!-- 列表 -->
  87. <a-table
  88. class="sTable"
  89. ref="table"
  90. size="default"
  91. :rowKey="(record) => record.id"
  92. :columns="columns"
  93. :dataSource="loadData"
  94. :scroll="{ x: 2070, y: tableHeight }"
  95. :pagination="paginationProps"
  96. bordered>
  97. <!-- 产品分类 -->
  98. <template slot="productType" slot-scope="text, record">
  99. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  100. <span v-else>--</span>
  101. </template>
  102. <!-- 预警提示 -->
  103. <template slot="warnTip" slot-scope="text, record">
  104. <span v-if="record.warnTipDictValue" :class="[record.warnTip=='OVERFLOW'?'yellow':record.warnTip=='NOT_ENOUGH'?'red':record.warnTip=='LACK'?'blue':record.warnTip=='NORMAL'?'green':'']">{{ record.warnTipDictValue }}</span>
  105. <span v-else>--</span>
  106. </template>
  107. <!-- 在途数 -->
  108. <template slot="inTransit" slot-scope="text, record" >
  109. <div>
  110. <a-input-number
  111. id="inventoryWarningList-inTransit"
  112. v-model="record.inTransit"
  113. :precision="0"
  114. :min="0"
  115. :max="999999"
  116. placeholder="请输入在途数" />
  117. </div>
  118. </template>
  119. <!-- 最大库存数 -->
  120. <template slot="upperLimit" slot-scope="text, record" >
  121. <div>
  122. <a-input-number
  123. id="inventoryWarningList-upperLimit"
  124. v-model="record.upperLimit"
  125. :precision="0"
  126. :min="0"
  127. :max="999999"
  128. placeholder="请输入最大库存数" />
  129. </div>
  130. </template>
  131. <!-- 最小库存数 -->
  132. <template slot="lowerLimit" slot-scope="text, record" >
  133. <div>
  134. <a-input-number
  135. id="inventoryWarningList-lowerLimit"
  136. v-model="record.lowerLimit"
  137. :precision="0"
  138. :min="0"
  139. :max="999999"
  140. placeholder="请输入最小库存数" />
  141. </div>
  142. </template>
  143. <!-- 操作 -->
  144. <template slot="action" slot-scope="text, record">
  145. <a-button type="primary" class="button-primary" @click="handleSave(record)" id="inventoryWarningList-add-btn">保存</a-button>
  146. </template>
  147. </a-table>
  148. </a-card>
  149. </template>
  150. <script>
  151. import moment from 'moment'
  152. import { STable, VSelect } from '@/components'
  153. import { stockWarnList, stockWarnSaveBatch } from '@/api/stockWarn'
  154. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  155. import { dealerProductTypeList } from '@/api/dealerProductType'
  156. export default {
  157. components: { STable, VSelect },
  158. data () {
  159. return {
  160. advanced: false, // 高级搜索 展开/关闭
  161. tableHeight: 0,
  162. queryParam: { // 查询条件
  163. productCode: '',
  164. productName: '',
  165. productOrigCode: '', // 原厂编码
  166. productBrandSn: undefined,
  167. productTypeSn1: undefined,
  168. productTypeSn2: undefined,
  169. productTypeSn3: undefined,
  170. warnTip: undefined
  171. },
  172. exportLoading: false, // 导出loading
  173. disabled: false, // 查询、重置按钮是否可操作
  174. productBrandList: [], // 产品品牌下拉数据
  175. productTypeList: [], // 产品类别下拉数据
  176. productType: [],
  177. columns: [
  178. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  179. { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  180. { title: '产品名称', dataIndex: 'productName', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  181. { title: '原厂编码', dataIndex: 'productOrigCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  182. { title: '产品品牌', dataIndex: 'brandName', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  183. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 200, align: 'center' },
  184. { title: '实时库存数(个)', dataIndex: 'stockQty', width: 130, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  185. { title: '在途数(个)', scopedSlots: { customRender: 'inTransit' }, width: 130, align: 'center' },
  186. { title: '总库存数(个)', dataIndex: 'totalStockQty', width: 130, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  187. { title: '最大库存数(个)', scopedSlots: { customRender: 'upperLimit' }, width: 130, align: 'center' },
  188. { title: '最小库存数(个)', scopedSlots: { customRender: 'lowerLimit' }, width: 130, align: 'center' },
  189. { title: '差异数量', dataIndex: 'differenceNum', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  190. { title: '预警提示', scopedSlots: { customRender: 'warnTip' }, width: 100, align: 'center' },
  191. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  192. ],
  193. loadData: [],
  194. pageNo: 1, // 分页页码
  195. pageSize: 10, // 分页 每页多少条
  196. paginationProps: {
  197. showSizeChanger: true, // 是否可以改变 pageSize
  198. total: 0, // 分页总条数
  199. current: 1,
  200. onShowSizeChange: (current, pageSize) => this.changePageSize(current, pageSize),
  201. onChange: (current) => this.changePage(current)
  202. }
  203. }
  204. },
  205. methods: {
  206. // 分页 一页多少条change
  207. changePageSize (current, pageSize) {
  208. this.pageNo = current
  209. this.pageSize = pageSize
  210. this.pageInit()
  211. },
  212. // 分页 页码change
  213. changePage (current) {
  214. this.pageNo = current
  215. this.pageInit()
  216. },
  217. // 列表数据
  218. pageInit (pageNo) {
  219. if (this.tableHeight == 0) {
  220. this.tableHeight = window.innerHeight - 380
  221. }
  222. this.disabled = true
  223. this.pageNo = pageNo || this.pageNo
  224. const params = Object.assign({ pageNo: this.pageNo, pageSize: this.pageSize }, this.queryParam)
  225. stockWarnList(params).then(res => {
  226. if (res.status == 200) {
  227. const data = res.data
  228. this.paginationProps.total = Number(res.data.count) || 0
  229. this.paginationProps.current = this.pageNo
  230. const no = (data.pageNo - 1) * data.pageSize
  231. for (var i = 0; i < data.list.length; i++) {
  232. data.list[i].no = no + i + 1
  233. }
  234. this.loadData = data.list
  235. this.disabled = false
  236. } else {
  237. this.paginationProps.total = 0
  238. this.paginationProps.current = 1
  239. this.loadData = []
  240. }
  241. })
  242. },
  243. // 保存
  244. handleSave (row, isBatch) {
  245. const params = []
  246. if (isBatch) { // 批量更新
  247. let dataInd = -1
  248. this.loadData.map((item, index) => {
  249. if ((!item.inTransit && item.inTransit != 0) || (!item.upperLimit && item.upperLimit != 0) || (!item.lowerLimit && item.lowerLimit != 0)) {
  250. dataInd = 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 != -1) {
  260. this.$message.warning('请完善第' + dataInd + '行数据后再提交')
  261. return
  262. }
  263. } else { // 单个保存
  264. if (!row.inTransit && row.inTransit != 0) {
  265. this.$message.warning('请输入在途数')
  266. return
  267. }
  268. if (!row.upperLimit && row.upperLimit != 0) {
  269. this.$message.warning('请输入最大库存数')
  270. return
  271. }
  272. if (!row.lowerLimit && row.lowerLimit != 0) {
  273. this.$message.warning('请输入最小库存数')
  274. return
  275. }
  276. params.push({
  277. id: row.id,
  278. inTransit: row.inTransit,
  279. upperLimit: row.upperLimit,
  280. lowerLimit: row.lowerLimit
  281. })
  282. }
  283. stockWarnSaveBatch(params).then(res => {
  284. if (res.status == 200) {
  285. this.$message.success(res.message)
  286. this.pageInit()
  287. }
  288. })
  289. },
  290. // 重置
  291. resetSearchForm () {
  292. this.queryParam.productCode = ''
  293. this.queryParam.productName = ''
  294. this.queryParam.productOrigCode = ''
  295. this.queryParam.productBrandSn = undefined
  296. this.queryParam.productTypeSn1 = undefined
  297. this.queryParam.productTypeSn2 = undefined
  298. this.queryParam.productTypeSn3 = undefined
  299. this.queryParam.warnTip = undefined
  300. this.pageInit(1)
  301. },
  302. // 批量更新
  303. handleupdate () {
  304. const _this = this
  305. this.$confirm({
  306. title: '提示',
  307. content: '确定提交批量更新的内容吗?',
  308. centered: true,
  309. onOk () {
  310. _this.handleSave('', 'batch')
  311. }
  312. })
  313. },
  314. // 产品分类 change
  315. changeProductType (val, opt) {
  316. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  317. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  318. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  319. },
  320. // 产品品牌 列表
  321. getProductBrand () {
  322. // sysFlag不传,此处应查询所有产品
  323. dealerProductBrandQuery({}).then(res => {
  324. if (res.status == 200) {
  325. this.productBrandList = res.data
  326. } else {
  327. this.productBrandList = []
  328. }
  329. })
  330. },
  331. // 产品分类 列表
  332. getProductType () {
  333. dealerProductTypeList({}).then(res => {
  334. if (res.status == 200) {
  335. this.productTypeList = res.data
  336. } else {
  337. this.productTypeList = []
  338. }
  339. })
  340. },
  341. filterOption (input, option) {
  342. return (
  343. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  344. )
  345. },
  346. // 导出
  347. handleExport () {
  348. const params = this.queryParam
  349. this.exportLoading = true
  350. // customerBundleExportDelay(params).then(res => {
  351. // this.exportLoading = false
  352. // this.download(res)
  353. // })
  354. },
  355. // 下载
  356. download (data) {
  357. if (!data) { return }
  358. const url = window.URL.createObjectURL(new Blob([data]))
  359. const link = document.createElement('a')
  360. link.style.display = 'none'
  361. link.href = url
  362. const a = moment().format('YYYYMMDDHHmmss')
  363. const fname = '库存预警' + a
  364. link.setAttribute('download', fname + '.xlsx')
  365. document.body.appendChild(link)
  366. link.click()
  367. }
  368. },
  369. beforeRouteEnter (to, from, next) {
  370. next(vm => {
  371. vm.pageInit(1)
  372. vm.getProductType()
  373. vm.getProductBrand()
  374. })
  375. }
  376. }
  377. </script>
  378. <style lang="less">
  379. .inventoryWarningList-wrap{
  380. .green{
  381. color: #19be6b;
  382. }
  383. .red{
  384. color: #ed1c24;
  385. }
  386. .yellow{
  387. color: #ff9900;
  388. }
  389. .blue{
  390. color: #2db7f5;
  391. }
  392. }
  393. </style>