123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <template>
- <view class="content">
- <z-paging ref="paging" @query="getRow" use-virtual-list cell-height-mode="dynamic" use-compatibility-mode :extra-data="extraData">
- <view slot="top">
- <view class="tab-search">
- <u-search placeholder="请输入产品名称/轮胎规格" shape="round" :clearabled="true" show-action v-model="queryWord" @clear="searchList" @search="searchList" @custom="searchList"></u-search>
- </view>
- </view>
- </z-paging>
- </view>
- </template>
- <script>
- import { queryPromoProductByPage } from '@/api/video.js'
- import { purchaseSave } from '@/api/purchase.js'
- export default {
- data() {
- return {
- extraData:{
- id: 'promoProductList',
- // 添加产品
- chooseProduct:(item)=>{
- this.chooseProduct(item)
- }
- },
- promoActiveSn: null,
- chooseList: [],
- screenWidth: 0,
- showChoosePopu: false,
- queryWord: ''
- };
- },
- onLoad(opts) {
- uni.setNavigationBarTitle({
- title: opts.title||'促销活动产品'
- })
- this.screenWidth = uni.getSystemInfoSync().windowWidth
- this.$store.state.vuex_tempData = null
- this.promoActiveSn = opts.promoActiveSn
- // 购物车是否有缓存
- const cacheList = this.$store.state.vuex_cartList.find(k => k.sn == this.promoActiveSn)
- this.chooseList = cacheList ? JSON.parse(JSON.stringify(cacheList.list)) : []
- },
- onShow() {
- this.showChoosePopu=false
- },
- onUnload() {
- // 存储已选列表值
- const hasCache = this.$store.state.vuex_cartList.find(k => k.sn == this.promoActiveSn)
- if(hasCache){
- hasCache.list = this.chooseList
- }else{
- this.$store.state.vuex_cartList.push({sn:this.promoActiveSn,list: this.chooseList})
- }
- this.$u.vuex('vuex_cartList', this.$store.state.vuex_cartList)
-
- // 清空数据
- this.chooseList = null
- },
- methods: {
- // 查询列表
- searchList(){
- this.$refs.paging.reload()
- },
- // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用this.$refs.paging.reload()即可
- getRow(pageNo, pageSize) {
- console.log('pageNo',pageNo)
- console.log('pageSize',pageSize)
- let _this = this
- let params = {
- pageNo: pageNo,
- pageSize: pageSize,
- queryWord: this.queryWord,
- promoActiveSn: this.promoActiveSn
- }
- queryPromoProductByPage(params).then(res => {
- if (res.status == 200) {
- const list = res.data.list||[]
- const ret = []
- if(list.length%2!=0){
- list.push(null)
- }
- for(let i=0;i<list.length;i=i+2){
- const a = list[i]
- const hasAChecked = this.chooseList.find(s=>s.id == a.id)
- const b = list[i+1]
- const hasBChecked = this.chooseList.find(s=>s.id == b.id)
- // 如果超出
- if(b){
- ret.push({list:[this.formatData(a,hasAChecked),this.formatData(b,hasBChecked)]})
- }else{
- ret.push({list:[this.formatData(a,hasAChecked)]})
- }
- }
- _this.$refs.paging.complete(ret);
- }
- })
- },
- // 格式化数据
- formatData(k,hasChecked){
- return {
- id: k.id,
- cost: k.cost,
- checked: !!hasChecked,
- qty: !!hasChecked ? hasChecked.qty : 0,
- productCode: k.productCode,
- productSn: k.productSn,
- productImage: k.productImage,
- productName: k.productName,
- productOrigCode: k.productOrigCode,
- promoActiveSn: k.promoActiveSn,
- promoRuleSn: k.promoRuleSn,
- promoRuleValue: k.promoRuleValue,
- promoRuleType: k.promoRuleType,
- show: false
- }
- },
- // 添加产品
- chooseProduct(item){
-
- }
- },
- };
- </script>
- <style lang="less" scoped>
- .content{
- width: 100%;
- height: 100vh;
- }
- .tab-search{
- padding: 15rpx 20rpx;
- background: #fff;
- }
- </style>
|