promoProduct.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="content">
  3. </view>
  4. </template>
  5. <script>
  6. import { queryPromoProductByPage } from '@/api/video.js'
  7. import { purchaseSave } from '@/api/purchase.js'
  8. export default {
  9. data() {
  10. return {
  11. extraData:{
  12. id: 'promoProductList',
  13. // 添加产品
  14. chooseProduct:(item)=>{
  15. this.chooseProduct(item)
  16. }
  17. },
  18. promoActiveSn: null,
  19. chooseList: [],
  20. screenWidth: 0,
  21. showChoosePopu: false,
  22. queryWord: ''
  23. };
  24. },
  25. onLoad(opts) {
  26. uni.setNavigationBarTitle({
  27. title: opts.title||'促销活动产品'
  28. })
  29. this.screenWidth = uni.getSystemInfoSync().windowWidth
  30. this.$store.state.vuex_tempData = null
  31. this.promoActiveSn = opts.promoActiveSn
  32. // 购物车是否有缓存
  33. const cacheList = this.$store.state.vuex_cartList.find(k => k.sn == this.promoActiveSn)
  34. this.chooseList = cacheList ? JSON.parse(JSON.stringify(cacheList.list)) : []
  35. },
  36. onShow() {
  37. this.showChoosePopu=false
  38. },
  39. onUnload() {
  40. // 存储已选列表值
  41. const hasCache = this.$store.state.vuex_cartList.find(k => k.sn == this.promoActiveSn)
  42. if(hasCache){
  43. hasCache.list = this.chooseList
  44. }else{
  45. this.$store.state.vuex_cartList.push({sn:this.promoActiveSn,list: this.chooseList})
  46. }
  47. this.$u.vuex('vuex_cartList', this.$store.state.vuex_cartList)
  48. // 清空数据
  49. this.chooseList = null
  50. },
  51. methods: {
  52. // 查询列表
  53. searchList(){
  54. this.$refs.paging.reload()
  55. },
  56. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用this.$refs.paging.reload()即可
  57. getRow(pageNo, pageSize) {
  58. console.log('pageNo',pageNo)
  59. console.log('pageSize',pageSize)
  60. let _this = this
  61. let params = {
  62. pageNo: pageNo,
  63. pageSize: pageSize,
  64. queryWord: this.queryWord,
  65. promoActiveSn: this.promoActiveSn
  66. }
  67. queryPromoProductByPage(params).then(res => {
  68. if (res.status == 200) {
  69. const list = res.data.list||[]
  70. const ret = []
  71. if(list.length%2!=0){
  72. list.push(null)
  73. }
  74. for(let i=0;i<list.length;i=i+2){
  75. const a = list[i]
  76. const hasAChecked = this.chooseList.find(s=>s.id == a.id)
  77. const b = list[i+1]
  78. const hasBChecked = this.chooseList.find(s=>s.id == b.id)
  79. // 如果超出
  80. if(b){
  81. ret.push({list:[this.formatData(a,hasAChecked),this.formatData(b,hasBChecked)]})
  82. }else{
  83. ret.push({list:[this.formatData(a,hasAChecked)]})
  84. }
  85. }
  86. _this.$refs.paging.complete(ret);
  87. }
  88. })
  89. },
  90. // 格式化数据
  91. formatData(k,hasChecked){
  92. return {
  93. id: k.id,
  94. cost: k.cost,
  95. checked: !!hasChecked,
  96. qty: !!hasChecked ? hasChecked.qty : 0,
  97. productCode: k.productCode,
  98. productSn: k.productSn,
  99. productImage: k.productImage,
  100. productName: k.productName,
  101. productOrigCode: k.productOrigCode,
  102. promoActiveSn: k.promoActiveSn,
  103. promoRuleSn: k.promoRuleSn,
  104. promoRuleValue: k.promoRuleValue,
  105. promoRuleType: k.promoRuleType,
  106. show: false
  107. }
  108. },
  109. // 添加产品
  110. chooseProduct(item){
  111. }
  112. },
  113. };
  114. </script>
  115. <style lang="less" scoped>
  116. .content{
  117. width: 100%;
  118. height: 100vh;
  119. }
  120. .tab-search{
  121. padding: 15rpx 20rpx;
  122. background: #fff;
  123. }
  124. </style>