123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- <template>
- <app-layout>
- <app-list v-if="loading" :hidden="false" top="0" :theme="getTheme" :list="list" v-on:update="update" v-on:change="getTotal" v-on:updateList="updateList"></app-list>
- <view class="list" v-if="other.length > 0">
- <view class="title">其他套餐</view>
- <view v-for="(item, index) in other" :key="index" class="item dir-left-nowrap">
- <app-composition :theme="getTheme" @click="choose(item)" @look="choose(item)" :item="item"></app-composition>
- </view>
- </view>
- <view v-if="list.length > 0" :class="['bottom-space', `${iphone_x? 'iphone_x':''}`]"></view>
- <view v-if="list.length > 0" :class="['bottom','main-between','cross-center', `${iphone_x? 'iphone_x':''}`]">
- <view>
- <view class="dir-left-nowrap cross-center">
- <view>总计</view>
- <view class="total-price" :class="getTheme + '-m-text ' + getTheme">¥{{total == 0 ? '0.00' : total}}</view>
- </view>
- <view class="discount" :class="getTheme + '-m-text ' + getTheme">已省¥{{max_discount}}</view>
- </view>
- <view @click="toBuy" class="submit-btn" :class="getTheme + '-m-back ' + getTheme">立即购买</view>
- </view>
- <view class="dialog-bg" v-if="showNoAttr">
- <view class="dialog">
- <view class="dialog-title">
- <view class="dialog-big-title">以下商品未选择规格</view>
- <view>请选择规格后购买</view>
- </view>
- <view :class="[`${noAttrList.length > 4 ? 'dir-left-wrap' : 'main-center'}`,`dialog-goods-list`]">
- <view class="dialog-goods" v-for="(item, index) in noAttrList" :key="index">
- <image :src="item.cover_pic"></image>
- </view>
- </view>
- <view @click="close" class="dialog-close" :class="getTheme + '-m-text ' + getTheme">我知道了</view>
- </view>
- </view>
- <view class='no-tip' v-if="list.length == 0 && loading">
- <image src="/static/image/pull-off.png"></image>
- <view>您选购的套餐已下架</view>
- <view @click="toComposition" class="to-composition" :class="getTheme + '-m-back ' + getTheme">逛逛套餐专区</view>
- </view>
- </app-layout>
- </template>
- <script>
- import {mapGetters} from "vuex";
- import appList from '../components/app-list/app-list';
- import appComposition from "../../../components/basic-component/app-composition/app-composition.vue";
- export default {
- data() {
- return {
- list: [],
- other: [],
- total: 0,
- showNoAttr: false,
- noAttrList: [],
- goods_id: '',
- max_discount: '0.00',
- page: 2,
- hidden: false,
- iphone_x: false,
- noMore: false,
- composition_id: '',
- loading: false
- }
- },
- components: {
- 'app-list': appList,
- 'app-composition': appComposition
- },
- computed: {
- ...mapGetters('mallConfig', {
- getTheme: 'getTheme',
- })
- },
- methods: {
- choose(item) {
- this.composition_id = item.id;
- this.total = '0.00';
- this.max_discount = '0.00';
- this.getDetail();
- },
- toComposition() {
- uni.redirectTo({
- url: '/plugins/composition/index/index'
- });
- },
- isCanbuy(goods){
- console.log(goods)
- if (this.$user.isLogin() && this.$store.state.user.info) {
- let member_level =this.$store.state.user.info.identity.member_level;
- if(member_level<goods.member_level){
- uni.showModal({
- title:"提示",
- content:"套餐中有商品"+goods.name+"不能购买,需达到"+goods.member_name+"会员才可购买",
- showCancel:true,
- buttonText: '升级',
- success:(res)=>{
- if (res.confirm) {
- uni.navigateTo({
- // url:"/pages/member/index/index",
- url: '/pages/member/upgrade/upgrade?level=' + member_level + '&other=' +goods.member_level
- })
- return false;
- }
-
- }
- })
- return false;
- }else{
- return true;
- }
-
- }
- },
- toBuy() {
- let that = this;
- let attr = [];
- let list = [
- {
- mch_id: 0,
- composition_list: []
- }
- ]
-
- let isCanbuy = true;
-
-
- for(let i in that.list) {
- // console.log(that.list[i])
- // if(!that.isCanbuy(that.list[i].host_list[0])){
- // isCanbuy = false;
- // }
-
- for(let j in that.list[i].goods_list){
- if(!that.isCanbuy(that.list[i].goods_list[j])){
- isCanbuy = false;
- }
- }
- }
-
- if(!isCanbuy){
- return;
- }
-
-
- if(that.noAttrList.length > 0) {
- that.showNoAttr = true;
- // for(let i in that.noAttrList) {
- // if(!that.isCanbuy(that.noAttrList[i]))
- // return;
- // }
- }
- //else {
- for(let i in that.list) {
- attr = [];
- if(that.list[i].choose) {
- let arr = {
- composition_id: that.list[i].id,
- goods_list: []
- }
- if(that.list[i].host_list.length > 0) {
- for(let x in that.list[i].host_list[0].choose_attr.attr_list) {
- attr.push({
- attr_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_id,
- attr_group_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_group_id,
- })
- }
- arr.goods_list.push({
- id: that.list[i].host_list[0].goods_id,
- num: 1,
- goods_attr_id: that.list[i].host_list[0].choose_attr.goods_attr_id,
- attr: []
- })
- }
- let goods_attr = [];
- for(let y in that.list[i].goods_list) {
- if(that.list[i].goods_list[y].choose_attr && that.list[i].goods_list[y].choose_attr.attr_list.length > 0) {
- for(let x in that.list[i].goods_list[y].choose_attr.attr_list) {
- attr.push({
- attr_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_id,
- attr_group_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_group_id,
- })
- }
- arr.goods_list.push({
- id: that.list[i].goods_list[y].goods_id,
- num: 1,
- goods_attr_id: that.list[i].goods_list[y].choose_attr.goods_attr_id,
- attr: attr,
- service_label:that.list[i].goods_list[y].choose_attr.service_label
- })
- }
- }
- list[0].composition_list.push(arr);
- }else {
- let arr = {
- composition_id: that.list[i].id,
- goods_list: []
- }
- if(that.list[i].host_list.length > 0 && that.list[i].host_list[0].choose_goods) {
- for(let x in that.list[i].host_list[0].choose_attr.attr_list) {
- attr.push({
- attr_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_id,
- attr_group_id: that.list[i].host_list[0].choose_attr.attr_list[x].attr_group_id,
- })
- }
- arr.goods_list.push({
- id: that.list[i].host_list[0].goods_id,
- num: 1,
- goods_attr_id: that.list[i].host_list[0].choose_attr.goods_attr_id,
- attr: attr
- })
- }
- let noChoose = true;
- for(let y in that.list[i].goods_list) {
- if(that.list[i].goods_list[y].choose_goods && that.list[i].goods_list[y].choose_attr.attr_list) {
- noChoose = false;
- for(let x in that.list[i].goods_list[y].choose_attr.attr_list) {
- attr.push({
- attr_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_id,
- attr_group_id: that.list[i].goods_list[y].choose_attr.attr_list[x].attr_group_id,
- })
- }
- arr.goods_list.push({
- id: that.list[i].goods_list[y].goods_id,
- num: 1,
- goods_attr_id: that.list[i].goods_list[y].choose_attr.goods_attr_id,
- attr: attr,
- service_label:that.list[i].goods_list[y].choose_attr.service_label
- })
- }
- }
- if(arr.goods_list.length > 0) {
- list[0].composition_list.push(arr);
- }
- }
- }
- if(list[0].composition_list.length == 0) {
- uni.showToast({
- title: '请选择套餐',
- icon: 'none',
- duration: 1000
- });
- }else {
- for(let i in list[0].composition_list) {
- if(list[0].composition_list[i].goods_list.length == 1) {
- list[0].composition_list.splice(i,1)
- }
- }
- if(list[0].composition_list.length == 0) {
- uni.showToast({
- title: '请选择搭配商品',
- icon: 'none',
- duration: 1000
- });
- }else {
- list[0].goods_list = [];
- for (let j in list[0].composition_list) {
- for (let y in list[0].composition_list[j].goods_list) {
- list[0].composition_list[j].goods_list[y].cart_id = 0;
- list[0].goods_list.push(list[0].composition_list[j].goods_list[y])
- }
- }
-
- let jump_url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(list)}`;
- jump_url += `&preview_url=${encodeURIComponent(this.$api.composition.order_preview)}&submit_url=${encodeURIComponent(this.$api.composition.order_submit)}&plugin=composition`;
- this.$jump({
- open_type: 'navigate',
- url: jump_url,
- });
- }
- }
- //}
- },
- close () {
- this.showNoAttr = false;
- },
- updateList(e) {
- console.log(e)
- this.list = e;
-
- },
- update(e) {
- this.noAttrList = e;
- },
- getTotal(e,max_discount) {
- this.total = e;
- if(max_discount) {
- this.max_discount = max_discount.toFixed(2)
- }
- },
- getDetail() {
- let that = this;
- that.loading = false;
- uni.showLoading({
- mask: true,
- title: '加载中...',
- });
- let para = {
- composition_id: that.composition_id
- }
- if(that.goods_id > 0) {
- para.goods_id = that.goods_id
- }
- that.$request({
- url: that.goods_id > 0 ? that.$api.composition.detail : that.$api.composition.composition_detail,
- data: para
- }).then(response=>{
- that.loading = true;
- uni.hideLoading();
- if(response.code == 0) {
- if(that.goods_id > 0) {
- that.list = response.data.other_list;
- that.other = response.data.list;
- }else {
- that.list = [];
- that.list[0] = response.data.composition;
- }
- if(that.other.length < 4) {
- that.noMore = true;
- }
- for(let i in that.list) {
- that.list[i].choose = false;
- for(let idx in that.list[i].goods_list) {
- that.list[i].goods_list[idx].choose_attr = null;
- if(that.list[i].goods_list[idx].goods_attr.length == 1) {
- that.list[i].goods_list[idx].choose_attr = that.list[i].goods_list[idx].goods_attr[0];
- that.list[i].goods_list[idx].choose_attr.number = 1;
- that.list[i].goods_list[idx].total_price = (+that.list[i].goods_list[idx].choose_attr.price - +that.list[i].goods_list[idx].price).toFixed(2)
- }
- if(that.list[i].type == 2) {
- that.list[i].host_list[0].choose_attr = null;
- if(that.list[i].host_list[0].goods_attr.length == 1) {
- that.list[i].host_list[0].choose_attr = that.list[i].host_list[0].goods_attr[0];
- that.list[i].host_list[0].choose_attr.number = 1;
- that.list[i].host_list[0].total_price = (+that.list[i].host_list[0].choose_attr.price - +that.list[i].host_list[0].price).toFixed(2)
- }
- that.list[i].goods_list[idx].choose_goods = false;
- that.list[i].host_list[0].choose_goods = true;
- that.list[i].host_list[0].opacity = 0.3;
- }
- }
- }
- if(that.list[0].type == 1) {
- that.list[0].choose = true;
- that.max_discount = that.list[0].max_discount;
- }
- }else {
- uni.hideLoading();
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.loading = true;
- uni.hideLoading();
- that.$hideLoading();
- });
- },
- getMore() {
- let that = this;
- uni.showLoading({
- title: '加载中'
- });
- that.$request({
- url: that.$api.composition.detail,
- data: {
- goods_id: that.goods_id,
- composition_id: that.composition_id,
- page: that.page
- }
- }).then(response=>{
- uni.hideLoading();
- if(response.code == 0) {
- if(response.data.list.length == 0) {
- this.noMore = true;
- return false;
- }
- that.page++;
- that.other = that.other.concat(response.data.list);
- for(let i in that.list) {
- that.list[i].choose = false;
- for(let idx in that.list[i].goods_list) {
- that.list[i].goods_list[idx].choose_attr = null;
- if(that.list[i].type == 2) {
- that.list[i].host_list[0].choose_attr = null;
- that.list[i].host_list[0].opacity = 1;
- that.list[i].goods_list[idx].choose_goods = false;
- that.list[i].host_list[0].choose_goods = false;
- }
- }
- }
- }else {
- uni.hideLoading();
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.$hideLoading();
- });
- },
- },
- onReachBottom() {
- if(!this.noMore) {
- this.getMore();
- }
- },
- onLoad(option) {
- let that = this;
- uni.getSystemInfo({
- success: function (res) {
- if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
- that.iphone_x = true;
- }
- }
- })
- this.goods_id = option.goods_id > 0 ? option.goods_id : '';
- this.composition_id = option.composition_id;
- that.getDetail();
- },
- }
- </script>
- <style scoped lang="scss">
- .no-tip {
- position: fixed;
- top: #{120rpx};
- left: 0;
- right: 0;
- margin: 0 auto;
- color: #666666;
- font-size: #{24rpx};
- width: #{240rpx};
- text-align: center;
- image {
- height: #{240rpx};
- width: #{240rpx};
- margin-bottom: #{20rpx};
- }
- .to-composition {
- border-radius: #{33rpx};
- width: #{246rpx};
- text-align: center;
- height: #{66rpx};
- line-height: #{66rpx};
- margin-top: #{38rpx};
- color: #fff;
- }
- }
- .list {
- padding: #{24rpx};
- .title {
- font-size: #{28rpx};
- color: #353535;
- }
- .item {
- margin-top: #{20rpx};
- padding: #{24rpx};
- border-radius: #{16rpx};
- background-color: #fff;
- }
- }
- .dialog-bg {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: rgba(0,0,0,.3);
- z-index: 202;
- .dialog {
- width: #{630rpx};
- margin: #{260rpx} auto 0;
- background-color: #fff;
- padding-top: #{40rpx};
- border-radius: #{16rpx};
- .dialog-title {
- text-align: center;
- font-size: #{26rpx};
- color: #999999;
- .dialog-big-title {
- font-size: #{32rpx};
- color: #353535;
- margin-bottom: #{10rpx};
- }
- }
- .dialog-goods-list {
- padding: 0 #{65rpx};
- margin: #{26rpx} 0 #{48rpx};
- .dialog-goods {
- width: #{80rpx};
- height: #{80rpx};
- border-radius: #{8rpx};
- margin: #{10rpx};
- image {
- border-radius: #{8rpx};
- width: #{80rpx};
- height: #{80rpx};
- }
- }
- }
- .dialog-close {
- width: #{630rpx};
- border-top: #{2rpx} solid #e2e2e2;
- font-size: #{32rpx};
- text-align: center;
- padding: #{25rpx} 0;
- }
- }
- }
- .bottom {
- width: 100%;
- height: #{120rpx};
- position: fixed;
- bottom: 0;
- left: 0;
- z-index: 30;
- background-color: #fff;
- border-top: #{2rpx} solid #e2e2e2;
- font-size: #{24rpx};
- color: #353535;
- padding: 0 #{20rpx};
- &.iphone_x {
- height: #{150rpx};
- padding-bottom: #{50rpx};
- }
- .total-price {
- font-size: #{36rpx};
- margin-left: #{8rpx};
- }
- .submit-btn {
- width: #{222rpx};
- height: #{78rpx};
- border-radius: #{39rpx};
- color: #fff;
- font-size: #{32rpx};
- line-height: #{78rpx};
- text-align: center;
- }
- .discount {
- font-size: #{24rpx};
- }
- }
- .bottom-space {
- height: #{110rpx};
- &.iphone_x {
- height: #{160rpx};
- }
- }
- </style>
|