detailProductList.vue 20 KB

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