detailProductList.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <div class="productInfoList-wrap" style="position: relative;">
  3. <!-- alert -->
  4. <div style="margin-bottom: 10px;display: flex;align-items: center;" v-if="!showEmpty">
  5. <div style="display: flex;align-items: center;">
  6. <a-button id="dispatch-delAll" type="danger" :disabled="newLoading" @click="delSalerDetailAll">批量删除</a-button>
  7. <span style="margin-left: 10px;" v-if="selectedRowKeys.length">已选 {{ selectedRowKeys.length }} 项</span>
  8. </div>
  9. <div style="padding-left: 20px;">
  10. <slot name="total"></slot>
  11. </div>
  12. </div>
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <ve-table
  15. border-y
  16. :scroll-width="0"
  17. :max-height="tableHeight"
  18. :show-header="showTableHead"
  19. :row-style-option="{clickHighlight: true}"
  20. :cellSelectionOption="{enable: false}"
  21. :virtual-scroll-option="{enable: true}"
  22. :columns="columns"
  23. :table-data="dataSource"
  24. row-key-field-name="id"
  25. :checkbox-option="checkboxOption"
  26. />
  27. <div v-show="showEmpty" class="empty-data3"><a-empty description="暂无产品" :image="simpleImage"/></div>
  28. </a-spin>
  29. <!-- 活动规则详情 -->
  30. <detailModal :openModal="openDetailModal" :itemSn="detailSn" @close="closeDetailModal"></detailModal>
  31. </div>
  32. </template>
  33. <script>
  34. import { commonMixin } from '@/utils/mixin'
  35. import { deleteBatch, waitDispatchDetailAllList, updateQty } from '@/api/waitDispatchDetail'
  36. import { Empty } from 'ant-design-vue'
  37. import { STable, VSelect } from '@/components'
  38. import detailModal from '@/views/promotionRulesManagement/dealerPromotions/detailModal.vue'
  39. import chooseWarehouse from '@/views/common/chooseWarehouse'
  40. export default {
  41. name: 'DetailProductList',
  42. mixins: [commonMixin],
  43. components: { STable, VSelect, chooseWarehouse, detailModal },
  44. props: {
  45. newLoading: {
  46. type: Boolean,
  47. default: false
  48. },
  49. maxHeight: { // 表格高度
  50. type: [String, Number],
  51. default: '300'
  52. },
  53. showHeader: { // 是否显示表格头部
  54. type: Boolean,
  55. default: true
  56. }
  57. },
  58. data () {
  59. return {
  60. productForm: {
  61. dispatchBillSn: '' // 下推单sn
  62. },
  63. disabled: false, // 查询、重置按钮是否可操作
  64. spinning: false,
  65. simpleImage: Empty.PRESENTED_IMAGE_SIMPLE, // 无数据图片
  66. dataSource: [], // 原始数据
  67. tableHeight: this.maxHeight, // 表格高度
  68. // 可拖曳调整列宽
  69. columnWidthResizeOption: {
  70. enable: true,
  71. minWidth: 50
  72. },
  73. showEmpty: false, // 是否显示暂无数据
  74. showTableHead: true, // 是否显示表格头部
  75. disableSelectedRowKeys: [], // 禁用的行
  76. selectedRowKeys: [], // 已选行
  77. detailData: null, // 详情数据
  78. activeList: [], // 参与活动列表
  79. openDetailModal: false, // 活动规则详情弹框
  80. detailSn: null // 活动详情sn
  81. }
  82. },
  83. computed: {
  84. // 表格复选框设置
  85. checkboxOption () {
  86. return {
  87. disableSelectedRowKeys: this.disableSelectedRowKeys,
  88. selectedRowKeys: this.selectedRowKeys,
  89. // 行选择改变事件
  90. selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
  91. this.selectedRowChange({ row, isSelected, selectedRowKeys })
  92. },
  93. // 全选改变事件
  94. selectedAllChange: ({ isSelected, selectedRowKeys }) => {
  95. this.selectedAllChange({ isSelected, selectedRowKeys })
  96. }
  97. }
  98. },
  99. columns () {
  100. const _this = this
  101. // 价格
  102. const priceFormat = function (data) {
  103. return _this.toThousands(data) || '--'
  104. }
  105. // 数字
  106. const numsFormat = function (data) {
  107. return data || data == 0 ? data : '--'
  108. }
  109. // 单号
  110. const codeFormat = function (record, data, h) {
  111. return (
  112. <div>
  113. <span style="padding-right: 10px;">{data}</span>
  114. {record.promotionFlag.indexOf('GIFT') >= 0 ? <a-badge count="促" numberStyle={{ backgroundColor: '#52c41a', zoom: '0.7' }}/> : ''}
  115. {record.promotionFlag.indexOf('DISCOUNT') >= 0 ? <a-badge count="特" numberStyle={{ backgroundColor: '#faad14', zoom: '0.7' }}/> : ''}
  116. {record.promotionFlag.indexOf('GATE') >= 0 ? <a-badge count="槛" numberStyle={{ backgroundColor: '#108ee9', zoom: '0.7' }}/> : ''}
  117. {record.promotionFlag.indexOf('REGULAR') >= 0 ? <a-badge count="正" numberStyle={{ backgroundColor: '#ff5500', zoom: '0.7' }}/> : ''}
  118. {Number(record.stockQty || 0) < Number(record.unpushedQty || 0) ? (<a-badge count="缺" number-style={{ zoom: '0.7' }}></a-badge>) : ''}
  119. </div>
  120. )
  121. }
  122. // 输入框
  123. const inputFormat = function (record, data, h) {
  124. if (record.surplusQty > 0) {
  125. return (
  126. <div>
  127. <a-input-number
  128. id={'dispatch-qty-' + record.productSn}
  129. size="small"
  130. value={record.qty}
  131. onChange={e => record.qty = e}
  132. onBlur={e => _this.cancelNumsChange(e, record)}
  133. precision={0}
  134. min={1}
  135. max={record.surplusQty}
  136. style="width: 100%;"
  137. placeholder="请输入" />
  138. </div>
  139. )
  140. }
  141. return '--'
  142. }
  143. // 操作按钮
  144. const actionFormat = function (record, data, h) {
  145. if (record.surplusQty > 0) {
  146. return (
  147. <div>
  148. <a-button
  149. id={'dispatch-delBtn-' + record.productSn}
  150. size="small"
  151. type="link"
  152. class="button-error"
  153. onClick={() => _this.handleDel(record)}
  154. >删除</a-button>
  155. </div>
  156. )
  157. }
  158. return '--'
  159. }
  160. const arr = [
  161. { title: '', field: '', key: 'acheck', width: 60, type: 'checkbox', align: 'center' },
  162. { title: '序号', field: 'no', key: 'a', width: 60, align: 'center', operationColumn: false },
  163. { title: '产品编码', field: 'productCode', key: 'b', width: 350, align: 'left', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return codeFormat(row, row[column.field], h) } },
  164. { title: '出库仓库', field: 'warehouseName', key: 'e', width: 150, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
  165. { title: '待下推数量', field: 'surplusQty', key: 'o', width: 150, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } },
  166. { title: '本次下推数', field: 'qty', key: 'r', width: 150, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return inputFormat(row, row[column.field], h) } },
  167. { title: '单位', field: 'productOrigUnit', width: 100, key: 'i', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
  168. { title: '操作', field: 'action', width: 100, key: 's', align: 'center', fixed: 'right', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return actionFormat(row, row[column.field], h) } }
  169. ]
  170. if (this.detailData && this.detailData.promoFlag == 1) {
  171. arr.splice(2, 0, {
  172. title: '规则数量',
  173. field: 'prompName',
  174. key: 'm',
  175. align: 'center',
  176. width: 80,
  177. operationColumn: false,
  178. ellipsis: { showTitle: false },
  179. renderBodyCell: ({ row, column, rowIndex }, h) => {
  180. return (
  181. row.promoRuleSnList && row.promoRuleSnList.length > 0
  182. ? <a-popover placement="right">
  183. <template slot="content">
  184. {row.promoRuleSnList.map(item => {
  185. return (
  186. <div
  187. id={'ruleDetail-' + row.productSn}
  188. title="点击查看详情"
  189. style="padding:5px 0;cursor: pointer;"
  190. onClick={() => _this.showRuleDetail(item)}
  191. >{ _this.activeRuleFilter(item) }</div>
  192. )
  193. })}
  194. </template>
  195. <a-button type="link" id={'ruleSn-' + row.productSn} size="small" class="button-info">
  196. {row.promoRuleSnList.length}<span style="zoom:0.6;color: #666;">个 ∨</span>
  197. </a-button>
  198. </a-popover>
  199. : <div>--</div>
  200. )
  201. } })
  202. arr.splice(3, 0, { title: '产品名称', field: 'productName', key: 'c', align: 'left', operationColumn: false, ellipsis: { showTitle: true }, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } })
  203. } else {
  204. arr.splice(2, 0, { title: '产品名称', field: 'productName', key: 'c', align: 'left', operationColumn: false, ellipsis: { showTitle: true }, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } })
  205. }
  206. return arr
  207. }
  208. },
  209. methods: {
  210. // 参与规则名称
  211. activeRuleFilter (val) {
  212. const row = this.activeList.length && this.activeList.find(item => item.promoRuleSn == val)
  213. return row ? row.promotionRule.description + '-' + row.promotion.description : ''
  214. },
  215. // 查看参与规则详情
  216. showRuleDetail (promoRuleSn) {
  217. this.detailSn = promoRuleSn
  218. this.openDetailModal = true
  219. },
  220. // 关闭详情弹窗
  221. closeDetailModal () {
  222. this.detailSn = null
  223. this.openDetailModal = false
  224. },
  225. // 选择单元格
  226. selectedRowChange ({ row, isSelected, selectedRowKeys }) {
  227. this.selectedRowKeys = selectedRowKeys
  228. },
  229. // 全选行
  230. selectedAllChange ({ isSelected, selectedRowKeys }) {
  231. this.selectedRowKeys = selectedRowKeys
  232. },
  233. // 数据查询
  234. async searchTable () {
  235. this.selectedRowKeys = []
  236. this.disableSelectedRowKeys = []
  237. this.dataSource = []
  238. this.disabled = true
  239. this.spinning = true
  240. const params = this.productForm
  241. // 带下推产品
  242. const listData = await waitDispatchDetailAllList(params).then(res => res.data)
  243. this.dataSource = listData
  244. // 格式化数据
  245. let f = 0
  246. let hasLt = false
  247. this.dataSource.map((item, i) => {
  248. if (item.id.indexOf('promo-') >= 0) { f = f - 1 }
  249. item.no = i + 1 + f
  250. const productCode = (item.productEntity && item.productEntity.code) || (item.dealerProductEntity && item.dealerProductEntity.code)
  251. const productName = (item.productEntity && item.productEntity.name) || (item.dealerProductEntity && item.dealerProductEntity.name)
  252. const productOrigCode = (item.productEntity && item.productEntity.origCode) || (item.dealerProductEntity && item.dealerProductEntity.origCode)
  253. const productOrigUnit = (item.productEntity && item.productEntity.unit) || (item.dealerProductEntity && item.dealerProductEntity.unit)
  254. const warehouseName = item.dispatchBill && item.dispatchBill.warehouseName || ''
  255. const prompName = item.promotionRule ? (item.promotionRule.promotion && item.promotionRule.promotion.description) + '(' + item.promotionRule.description + ')' : '--'
  256. item.productCode = productCode || '--'
  257. item.productName = productName || '--'
  258. item.productOrigCode = productOrigCode == ' ' ? '--' : productOrigCode
  259. item.productOrigUnit = productOrigUnit || '--'
  260. item.warehouseName = warehouseName || '--'
  261. item.promoRuleSnList = item.promotionRuleList && item.promotionRuleList.map(item => item.promotionRuleSn) // 规则sn
  262. item.qtyBackups = item.qty
  263. item.prompName = prompName || '--'
  264. const productBrand = (item.productEntity && item.productEntity.productBrandName) || (item.dealerProductEntity && item.dealerProductEntity.productBrandName)
  265. const productType3 = (item.productEntity && item.productEntity.productTypeName3) || (item.dealerProductEntity && item.dealerProductEntity.productTypeName3)
  266. if (productBrand && productBrand.indexOf('箭冠') >= 0 && productBrand && productType3.indexOf('轮胎') >= 0) {
  267. hasLt = true
  268. }
  269. })
  270. this.showEmpty = this.dataSource.length <= 0
  271. const len = this.dataSource.length
  272. if (len < 8) {
  273. this.tableHeight = this.showEmpty ? 200 : (len + 1) * 34 - 1 + 'px'
  274. } else {
  275. this.tableHeight = this.maxHeight + 'px'
  276. }
  277. this.$emit('upStockType', hasLt)
  278. this.spinning = false
  279. this.disabled = false
  280. },
  281. // 重置
  282. resetSearchForm () {
  283. this.dataSource = []
  284. this.clearSelectTable()
  285. this.searchTable()
  286. },
  287. // 页面初始化
  288. pageInit (productForm, detailData, activeList) {
  289. this.productForm = Object.assign(this.productForm, productForm)
  290. this.detailData = detailData
  291. this.activeList = activeList
  292. // 查询列表
  293. this.resetSearchForm()
  294. },
  295. // 清空选项
  296. clearSelectTable () {
  297. this.selectedRowKeys = []
  298. },
  299. // 取消数量修改
  300. cancelNumsChange (e, record) {
  301. const _this = this
  302. const val = e.target.value
  303. if (val && val != record.qtyBackups && val <= record.surplusQty) {
  304. _this.spinning = true
  305. updateQty({
  306. dispatchBillDetailSn: record.dispatchBillDetailSn,
  307. qty: record.qty,
  308. salesBillSn: _this.detailData.salesBillSn,
  309. dispatchBillSn: _this.productForm.dispatchBillSn
  310. }).then(res => {
  311. if (res.status == 200) {
  312. _this.$message.success(res.message)
  313. _this.spinning = false
  314. _this.$emit('refashTable', true)
  315. } else {
  316. record.qty = record.qtyBackups
  317. _this.spinning = false
  318. }
  319. })
  320. } else {
  321. record.qty = record.qtyBackups
  322. }
  323. },
  324. // 删除产品
  325. handleDel (row) {
  326. const _this = this
  327. this.$confirm({
  328. title: '提示',
  329. content: '确认要删除吗?',
  330. centered: true,
  331. closable: true,
  332. onOk () {
  333. _this.deleteFun(row, 0)
  334. }
  335. })
  336. },
  337. // 删除接口
  338. deleteFun (row, type) {
  339. const _this = this
  340. _this.spinning = true
  341. deleteBatch({
  342. dispatchBillSn: this.productForm.dispatchBillSn,
  343. dispatchBillDetailList: type == 0 ? [row.dispatchBillDetailSn] : row
  344. }).then(res => {
  345. if (res.status == 200) {
  346. _this.$emit('refashTable', true)
  347. _this.$message.success(res.message)
  348. _this.spinning = false
  349. } else {
  350. _this.spinning = false
  351. }
  352. })
  353. },
  354. // 批量删除
  355. delSalerDetailAll () {
  356. const _this = this
  357. const chooseList = this.selectedRowKeys
  358. if (chooseList.length == 0) {
  359. _this.$message.warning('请选择待下推产品!')
  360. return
  361. }
  362. const chooseRow = this.dataSource.filter(item => chooseList.includes(item.id) && item.id.indexOf('promo-') < 0)
  363. const obj = []
  364. chooseRow && chooseRow.map(item => {
  365. obj.push(item.dispatchBillDetailSn)
  366. })
  367. this.$confirm({
  368. title: '提示',
  369. content: '确认要批量删除吗?',
  370. centered: true,
  371. closable: true,
  372. onOk () {
  373. _this.deleteFun(obj, 1)
  374. }
  375. })
  376. }
  377. }
  378. }
  379. </script>
  380. <style lang="less">
  381. .empty-data3{
  382. color: #999;
  383. text-align: center;
  384. padding: 20px;
  385. position: absolute;
  386. top: 30px;
  387. width: 100%;
  388. }
  389. .ve-table-body-td{
  390. .active-title{
  391. display: flex;
  392. align-items: center;
  393. justify-content: space-between;
  394. padding: 10px;
  395. background: #f3f8fa;
  396. }
  397. }
  398. .ve-table .ve-table-container .ve-table-content-wrapper table.ve-table-content tbody.ve-table-body tr.ve-table-body-tr td.table-body-cell-no,
  399. .ve-table .ve-table-container .ve-table-content-wrapper table.ve-table-content tbody.ve-table-body tr.ve-table-expand-tr td.table-body-cell-no{
  400. padding: 0;
  401. }
  402. .ve-table .ve-table-container .ve-table-content-wrapper{
  403. border-bottom: 1px solid #ddd;
  404. }
  405. </style>