detailProductList.vue 14 KB

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