123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- <template>
- <div class="productInfoList-wrap" style="position: relative;">
- <!-- alert -->
- <div style="margin-bottom: 10px;display: flex;align-items: center;" v-if="!showEmpty">
- <div style="display: flex;align-items: center;">
- <a-button id="dispatch-delAll" type="danger" :disabled="newLoading" @click="delSalerDetailAll">批量删除</a-button>
- <span style="margin-left: 10px;" v-if="selectedRowKeys.length">已选 {{ selectedRowKeys.length }} 项</span>
- </div>
- <div style="padding-left: 20px;">
- <slot name="total"></slot>
- </div>
- </div>
- <a-spin :spinning="spinning" tip="Loading...">
- <ve-table
- border-y
- :scroll-width="0"
- :max-height="tableHeight"
- :show-header="showTableHead"
- :row-style-option="{clickHighlight: true}"
- :cellSelectionOption="{enable: false}"
- :virtual-scroll-option="{enable: true}"
- :columns="columns"
- :table-data="dataSource"
- row-key-field-name="id"
- :checkbox-option="checkboxOption"
- />
- <div v-show="showEmpty" class="empty-data"><a-empty description="暂无产品" :image="simpleImage"/></div>
- </a-spin>
- </div>
- </template>
- <script>
- import { commonMixin } from '@/utils/mixin'
- import { deleteBatch, waitDispatchDetailAllList, updateQty } from '@/api/waitDispatchDetail'
- import { Empty } from 'ant-design-vue'
- import { STable, VSelect } from '@/components'
- import chooseWarehouse from '@/views/common/chooseWarehouse'
- export default {
- name: 'DetailProductList',
- mixins: [commonMixin],
- components: { STable, VSelect, chooseWarehouse },
- props: {
- newLoading: {
- type: Boolean,
- default: false
- },
- maxHeight: { // 表格高度
- type: [String, Number],
- default: '300'
- },
- showHeader: { // 是否显示表格头部
- type: Boolean,
- default: true
- }
- },
- data () {
- return {
- productForm: {
- dispatchBillSn: '' // 下推单sn
- },
- disabled: false, // 查询、重置按钮是否可操作
- spinning: false,
- simpleImage: Empty.PRESENTED_IMAGE_SIMPLE, // 无数据图片
- dataSource: [], // 原始数据
- tableHeight: this.maxHeight, // 表格高度
- // 可拖曳调整列宽
- columnWidthResizeOption: {
- enable: true,
- minWidth: 50
- },
- showEmpty: false, // 是否显示暂无数据
- showTableHead: true, // 是否显示表格头部
- disableSelectedRowKeys: [], // 禁用的行
- selectedRowKeys: [], // 已选行
- detailData: null, // 详情数据
- activeList: [] // 参与活动列表
- }
- },
- computed: {
- // 表格复选框设置
- checkboxOption () {
- return {
- disableSelectedRowKeys: this.disableSelectedRowKeys,
- selectedRowKeys: this.selectedRowKeys,
- // 行选择改变事件
- selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
- this.selectedRowChange({ row, isSelected, selectedRowKeys })
- },
- // 全选改变事件
- selectedAllChange: ({ isSelected, selectedRowKeys }) => {
- this.selectedAllChange({ isSelected, selectedRowKeys })
- }
- }
- },
- columns () {
- const _this = this
- // 价格
- const priceFormat = function (data) {
- return _this.toThousands(data) || '--'
- }
- // 数字
- const numsFormat = function (data) {
- return data || data == 0 ? data : '--'
- }
- // 单号
- const codeFormat = function (record, data, h) {
- return (
- <div>
- <span style="padding-right: 10px;">{data}</span>
- {record.promotionFlag.indexOf('GIFT') >= 0 ? <a-badge count="促" numberStyle={{ backgroundColor: '#52c41a', zoom: '0.7' }}/> : ''}
- {record.promotionFlag.indexOf('DISCOUNT') >= 0 ? <a-badge count="特" numberStyle={{ backgroundColor: '#faad14', zoom: '0.7' }}/> : ''}
- {record.promotionFlag.indexOf('GATE') >= 0 ? <a-badge count="槛" numberStyle={{ backgroundColor: '#108ee9', zoom: '0.7' }}/> : ''}
- {record.promotionFlag.indexOf('REGULAR') >= 0 ? <a-badge count="正" numberStyle={{ backgroundColor: '#ff5500', zoom: '0.7' }}/> : ''}
- {Number(record.stockQty || 0) < Number(record.unpushedQty || 0) ? (<a-badge count="缺" number-style={{ zoom: '0.7' }}></a-badge>) : ''}
- </div>
- )
- }
- // 输入框
- const inputFormat = function (record, data, h) {
- if (record.surplusQty > 0) {
- return (
- <div>
- <a-input-number
- id={'dispatch-qty-' + record.productSn}
- size="small"
- value={record.qty}
- onChange={e => record.qty = e}
- onBlur={e => _this.cancelNumsChange(e, record)}
- precision={0}
- min={1}
- max={record.surplusQty}
- style="width: 100%;"
- placeholder="请输入" />
- </div>
- )
- }
- return '--'
- }
- // 操作按钮
- const actionFormat = function (record, data, h) {
- if (record.surplusQty > 0) {
- return (
- <div>
- <a-button
- id={'dispatch-delBtn-' + record.productSn}
- size="small"
- type="link"
- class="button-error"
- onClick={() => _this.handleDel(record)}
- >删除</a-button>
- </div>
- )
- }
- return '--'
- }
- const arr = [
- { title: '', field: '', key: 'acheck', width: 60, type: 'checkbox', align: 'center' },
- { title: '序号', field: 'no', key: 'a', width: 60, align: 'center', operationColumn: false },
- { title: '产品编码', field: 'productCode', key: 'b', align: 'left', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return codeFormat(row, row[column.field], h) } },
- { title: '出库仓库', field: 'warehouseName', key: 'e', width: 150, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
- { title: '待下推数量', field: 'surplusQty', key: 'o', width: 150, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } },
- { title: '本次下推数', field: 'qty', key: 'r', width: 150, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return inputFormat(row, row[column.field], h) } },
- { title: '单位', field: 'productOrigUnit', width: 100, key: 'i', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
- { 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) } }
- ]
- if (this.detailData && this.detailData.promoFlag == 1) {
- arr.splice(2, 0, {
- title: '活动规则',
- field: 'prompName',
- key: 'm',
- align: 'center',
- operationColumn: false,
- ellipsis: { showTitle: false },
- renderBodyCell: ({ row, column, rowIndex }, h) => {
- return (
- row.promoRuleSnList && row.promoRuleSnList.length > 1
- ? <a-popover placement="right">
- <template slot="content">
- {row.promoRuleSnList.map(item => {
- return (
- <div
- id={'ruleDetail-' + row.productSn}
- style="padding:5px 0;cursor: pointer;"
- >{ _this.activeRuleFilter(item) }</div>
- )
- })}
- </template>
- <a-button type="link" id={'ruleSn-' + row.productSn} size="small" class="button-info">
- { _this.activeRuleFilter(row.promoRuleSnList[0]) }
- </a-button>
- </a-popover>
- : <div>
- {row.promoRuleSnList.map(item => <span>{_this.activeRuleFilter(item)}</span>)}
- </div>
- )
- } })
- 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] || '--' } })
- } else {
- 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] || '--' } })
- }
- return arr
- }
- },
- methods: {
- // 参与规则名称
- activeRuleFilter (val) {
- const row = this.activeList.length && this.activeList.find(item => item.promoRuleSn == val)
- return row ? row.promotionRule.description + '-' + row.promotion.description : ''
- },
- // 选择单元格
- selectedRowChange ({ row, isSelected, selectedRowKeys }) {
- this.selectedRowKeys = selectedRowKeys
- },
- // 全选行
- selectedAllChange ({ isSelected, selectedRowKeys }) {
- this.selectedRowKeys = selectedRowKeys
- },
- // 数据查询
- async searchTable () {
- this.selectedRowKeys = []
- this.disableSelectedRowKeys = []
- this.dataSource = []
- this.disabled = true
- this.spinning = true
- const params = this.productForm
- // 带下推产品
- const listData = await waitDispatchDetailAllList(params).then(res => res.data)
- this.dataSource = listData
- // 格式化数据
- let f = 0
- this.dataSource.map((item, i) => {
- if (item.id.indexOf('promo-') >= 0) { f = f - 1 }
- item.no = i + 1 + f
- const productCode = (item.productEntity && item.productEntity.code) || (item.dealerProductEntity && item.dealerProductEntity.code)
- const productName = (item.productEntity && item.productEntity.name) || (item.dealerProductEntity && item.dealerProductEntity.name)
- const productOrigCode = (item.productEntity && item.productEntity.origCode) || (item.dealerProductEntity && item.dealerProductEntity.origCode)
- const productOrigUnit = (item.productEntity && item.productEntity.unit) || (item.dealerProductEntity && item.dealerProductEntity.unit)
- const warehouseName = item.dispatchBill && item.dispatchBill.warehouseName || ''
- const prompName = item.promotionRule ? (item.promotionRule.promotion && item.promotionRule.promotion.description) + '(' + item.promotionRule.description + ')' : '--'
- item.productCode = productCode || '--'
- item.productName = productName || '--'
- item.productOrigCode = productOrigCode == ' ' ? '--' : productOrigCode
- item.productOrigUnit = productOrigUnit || '--'
- item.warehouseName = warehouseName || '--'
- item.promoRuleSnList = item.promotionRuleList && item.promotionRuleList.map(item => item.promotionRuleSn) // 规则sn
- item.qtyBackups = item.qty
- item.prompName = prompName || '--'
- })
- this.showEmpty = this.dataSource.length <= 0
- const len = this.dataSource.length
- if (len < 8) {
- this.tableHeight = (len + 1) * 34
- } else {
- this.tableHeight = (this.showEmpty ? 300 : this.maxHeight) + 'px'
- }
- this.spinning = false
- this.disabled = false
- },
- // 重置
- resetSearchForm () {
- this.dataSource = []
- this.clearSelectTable()
- this.searchTable()
- },
- // 页面初始化
- pageInit (productForm, detailData, activeList) {
- this.productForm = Object.assign(this.productForm, productForm)
- this.detailData = detailData
- this.activeList = activeList
- // 查询列表
- this.resetSearchForm()
- },
- // 清空选项
- clearSelectTable () {
- this.selectedRowKeys = []
- },
- // 取消数量修改
- cancelNumsChange (e, record) {
- const _this = this
- const val = e.target.value
- if (val && val != record.qtyBackups && val <= record.surplusQty) {
- _this.spinning = true
- updateQty({
- dispatchBillDetailSn: record.dispatchBillDetailSn,
- qty: record.qty,
- salesBillSn: _this.detailData.salesBillSn,
- dispatchBillSn: _this.productForm.dispatchBillSn
- }).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- _this.spinning = false
- _this.$emit('refashTable', true)
- } else {
- record.qty = record.qtyBackups
- _this.spinning = false
- }
- })
- } else {
- record.qty = record.qtyBackups
- }
- },
- // 删除产品
- handleDel (row) {
- const _this = this
- this.$confirm({
- title: '提示',
- content: '确认要删除吗?',
- centered: true,
- closable: true,
- onOk () {
- _this.deleteFun(row, 0)
- }
- })
- },
- // 删除接口
- deleteFun (row, type) {
- const _this = this
- _this.spinning = true
- deleteBatch({
- dispatchBillSn: this.productForm.dispatchBillSn,
- dispatchBillDetailList: type == 0 ? [row.dispatchBillDetailSn] : row
- }).then(res => {
- if (res.status == 200) {
- _this.$emit('refashTable', true)
- _this.$message.success(res.message)
- _this.spinning = false
- } else {
- _this.spinning = false
- }
- })
- },
- // 批量删除
- delSalerDetailAll () {
- const _this = this
- const chooseList = this.selectedRowKeys
- if (chooseList.length == 0) {
- _this.$message.warning('请选择待下推产品!')
- return
- }
- const chooseRow = this.dataSource.filter(item => chooseList.includes(item.id) && item.id.indexOf('promo-') < 0)
- const obj = []
- chooseRow && chooseRow.map(item => {
- obj.push(item.dispatchBillDetailSn)
- })
- this.$confirm({
- title: '提示',
- content: '确认要批量删除吗?',
- centered: true,
- closable: true,
- onOk () {
- _this.deleteFun(obj, 1)
- }
- })
- }
- }
- }
- </script>
- <style lang="less">
- .empty-data{
- color: #999;
- text-align: center;
- padding: 20px;
- position: absolute;
- bottom: 50px;
- width: 100%;
- }
- .ve-table-body-td{
- .active-title{
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 10px;
- background: #f3f8fa;
- }
- }
- .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,
- .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{
- padding: 0;
- }
- .ve-table .ve-table-container .ve-table-content-wrapper{
- border-bottom: 1px solid #ddd;
- }
- </style>
|