123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- <template>
- <!-- 已选配件列表 -->
- <a-spin :spinning="spinning" tip="Loading...">
- <ve-table
- border-y
- v-show="!showEmpty"
- :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"
- :cell-style-option="cellStyleOption"
- :cell-span-option="cellSpanOption"
- :column-width-resize-option="columnWidthResizeOption"
- />
- <div v-show="showEmpty" class="empty-data"><a-empty description="暂无产品" :image="simpleImage"/></div>
- <!-- 活动规则详情 -->
- <detailModal :openModal="openDetailModal" pageType="salesPage" :itemSn="detailSn" @close="closeDetailModal"></detailModal>
- </a-spin>
- </template>
- <script>
- import { commonMixin } from '@/utils/mixin'
- import { Empty } from 'ant-design-vue'
- import detailModal from '@/views/promotionRulesManagement/dealerPromotions/detailModal.vue'
- import { salesPromoQueryList } from '@/api/salesNew'
- import { salesDetailAllList, salesPromoDetailCount, salesDetaiCount } from '@/api/salesDetailNew'
- export default {
- name: 'DetailProductList',
- mixins: [commonMixin],
- components: { detailModal },
- props: {
- newLoading: Boolean, // loading
- detailData: { // 详情信息
- type: Object,
- default: function () { return null }
- },
- // 活动规则详情
- promo: {
- type: Object,
- default: function () { return null }
- },
- // 表格id
- id: {
- type: String,
- default: ''
- },
- // 仓库sn
- warehouseSn: {
- type: String,
- default: ''
- },
- // 是否促销产品
- promoFlag: {
- type: String,
- default: ''
- },
- // 销售单sn
- salesBillSn: {
- type: String,
- default: ''
- },
- // 是否显示城市价格
- showCityPrice: {
- type: Boolean,
- default: false
- },
- // 权限码
- authCode: {
- type: String,
- default: ''
- },
- // 最大高度
- maxHeight: {
- type: [String, Number],
- default: '300'
- },
- // 是否显示表格头部
- showHeader: {
- type: Boolean,
- default: true
- }
- },
- data () {
- return {
- spinning: false,
- openDetailModal: false, // 活动规则详情弹框
- detailSn: null, // 活动规则详情sn
- activeList: [], // 活动列表
- dataSource: [], // 列表原始数据
- tableHeight: this.maxHeight, // 表格高度
- // 自定义单元格样式
- cellStyleOption: {
- bodyCellClass: ({ row, column, rowIndex }) => {
- if (row.id.indexOf('promo-') >= 0 && column.field === 'no') {
- return 'table-body-cell-no'
- }
- }
- },
- // 表格列可拖曳
- columnWidthResizeOption: {
- // default false
- enable: true,
- // column resize min width
- minWidth: 50
- },
- // 自定义单元格内容
- cellSpanOption: {
- bodyCellSpan: this.bodyCellSpan
- },
- isCityPrice: false, // 是否显示市级价
- outStockStr: '', // 产品库存不足提示信息
- showEmpty: false, // 是否显示空数据图片
- showTableHead: true, // 是否显示表格头部
- colspanNums: 13, // 单元格合并列数
- hasOutStockOfActive: false,
- simpleImage: Empty.PRESENTED_IMAGE_SIMPLE // 空图片
- }
- },
- computed: {
- 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) {
- let ftext = ''
- let fcolor = ''
- if (record.promotionFlag == 'GIFT') {
- ftext = '促'
- fcolor = '#52c41a'
- }
- if (record.promotionFlag == 'GATE') {
- ftext = '槛'
- fcolor = '#108ee9'
- }
- return (
- <div>
- <span style="padding-right: 15px;">{data}</span>
- {ftext ? (<a-badge count={ftext} number-style={{ backgroundColor: fcolor, zoom: '80%' }}></a-badge>) : ''}
- {record.convertPromoGiftsQty ? (<a-badge count="转" number-style={{ backgroundColor: '#ffaa00', zoom: '80%' }}></a-badge>) : ''}
- {(Number(record.stockQty || 0) < Number(record.unpushedQty || 0)) && _this.showStock ? (<a-badge count="缺" number-style={{ zoom: '80%' }}></a-badge>) : ''}
- </div>
- )
- }
- // 编号,并且格式化活动分类行
- const noFormat = function (record, data, h) {
- const isBuyPSendP = record.promo && record.promo.promotionRule.convertExpenseFlag == 1 && record.promo.promotionRule.promotionRuleType == 'BUY_PROD_GIVE_PROD'
- return (
- <div>
- {record.id.indexOf('promo-') >= 0 ? (
- <div class="active-title">
- {record.promo ? (
- <div>
- <strong style="font-size:14px;">{record.promo.promotion.description}</strong>
- <span>({record.promo.promotionRule.description})</span>
- <span id="salesDetail-activeDesc" style="margin-left:20px;color:#00aaff;cursor: pointer;" onClick={() => _this.showDesc(record.promo)}>
- <a-icon title="查看活动详情" type="eye"/> 活动详情
- </span>
- </div>
- ) : (<div></div>)}
- <div>
- 款数:<strong>{record.total && record.total.totalCategory || '--'}</strong>;
- 数量:<strong>{record.total && record.total.totalQty || '--'}</strong>;
- {_this.$hasPermissions('B_salesEdit_salesPrice') ? (<span>总金额:<strong>{record.total && record.total.totalAmount || '--'}</strong>;</span>) : ('')}
- {_this.$hasPermissions('B_salesEdit_salesPrice') && record.promo && record.total && record.total.lossAmount ? (<span>优惠金额:<strong>{record.total.lossAmount}</strong>;</span>) : ('')}
- {_this.$hasPermissions('B_salesEdit_salesPrice') && record.promo && record.total && record.total.cgejyAmount > 0 && !isBuyPSendP ? (<span>采购额结余:<strong>{_this.toThousands(record.total.cgejyAmount)}</strong>;</span>) : ('')}
- {_this.$hasPermissions('B_salesEdit_salesPrice') && record.promo && record.total && record.total.cgejyAmount < 0 && !isBuyPSendP ? (<span>采购额超出:<strong>{_this.toThousands(record.total.cgeccAmount)}</strong>;</span>) : ('')}
- {_this.$hasPermissions('B_salesEdit_salesPrice') && record.promo && record.total && record.total.totalPromoGiftsAmount && isBuyPSendP ? (<span>促销产品转采购额金额:<strong>{_this.toThousands(record.total.totalPromoGiftsAmount)}</strong>;</span>) : ('')}
- {record.total && record.total.expenseAccountFlag != 'WAIT' ? (<span style="color:red;">{record.total.expenseAccountFlagDictValue}</span>) : ''}
- </div>
- </div>
- ) : (<span>{data}</span>)}
- </div>
- )
- }
- // 显示折扣价
- const discountPriceFormat = function (record, data, h) {
- return (
- <div>
- {_this.toThousands(data)}
- {record.promotionFlag == 'GIFT' || record.promotionFlag == 'DISCOUNT' ? (
- <span title="原价">({ _this.toThousands(record.origPrice)})</span>
- ) : ''}
- </div>
- )
- }
- // 列定义
- let arr = [
- { title: '序号', field: 'no', key: 'a', width: 50, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return noFormat(row, row[column.field], h) } },
- { title: '产品编码', field: 'productCode', key: 'b', width: 150, align: 'left', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return codeFormat(row, row[column.field], h) } },
- { title: '产品名称', field: 'productName', key: 'c', width: 250, align: 'left', operationColumn: false, ellipsis: { showTitle: true }, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
- { title: '原厂编码', field: 'productOrigCode', key: 'd', width: 150, align: 'left', operationColumn: false, ellipsis: { showTitle: true }, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
- { title: '出库仓库', field: 'warehouseName', key: 'e', width: 100, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } }
- ]
- // 计算可合并单元格数
- this.colspanNums = this.showConvertPromoGifts ? 6 : 5
- if (this.$hasPermissions(this.authCode + '_costPrice')) { // 成本价权限
- this.colspanNums = this.colspanNums + 1
- arr.push({ title: '成本价', field: 'showCost', width: 80, key: 'f', align: 'right', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return priceFormat(row[column.field]) } })
- }
- this.colspanNums = this.colspanNums + 2
- arr = arr.concat([
- { title: '单位', field: 'productOrigUnit', key: 'g', width: 80, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
- { title: '销售数量', field: 'qty', width: 80, key: 'h', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } }
- ])
- if (this.$hasPermissions(this.authCode + '_provincePrice')) {
- this.colspanNums = this.colspanNums + 1
- arr.push({ title: '省级价', field: 'provincePrice', width: 80, key: 'i', align: 'right', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return priceFormat(row[column.field]) } })
- }
- // 是否勾选市级价格
- if (this.isCityPrice) {
- this.colspanNums = this.colspanNums + 1
- arr.push({ title: '市级价', field: 'cityPrice', width: 80, key: 'j', align: 'right', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return priceFormat(row[column.field]) } })
- if (this.$hasPermissions(this.authCode + '_salesPrice')) { // 售价权限
- this.colspanNums = this.colspanNums + 1
- arr.push({ title: '销售价', field: 'price', width: 100, key: 'k', align: 'right', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return discountPriceFormat(row, row[column.field], h) } })
- }
- } else {
- if (this.$hasPermissions(this.authCode + '_salesPrice')) { // 售价权限
- this.colspanNums = this.colspanNums + 1
- arr.push({ title: '销售价', field: 'price', width: 100, key: 'l', align: 'right', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return discountPriceFormat(row, row[column.field], h) } })
- }
- }
- // 审核,需用到库存
- if (this.showStock) {
- this.colspanNums = this.colspanNums + 2
- arr.push({ title: '库存', field: 'stockQty', width: 80, key: 'm', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } })
- arr.push({ title: '第三方库存', field: 'stockQty', width: 80, key: 'mm', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } })
- }
- this.colspanNums = this.colspanNums + 3
- arr = arr.concat([
- { title: '待下推数', field: 'unpushedQty', width: 80, key: 'o', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } },
- { title: '已下推数', field: 'pushedQty', width: 80, key: 'p', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } }
- ])
- // 如果有转采购额
- if (this.showConvertPromoGifts) {
- arr.push({ title: '转采购额数量', field: 'convertPromoGiftsQty', width: 100, key: 'z', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row.convertPromoGiftsFlag ? numsFormat(row[column.field]) : '--' } })
- }
- arr.push({ title: '已取消数', field: 'cancelQty', width: 80, key: 'q', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } })
- return arr
- },
- // 是否有可转采购额
- hasConvertPromoGifts () {
- return this.detailData && this.detailData.totalConvertPromoGiftsQty
- },
- // 是否显示可转采购额
- showConvertPromoGifts () {
- return this.activeList && this.activeList.filter(item => item.enabledFlag == 1).find(item => item.promotionRule && item.promotionRule.convertExpenseFlag == 1 && item.promotionRule.promotionRuleType == 'BUY_PROD_GIVE_PROD')
- },
- // 是否显示库存列
- showStock () {
- return this.detailData && (this.detailData.billStatus == 'WAIT_AUDIT' || this.detailData.billStatus == 'HQ_CHANGE') && this.$hasPermissions('B_salesAudit')
- }
- },
- watch: {
- // 是否显示城市价格变化时
- showCityPrice (newValue, oldValue) {
- this.isCityPrice = newValue
- }
- },
- methods: {
- // 关闭详情弹窗
- closeDetailModal () {
- this.detailSn = null
- this.openDetailModal = false
- },
- // 合并活动分类单元格
- bodyCellSpan ({ row, column, rowIndex }) {
- if (row.id.indexOf('promo-') >= 0) {
- if (column.field == 'no') {
- return {
- rowspan: 1,
- colspan: this.colspanNums
- }
- } else {
- return {
- rowspan: 0,
- colspan: 0
- }
- }
- }
- },
- // 查看活动详情
- showDesc (row) {
- this.detailSn = row.promoRuleSn
- this.openDetailModal = true
- },
- // 获取销售单参与的活动列表
- pageInit () {
- salesPromoQueryList({ salesBillSn: this.salesBillSn }).then(res => {
- if (res.status == 200) {
- this.activeList = res.data || []
- }
- this.$nextTick(() => {
- this.searchTable()
- })
- })
- },
- // 查询表格数据
- async searchTable () {
- this.dataSource = []
- this.disabled = true
- this.spinning = true
- // 参数
- const params = {
- salesBillSn: this.salesBillSn,
- showStock: this.showStock,
- warehouseSn: this.warehouseSn,
- promotionFlag: this.promoFlag == '' ? undefined : this.promoFlag
- }
- // 参与活动数据
- const active = this.activeList.filter(item => item.enabledFlag == 1)
- // 是否有活动产品
- const hasSearchNormal = !params.promotionFlag || params.promotionFlag == 0
- // 没有活动产品时直接查询正常产品
- const proList = hasSearchNormal ? await salesDetailAllList(params).then(res => res.data) : []
- const norTotal = hasSearchNormal ? await salesDetaiCount(params).then(res => res.data) : null
- // 没有活动时,表格不显示统计数据
- let listData = active.length ? (proList.length ? [{
- id: 'promo-normal',
- total: norTotal
- }, ...proList] : []) : proList
- // 有促销活动产品时,循环获取每个活动的数据
- if (params.promotionFlag != 0) {
- // 循环获取活动产品
- for (let i = 0; i < active.length; i++) {
- const promo = active[i]
- const activeParams = {
- promoRuleSn: promo.promoRuleSn,
- promoSn: promo.promoSn,
- salesPromoSn: promo.salesPromoSn,
- ...params
- }
- // 获取活动产品统计
- const acTotal = await salesPromoDetailCount(activeParams).then(res => res.data)
- if (acTotal) {
- // 采购额结余
- acTotal.cgejyAmount = (Number(acTotal.totalPromoGiftsAmount || 0) - Number(acTotal.totalUsePromoGiftsAmount || 0)).toFixed(2)
- // 采购额超出
- acTotal.cgeccAmount = (Number(acTotal.totalUsePromoGiftsAmount || 0) - Number(acTotal.totalPromoGiftsAmount || 0)).toFixed(2)
- }
- // 有数据时才调用接口,避免做无用的调用
- if (acTotal && acTotal.totalQty) {
- // 获取活动产品列表
- const aclist = await salesDetailAllList(activeParams).then(res => res.data)
- // 合并结果数据
- const retList = aclist.length ? [{
- id: 'promo-' + i,
- promo: promo,
- total: acTotal
- }, ...aclist] : []
- // 将活动产品数据拼接
- listData = aclist && aclist.length ? listData.concat(retList) : listData
- }
- }
- // 如果活动没有任何产品,不显示统计一行
- if (active.length) {
- // 判断是否有活动产品
- const hasAcp = listData.filter(item => item.id != 'promo-normal').filter(item => item.id.indexOf('promo-') >= 0)
- if (hasAcp && hasAcp.length == 0) {
- listData = listData.filter(item => item.id.indexOf('promo-') < 0) || []
- }
- }
- }
- // 赋值
- this.dataSource = listData
- // 格式化数据
- let f = 0
- let str = ''
- this.outStockStr = ''
- 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)
- item.productCode = productCode || '--'
- item.productName = productName || '--'
- item.productOrigCode = productOrigCode == ' ' ? '--' : productOrigCode
- item.productOrigUnit = productOrigUnit || '--'
- item.epushedQty = Number(item.pushedQty) - Number(item.pushQty)
- // 判断是否有转采购单
- if (item.unpushedQty && (Number(item.stockQty) < Number(item.unpushedQty))) {
- str += item.productCode + '、'
- if (item.promotionFlag != 0) {
- this.hasOutStockOfActive = true
- }
- }
- })
- // 是否有缺货明细
- if (str.length > 0) {
- str = str.substr(0, str.length - 1)
- this.outStockStr = '产品编号为:' + str + '的产品库存不足;'
- }
- this.showEmpty = this.dataSource.length <= 0
- this.tableHeight = (this.showEmpty ? 200 : this.maxHeight) + 'px'
- this.spinning = false
- this.disabled = false
- }
- }
- }
- </script>
- <style lang="less">
- .empty-data{
- color: #999;
- text-align: center;
- padding: 20px;
- }
- .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>
|