detailProductList.vue 15 KB

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