detailProductList.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <!-- 已选配件列表 -->
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <ve-table
  5. border-y
  6. v-show="!showEmpty"
  7. :scroll-width="0"
  8. :max-height="tableHeight"
  9. :show-header="showTableHead"
  10. :row-style-option="{clickHighlight: true}"
  11. :cellSelectionOption="{enable: false}"
  12. :virtual-scroll-option="{enable: true}"
  13. :columns="columns"
  14. :table-data="dataSource"
  15. row-key-field-name="id"
  16. :cell-style-option="cellStyleOption"
  17. :cell-span-option="cellSpanOption"
  18. :column-width-resize-option="columnWidthResizeOption"
  19. />
  20. <div v-show="showEmpty" class="empty-data"><a-empty description="暂无产品" :image="simpleImage"/></div>
  21. <!-- 活动规则详情 -->
  22. <detailModal :openModal="openDetailModal" pageType="salesPage" :itemSn="detailSn" @close="closeDetailModal"></detailModal>
  23. </a-spin>
  24. </template>
  25. <script>
  26. import { commonMixin } from '@/utils/mixin'
  27. import { Empty } from 'ant-design-vue'
  28. import detailModal from '@/views/promotionRulesManagement/dealerPromotions/detailModal.vue'
  29. import { salesPromoQueryList } from '@/api/salesNew'
  30. import { salesDetailAllList, salesPromoDetailCount, salesDetaiCount } from '@/api/salesDetailNew'
  31. export default {
  32. name: 'DetailProductList',
  33. mixins: [commonMixin],
  34. components: { detailModal },
  35. props: {
  36. newLoading: Boolean, // loading
  37. detailData: { // 详情信息
  38. type: Object,
  39. default: function () { return null }
  40. },
  41. // 活动规则详情
  42. promo: {
  43. type: Object,
  44. default: function () { return null }
  45. },
  46. // 表格id
  47. id: {
  48. type: String,
  49. default: ''
  50. },
  51. // 仓库sn
  52. warehouseSn: {
  53. type: String,
  54. default: ''
  55. },
  56. // 是否促销产品
  57. promoFlag: {
  58. type: String,
  59. default: ''
  60. },
  61. // 销售单sn
  62. salesBillSn: {
  63. type: String,
  64. default: ''
  65. },
  66. // 是否显示城市价格
  67. showCityPrice: {
  68. type: Boolean,
  69. default: false
  70. },
  71. // 权限码
  72. authCode: {
  73. type: String,
  74. default: ''
  75. },
  76. // 最大高度
  77. maxHeight: {
  78. type: [String, Number],
  79. default: '300'
  80. },
  81. // 是否显示表格头部
  82. showHeader: {
  83. type: Boolean,
  84. default: true
  85. }
  86. },
  87. data () {
  88. return {
  89. spinning: false,
  90. openDetailModal: false, // 活动规则详情弹框
  91. detailSn: null, // 活动规则详情sn
  92. activeList: [], // 活动列表
  93. dataSource: [], // 列表原始数据
  94. tableHeight: this.maxHeight, // 表格高度
  95. // 自定义单元格样式
  96. cellStyleOption: {
  97. bodyCellClass: ({ row, column, rowIndex }) => {
  98. if (row.id.indexOf('promo-') >= 0 && column.field === 'no') {
  99. return 'table-body-cell-no'
  100. }
  101. }
  102. },
  103. // 表格列可拖曳
  104. columnWidthResizeOption: {
  105. // default false
  106. enable: true,
  107. // column resize min width
  108. minWidth: 50
  109. },
  110. // 自定义单元格内容
  111. cellSpanOption: {
  112. bodyCellSpan: this.bodyCellSpan
  113. },
  114. isCityPrice: false, // 是否显示市级价
  115. outStockStr: '', // 产品库存不足提示信息
  116. showEmpty: false, // 是否显示空数据图片
  117. showTableHead: true, // 是否显示表格头部
  118. colspanNums: 13, // 单元格合并列数
  119. hasOutStockOfActive: false,
  120. simpleImage: Empty.PRESENTED_IMAGE_SIMPLE // 空图片
  121. }
  122. },
  123. computed: {
  124. columns () {
  125. const _this = this
  126. // 价格单元格
  127. const priceFormat = function (data) {
  128. return _this.toThousands(data) || '--'
  129. }
  130. // 数字单元格
  131. const numsFormat = function (data) {
  132. return data || data == 0 ? data : '--'
  133. }
  134. // 销售单号
  135. const codeFormat = function (record, data, h) {
  136. let ftext = ''
  137. let fcolor = ''
  138. if (record.promotionFlag == 'GIFT') {
  139. ftext = '促'
  140. fcolor = '#52c41a'
  141. }
  142. if (record.promotionFlag == 'GATE') {
  143. ftext = '槛'
  144. fcolor = '#108ee9'
  145. }
  146. return (
  147. <div>
  148. <span style="padding-right: 15px;">{data}</span>
  149. {ftext ? (<a-badge count={ftext} number-style={{ backgroundColor: fcolor, zoom: '80%' }}></a-badge>) : ''}
  150. {record.convertPromoGiftsQty ? (<a-badge count="转" number-style={{ backgroundColor: '#ffaa00', zoom: '80%' }}></a-badge>) : ''}
  151. {(Number(record.stockQty || 0) < Number(record.unpushedQty || 0)) && _this.showStock ? (<a-badge count="缺" number-style={{ zoom: '80%' }}></a-badge>) : ''}
  152. </div>
  153. )
  154. }
  155. // 编号,并且格式化活动分类行
  156. const noFormat = function (record, data, h) {
  157. const isBuyPSendP = record.promo && record.promo.promotionRule.convertExpenseFlag == 1 && record.promo.promotionRule.promotionRuleType == 'BUY_PROD_GIVE_PROD'
  158. return (
  159. <div>
  160. {record.id.indexOf('promo-') >= 0 ? (
  161. <div class="active-title">
  162. {record.promo ? (
  163. <div>
  164. <strong style="font-size:14px;">{record.promo.promotion.description}</strong>
  165. <span>({record.promo.promotionRule.description})</span>
  166. <span id="salesDetail-activeDesc" style="margin-left:20px;color:#00aaff;cursor: pointer;" onClick={() => _this.showDesc(record.promo)}>
  167. <a-icon title="查看活动详情" type="eye"/> 活动详情
  168. </span>
  169. </div>
  170. ) : (<div></div>)}
  171. <div>
  172. 款数:<strong>{record.total && record.total.totalCategory || '--'}</strong>;
  173. 数量:<strong>{record.total && record.total.totalQty || '--'}</strong>;
  174. {_this.$hasPermissions('B_salesEdit_salesPrice') ? (<span>总金额:<strong>{record.total && record.total.totalAmount || '--'}</strong>;</span>) : ('')}
  175. {_this.$hasPermissions('B_salesEdit_salesPrice') && record.promo && record.total && record.total.lossAmount ? (<span>优惠金额:<strong>{record.total.lossAmount}</strong>;</span>) : ('')}
  176. {_this.$hasPermissions('B_salesEdit_salesPrice') && record.promo && record.total && record.total.cgejyAmount > 0 && !isBuyPSendP ? (<span>采购额结余:<strong>{_this.toThousands(record.total.cgejyAmount)}</strong>;</span>) : ('')}
  177. {_this.$hasPermissions('B_salesEdit_salesPrice') && record.promo && record.total && record.total.cgejyAmount < 0 && !isBuyPSendP ? (<span>采购额超出:<strong>{_this.toThousands(record.total.cgeccAmount)}</strong>;</span>) : ('')}
  178. {_this.$hasPermissions('B_salesEdit_salesPrice') && record.promo && record.total && record.total.totalPromoGiftsAmount && isBuyPSendP ? (<span>促销产品转采购额金额:<strong>{_this.toThousands(record.total.totalPromoGiftsAmount)}</strong>;</span>) : ('')}
  179. {record.total && record.total.expenseAccountFlag != 'WAIT' ? (<span style="color:red;">{record.total.expenseAccountFlagDictValue}</span>) : ''}
  180. </div>
  181. </div>
  182. ) : (<span>{data}</span>)}
  183. </div>
  184. )
  185. }
  186. // 显示折扣价
  187. const discountPriceFormat = function (record, data, h) {
  188. return (
  189. <div>
  190. {_this.toThousands(data)}
  191. {record.promotionFlag == 'GIFT' || record.promotionFlag == 'DISCOUNT' ? (
  192. <span title="原价">({ _this.toThousands(record.origPrice)})</span>
  193. ) : ''}
  194. </div>
  195. )
  196. }
  197. // 列定义
  198. let arr = [
  199. { title: '序号', field: 'no', key: 'a', width: 50, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return noFormat(row, row[column.field], h) } },
  200. { title: '产品编码', field: 'productCode', key: 'b', width: 150, align: 'left', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return codeFormat(row, row[column.field], h) } },
  201. { title: '产品名称', field: 'productName', key: 'c', width: 250, align: 'left', operationColumn: false, ellipsis: { showTitle: true }, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
  202. { title: '原厂编码', field: 'productOrigCode', key: 'd', width: 150, align: 'left', operationColumn: false, ellipsis: { showTitle: true }, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
  203. { title: '出库仓库', field: 'warehouseName', key: 'e', width: 100, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } }
  204. ]
  205. // 计算可合并单元格数
  206. this.colspanNums = this.showConvertPromoGifts ? 6 : 5
  207. if (this.$hasPermissions(this.authCode + '_costPrice')) { // 成本价权限
  208. this.colspanNums = this.colspanNums + 1
  209. arr.push({ title: '成本价', field: 'showCost', width: 80, key: 'f', align: 'right', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return priceFormat(row[column.field]) } })
  210. }
  211. this.colspanNums = this.colspanNums + 2
  212. arr = arr.concat([
  213. { title: '单位', field: 'productOrigUnit', key: 'g', width: 80, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
  214. { title: '销售数量', field: 'qty', width: 80, key: 'h', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } }
  215. ])
  216. if (this.$hasPermissions(this.authCode + '_provincePrice')) {
  217. this.colspanNums = this.colspanNums + 1
  218. arr.push({ title: '省级价', field: 'provincePrice', width: 80, key: 'i', align: 'right', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return priceFormat(row[column.field]) } })
  219. }
  220. // 是否勾选市级价格
  221. if (this.isCityPrice) {
  222. this.colspanNums = this.colspanNums + 1
  223. arr.push({ title: '市级价', field: 'cityPrice', width: 80, key: 'j', align: 'right', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return priceFormat(row[column.field]) } })
  224. if (this.$hasPermissions(this.authCode + '_salesPrice')) { // 售价权限
  225. this.colspanNums = this.colspanNums + 1
  226. 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) } })
  227. }
  228. } else {
  229. if (this.$hasPermissions(this.authCode + '_salesPrice')) { // 售价权限
  230. this.colspanNums = this.colspanNums + 1
  231. 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) } })
  232. }
  233. }
  234. // 审核,需用到库存
  235. if (this.showStock) {
  236. this.colspanNums = this.colspanNums + 2
  237. arr.push({ title: '库存', field: 'stockQty', width: 80, key: 'm', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } })
  238. arr.push({ title: '第三方库存', field: 'stockQty', width: 80, key: 'mm', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } })
  239. }
  240. this.colspanNums = this.colspanNums + 3
  241. arr = arr.concat([
  242. { title: '待下推数', field: 'unpushedQty', width: 80, key: 'o', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } },
  243. { title: '已下推数', field: 'pushedQty', width: 80, key: 'p', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } }
  244. ])
  245. // 如果有转采购额
  246. if (this.showConvertPromoGifts) {
  247. 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]) : '--' } })
  248. }
  249. arr.push({ title: '已取消数', field: 'cancelQty', width: 80, key: 'q', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field]) } })
  250. return arr
  251. },
  252. // 是否有可转采购额
  253. hasConvertPromoGifts () {
  254. return this.detailData && this.detailData.totalConvertPromoGiftsQty
  255. },
  256. // 是否显示可转采购额
  257. showConvertPromoGifts () {
  258. 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')
  259. },
  260. // 是否显示库存列
  261. showStock () {
  262. return this.detailData && (this.detailData.billStatus == 'WAIT_AUDIT' || this.detailData.billStatus == 'HQ_CHANGE') && this.$hasPermissions('B_salesAudit')
  263. }
  264. },
  265. watch: {
  266. // 是否显示城市价格变化时
  267. showCityPrice (newValue, oldValue) {
  268. this.isCityPrice = newValue
  269. }
  270. },
  271. methods: {
  272. // 关闭详情弹窗
  273. closeDetailModal () {
  274. this.detailSn = null
  275. this.openDetailModal = false
  276. },
  277. // 合并活动分类单元格
  278. bodyCellSpan ({ row, column, rowIndex }) {
  279. if (row.id.indexOf('promo-') >= 0) {
  280. if (column.field == 'no') {
  281. return {
  282. rowspan: 1,
  283. colspan: this.colspanNums
  284. }
  285. } else {
  286. return {
  287. rowspan: 0,
  288. colspan: 0
  289. }
  290. }
  291. }
  292. },
  293. // 查看活动详情
  294. showDesc (row) {
  295. this.detailSn = row.promoRuleSn
  296. this.openDetailModal = true
  297. },
  298. // 获取销售单参与的活动列表
  299. pageInit () {
  300. salesPromoQueryList({ salesBillSn: this.salesBillSn }).then(res => {
  301. if (res.status == 200) {
  302. this.activeList = res.data || []
  303. }
  304. this.$nextTick(() => {
  305. this.searchTable()
  306. })
  307. })
  308. },
  309. // 查询表格数据
  310. async searchTable () {
  311. this.dataSource = []
  312. this.disabled = true
  313. this.spinning = true
  314. // 参数
  315. const params = {
  316. salesBillSn: this.salesBillSn,
  317. showStock: this.showStock,
  318. warehouseSn: this.warehouseSn,
  319. promotionFlag: this.promoFlag == '' ? undefined : this.promoFlag
  320. }
  321. // 参与活动数据
  322. const active = this.activeList.filter(item => item.enabledFlag == 1)
  323. // 是否有活动产品
  324. const hasSearchNormal = !params.promotionFlag || params.promotionFlag == 0
  325. // 没有活动产品时直接查询正常产品
  326. const proList = hasSearchNormal ? await salesDetailAllList(params).then(res => res.data) : []
  327. const norTotal = hasSearchNormal ? await salesDetaiCount(params).then(res => res.data) : null
  328. // 没有活动时,表格不显示统计数据
  329. let listData = active.length ? (proList.length ? [{
  330. id: 'promo-normal',
  331. total: norTotal
  332. }, ...proList] : []) : proList
  333. // 有促销活动产品时,循环获取每个活动的数据
  334. if (params.promotionFlag != 0) {
  335. // 循环获取活动产品
  336. for (let i = 0; i < active.length; i++) {
  337. const promo = active[i]
  338. const activeParams = {
  339. promoRuleSn: promo.promoRuleSn,
  340. promoSn: promo.promoSn,
  341. salesPromoSn: promo.salesPromoSn,
  342. ...params
  343. }
  344. // 获取活动产品统计
  345. const acTotal = await salesPromoDetailCount(activeParams).then(res => res.data)
  346. if (acTotal) {
  347. // 采购额结余
  348. acTotal.cgejyAmount = (Number(acTotal.totalPromoGiftsAmount || 0) - Number(acTotal.totalUsePromoGiftsAmount || 0)).toFixed(2)
  349. // 采购额超出
  350. acTotal.cgeccAmount = (Number(acTotal.totalUsePromoGiftsAmount || 0) - Number(acTotal.totalPromoGiftsAmount || 0)).toFixed(2)
  351. }
  352. // 有数据时才调用接口,避免做无用的调用
  353. if (acTotal && acTotal.totalQty) {
  354. // 获取活动产品列表
  355. const aclist = await salesDetailAllList(activeParams).then(res => res.data)
  356. // 合并结果数据
  357. const retList = aclist.length ? [{
  358. id: 'promo-' + i,
  359. promo: promo,
  360. total: acTotal
  361. }, ...aclist] : []
  362. // 将活动产品数据拼接
  363. listData = aclist && aclist.length ? listData.concat(retList) : listData
  364. }
  365. }
  366. // 如果活动没有任何产品,不显示统计一行
  367. if (active.length) {
  368. // 判断是否有活动产品
  369. const hasAcp = listData.filter(item => item.id != 'promo-normal').filter(item => item.id.indexOf('promo-') >= 0)
  370. if (hasAcp && hasAcp.length == 0) {
  371. listData = listData.filter(item => item.id.indexOf('promo-') < 0) || []
  372. }
  373. }
  374. }
  375. // 赋值
  376. this.dataSource = listData
  377. // 格式化数据
  378. let f = 0
  379. let str = ''
  380. this.outStockStr = ''
  381. this.dataSource.map((item, i) => {
  382. if (item.id.indexOf('promo-') >= 0) { f = f - 1 }
  383. item.no = i + 1 + f
  384. // 格式化数据,产品编码、产品名称、原厂编码、包装数单位
  385. const productCode = (item.productEntity && item.productEntity.code) || (item.dealerProductEntity && item.dealerProductEntity.code)
  386. const productName = (item.productEntity && item.productEntity.name) || (item.dealerProductEntity && item.dealerProductEntity.name)
  387. const productOrigCode = (item.productEntity && item.productEntity.origCode) || (item.dealerProductEntity && item.dealerProductEntity.origCode)
  388. const productOrigUnit = (item.productEntity && item.productEntity.unit) || (item.dealerProductEntity && item.dealerProductEntity.unit)
  389. item.productCode = productCode || '--'
  390. item.productName = productName || '--'
  391. item.productOrigCode = productOrigCode == ' ' ? '--' : productOrigCode
  392. item.productOrigUnit = productOrigUnit || '--'
  393. item.epushedQty = Number(item.pushedQty) - Number(item.pushQty)
  394. // 判断是否有转采购单
  395. if (item.unpushedQty && (Number(item.stockQty) < Number(item.unpushedQty))) {
  396. str += item.productCode + '、'
  397. if (item.promotionFlag != 0) {
  398. this.hasOutStockOfActive = true
  399. }
  400. }
  401. })
  402. // 是否有缺货明细
  403. if (str.length > 0) {
  404. str = str.substr(0, str.length - 1)
  405. this.outStockStr = '产品编号为:' + str + '的产品库存不足;'
  406. }
  407. this.showEmpty = this.dataSource.length <= 0
  408. this.tableHeight = (this.showEmpty ? 200 : this.maxHeight) + 'px'
  409. this.spinning = false
  410. this.disabled = false
  411. }
  412. }
  413. }
  414. </script>
  415. <style lang="less">
  416. .empty-data{
  417. color: #999;
  418. text-align: center;
  419. padding: 20px;
  420. }
  421. .ve-table-body-td{
  422. .active-title{
  423. display: flex;
  424. align-items: center;
  425. justify-content: space-between;
  426. padding: 10px;
  427. background: #f3f8fa;
  428. }
  429. }
  430. .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,
  431. .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{
  432. padding: 0;
  433. }
  434. .ve-table .ve-table-container .ve-table-content-wrapper{
  435. border-bottom: 1px solid #ddd;
  436. }
  437. </style>