cart.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <template>
  2. <view :style="themeColor()">
  3. <view class="bg-page min-h-[100vh] overflow-hidden flex flex-col" v-if="!loading">
  4. <view v-if="!info" class="pb-[100rpx]">
  5. <view class="empty-page">
  6. <image class="img" :src="img('static/resource/images/system/login.png')" mode="aspectFit" />
  7. <view class="desc">暂未登录</view>
  8. <button shape="circle" plain="true" class="btn" @click="toLogin">去登录</button>
  9. </view>
  10. <ns-goods-recommend></ns-goods-recommend>
  11. </view>
  12. <view v-else-if="!cartList.length" class="pb-[100rpx]">
  13. <view class="empty-page">
  14. <image class="img" :src="img('addon/mall/cart-empty.png')" mode="aspectFit" />
  15. <view class="desc">赶紧去逛逛, 购买心仪的商品吧</view>
  16. <button shape="circle" plain="true" class="btn" @click="redirect({ url: '/addon/mall/pages/goods/list' })">去逛逛</button>
  17. </view>
  18. <ns-goods-recommend></ns-goods-recommend>
  19. </view>
  20. <block v-else>
  21. <view class="flex-1 h-0">
  22. <scroll-view class="scroll-height box-border" :scroll-y="true">
  23. <view class="py-[var(--top-m)] sidebar-margin">
  24. <view class="box-border" v-if="cartList.length">
  25. <view class="bg-[#fff] flex px-[var(--pad-sidebar-m)] justify-between items-center h-[80rpx] box-border font-400 text-[24rpx] mb-[24rpx] leading-[30rpx] rounded-[var(--rounded-big)]">
  26. <view class="flex items-center text-[24rpx] text-[#333]">
  27. <text>共<text class="text-[28rpx] mx-[2rpx] text-[var(--price-text-color)]">{{checkedNum }}</text>件商品</text>
  28. </view>
  29. <text @click="isEdit = !isEdit" class="text-[var(--text-color-light6)] text-[24rpx]">{{ isEdit ? '完成' : '管理' }}</text>
  30. </view>
  31. <view v-for="(item, index) in cartList" :key="index" class="bg-[#fff] mb-[20rpx] rounded-[var(--rounded-big)] pb-[10rpx]">
  32. <view class="flex px-[var(--pad-sidebar-m)] py-[var(--pad-top-m)] border-0 border-[#f0f0f0] border-solid border-b-[2rpx] items-baseline">
  33. <text v-if="item.disabled" class="iconfont text-color text-[34rpx] mr-[20rpx] w-[34rpx] h-[34rpx] rounded-[17rpx]" :class="{ 'iconxuanze1 ':item.checked,'bg-[#F5F5F5]':!item.checked}"></text>
  34. <text v-else class="iconfont text-color text-[34rpx] mr-[20rpx] w-[34rpx] h-[34rpx] rounded-[17rpx]" :class="{ 'iconxuanze1 ':item.checked,'bg-[#F5F5F5]':!item.checked}" @click="isClickSite(item)"></text>
  35. <text class="iconfont iconVector-25 text-[32rpx]"></text>
  36. <text class="ml-[12rpx] text-[28rpx] flex-1 truncate">{{item.site_name }}</text>
  37. </view>
  38. <u-swipe-action ref="swipeActiveRef">
  39. <block v-for="(subItem, subIndex) in item.goods_list" :key="subIndex">
  40. <view v-if="subItem.goodsSku" class="py-[20rpx] overflow-hidden w-full">
  41. <u-swipe-action-item :options="cartOptions" @click="swipeClick(index,subIndex,subItem)">
  42. <view class="flex px-[var(--pad-sidebar-m)]">
  43. <text class="self-center w-[34rpx] h-[34rpx] rounded-[17rpx] mr-[32rpx] bg-[#F5F5F5] overflow-hidden flex-shrink-0" v-if="subItem.disabled"></text>
  44. <text v-else class="self-center iconfont text-color text-[34rpx] mr-[32rpx] w-[34rpx] h-[34rpx] rounded-[17rpx] overflow-hidden flex-shrink-0" :class="{ 'iconxuanze1':subItem.checked,'bg-[#F5F5F5]':!subItem.checked}" @click="changeItem(item,subItem)">
  45. </text>
  46. <view class="relative w-[200rpx] h-[200rpx] rounded-[var(--goods-rounded-big)] overflow-hidden">
  47. <u--image class="rounded-[var(--goods-rounded-big)] overflow-hidden" width="200rpx" height="200rpx" @click="toDetail(subItem)" :src="img(subItem.goodsSku.sku_image_thumb_mid||'')" mode="aspectFill">
  48. <template #error>
  49. <image class="w-[200rpx] h-[200rpx] rounded-[var(--goods-rounded-big)] overflow-hidden" :src="img('static/resource/images/diy/shop_default.jpg')" mode="aspectFill"></image>
  50. </template>
  51. </u--image>
  52. <view v-if="subItem.disabled" class="absolute top-0 right-0 left-0 bottom-0 flex justify-center items-center bg-black bg-opacity-50 text-white rounded-[var(--goods-rounded-big)]">已下架</view>
  53. </view>
  54. <view class="flex flex-1 flex-col justify-between ml-[20rpx]">
  55. <view class="w-[100%] flex flex-col items-baseline">
  56. <view class="text-[#333] text-[28rpx] max-h-[80rpx] leading-[40rpx] multi-hidden font-400">
  57. {{ subItem.goods.goods_name }}
  58. </view>
  59. <view class="box-border max-w-[376rpx] mt-[10rpx] px-[14rpx] h-[36rpx] leading-[36rpx] truncate text-[var(--text-color-light6)] bg-[#F5F5F5] text-[22rpx] rounded-[20rpx]" v-if="subItem.goodsSku && subItem.goodsSku.sku_spec_format">
  60. {{ subItem.goodsSku.sku_spec_format }}
  61. </view>
  62. </view>
  63. <view v-if="subItem.goods && subItem.goods.goods_label_name && subItem.goods.goods_label_name.length"
  64. class="flex flex-wrap mb-[auto]">
  65. <template v-for="(tagItem, tagIndex) in subItem.goods.goods_label_name">
  66. <image class="img-tag" v-if="tagItem.style_type == 'icon' && tagItem.icon" :src="img(tagItem.icon)" mode="heightFix" @error="diyGoods.error(tagItem,'icon')" />
  67. <view class="base-tag" v-else-if="tagItem.style_type == 'diy' || !tagItem.icon" :style="diyGoods.baseTagStyle(tagItem)">{{ tagItem.label_name }}</view>
  68. </template>
  69. </view>
  70. <view class="flex justify-between items-end self-end mt-[10rpx] w-[100%]">
  71. <view class="text-[var(--price-text-color)] price-font truncate max-w-[200rpx]">
  72. <text class="text-[24rpx] font-500">¥</text>
  73. <text class="text-[40rpx] font-500">{{ parseFloat(goodsPrice(subItem)).toFixed(2).split('.')[0] }}</text>
  74. <text class="text-[24rpx] font-500">.{{ parseFloat(goodsPrice(subItem)).toFixed(2).split('.')[1] }}</text>
  75. <image class="h-[24rpx] ml-[6rpx]" v-if="priceType(subItem) == 'member_price'" :src="img('addon/mall/VIP.png')" mode="heightFix" />
  76. <image class="h-[24rpx] ml-[6rpx]" v-if="priceType(subItem) == 'discount_price'" :src="img('addon/mall/discount.png')" mode="heightFix" />
  77. </view>
  78. <u-number-box v-model="subItem.num" :min="numLimit(subItem).min" :max="numLimit(subItem).max" integer :step="1" input-width="68rpx" input-height="52rpx" button-size="52rpx" disabledInput @change="numChange($event, subItem)">
  79. <template #minus>
  80. <view class="relative w-[26rpx] h-[26rpx]" @click="reduceNumChange(subItem)">
  81. <text :class="{ 'text-[var(--text-color-light9)]': subItem.num === numLimit(subItem).min, 'text-[#303133]': subItem.num !== numLimit(subItem).min }" class="text-[24rpx] absolute flex items-center justify-center -left-[20rpx] -bottom-[20rpx] -right-[20rpx] -top-[20rpx] font-500 nc-iconfont nc-icon-jianV6xx"></text>
  82. </view>
  83. </template>
  84. <template #input>
  85. <input
  86. class="text-[#303133] text-[28rpx] mx-[14rpx] w-[80rpx] h-[44rpx] bg-[var(--temp-bg)] leading-[44rpx] text-center rounded-[6rpx]"
  87. type="number" @input="goodsSkuInputFn(subItem)"
  88. @blur="goodsSkuBlurFn($event, subItem)"
  89. @click.stop v-model="subItem.num" />
  90. </template>
  91. <template #plus>
  92. <view class="relative w-[26rpx] h-[26rpx]" @click="addNumChange(subItem)">
  93. <text :class="{ 'text-[var(--text-color-light9)]': subItem.num === numLimit(subItem).max, ' text-[#303133]': subItem.num !== numLimit(subItem).max }" class="ttext-[24rpx] absolute flex items-center justify-center -left-[20rpx] -bottom-[20rpx] -right-[20rpx] -top-[20rpx] font-500 nc-iconfont nc-icon-jiahaoV6xx"></text>
  94. </view>
  95. </template>
  96. </u-number-box>
  97. </view>
  98. </view>
  99. </view>
  100. </u-swipe-action-item>
  101. </view>
  102. </block>
  103. </u-swipe-action>
  104. </view>
  105. </view>
  106. </view>
  107. <ns-goods-recommend></ns-goods-recommend>
  108. </scroll-view>
  109. </view>
  110. </block>
  111. </view>
  112. <!-- #ifdef H5 -->
  113. <view v-if="cartList.length" class="flex h-[96rpx] items-center bg-[#fff] fixed left-0 right-0 bottom-[50px] pl-[30rpx] pr-[20rpx] box-solid mb-ios justify-between border-0 border-t-[2rpx] border-solid border-[#f6f6f6]">
  114. <view class="flex items-center" @click="allChange">
  115. <text class="self-center iconfont text-color text-[34rpx] mr-[10rpx] w-[34rpx] h-[34rpx] rounded-[17rpx] overflow-hidden flex-shrink-0" :class=" isSelectAll ? 'iconxuanze1' : 'bg-[#F5F5F5]'"></text>
  116. <text class="font-400 text-[#303133] text-[26rpx]">全选</text>
  117. </view>
  118. <view class="flex items-center">
  119. <view class="flex-1 flex items-center justify-between" v-if="!isEdit">
  120. <view class="flex items-center mr-[20rpx] text-[var(--price-text-color)] leading-[44rpx]">
  121. <view class="font-400 text-[#303133] text-[28rpx]">合计:</view>
  122. <text class="text-[var(--price-text-color)] price-font text-[32rpx] font-bold">
  123. ¥{{ parseFloat(total) }}
  124. </text>
  125. </view>
  126. <button class="w-[180rpx] h-[70rpx] font-500 text-[26rpx] leading-[70rpx] !text-[#fff] m-0 rounded-full primary-btn-bg remove-border" @click="settlement">结算</button>
  127. </view>
  128. <view class="flex-1 flex items-center justify-end" v-else>
  129. <button class="w-[180rpx] h-[70rpx] font-500 text-[26rpx] leading-[70rpx] !text-[#fff] m-0 rounded-full primary-btn-bg remove-border" @click="deleteCartFn">删除</button>
  130. </view>
  131. </view>
  132. </view>
  133. <!-- #endif -->
  134. <!-- #ifndef H5 -->
  135. <view v-if="cartList.length" class="pl-[30rpx] pr-[20rpx] flex h-[96rpx] items-center bg-[#fff] fixed left-0 right-0 bottom-[100rpx] box-solid mb-ios justify-between border-0 border-t-[2rpx] border-solid border-[#f6f6f6]">
  136. <view class="flex items-center" @click="allChange">
  137. <text class="self-center iconfont text-color text-[30rpx] mr-[20rpx] w-[34rpx] h-[34rpx] rounded-[17rpx] overflow-hidden flex-shrink-0" :class=" isSelectAll ? 'iconxuanze1' : 'bg-[#F5F5F5]'"></text>
  138. <text class="font-400 text-[#303133] text-[26rpx]">全选</text>
  139. </view>
  140. <view class="flex items-center">
  141. <view class="flex-1 flex items-center justify-between" v-if="!isEdit">
  142. <view class="flex items-center mr-[67rpx] text-[var(--price-text-color)] leading-[44rpx]">
  143. <view class="font-400 text-[#303133] text-[28rpx]">合计:</view>
  144. <text class="text-[var(--price-text-color)] price-font text-[32rpx] font-bold">
  145. ¥{{ parseFloat(total) }}
  146. </text>
  147. </view>
  148. <!-- #ifdef H5 -->
  149. <button class="w-[188rpx] h-[70rpx] font-500 text-[26rpx] leading-[72rpx] !text-[#fff] m-0 rounded-full primary-btn-bg remove-border" @click="settlement">结算</button>
  150. <!-- #endif -->
  151. <!-- #ifdef MP-WEIXIN -->
  152. <!-- <button v-if="isBindMobile && info && !info.mobile" class="w-[180rpx] h-[70rpx] font-500 text-[26rpx] leading-[70rpx] !text-[#fff] m-0 rounded-full primary-btn-bg remove-border" open-type="getPhoneNumber" @getphonenumber="memberStore.bindMobile">结算</button>
  153. <button v-else class="w-[180rpx] h-[70rpx] font-500 text-[26rpx] leading-[70rpx] !text-[#fff] m-0 rounded-full primary-btn-bg remove-border" @click="settlement">结算</button> -->
  154. <button class="w-[180rpx] h-[70rpx] font-500 text-[26rpx] leading-[70rpx] !text-[#fff] m-0 rounded-full primary-btn-bg remove-border"
  155. @click="settlement">结算</button>
  156. <!-- #endif -->
  157. </view>
  158. <view class="flex-1 flex items-center justify-end" v-else>
  159. <button class="w-[188rpx] h-[70rpx] font-500 text-[26rpx] leading-[72rpx] !text-[#fff] m-0 rounded-full primary-btn-bg remove-border" @click="deleteCartFn">删除</button>
  160. </view>
  161. </view>
  162. </view>
  163. <!-- #endif -->
  164. <loading-page :loading="loading"></loading-page>
  165. <tabbar />
  166. <!-- 强制绑定手机号 -->
  167. <bind-mobile ref="bindMobileRef" />
  168. </view>
  169. </template>
  170. <script setup lang="ts">
  171. import { ref, computed, watch, nextTick } from 'vue'
  172. import useMemberStore from '@/stores/member'
  173. import { useLogin } from '@/hooks/useLogin'
  174. import { onShow } from '@dcloudio/uni-app'
  175. import { img, redirect, getToken } from '@/utils/common'
  176. import useCartStore from '@/addon/mall/stores/cart'
  177. import { getCartGoodsList } from '@/addon/mall/api/cart'
  178. import bindMobile from '@/components/bind-mobile/bind-mobile.vue';
  179. import {t} from "@/locale";
  180. import { useGoods } from '@/addon/mall/hooks/useGoods'
  181. import nsGoodsRecommend from '@/addon/mall/components/ns-goods-recommend/ns-goods-recommend.vue';
  182. const diyGoods = useGoods();
  183. const memberStore = useMemberStore()
  184. const info = computed(() => memberStore.info)
  185. const loading = ref(true)
  186. const optionLoading = ref(false)
  187. const total = ref('0.00')
  188. const cartList = ref<object[]>([])
  189. const isEdit = ref(false)
  190. const cartStore = useCartStore();
  191. const getCartGoodsListFn = () => {
  192. getCartGoodsList({}).then(({data}) => {
  193. cartList.value = []
  194. loading.value = false
  195. cartList.value = Object.values(data).map((item: any)=> {
  196. item.checked = false
  197. item.goods_list.map((subItem: any) =>{
  198. if (subItem.goods.status == 1 && subItem.goods.delete_time == 0) {
  199. if (subItem.goodsSku.stock) {
  200. if (subItem.num > subItem.goodsSku.stock) subItem.num = subItem.goodsSku.stock;
  201. subItem.checked = false
  202. }else{
  203. subItem.disabled = true
  204. }
  205. } else {
  206. subItem.disabled = true
  207. }
  208. return subItem
  209. })
  210. item.disabled = item.goods_list.every((subItem: any) => subItem.disabled)
  211. return item
  212. })
  213. isSelectAll.value = false
  214. allChange()
  215. }).catch((err)=>{
  216. if(err.code==401){
  217. cartList.value = []
  218. loading.value = false
  219. }
  220. })
  221. }
  222. onShow(() => {
  223. getCartGoodsListFn()
  224. cartStore.getList();
  225. })
  226. const goodsSkuInputFn = (data: any) => {
  227. setTimeout(() => {
  228. if (!data.num || data.num <= numLimit(data).min) {
  229. data.num = numLimit(data).min;
  230. }
  231. if (data.num >= numLimit(data).max) {
  232. data.num = numLimit(data).max;
  233. }
  234. uni.$u.debounce((event: any) => {
  235. cartStore.increase({
  236. id: data.id,
  237. goods_id: data.goods_id,
  238. sku_id: data.sku_id,
  239. stock: data.goodsSku.stock,
  240. sale_price: data.goodsSku.sale_price,
  241. site_id: data.site_id,
  242. num: Number(data.num)
  243. }, 0);
  244. }, 500)
  245. }, 0)
  246. }
  247. const goodsSkuBlurFn = (event: any, subItem: any) => {
  248. setTimeout(() => {
  249. const data: any = subItem
  250. if (!data.num || data.num <= numLimit(data).min) {
  251. data.num = numLimit(data).min;
  252. }
  253. if (data.num >= numLimit(data).max) {
  254. data.num = numLimit(data).max;
  255. }
  256. uni.$u.debounce((event: any) => {
  257. cartStore.increase({
  258. id: data.id,
  259. goods_id: data.goods_id,
  260. sku_id: data.sku_id,
  261. stock: data.goodsSku.stock,
  262. sale_price: data.goodsSku.sale_price,
  263. site_id: data.site_id,
  264. num: Number(data.num)
  265. }, 0);
  266. }, 500)
  267. }, 0)
  268. }
  269. // 总共数量
  270. // 选择数量
  271. const checkedNum = computed(() => {
  272. let num = 0
  273. cartList.value.forEach((item: any) => {
  274. item.goods_list.forEach((subItem: any)=>{
  275. if(subItem.checked){
  276. num += Number(subItem.num)
  277. }
  278. })
  279. })
  280. return num
  281. })
  282. // 计算总价
  283. watch(() => cartList.value, () => {
  284. let value = 0
  285. cartList.value.forEach((item,index) => {
  286. item.goods_list.forEach(subItem => {
  287. if (subItem.checked && subItem.goodsSku){
  288. let price: any = 0;
  289. if (subItem.goods.is_discount && subItem.goodsSku.sale_price != subItem.goodsSku.price ) {
  290. price = subItem.goodsSku.sale_price // 折扣价
  291. } else if (subItem.goods.member_discount && getToken() && subItem.goodsSku.member_price != subItem.goodsSku.price) {
  292. price = subItem.goodsSku.member_price // 会员价
  293. } else {
  294. price = subItem.goodsSku.price
  295. }
  296. value += parseFloat(price) * subItem.num
  297. }
  298. })
  299. })
  300. total.value = value.toFixed(2)
  301. }, { deep: true })
  302. const toLogin = () => {
  303. useLogin().setLoginBack({ url: '/addon/mall/pages/goods/cart' })
  304. }
  305. const toDetail = (data: any) => {
  306. redirect({ url: '/addon/mall/pages/goods/detail', param: { goods_id: data.goods_id } })
  307. }
  308. const numChange = (event: any, subItem: any) => {
  309. uni.$u.debounce((event: any) => {
  310. const data = subItem
  311. cartStore.increase({
  312. id: data.id,
  313. goods_id: data.goods_id,
  314. sku_id: data.sku_id,
  315. stock: data.goodsSku.stock,
  316. sale_price: data.goodsSku.sale_price,
  317. num: data.num,
  318. site_id: data.site_id
  319. }, 0);
  320. }, 500)
  321. }
  322. const addNumChange = (data: any) => {
  323. if (data.num >= data.goods.stock) {
  324. uni.showToast({ title: "商品库存不足", icon: 'none' });
  325. return;
  326. }
  327. if (data.goods.is_limit) {
  328. let tips = `该商品单次限购${ data.goods.max_buy }件`;
  329. if (data.goods.limit_type != 1) { //单次限购
  330. tips = `该商品每人限购${ data.goods.max_buy }件`;
  331. }
  332. if (data.num >= data.goods.max_buy) {
  333. uni.showToast({ title: tips, icon: 'none' })
  334. }
  335. }
  336. }
  337. const reduceNumChange = (data: any) => {
  338. if (data.goods.is_limit && data.goods.min_buy) {
  339. let tips = `该商品起购${ data.goods.min_buy }件`;
  340. if (data.num <= data.goods.min_buy) {
  341. uni.showToast({ title: tips, icon: 'none' })
  342. }
  343. }
  344. }
  345. const numLimit = (data: any) => {
  346. let obj = {
  347. min: 1,
  348. max: data.goodsSku.stock || 1
  349. };
  350. // 限购 - 是否开启限购
  351. if (data.goods.is_limit) {
  352. if (data.goods.max_buy) {
  353. let max_buy = 0;
  354. max_buy = data.goods.max_buy;
  355. if (max_buy > data.goods.stock) {
  356. obj.max = data.goods.stock
  357. } else if (max_buy <= data.goods.stock) {
  358. obj.max = max_buy;
  359. }
  360. }
  361. }
  362. // 起售
  363. if (data.goods.min_buy > 0) {
  364. obj.min = data.goods.min_buy;
  365. }
  366. return obj;
  367. }
  368. const cartOptions = ref([
  369. {
  370. text: t('delete'),
  371. style: {
  372. backgroundColor: 'var(--primary-color)',
  373. width: '100rpx',
  374. height: '100%',
  375. borderRadius: '10rpx'
  376. }
  377. }
  378. ])
  379. const swipeActiveRef = ref(null)
  380. const swipeClick = (index: any, subIndex: any, subItem: any) => {
  381. if (optionLoading.value) return
  382. optionLoading.value = true
  383. cartStore.delete(subItem.id, () => {
  384. cartList.value[index].goods_list.splice(subIndex, 1)
  385. if(cartList.value[index].goods_list.length == 0){
  386. cartList.value.splice(index, 1)
  387. }
  388. nextTick(()=>{
  389. if(swipeActiveRef.value){
  390. swipeActiveRef.value[index].closeOther()
  391. }
  392. })
  393. optionLoading.value = false
  394. })
  395. }
  396. //判断是否全选
  397. const isSelectAll = ref(false)
  398. const isallclick = ()=>{
  399. const isActve = cartList.value.every((item: any) => {
  400. return item.checked
  401. })
  402. if (isActve) { isSelectAll.value = true } else { isSelectAll.value= false }
  403. }
  404. // 选择单个商品
  405. const changeItem = (data: any, value: any) =>{
  406. value.checked = !value.checked
  407. let arr: any =[];
  408. data.goods_list.forEach((item: any) => {
  409. if(item.checked != undefined){
  410. arr.push(item)
  411. }
  412. })
  413. const isActve = arr.every((item: any) => {
  414. return item.checked
  415. })
  416. if (isActve) { data.checked = true } else { data.checked = false }
  417. isallclick()
  418. }
  419. // 选择店铺
  420. const isClickSite = (data: any) =>{
  421. data.checked = !data.checked
  422. if (data.checked) {
  423. data.goods_list.forEach((item: any) => {
  424. if(!item.disabled){
  425. item.checked = true
  426. }
  427. })
  428. } else {
  429. data.goods_list.forEach((item: any) => {
  430. if(!item.disabled){
  431. item.checked = false
  432. }
  433. });
  434. }
  435. isallclick()
  436. }
  437. // 全选
  438. const allChange = () =>{
  439. isSelectAll.value = !isSelectAll.value
  440. if (isSelectAll.value) {
  441. cartList.value.forEach((item: any) => {
  442. item.checked = item.goods_list.some((item: any) => {
  443. return !item.disabled
  444. })
  445. item.goods_list.forEach((subItem: any) => {
  446. if(!subItem.disabled){
  447. subItem.checked = true
  448. }
  449. })
  450. })
  451. } else {
  452. cartList.value.forEach((item: any) => {
  453. item.checked = false
  454. item.goods_list.forEach((subItem: any) => {
  455. if(!subItem.disabled){
  456. subItem.checked = false
  457. }
  458. })
  459. })
  460. }
  461. }
  462. //强制绑定手机号
  463. const bindMobileRef: any = ref(null)
  464. const isBindMobile = ref(uni.getStorageSync('isbindmobile'))
  465. /**
  466. * 结算
  467. */
  468. const settlement = () => {
  469. // #ifdef H5
  470. // if(uni.getStorageSync('isbindmobile')){
  471. // bindMobileRef.value.open()
  472. // return false
  473. // }
  474. // #endif
  475. if (!checkedNum.value) {
  476. uni.showToast({ title: '还没有选择商品', icon: 'none' })
  477. return
  478. }
  479. let body: any = {}
  480. cartList.value.forEach((item: any) => {
  481. body[item.site_id] = {}
  482. })
  483. for(let key in body){
  484. cartList.value.forEach((item: any) => {
  485. if (item.site_id == key) {
  486. body[key].cart_ids = []
  487. item.goods_list.forEach((subItem: any) => {
  488. if (subItem.checked) {
  489. body[key].cart_ids.push(subItem.id)
  490. }
  491. })
  492. }
  493. })
  494. if (!body[key].cart_ids.length){
  495. delete body[key]
  496. }
  497. }
  498. uni.setStorage({
  499. key: 'orderCreateData',
  500. data: {
  501. body: body
  502. },
  503. success() {
  504. redirect({ url: '/addon/mall/pages/order/payment' })
  505. }
  506. })
  507. }
  508. /**
  509. * 删除
  510. */
  511. const deleteCartFn = () => {
  512. if (!checkedNum.value) {
  513. uni.showToast({ title: '还没有选择商品', icon: 'none' })
  514. return
  515. }
  516. if (optionLoading.value) return
  517. optionLoading.value = true
  518. const ids:any = []
  519. if(isSelectAll.value){
  520. cartList.value.forEach((item: any) => {
  521. item.goods_list.forEach((subItem: any) => {
  522. ids.push(subItem.id)
  523. })
  524. })
  525. }else{
  526. cartList.value.forEach((item: any) => {
  527. item.goods_list.forEach((subItem: any) => {
  528. if (subItem.checked) {
  529. ids.push(subItem.id)
  530. }
  531. })
  532. })
  533. }
  534. cartStore.delete(ids, () => {
  535. getCartGoodsListFn()
  536. optionLoading.value = false
  537. })
  538. }
  539. // 价格类型
  540. let priceType = (data:any) =>{
  541. let type = "";
  542. if(data.goods.is_discount && data.goodsSku.sale_price != data.goodsSku.price){
  543. type = 'discount_price'// 折扣
  544. }else if(data.goods.member_discount && getToken() && data.goodsSku.member_price != data.goodsSku.price){
  545. type = 'member_price' // 会员价
  546. }else{
  547. type = ""
  548. }
  549. return type;
  550. }
  551. // 商品价格
  552. let goodsPrice = (data:any) =>{
  553. let price = "0.00";
  554. if(data.goods.is_discount && data.goodsSku.sale_price != data.goodsSku.price){
  555. price = data.goodsSku.sale_price ? data.goodsSku.sale_price : data.goodsSku.price // 折扣价
  556. }else if(data.goods.member_discount && getToken() && data.goodsSku.member_price != data.goodsSku.price){
  557. price = data.goodsSku.member_price ? data.goodsSku.member_price : data.goodsSku.price // 会员价
  558. }else{
  559. price = data.goodsSku.price
  560. }
  561. return price;
  562. }
  563. </script>
  564. <style lang="scss" scoped>
  565. @import '@/addon/mall/styles/common.scss';
  566. .remove-border {
  567. &::after {
  568. border: none;
  569. }
  570. }
  571. :deep(uni-page) {
  572. background: var(--page-bg-color);
  573. }
  574. uni-page-body {
  575. height: 100%;
  576. }
  577. .text-color {
  578. color: var(--primary-color);
  579. }
  580. .bg-color {
  581. background-color: var(--primary-color);
  582. }
  583. :deep(.tab-bar-placeholder) {
  584. display: none !important;
  585. }
  586. :deep(.u-tabbar__placeholder) {
  587. display: none !important;
  588. }
  589. /* #ifdef H5 */
  590. .scroll-height {
  591. height: calc(100vh - 100rpx - 50px - constant(safe-area-inset-bottom));
  592. height: calc(100vh - 100rpx - 50px - env(safe-area-inset-bottom));
  593. }
  594. /* #endif */
  595. /* #ifndef H5 */
  596. .scroll-height {
  597. height: calc(100vh - 200rpx - constant(safe-area-inset-bottom));
  598. height: calc(100vh - 200rpx - env(safe-area-inset-bottom));
  599. }
  600. /* #endif */
  601. .text-ellipsis{
  602. display: -webkit-box;
  603. -webkit-box-orient: vertical;
  604. -webkit-line-clamp: 2;
  605. overflow: hidden;
  606. }
  607. :deep(.u-swipe-action-item__right) {
  608. padding: 2rpx;
  609. }
  610. :deep(.u-swipe-action-item__right__button__wrapper){
  611. padding:0 10rpx !important;
  612. }
  613. :deep(.u-swipe-action-item__right__button__wrapper__text){
  614. font-size:24rpx !important;
  615. }
  616. :deep(.u-tabbar .u-tabbar__content) {
  617. z-index: 99999 !important;
  618. }
  619. </style>