2024-12-27 15:03:48 +08:00
|
|
|
|
<script setup>
|
|
|
|
|
// 商品收藏
|
|
|
|
|
|
|
|
|
|
import {
|
2025-01-21 22:33:44 +08:00
|
|
|
|
ref,
|
|
|
|
|
reactive,
|
2025-01-23 00:57:47 +08:00
|
|
|
|
computed,
|
|
|
|
|
getCurrentInstance,
|
2024-12-27 15:03:48 +08:00
|
|
|
|
} from 'vue';
|
|
|
|
|
import apex from '@/components/header/apex'
|
2025-01-19 13:55:21 +08:00
|
|
|
|
import {
|
|
|
|
|
onReachBottom,
|
|
|
|
|
onPullDownRefresh,
|
|
|
|
|
onShow,
|
|
|
|
|
onLoad,
|
|
|
|
|
onReady,
|
|
|
|
|
} from '@dcloudio/uni-app';
|
|
|
|
|
//
|
|
|
|
|
import api from '@/api/index.js';
|
|
|
|
|
// util
|
|
|
|
|
import util from '@/common/js/util';
|
2025-01-23 00:57:47 +08:00
|
|
|
|
// 生成订单
|
|
|
|
|
import makeOrder from '@/components/shop/detail/makeOrder.vue'
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
proxy
|
|
|
|
|
} = getCurrentInstance()
|
2024-12-27 15:03:48 +08:00
|
|
|
|
//
|
|
|
|
|
const setting = ref(false)
|
2025-01-23 00:57:47 +08:00
|
|
|
|
// 当前操作的收藏下标
|
|
|
|
|
const listCurrent = reactive([0, 0])
|
2025-01-21 22:33:44 +08:00
|
|
|
|
// 收藏列表
|
|
|
|
|
const list = reactive({
|
|
|
|
|
data: [],
|
|
|
|
|
})
|
2025-01-23 00:57:47 +08:00
|
|
|
|
// 已选的商品列表
|
|
|
|
|
const selectList = computed(() => {
|
|
|
|
|
let result = []
|
|
|
|
|
list.data.map(item => {
|
|
|
|
|
result.push(...item.shopifyProductInfos.filter(secItem => secItem.selected))
|
|
|
|
|
})
|
|
|
|
|
return result
|
|
|
|
|
})
|
|
|
|
|
// 总价
|
|
|
|
|
const totalPrice = computed(() => {
|
|
|
|
|
return selectList.value.reduce((last, current) => {
|
|
|
|
|
return last + current.price * current.payNum
|
|
|
|
|
}, 0)
|
|
|
|
|
})
|
|
|
|
|
// 当前商品
|
|
|
|
|
const productCurrent = computed({
|
|
|
|
|
get() {
|
|
|
|
|
let result = {}
|
|
|
|
|
if (list.data[listCurrent[0]]) result = list.data[listCurrent[0]].shopifyProductInfos[listCurrent[
|
|
|
|
|
1]]
|
|
|
|
|
return result
|
|
|
|
|
},
|
|
|
|
|
set(val) {
|
|
|
|
|
list.data[listCurrent[0]].shopifyProductInfos[listCurrent[1]] = val
|
|
|
|
|
}
|
|
|
|
|
})
|
2025-01-19 13:55:21 +08:00
|
|
|
|
|
|
|
|
|
onLoad(() => {
|
|
|
|
|
// 获取列表
|
|
|
|
|
getList()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 获取列表
|
|
|
|
|
function getList() {
|
|
|
|
|
api.shop.getCollectList({}).then(res => {
|
2025-01-21 22:33:44 +08:00
|
|
|
|
if (res.code == 200) {
|
2025-01-23 00:57:47 +08:00
|
|
|
|
// 收藏列表的数据
|
|
|
|
|
list.data = res.data.map(item => {
|
|
|
|
|
// 收藏列表里面的商品
|
|
|
|
|
item.shopifyProductInfos = item.shopifyProductInfos.map(secItem => {
|
|
|
|
|
// 产品图片
|
|
|
|
|
secItem.formatSliderImage = secItem.sliderImage.split(',')[0]
|
|
|
|
|
// 产品购买数量
|
|
|
|
|
secItem.payNum = 1
|
|
|
|
|
// 产品规格的索引
|
|
|
|
|
secItem.spaceIndex = 0
|
|
|
|
|
// 产品购买规格
|
|
|
|
|
secItem.spec = secItem.specs[secItem.spaceIndex] || {}
|
|
|
|
|
// 是否选择
|
|
|
|
|
secItem.selected = false
|
|
|
|
|
return secItem
|
|
|
|
|
})
|
|
|
|
|
return item
|
|
|
|
|
})
|
2025-01-21 22:33:44 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
util.alert({
|
|
|
|
|
content: res.msg,
|
|
|
|
|
showCancel: false,
|
|
|
|
|
})
|
2025-01-19 13:55:21 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
2025-01-21 22:33:44 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 规格选择
|
2025-01-23 00:57:47 +08:00
|
|
|
|
* @param {Object} index
|
|
|
|
|
* @param {Object} secIndex
|
2025-01-21 22:33:44 +08:00
|
|
|
|
*/
|
2025-01-23 00:57:47 +08:00
|
|
|
|
function handleSpec(index, secIndex) {
|
|
|
|
|
Object.assign(listCurrent, [index, secIndex])
|
|
|
|
|
proxy.$refs.makeOrderRef.open({
|
|
|
|
|
spaceIndex: productCurrent.value.spaceIndex,
|
|
|
|
|
payNum: productCurrent.value.payNum,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 选择规格和数量
|
|
|
|
|
* @param {Object} event
|
|
|
|
|
*/
|
|
|
|
|
function handleMakeConfirm(event) {
|
|
|
|
|
productCurrent.value.payNum = event.payNum
|
|
|
|
|
productCurrent.value.spec = event.spec
|
|
|
|
|
productCurrent.value.spaceIndex = event.spaceIndex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 商品的选中
|
|
|
|
|
* @param {Object} index 商家下标
|
|
|
|
|
* @param {Object} secIndex 商品下标
|
|
|
|
|
*/
|
|
|
|
|
function handleSelect(index, secIndex) {
|
|
|
|
|
const item = list.data[index].shopifyProductInfos[secIndex]
|
|
|
|
|
item.selected = !item.selected
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 取消收藏
|
|
|
|
|
function handleCancelCollect() {
|
|
|
|
|
console.log('data', selectList.value, list.data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 提交
|
|
|
|
|
function handleSubmit() {
|
|
|
|
|
console.log('data', selectList.value, list.data)
|
|
|
|
|
// 验证必填项
|
|
|
|
|
if (selectList.value.length == 0) {
|
|
|
|
|
util.alert('请选择商品')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let data = selectList.value.map(item => {
|
|
|
|
|
return {
|
|
|
|
|
// 产品id
|
|
|
|
|
productId: item.id,
|
|
|
|
|
// 规格id
|
|
|
|
|
attrValueId: item.spec.id,
|
|
|
|
|
// 数量
|
|
|
|
|
payNum: item.payNum,
|
|
|
|
|
// 0-普通订单,1-视频号订单
|
|
|
|
|
orderType: 0,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
console.log('request data', data)
|
|
|
|
|
// 产生待付款订单
|
|
|
|
|
api.shop.addOrder({
|
|
|
|
|
data,
|
|
|
|
|
}).then(rs => {
|
|
|
|
|
if (rs.code === 200) {
|
|
|
|
|
// 如果返回了订单 继续支付订单
|
|
|
|
|
if (rs.data && rs.data[0]) uni.navigateTo({
|
|
|
|
|
url: util.setUrl('/pages/shop/commodity/payment', {
|
|
|
|
|
orderId: rs.data[0].orderId,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
util.alert({
|
|
|
|
|
content: rs.msg,
|
|
|
|
|
showCancel: false,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2025-01-21 22:33:44 +08:00
|
|
|
|
}
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<view class="app">
|
|
|
|
|
<apex title="商品收藏">
|
|
|
|
|
<template #right>
|
|
|
|
|
<view class="f26" @click="setting = !setting">
|
|
|
|
|
<text v-if="setting">完成</text>
|
|
|
|
|
<text v-else>管理</text>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
</apex>
|
|
|
|
|
|
|
|
|
|
<view class="list">
|
2025-01-23 00:57:47 +08:00
|
|
|
|
<view class="item oh mb20 plr30 bfff" v-for="(item,index) in list.data" :key="item.id">
|
2024-12-27 15:03:48 +08:00
|
|
|
|
<!-- 店铺 -->
|
|
|
|
|
<view class="store line df aic ptb20 thd f1 f28">
|
2025-01-23 00:57:47 +08:00
|
|
|
|
<image class="wh50 br10" :src="item.rectangleLogo" mode="aspectFill" />
|
2025-01-21 22:33:44 +08:00
|
|
|
|
<view class="name ml10 c333">{{item.name}}</view>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<!-- 商品信息 -->
|
2025-01-23 00:57:47 +08:00
|
|
|
|
<view class="product line df ptb20" v-for="(secItem,secIndex) in item.shopifyProductInfos"
|
|
|
|
|
:key="secItem.id">
|
|
|
|
|
<view class="fmid mr10" @click="handleSelect(index,secIndex)">
|
|
|
|
|
<template v-if="secItem.selected">
|
|
|
|
|
<uni-icons type="checkbox-filled" size="40rpx" color="#F8BA4D" />
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
2025-01-23 00:57:47 +08:00
|
|
|
|
<uni-icons type="circle" size="40rpx" color="#aaa" />
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</template>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view class="poster wh160">
|
2025-01-23 00:57:47 +08:00
|
|
|
|
<image class="wh160 br10" :src="secItem.formatSliderImage" mode="aspectFill" />
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
2025-01-21 22:33:44 +08:00
|
|
|
|
<view class="info oh df fdc jcsb f1 ml20">
|
|
|
|
|
<view class="name thd c333 f28">{{item.name}}</view>
|
|
|
|
|
|
2025-01-23 00:57:47 +08:00
|
|
|
|
<view class="spec line df aic thd mtb10 ptb10 plr10 df aic c666 f24 br10"
|
|
|
|
|
@click="handleSpec(index,secIndex)">
|
|
|
|
|
<view class="thd f1">已选规格: {{secItem.spec.sku}}</view>
|
|
|
|
|
<view class="">x{{secItem.payNum}}</view>
|
2025-01-21 22:33:44 +08:00
|
|
|
|
</view>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
|
|
|
|
|
<view class="other df aic">
|
|
|
|
|
<view class="price c333">
|
|
|
|
|
<text class="f20">¥</text>
|
2025-01-21 22:33:44 +08:00
|
|
|
|
<text class="f30">{{secItem.price}}</text>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
2025-01-21 22:33:44 +08:00
|
|
|
|
<view class="count ml20 fs0 c999 f24">销量:{{secItem.sales}}</view>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view class="fill" style="height: 180rpx;"></view>
|
|
|
|
|
|
|
|
|
|
<view class="footer rows plr30 bfff shadow">
|
2025-01-23 00:57:47 +08:00
|
|
|
|
<view class="c999 f26">已选择{{selectList.length}}款</view>
|
|
|
|
|
<view class="col df aic" v-if="!setting">
|
|
|
|
|
<view class="total mr20">
|
2024-12-27 15:03:48 +08:00
|
|
|
|
<text class="c333 f20">合计</text>
|
|
|
|
|
<text class="cFF9B27 f20">¥</text>
|
2025-01-23 00:57:47 +08:00
|
|
|
|
<text class="cFF9B27 f46">{{totalPrice}}</text>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
2025-01-23 00:57:47 +08:00
|
|
|
|
<view class="btn primary w200" @click="handleSubmit">去结算</view>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
2025-01-23 00:57:47 +08:00
|
|
|
|
|
|
|
|
|
<view class="btn primary w200" @click="handleCancelCollect" v-else>取消收藏</view>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2025-01-23 00:57:47 +08:00
|
|
|
|
|
|
|
|
|
<!-- 立即支付 -->
|
|
|
|
|
<makeOrder ref="makeOrderRef" mode="collect" :detail="productCurrent" @confirm="handleMakeConfirm" />
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
// 产品
|
|
|
|
|
.item {
|
|
|
|
|
.line+.line {
|
|
|
|
|
border-top: 2rpx solid #eee;
|
|
|
|
|
}
|
2025-01-21 22:33:44 +08:00
|
|
|
|
|
|
|
|
|
// 规格
|
|
|
|
|
.spec {
|
|
|
|
|
border: 2rpx solid #ddd;
|
|
|
|
|
}
|
2024-12-27 15:03:48 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|