123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629 |
- <template>
- <view class="video-pagesCons">
- <view class="tab-search">
- <u-search placeholder="请输入产品名称/轮胎规格" shape="round" :clearabled="true" show-action v-model="queryWord" @clear="pageInit" @search="pageInit" @custom="pageInit"></u-search>
- </view>
- <view class="tab-body">
- <view class="product-list" id="list">
- <view
- class="check-order-list"
- v-for="(item,index) in list"
- :key="item.id"
- >
- <productItem
- v-if="item.top > curScrollTop-showScrollHeight*2 && item.top < curScrollTop + showScrollHeight*3"
- :item="item"
- :checked="item.checked"
- @chooseProduct="chooseProduct"
- ></productItem>
- </view>
- </view>
- <view style="padding: 20upx;">
- <u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
- <u-loadmore v-if="(total>=list.length&&list.length)||status=='loading'" :status="status" />
- </view>
- </view>
-
- <view class="bottom-bar" @click="clearAction" v-if="total>0">
- <view class="bottom-bar-left">
- <view class="bottom-bar-left-item">
- <view class="bottom-bar-left-item-icon" @click="openChoose">
- <u-icon name="shopping-cart" size="40"></u-icon>
- <u-badge type="error" :count="totalNum" :offset="[-7,-8]"></u-badge>
- </view>
- </view>
- <view class="bottom-bar-left-item" v-if="showChoosePopu">
- 合计:<view class="price-txt">¥<text>{{totalAmount}}</text></view>
- </view>
- </view>
- <view :class="'bottom-bar-right bg-'+(showChoosePopu?'1':'0')" @click="submitOrder">
- <view class="bottom-bar-right-item">{{showChoosePopu?'确认采购':'去结算'}}</view>
- </view>
- </view>
-
- <page-container
- :show="showChoosePopu"
- :round="true"
- position="bottom"
- custom-style="height:90%"
- @enter="openRender"
- @afterleave="closePopu">
- <scroll-view
- :style="{width:screenWidth + 'px',height:'100%'}"
- scroll-y="true"
- @scroll="onscrollPopu"
- id="popuScroll"
- >
- <view class="choose-title">
- <view class="flex align_center">
- <view>已选<text class="p-nums">{{chooseLength}}</text>款产品 </view>
- <u-button @click="claerChoose" size="mini" type="error" plain style="margin: 0 20upx;">清空列表</u-button>
- <text class="choose-inf">左滑删除产品</text>
- </view>
- <view class="choose-close" @click="showChoosePopu=false">
- <u-icon name="close" size="30"></u-icon>
- </view>
- </view>
- <view class="choose-product-list" v-if="showSwipeAction">
- <view
- v-for="(item, index) in chooseList"
- :key="item.id"
- >
- <u-swipe-action
- :show="item.show"
- :index="item.id"
- @click="chooseClick"
- @open="chooseOpen"
- :options="chooseOptions"
- v-if="item.top > curScrollPopuTop-showScrollPopuHeight/2 && item.top < curScrollPopuTop + showScrollPopuHeight*1.5"
- >
- <chooseProductItem
- :item="item"
- :width="screenWidth-20"
- @changeQty="changeQty"></chooseProductItem>
- </u-swipe-action>
- </view>
- </view>
- </scroll-view>
- </page-container>
- </view>
- </template>
- <script>
- import {
- mapState,
- mapMutations,
- } from 'vuex'
- import { queryPromoProductByPage } from '@/api/video.js'
- import { purchaseSave } from '@/api/purchase.js'
- import productItem from '@/pagesB/components/productItem.vue'
- import chooseProductItem from '@/pagesB/components/chooseProductItem.vue'
- export default {
- components:{
- productItem,
- chooseProductItem
- },
- data() {
- return {
- status: 'loading',
- noDataText: '暂无数据',
- promoActiveSn: null,
- submitOk: false,
- queryWord: '',
- pageNo: 1,
- pageSize: 6,
- list: [],
- total: 0,
-
- showChoosePopu: false,
- chooseList:[],
- chooseOptions:[
- {
- text: '删除',
- style: {
- backgroundColor: '#dd524d'
- }
- }
- ],
- screenWidth: 750,
- showSwipeAction: false,
- curScrollPopuTop:0,
- showScrollPopuHeight:0,
- popuItemHeight: 133,
-
- showScrollHeight: 0,
- curScrollTop: 0 ,
- scrolltimer: null,
- }
- },
- computed: {
- ...mapState(['hasLogin']),
- userInfo(){
- return this.$store.state.vuex_userInfo
- },
-
- chooseLength(){
- return this.chooseList.length
- },
-
- totalAmount(){
- let total = 0
- this.chooseList.forEach(key => {
- total = total + key.cost * key.qty
- })
- return total.toFixed(2)
- },
-
- totalNum(){
- let total = 0
- this.chooseList.forEach(key => {
- total = total + key.qty
- })
- return total
- },
- },
- 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)) : []
- if(this.chooseList.length){
- this.updateChooseListTop()
- }
-
- this.pageInit()
- },
- 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
- this.list = null
- },
-
- onReachBottom() {
- if(this.list.length < this.total){
- this.pageNo += 1
- this.getRow()
- }else{
- this.status = "nomore"
- }
- },
-
- onPageScroll(e){
- console.log(e,'----')
-
- if(!this.showChoosePopu){
-
- clearTimeout(this.scrolltimer)
-
- this.scrolltimer = setTimeout(() => {
- this.curScrollTop = e.scrollTop
- }, 17)
- }
- },
- methods: {
-
- pageInit(){
-
- this.total = 0
- this.pageNo = 1
- this.list = []
-
- this.getRow()
- },
-
- chooseProduct(item){
- const rowItem = this.list.find(k => k.id == item.id)
- if(!rowItem.checked){
- rowItem.checked = true
- rowItem.qty = 1
- rowItem.show = false
- this.chooseList.unshift(this.$u.deepClone(rowItem))
-
- this.updateChooseListTop()
- }else{
- rowItem.qty = rowItem.qty + 1
-
- const row = this.chooseList.find(key => key.id == rowItem.id)
- if(row){
- row.qty = row.qty + 1
- }
- this.chooseList.splice()
- }
- },
-
- openRender(){
- const query = uni.createSelectorQuery().in(this);
- query.select('#popuScroll').boundingClientRect(data => {
- if (data) {
- const maxRows = Math.ceil(data.height/this.popuItemHeight)
- this.showScrollPopuHeight = this.popuItemHeight * maxRows
-
- setTimeout(()=>{
- this.showSwipeAction = true
- },100)
- }
- }).exec();
- },
-
- closePopu(){
- this.showChoosePopu = false
- this.showSwipeAction = false
- if(this.submitOk){
- uni.hideLoading()
- uni.navigateTo({
- url: "/pagesB/procureOrder"
- })
- }
- },
-
- updateChooseListTop(){
- this.chooseList.forEach((item,index)=>{
- item.top = (index+1)* this.popuItemHeight
- })
- this.chooseList.splice()
- },
-
- openChoose(){
- this.submitOk = false
- console.log(this.chooseList)
- if(this.chooseLength){
- this.showChoosePopu = !this.showChoosePopu
- }else{
- this.$u.toast(`请选择产品`);
- }
- },
-
- onscrollPopu(e){
- console.log(e.detail.scrollTop)
- this.curScrollPopuTop = e.detail.scrollTop
-
-
-
-
-
-
- },
-
- changeQty(e){
- const rowIndex = this.chooseList.findIndex(key => key.id == e.index)
- if(rowIndex>=0){
- this.chooseList[rowIndex].qty = e.value
- this.chooseList.splice()
- }
-
- const aindex = this.list.findIndex(key => key.id == e.index)
- if(aindex>=0){
- this.list[aindex].qty = e.value
- this.list.splice()
- }
- },
-
- chooseClick(index, btns){
- if(btns == 0) {
-
- const aindex = this.chooseList.findIndex(item => item.id == index)
- if(aindex>=0){
- this.chooseList.splice(aindex, 1);
-
- this.updateChooseListTop()
- }
-
-
- const row = this.list.find(item => item.id == index)
- if(row){
- row.checked = false
- row.qty = 0
- }
-
-
- if(this.chooseList.length==0){
- this.clearChooseData()
- }
- this.$u.toast(`删除成功!`);
- }
- },
-
- chooseOpen(index){
-
-
- const row = this.chooseList.find(item => item.id == index)
- if(row) {
- row.show = true
- }
- this.chooseList.map((item, idx) => {
- if(index != item.id) this.chooseList[idx].show = false;
- })
- },
-
- clearAction(){
- this.chooseList.map(item => {
- item.show = false
- })
- this.chooseList.splice()
- },
-
- claerChoose(){
- const _this = this
- uni.showModal({
- title: '提示',
- content: '确定清空已选列表?',
- confirmText: '确定',
- success(res) {
- if(res.confirm){
- _this.clearChooseData()
- }
- }
- })
- },
-
- clearChooseData(){
- this.chooseList = []
- this.showChoosePopu = false
-
- this.list.filter(item => item.checked).map(item=>{
- item.checked = false
- item.qty = 0
- })
- },
-
- getRow () {
- let _this = this
- let params = {
- pageNo: this.pageNo,
- pageSize: this.pageSize,
- queryWord: this.queryWord,
- promoActiveSn: this.promoActiveSn
- }
-
- const rowHeight = 287
- const pageHeight = uni.getSystemInfoSync().windowHeight
- const maxShowNums = Math.ceil( pageHeight / rowHeight )
- console.log(maxShowNums)
- this.showScrollHeight = rowHeight * maxShowNums
-
- this.status = "loading"
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- queryPromoProductByPage(params).then(res => {
- if (res.code == 200 || res.status == 204 || res.status == 200) {
- const list = res.data.list||[]
- const ret = []
- let curPageNums = (this.pageNo - 1) * this.pageSize / 2
-
- list.map((k,i) => {
-
- const hasChecked = this.chooseList.find(s=>s.id == k.id)
- curPageNums = (i+1) % 2 != 0 ? curPageNums + 1 : curPageNums
- ret.push({
- 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,
- top: rowHeight * curPageNums
- })
- })
- _this.list = _this.list.concat(ret)
- console.log(_this.list)
- _this.total = res.data.count || 0
- } else {
- _this.list = []
- _this.total = 0
- _this.noDataText = res.message
- }
- _this.$nextTick(()=>{
- uni.hideLoading()
- })
- _this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
- })
- },
-
- submitOrder(){
- if(this.showChoosePopu){
- uni.showLoading({
- title: '提交中...',
- mask: true
- })
- const detailList = []
- this.chooseList.map(item => {
- detailList.push({
- promoActiveSn: this.promoActiveSn,
- promoRuleSn:item.promoRuleSn,
- productSn:item.productSn,
- productCode:item.productCode,
- qty:item.qty,
- price:item.cost,
- giveAmount:item.promoRuleValue
- })
- })
- purchaseSave({
- promoActiveSn: this.promoActiveSn,
- detailList: detailList
- }).then(res => {
- if(res.status == 200){
- res.data.detailList = []
- this.$store.state.vuex_tempData = res.data
- this.clearChooseData()
- this.submitOk = true
- }else{
- uni.showToast({
- title: res.message,
- icon: 'none'
- })
- }
- })
- }else{
- this.openChoose()
- }
- },
- }
- }
- </script>
- <style lang="less">
- page{
- height: 100vh;
- }
- .video-pagesCons{
- height: 100vh;
- position: relative;
- .tab-search{
- padding: 15rpx 20rpx;
- background: #fff;
- position: fixed;
- top:0;
- left:0;
- width:100%;
- z-index:20;
- }
- .tab-body{
- display: flex;
- flex-direction: column;
- flex-grow: 1;
- padding: 90rpx 0 170rpx 0;
- .product-list{
- display: flex;
- flex-wrap: wrap;
- }
- .check-order-list{
- width: 50%;
- padding: 10upx;
- height: 287px;
- }
- }
- .bottom-bar{
- height: 130upx;
- z-index: 200;
- background-color: #fff;
- display: flex;
- align-items: center;
- justify-content: space-between;
- font-size: 32upx;
- position: fixed;
- bottom:0;
- left:0;
- width:100%;
- .bottom-bar-left{
- padding: 0 30upx;
- flex-grow: 1;
- display: flex;
- align-items: center;
- }
- .bottom-bar-left-item{
- padding-right: 20rpx;
- font-size: 24rpx;
- display: flex;
- align-items: center;
- }
- .bottom-bar-left-item-icon{
- position: relative;
- background: #2196F3;
- padding: 20rpx;
- border-radius: 100%;
- color: #fff;
- }
- .bottom-bar-right{
- padding: 0 50rpx;
- height: 100%;
- background: #2196F3;
- display: flex;
- align-items: center;
- .bottom-bar-right-item{
- color: #fff;
- }
- }
- .bg-0{
- background: #2196F3;
- }
- .bg-1{
- background: #f44336;
- }
- }
- .price-txt{
- color: red;
- text{
- font-size: 36rpx;
- }
- }
- .choose-title{
- display: flex;
- align-items:center;
- justify-content: space-between;
- padding: 0 25rpx;
- position: fixed;
- background: #fff;
- width: 100%;
- z-index: 3;
- border-bottom: 1px solid #eee;
- border-radius: 40rpx 40rpx 0 0;
- > view{
- padding: 25rpx 0;
- }
- .p-nums{
- color: #2196F3;
- margin: 0 6rpx;
- }
- .choose-inf{
- color: #999;
- font-size: 24rpx;
- }
- .choose-close{
- padding: 25rpx 20rpx;
- }
- }
- .choose-product-list{
- padding: 100rpx 20rpx 150rpx;
- width: 100%;
- position: relative;
- > view{
- height: 133px;
- }
- }
- .back-price{
- padding: 6rpx 65rpx;
- background: rgba(255 ,87 ,34 , 1);
- position: absolute;
- top: 18rpx;
- right: -45rpx;
- color: #fff;
- z-index: 2;
- font-size: 20rpx;
- text-align: center;
- transform: rotate(40deg);
- display: flex;
- align-items: center;
- text{
- font-size: 28rpx;
- margin: 0 5rpx;
- }
- }
- }
- </style>
|