detailProductList.vue 18 KB

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