活动按钮状态流转

This commit is contained in:
2026-03-25 15:53:37 +08:00
commit 37346e790f
2762 changed files with 240282 additions and 0 deletions

498
pagesMall/goods/details.vue Normal file
View File

@@ -0,0 +1,498 @@
<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者助力商协会发展
+----------------------------------------------------------------------
| Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
+----------------------------------------------------------------------
| 沃德商协会系统并不是自由软件不加密并不代表开源未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
+----------------------------------------------------------------------
| 商品详情 开发者: 麦沃德科技-半夏
+---------------------------------------------------------------------- -->
<template>
<page-meta :page-style="'overflow:' + (pageShow ? 'hidden' : 'visible')"></page-meta>
<view class="container" :style="{'--theme-color': themeColor}">
<!-- 标题栏 -->
<title-bar :showBack="true" title="商品详情"></title-bar>
<!-- 内容区 -->
<view class="container-main" v-if="loadEnd">
<view class="main-carousel">
<carousel :show-data="carouselList" height="660rpx" radius="0" right="32rpx" bottom="106rpx"></carousel>
</view>
<view class="main-info">
<view class="info-price">
<view class="title"><text></text>{{goodsDetails.price}}</view>
<view class="subtitle">{{goodsDetails.ot_price}}</view>
</view>
<view class="info-title">{{goodsDetails.name}}</view>
<view class="info-parameter" @click="handleExpand()">
<view class="parameter-title">参数</view>
<view class="parameter-value" :class="{'multiLine': isMultiLine, 'text-ellipsis' : !isExpand && isMultiLine}">
<text id="specsText">{{goodsDetails.paramJson}}</text>
</view>
<view class="parameter-more" :class="{rotate: isExpand}" v-if="isMultiLine">
<image class="icon" src="/static/mall/icon-down.png" mode="aspectFit"></image>
</view>
</view>
</view>
<view class="main-content">
<view class="content-title">商品详情</view>
<mp-html :content="goodsDetails.content" />
</view>
<view class="main-footer">
<view class="flex align-items-center">
<!-- #ifdef MP-WEIXIN -->
<button class="footer-item clear" open-type="share">
<image class="item-icon" src="/static/share.png" mode="aspectFit"></image>
<text class="item-text">分享</text>
</button>
<!-- #endif -->
<view class="footer-item" @click="toShoppingCart()">
<image class="item-icon" src="/static/mall/cart.png" mode="aspectFit"></image>
<text class="item-text">购物车</text>
<view class="item-number" v-if="Number(cartNumber) > 0">{{cartNumber}}</view>
</view>
<view class="flex-item flex justify-content-end">
<view class="footer-btn flex-item" style="background: #FFA820" @click="handleAddCart()">加入购物车</view>
<view class="footer-btn flex-item" :style="{background: themeColor}" @click="toOrder()">立即购买</view>
</view>
</view>
<view class="safe-padding"></view>
</view>
</view>
<!-- 选择数量弹窗 -->
<quantity-modal ref="quantityModal" @confirm="changeQuantity" @onChange="pageChange"></quantity-modal>
</view>
</template>
<script>
import { mapState } from "vuex"
// #ifdef H5
import wx from 'weixin-js-sdk';
// #endif
import carousel from "@/pages/component/carousel/carousel.vue"
import quantityModal from "@/pagesMall/component/modal/quantity.vue"
export default {
components: {
carousel,
quantityModal,
},
data() {
return {
// 页面是否阻止滚动
pageShow: false,
// 是否加载完成
loadEnd: false,
// 商品Id
goodsId: '',
// 商品详情
goodsDetails: {},
// 商品参数是否展开
isExpand: false,
// 商品参数是否存在多行
isMultiLine: false,
// 轮播图列表
carouselList: [],
// 购物车数量
cartNumber: 0,
}
},
computed: {
...mapState({
themeColor: state => state.app.themeColor,
}),
},
onLoad(option) {
this.goodsId = option.id
uni.showLoading({
title: "加载中"
})
this.getGoodsDetails(() => {
uni.hideLoading()
this.loadEnd = true
// #ifdef H5
this.initConfig()
// #endif
})
},
onShow() {
if (uni.getStorageSync("token")) this.getCartNumber()
},
onShareAppMessage() {
return {
title: this.goodsDetails.name,
path: '/pagesMall/goods/details?id=' + this.goodsId,
imageUrl: this.carouselList[0].image,
}
},
onShareTimeline() {
return {
title: this.goodsDetails.name,
path: '/pagesMall/goods/details?id=' + this.goodsId,
imageUrl: this.carouselList[0].image,
}
},
methods: {
// 改变页面滚动状态
pageChange(state) {
this.pageShow = state
},
// #ifdef H5
// 微信公众号初始化方法
initConfig() {
this.$util.request("main.WeChatConfig", {
url: location.href.split('#')[0]
}).then(res => {
if (res.code == 1) {
wx.config({
debug: false,
appId: res.data.appId,
timestamp: Number(res.data.timestamp),
nonceStr: res.data.nonceStr,
signature: res.data.signature,
jsApiList: ["updateAppMessageShareData", "updateTimelineShareData", "wx-open-launch-weapp"],
openTagList: ["updateAppMessageShareData", "updateTimelineShareData", 'wx-open-launch-weapp'],
})
wx.ready(() => {
wx.updateAppMessageShareData({
title: this.goodsDetails.name,
desc: "",
link: window.location.href,
imgUrl: this.carouselList[0].image,
});
wx.updateTimelineShareData({
title: this.goodsDetails.name,
link: window.location.href,
imgUrl: this.carouselList[0].image,
});
});
} else {
uni.hideLoading()
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
uni.hideLoading()
console.error('通过config接口注入权限验证配置 ', error)
})
},
// #endif
// 获取商品详情
getGoodsDetails(fn) {
this.$util.request("mall.goodsDetails", {
id: this.goodsId
}).then(res => {
if (fn) fn()
if (res.code == 1) {
this.goodsDetails = res.data
this.carouselList = this.splitImages(res.data.slider_images)
if (res.data.param_json) {
let paramJsons = JSON.parse(res.data.param_json);
let tempJson = [];
for (let key in paramJsons) {
tempJson.push(key + ':' + paramJsons[key]);
}
this.goodsDetails.paramJson = tempJson.join(" ");
}
this.$nextTick(() => {
this.getCollapse()
})
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
if (fn) fn()
console.error('获取商品详情', error)
})
},
// 字符串转数组格式图片
splitImages(images) {
try {
if (images) return images.split(',');
else return []
} catch (error) {
return [];
}
},
// 前往订单确认
toOrder() {
if (uni.getStorageSync("token")) {
this.$refs.quantityModal.open(1, 1)
} else {
uni.navigateTo({
url: "/pages/login/index",
animationType: "fade-in"
})
}
},
// 展示更多切换事件
handleExpand() {
this.isExpand = !this.isExpand
},
// 获取文字是否存在折叠
getCollapse() {
uni.createSelectorQuery().select('#specsText').boundingClientRect((rect) => {
if (rect.height > uni.upx2px(40)) {
this.isMultiLine = true
this.isExpand = false
} else {
this.isMultiLine = false
this.isExpand = true
}
}).exec();
},
// 获取购物车数量
getCartNumber() {
this.$util.request("mall.cartNumber").then(res => {
if (res.code == 1) {
this.cartNumber = res.data.number || 0
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
console.error('获取购物车数量', error)
})
},
// 加入购物车
handleAddCart() {
if (uni.getStorageSync("token")) {
this.$refs.quantityModal.open(1, 2)
} else {
uni.navigateTo({
url: "/pages/login/index",
animationType: "fade-in"
})
}
},
// 改变选择的数量
changeQuantity(number, type) {
if (type == 1) {
const mallOrder = {
isCartItem: false,
list: [{
id: this.goodsDetails.id,
name: this.goodsDetails.name,
image: this.goodsDetails.image,
price: this.goodsDetails.price,
number: number
}]
}
this.$store.commit("app/setMallOrder", mallOrder)
this.$util.toPage({
mode: 1,
path: "/pagesMall/goods/order",
})
} else {
uni.showLoading({
title: "加载中",
mask: true,
})
this.$util.request("mall.addCart", {
goods_id: this.goodsDetails.id,
number: number
}).then(res => {
uni.hideLoading()
if (res.code == 1) {
this.cartNumber = res.data.number || 0
uni.showToast({
icon: "success",
title: "添加成功",
duration: 2000
})
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
uni.hideLoading()
console.error('加入购物车', error)
})
}
},
// 跳转购物车
toShoppingCart() {
this.$util.toPage({
mode: 1,
path: "/pagesMall/cart/index"
})
},
}
}
</script>
<style lang="scss">
.container {
.container-main {
padding-bottom: 112rpx;
.main-info {
position: relative;
z-index: 9;
margin-top: -74rpx;
padding: 32rpx 40rpx;
border-radius: 40rpx 40rpx 0 0;
background: #FFF;
.info-price {
display: flex;
align-items: flex-end;
.title {
color: var(--theme-color);
font-size: 48rpx;
font-weight: 600;
line-height: 1;
padding: 10rpx 0;
text {
font-size: 28rpx;
}
}
.subtitle {
margin-left: 24rpx;
color: #8D929C;
font-size: 28rpx;
line-height: 40rpx;
text-decoration-line: line-through;
padding: 10rpx 0;
}
}
.info-title {
margin-top: 32rpx;
color: #5A5B6E;
font-size: 32rpx;
font-weight: 600;
line-height: 44rpx;
}
.info-parameter {
margin-top: 32rpx;
display: flex;
.parameter-title {
color: #5A5B6E;
font-size: 28rpx;
font-weight: 600;
line-height: 40rpx;
}
.parameter-value {
flex: 1;
margin-left: 32rpx;
height: 40rpx;
color: #8D929C;
font-size: 28rpx;
line-height: 40rpx;
overflow: hidden;
&.multiLine {
height: auto;
}
}
.parameter-more {
width: 24rpx;
height: 40rpx;
margin-left: 24rpx;
&.rotate {
transform: rotate(180deg);
}
}
}
}
.main-content {
flex: 1;
display: flex;
flex-direction: column;
padding: 32rpx 40rpx;
background: #FFFFFF;
margin-top: 12rpx;
.content-title {
color: #5A5B6E;
font-size: 28rpx;
font-weight: 600;
margin-bottom: 32rpx;
}
}
.main-footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 96;
background: #FFF;
border-top: 1rpx solid #F6F7FB;
padding: 16rpx 32rpx;
.footer-item {
position: relative;
margin-right: 32rpx;
display: flex;
flex-direction: column;
align-items: center;
min-width: 60rpx;
.item-icon {
width: 52rpx;
height: 52rpx;
}
.item-text {
color: #5A5B6E;
font-size: 20rpx;
line-height: 28rpx;
}
.item-number {
position: absolute;
top: 0;
left: 100%;
transform: translateX(-50%);
margin-left: -6rpx;
color: #FFF;
text-align: center;
font-size: 16rpx;
line-height: 20rpx;
min-width: 20rpx;
height: 20rpx;
border-radius: 10rpx;
padding: 0 4rpx;
background: var(--theme-color);
}
}
.footer-btn {
color: #ffffff;
font-size: 28rpx;
line-height: 40rpx;
padding: 20rpx;
border-radius: 16rpx;
background: var(--theme-color);
text-align: center;
margin-right: 20rpx;
&:last-child {
margin-right: 0;
}
}
}
}
}
</style>

183
pagesMall/goods/list.vue Normal file
View File

@@ -0,0 +1,183 @@
<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者助力商协会发展
+----------------------------------------------------------------------
| Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
+----------------------------------------------------------------------
| 沃德商协会系统并不是自由软件不加密并不代表开源未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
+----------------------------------------------------------------------
| 商品列表 开发者: 麦沃德科技-半夏
+---------------------------------------------------------------------- -->
<template>
<view class="container">
<!-- 标题栏 -->
<title-bar :title="pageTitle || '商品列表'"></title-bar>
<!-- 内容区 -->
<view class="container-main" v-if="loadEnd">
<mall-goods ref="mallGoods" v-if="goodsList.length"></mall-goods>
<empty top="30%" title="分类下暂无相关商品~" v-else></empty>
</view>
<!-- 底部导航 -->
<tab-bar></tab-bar>
</view>
</template>
<script>
import { mapState } from "vuex"
import mallGoods from '@/pagesMall/component/mall/goods.vue'
// #ifdef H5
import wx from 'weixin-js-sdk';
// #endif
export default {
components: {
mallGoods
},
data() {
return {
// 是否加载完成
loadEnd: false,
// 分类Id
screenId: '',
// 页面标题
pageTitle: "",
// 分类查询参数
page: 1,
limit: 20,
hasMore: false,
// 商品列表
goodsList: [],
};
},
computed: {
...mapState({
shareImage: state => state.app.shareImage,
shareTitle: state => state.app.shareTitle,
})
},
onLoad(option) {
uni.showLoading({
title: "加载中"
})
this.screenId = option.id
this.pageTitle = option.name ? decodeURIComponent(option.name) : "商品列表"
this.getGoodsList(() => {
this.loadEnd = true
uni.hideLoading()
})
// #ifdef H5
this.initConfig()
// #endif
},
onPullDownRefresh() {
this.page = 1
if (this.goodsList.length) this.$refs.mallGoods.clearList()
this.getGoodsList(() => {
uni.stopPullDownRefresh();
});
},
onReachBottom() {
if (this.hasMore) {
this.page++
this.getGoodsList();
}
},
onShareAppMessage() {
return {
title: this.shareTitle,
imageUrl: this.shareImage,
}
},
onShareTimeline() {
return {
title: this.shareTitle,
imageUrl: this.shareImage,
}
},
methods: {
// #ifdef H5
// 微信公众号初始化方法
initConfig() {
this.$util.request("main.WeChatConfig", {
url: location.href.split('#')[0]
}).then(res => {
if (res.code == 1) {
wx.config({
debug: false,
appId: res.data.appId,
timestamp: Number(res.data.timestamp),
nonceStr: res.data.nonceStr,
signature: res.data.signature,
jsApiList: ["updateAppMessageShareData", "updateTimelineShareData"],
openTagList: ["updateAppMessageShareData", "updateTimelineShareData"],
})
wx.ready(() => {
wx.updateAppMessageShareData({
title: this.shareTitle,
desc: "",
link: window.location.href,
imgUrl: this.shareImage,
});
wx.updateTimelineShareData({
title: this.shareTitle,
link: window.location.href,
imgUrl: this.shareImage,
});
});
} else {
uni.hideLoading()
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
uni.hideLoading()
console.error('通过config接口注入权限验证配置 ', error)
})
},
// #endif
// 获取分类筛选的商品
getGoodsList(fn) {
this.$util.request("mall.goodsList", {
page: this.page,
limit: this.limit,
category_id: this.screenId
}).then(res => {
if (fn) fn()
if (res.code == 1) {
let list = res.data.data
this.hasMore = this.page < res.data.total / this.limit ? true : false
this.goodsList = this.page == 1 ? list : [...this.goodsList, ...list];
this.$nextTick(() => {
if (this.goodsList.length) this.$refs.mallGoods.getList(this.goodsList)
})
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
if (fn) fn()
console.error('获取商品列表', error)
})
},
// 瀑布流加载完成
waterfallLoadEnd() {
this.waterfallData.reset = false;
if (this.hasMore) this.waterfallData.status = 'await';
else this.waterfallData.status = "finish"
}
}
}
</script>
<style lang="scss">
.container {
.container-main {
padding: 32rpx;
}
}
</style>

612
pagesMall/goods/order.vue Normal file
View File

@@ -0,0 +1,612 @@
<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者助力商协会发展
+----------------------------------------------------------------------
| Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
+----------------------------------------------------------------------
| 沃德商协会系统并不是自由软件不加密并不代表开源未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
+----------------------------------------------------------------------
| 订单确认 开发者: 麦沃德科技-半夏
+---------------------------------------------------------------------- -->
<template>
<page-meta :page-style="'overflow:' + (pageShow ? 'hidden' : 'visible')"></page-meta>
<view class="container" :style="{ '--theme-color': themeColor }">
<!-- 标题栏 -->
<title-bar :showBack="true" title="订单确认"></title-bar>
<!-- 内容区 -->
<view class="container-main" v-if="loadEnd">
<!-- 发货方式 -->
<view class="main-method flex align-items-center" @click="openDeliveryMethod" v-if="mallConfig.self_pickup_status == 1">
<view class="method-title">发货方式</view>
<view class="method-value flex-item">{{deliveryMethod == 2 ? "到店自提" : "快递发货"}}</view>
<image class="method-icon" src="/static/right.png" mode="aspectFit"></image>
</view>
<!-- 到店自提 -->
<view class="main-address" v-if="deliveryMethod == 2">
<view class="address-title">自提地址</view>
<view class="address-box flex align-items-center" @click="toNavigation()">
<view class="box-text flex-item">{{mallConfig.address}}</view>
<view class="box-icon" :style="{'background-image': 'url('+ iconMore +')'}" v-if="iconMore"></view>
</view>
<view class="address-info flex flex-wrap" v-if="mallConfig.mobile" @click="onContact()">{{mallConfig.mobile}}</view>
</view>
<!-- 地址选择 -->
<view class="main-address" @click="chooseAddress()" v-else>
<view class="address-box flex align-items-center">
<view class="box-text flex-item">{{addressData.address || "请选择收货地址"}}</view>
<view class="box-icon" :style="{'background-image': 'url('+ iconMore +')'}" v-if="iconMore"></view>
</view>
<view class="address-info flex flex-wrap" v-if="addressData.name && addressData.tel">
<text>{{addressData.name || ""}}</text>
<text>{{addressData.tel || ""}}</text>
</view>
</view>
<!-- 商品信息 -->
<view class="main-goods">
<block v-for="(item, index) in goodsData" :key="index">
<mall-store :show-data="item" :show-number="item.number" @changeNumber="changeNumber($event, index)"></mall-store>
</block>
</view>
<!-- 商品费用 -->
<view class="main-cost">
<view class="cost-info">
<view class="title">商品总额</view>
<view class="value">{{totalPrice}}</view>
</view>
<view class="cost-info" v-if="deliveryMethod == 1">
<view class="title">运费总额</view>
<view class="value">{{parseFloat(orderFreight).toFixed(2)}}</view>
</view>
</view>
<!-- 底部按钮 -->
<view class="main-footer">
<view class="flex align-items-center">
<view class="footer-money text-ellipsis-more"><text></text>{{getOrderAmount()}}</view>
<view class="footer-btn flex-item" @click="submitOrder()" v-if="userMobile">提交订单</view>
<button class="footer-btn flex-item clear" open-type="getPhoneNumber" @getphonenumber="bindPhoneNumber" v-else>提交订单</button>
</view>
<view class="safe-padding"></view>
</view>
</view>
<!-- 发货方式选择弹窗 -->
<select-picker ref="selectPicker" title="发货方式" @confirm="changeDeliveryMethod" @onChange="pageChange"></select-picker>
<!-- 选择地址弹窗 -->
<address-modal ref="addressModal" @confirm="changeAddress" @onChange="pageChange"></address-modal>
<!-- 选择数量弹窗 -->
<quantity-modal ref="quantityModal" @confirm="changeQuantity" @onChange="pageChange"></quantity-modal>
</view>
</template>
<script>
import { mapState } from "vuex"
import svgData from "@/common/svg.js"
import mallStore from "@/pagesMall/component/mall/store.vue"
import selectPicker from "@/pages/component/picker/select.vue"
import addressModal from "@/pagesMall/component/modal/address.vue"
import quantityModal from "@/pagesMall/component/modal/quantity.vue"
export default {
components: {
mallStore,
selectPicker,
addressModal,
quantityModal,
},
data() {
return {
// 页面是否阻止滚动
pageShow: false,
// 是否加载完成
loadEnd: false,
// 商品数据
goodsData: [],
// 发货方式
deliveryMethod: 1,
// 已选地址
addressData: {},
// 订单运费
orderFreight: 0,
// 是否为购物车商品
isCartItem: false,
// 商城配置
mallConfig: {},
};
},
computed: {
...mapState({
themeColor: state => state.app.themeColor,
iconMore: state => {
return svgData.svgToUrl("more", state.app.themeColor)
},
userMobile: state => state.user.mobile,
subscribeIds: state => state.app.subscribeNotifyIds,
}),
totalPrice() {
var result = this.goodsData.reduce((sum, item) => sum + (parseFloat(item.price) * parseInt(item.number)), 0)
return parseFloat(result).toFixed(2);
},
},
onLoad() {
uni.showLoading({
title: "加载中"
})
this.getMallConfig()
this.getGoodsDetails(() => {
uni.hideLoading()
this.loadEnd = true
})
},
methods: {
// 改变页面滚动状态
pageChange(state) {
this.pageShow = state
},
// 获取商品详情
getGoodsDetails(fn) {
if (this.$store.state.app?.mallOrder?.list?.length) {
this.goodsData = this.$store.state.app.mallOrder.list || []
this.isCartItem = this.$store.state.app.mallOrder.isCartItem || false
this.getAddress(() => {
this.getPostage(fn)
})
} else {
uni.hideLoading()
uni.showModal({
title: "提示",
content: "请选择商品后下单",
showCancel: false,
confirmText: "返回",
confirmColor: this.themeColor,
complete: () => {
uni.navigateBack()
}
})
}
},
// 获取商城配置
getMallConfig() {
this.$util.request("mall.config").then(res => {
if (res.code == 1) {
this.mallConfig = res.data
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
console.error('获取商城配置', error)
})
},
// 获取默认地址
getAddress(fn) {
this.$util.request("mall.address.list", {
is_default: 1
}).then(res => {
if (res.code == 1) {
if (res.data[0]) this.addressData = res.data[0]
if (fn) fn()
} else {
if (fn) fn()
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
if (fn) fn()
console.error('获取默认地址', error)
})
},
// 获取运费
getPostage(fn) {
if (this.deliveryMethod == 2) {
if (fn) fn()
return
}
if (!this.addressData || !this.addressData.id) {
if (fn) fn()
return
}
this.$util.request("mall.getPostage", {
pay_price: this.totalPrice,
address_id: this.addressData.id
}).then(res => {
if (fn) fn()
if (res.code == 1) {
this.orderFreight = parseFloat(res.data.price)
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
if (fn) fn()
console.error('获取运费', error)
})
},
// 绑定手机号
bindPhoneNumber(e) {
if (e.detail.errMsg == "getPhoneNumber:ok") {
uni.showLoading({
mask: true,
title: "加载中",
})
uni.login({
provider: 'weixin',
success: loginRes => {
let data = e.detail
data.code = loginRes.code
this.$util.request("login.bindMobile", data).then(res => {
uni.hideLoading()
if (res.code == 1) {
this.$store.commit('user/updateMobile', res.data.phoneNumber)
this.submitOrder()
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
uni.hideLoading()
console.error('获取用户手机号码 ', error)
})
},
fail: () => {
uni.hideLoading()
uni.showToast({
icon: "none",
title: "授权手机号失败,请重试"
})
}
});
} else {
uni.showToast({
title: '获取手机号失败,请重新获取',
icon: 'none'
})
}
},
// 打开发货方式弹窗
openDeliveryMethod() {
const methodList = [
{ id: 1, name: "快递发货" },
{ id: 2, name: "到店自提" },
]
this.$refs.selectPicker.open(methodList, this.deliveryMethod)
},
// 改变发货方式
changeDeliveryMethod(value) {
this.deliveryMethod = value.id
if (value.id == 1) {
uni.showLoading({
title: "加载中",
mask: true
})
this.getPostage(() => {
uni.hideLoading()
})
}
},
// 选择地址
chooseAddress() {
this.$refs.addressModal.open(this.addressData.id)
},
// 改变选择的地址
changeAddress(item) {
this.addressData = item
this.getPostage()
},
// 跳转地图导航
toNavigation() {
this.$util.toPage({
mode: 7,
address: {
latitude: this.mallConfig.latitude,
longitude: this.mallConfig.longitude,
address: this.mallConfig.address,
},
})
},
// 联系
onContact() {
this.$util.toPage({
mode: 6,
phone: this.mallConfig.mobile,
})
},
// 改变商品数量
changeNumber(type, index) {
if (type == 1) {
if (parseInt(this.goodsData[index].number) > 1) {
const goodsNumber = parseInt(this.goodsData[index].number) - 1
this.changeQuantity(goodsNumber, index)
}
} else if (type == 2) {
const goodsNumber = parseInt(this.goodsData[index].number) + 1
this.changeQuantity(goodsNumber, index)
} else if (type == 3) {
this.$refs.quantityModal.open(this.goodsData[index].number, index)
}
},
// 选择商品数量
changeQuantity(number, index) {
uni.showLoading({
mask: true,
title: "加载中"
})
if (this.isCartItem) {
this.$util.request("mall.updateCartNumber", {
goods_id: this.goodsData[index].id,
number: number,
}).then(res => {
if (res.code == 1) {
this.$set(this.goodsData[index], "number", parseInt(number))
this.getPostage(() => {
uni.hideLoading()
})
} else {
uni.hideLoading()
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
uni.hideLoading()
console.error('更新购物车商品数量', error)
})
} else {
this.$set(this.goodsData[index], "number", parseInt(number))
this.getPostage(() => {
uni.hideLoading()
})
}
},
// 获取订单总额
getOrderAmount() {
var result = 0
if (this.deliveryMethod == 2) result = parseFloat(this.totalPrice)
else result = parseFloat(this.totalPrice) + parseFloat(this.orderFreight)
return parseFloat(result).toFixed(2)
},
// 提交订单
submitOrder() {
if (this.deliveryMethod == 1 && (!this.addressData || !this.addressData.id)) {
uni.showToast({
title: "请选择收货地址",
icon: "none"
})
return;
}
uni.showLoading({
title: "提交中",
mask: true
})
this.subscribeMessage(() => {
var data = {
goods_id: this.goodsData.map(item => item.id).join(),
buy_now: this.isCartItem ? 2 : 1,
delivery_method: this.deliveryMethod,
}
if (!this.isCartItem) data.number = this.goodsData[0].number
if (this.deliveryMethod == 1) data.address_id = this.addressData.id
this.$util.request("mall.createOrder", data).then(res => {
uni.hideLoading()
if (res.code == 1) {
this.$util.toPage({
mode: 2,
path: `/pagesMall/order/payment?money=${this.getOrderAmount()}&id=${res.data.order_id}`
})
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(error => {
console.error('创建订单', error)
})
})
},
// 订阅消息
subscribeMessage(fn, number = 0) {
// #ifdef MP-WEIXIN
var tmplIds = []
if (this.subscribeIds?.applet_order_shipping_notification) tmplIds.push(this.subscribeIds.applet_order_shipping_notification)
if (this.subscribeIds?.applet_confirm_receipt_notification) tmplIds.push(this.subscribeIds.applet_confirm_receipt_notification)
uni.requestSubscribeMessage({
tmplIds,
success: () => {
fn()
},
fail: (error) => {
if (error.errCode == 20004) {
uni.hideLoading()
uni.showModal({
title: '提示',
content: '请前往设置打开接受通知',
confirmColor: this.themeColor,
confirmText: '继续提交',
success: (res) => {
if (res.confirm) {
fn()
}
},
})
} else if (error.errCode) {
uni.hideLoading()
uni.showModal({
title: '提示',
content: '消息订阅失败,无法接收到订单通知,错误码:' + error.errCode,
confirmColor: this.themeColor,
confirmText: '继续提交',
success: (res) => {
if (res.confirm) {
fn()
}
},
})
} else if (++number > 3) {
this.subscribeMessage(fn, number)
} else {
fn()
}
}
})
// #endif
// #ifndef MP-WEIXIN
fn()
// #endif
},
}
}
</script>
<style lang="scss">
.container {
.container-main {
padding: 32rpx 32rpx 144rpx;
.main-method {
border-radius: 20rpx;
padding: 32rpx;
background: #FFF;
margin-bottom: 32rpx;
.method-title {
color: #5A5B6E;
font-size: 28rpx;
font-weight: 600;
line-height: 40rpx;
}
.method-value {
margin-left: 24rpx;
color: #5A5B6E;
font-size: 28rpx;
line-height: 40rpx;
text-align: right;
}
.method-icon {
margin-left: 16rpx;
width: 32rpx;
height: 32rpx;
}
}
.main-address {
border-radius: 20rpx;
padding: 32rpx;
background: #FFF;
.address-title {
color: #5A5B6E;
font-size: 28rpx;
font-weight: 600;
line-height: 40rpx;
margin-bottom: 24rpx;
}
.address-box {
.box-text {
color: #5A5B6E;
font-size: 32rpx;
line-height: 44rpx;
margin-right: 64rpx;
}
.box-icon {
width: 32rpx;
height: 32rpx;
background-size: 32rpx;
}
}
.address-info {
margin-top: 24rpx;
color: #979797;
font-size: 28rpx;
line-height: 40rpx;
gap: 16rpx;
}
}
.main-goods {
margin-top: 32rpx;
display: flex;
flex-direction: column;
row-gap: 32rpx;
}
.main-cost {
margin-top: 32rpx;
padding: 32rpx;
border-radius: 16rpx;
background: #FFFFFF;
.cost-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 32rpx;
&:first-child {
margin-top: 0;
}
.title {
color: #979797;
font-size: 28rpx;
line-height: 40rpx;
}
.value {
color: var(--theme-color);
font-size: 28rpx;
line-height: 40rpx;
margin-left: 24rpx;
}
}
}
.main-footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 96;
background: #FFF;
border-top: 1rpx solid #F6F7FB;
padding: 16rpx 24rpx;
.footer-money {
color: var(--theme-color);
font-size: 40rpx;
line-height: 56rpx;
word-break: break-all;
text {
font-size: 28rpx;
}
}
.footer-btn {
margin-left: 24rpx;
padding: 20rpx 44rpx;
background: var(--theme-color);
border-radius: 16rpx;
color: #FFF;
text-align: center;
font-size: 28rpx;
line-height: 40rpx;
min-width: 220rpx;
}
}
}
}
</style>