index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <route lang="json5">
  2. {
  3. style: {
  4. navigationBarTitleText: '品质商城',
  5. navigationBarBackgroundColor: '#fff',
  6. },
  7. }
  8. </route>
  9. <script setup lang="ts">
  10. import { useRouter } from '../../../../core/utils/router'
  11. import { createProductItemBuy, getProduct, productPlacing } from '../../../../core/libs/requests'
  12. import { requestToast } from '../../../../core/utils/common'
  13. import { useUserStore } from '../../../../store'
  14. import { storeToRefs } from 'pinia'
  15. import BottomAppBar from '@/components/bottom-app-bar.vue'
  16. import ButtonEvo from '@/components/button-evo.vue'
  17. import { usePermissions } from '../../../../composables/permissions'
  18. import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html.vue'
  19. import { useToast } from 'wot-design-uni'
  20. const toast = useToast()
  21. const { clickByPermission } = usePermissions()
  22. const userStore = useUserStore()
  23. const router = useRouter()
  24. const { userInfo } = storeToRefs(userStore)
  25. const id = ref()
  26. const show = ref(false)
  27. const nums = ref(1)
  28. const type = ref<'add2Cart' | 'orderNow'>()
  29. const { data, run: setData } = useRequest(() => getProduct(id.value))
  30. const handleConfirm = async () => {
  31. // 积分
  32. const points = data.value?.showFavourable ? data.value?.favourablePoints : data.value?.points
  33. if (type.value === 'orderNow') {
  34. const body = {
  35. isShoppingCart: 0,
  36. userId: userInfo.value.userId,
  37. item: 3,
  38. list: [
  39. {
  40. productId: id.value,
  41. points,
  42. nums: nums.value,
  43. productName: data.value.prodcutName,
  44. orderImgUrl: data.value.productCoverImgUrl,
  45. vendorId: data.value.vendorId,
  46. },
  47. ],
  48. couponList: [],
  49. }
  50. const { data: res, code } = await requestToast(() => productPlacing(body))
  51. if (code !== 0) return
  52. await router.push(`/pages-sub/home/mall/confirm-order/index?data=${JSON.stringify(body)}`)
  53. }
  54. if (type.value === 'add2Cart') {
  55. await requestToast(
  56. () =>
  57. createProductItemBuy({
  58. doList: [
  59. {
  60. userId: userInfo.value.userId,
  61. productId: data.value?.productId || '',
  62. points,
  63. nums: nums.value,
  64. },
  65. ],
  66. }),
  67. { success: true, successTitle: '加入购物车成功' },
  68. )
  69. show.value = false
  70. }
  71. }
  72. const handleClick = (product) => {
  73. if (product?.isRestrict === 1 && product?.productRepertory === 0) {
  74. toast.show('库存不足')
  75. return null
  76. }
  77. console.log(product)
  78. const levelIds = product?.memberLevelIds.split(',')
  79. if (levelIds.length>0 && !levelIds.includes(String(userInfo.value.level.level))) {
  80. toast.show('您当前会员等级不符合兑换条件')
  81. return null
  82. }
  83. // 否则,执行原来的点击逻辑
  84. clickByPermission('mallExchange', () => {
  85. show.value = true
  86. type.value = 'orderNow'
  87. })
  88. }
  89. onLoad(async (query: { id: string }) => {
  90. id.value = query.id
  91. await setData()
  92. })
  93. onShareAppMessage(() => ({
  94. title: data.value?.prodcutName,
  95. imageUrl:data.value?.productCoverImgUrl,
  96. }))
  97. onShareTimeline(() => ({
  98. title: data.value?.prodcutName,
  99. imageUrl:data.value?.productCoverImgUrl,
  100. }))
  101. </script>
  102. <template>
  103. <view class="flex-grow flex flex-col">
  104. <div class="aspect-[1.34/1] relative">
  105. <div class="absolute aspect-[1.26/1] top-0 w-full">
  106. <swiper>
  107. <wd-swiper
  108. custom-class="rounded-1xl overflow-hidden aspect-[1.29/1]"
  109. width="100%"
  110. height="100%"
  111. :list="data?.productDetailsImgUrl?.split(',')"
  112. autoplay
  113. v-model:current="current"
  114. :indicator="{ type: 'dots-bar' } as any"
  115. @click="handleClick"
  116. ></wd-swiper>
  117. </swiper>
  118. </div>
  119. </div>
  120. <div class="relative flex-1 bg-white p-4 flex flex-col gap-4 rounded-tl-2xl rounded-tr-2xl">
  121. <div class="flex items-end gap-1">
  122. <div class="text-[#ef4343] text-[26px] font-normal font-['D-DIN_Exp'] leading-[20px]">
  123. <!-- 1000 -->
  124. {{ data?.showFavourable ? data?.favourablePoints : data?.points }}
  125. </div>
  126. <template v-if="String(data?.needPoints) === '0'">
  127. <div class="text-black/60 text-base font-normal font-['PingFang_SC'] leading-4">积分</div>
  128. </template>
  129. <template v-if="String(data?.needPoints) === '1'">
  130. <div class="text-black/60 text-base font-normal font-['PingFang_SC'] leading-4">
  131. 折(积分结算)
  132. </div>
  133. </template>
  134. <div
  135. v-if="Number(data?.productPrice)"
  136. class="w-[66px] text-black/30 text-xs font-normal font-['PingFang_SC'] leading-3"
  137. >
  138. <!-- ¥60 -->
  139. <span style="text-decoration: line-through">¥{{ data?.productPrice }}</span>
  140. </div>
  141. <div class="flex-1"></div>
  142. <template v-if="String(data?.needPoints) !== '1'">
  143. <div class="text-[#999999] text-xs font-normal font-['PingFang_SC']">
  144. {{ data?.isRestrict === 0 ? '不限库存' : `库存:${data?.productRepertory || 0}` }}
  145. </div>
  146. </template>
  147. </div>
  148. <div class="text-black text-xl font-normal font-['PingFang_SC']">
  149. <!-- 阿芙佳朵 -->
  150. {{ data?.prodcutName }}
  151. </div>
  152. <div class="h-0.25 bg-[#f6f6f6]"></div>
  153. <div class="text-black/90 text-base font-normal font-['PingFang_SC'] leading-normal">
  154. 积分兑换说明:
  155. </div>
  156. <div
  157. class="text-black/40 text-xs font-normal font-['PingFang_SC'] leading-[23px] whitespace-pre-wrap"
  158. >
  159. {{ data?.exchangeDesc }}
  160. <!-- · 不限制兑换个数-->
  161. <!-- <br />-->
  162. <!-- · 兑换后不支持退换货,如有问题可联系官方客户-->
  163. <!-- <br />-->
  164. <!-- · 规格:件-->
  165. <!-- <br />-->
  166. <!-- · 配送方式:到店自取-->
  167. </div>
  168. <div class="mx--4 h-2.5 bg-neutral-100"></div>
  169. <wd-divider>
  170. <div
  171. class="text-center text-black/40 text-xs font-normal font-['PingFang_SC'] leading-normal"
  172. >
  173. 商品详情
  174. </div>
  175. </wd-divider>
  176. <mpHtml :content="data?.contentDesc"></mpHtml>
  177. </div>
  178. <template v-if="String(data?.needPoints) === '0'">
  179. <BottomAppBar fixed placeholder>
  180. <div class="h-[63px] bg-white backdrop-blur-[20px] flex items-center justify-between gap-2">
  181. <div class="flex-1">
  182. <ButtonEvo
  183. block
  184. color="white"
  185. location="right"
  186. @click="clickByPermission('mallExchange', () => {(show = true), (type = 'add2Cart')})"
  187. >
  188. <span class="text-black/80">加入购物车</span>
  189. </ButtonEvo>
  190. </div>
  191. <div class="flex-1">
  192. <wd-button block :round="false" @click="clickByPermission('mallExchange', () => {handleClick(data)})">
  193. 立即兑换
  194. </wd-button>
  195. </div>
  196. </div>
  197. </BottomAppBar>
  198. </template>
  199. <wd-action-sheet v-model="show">
  200. <view class="px-7 py-11">
  201. <div class="flex gap-3 mb-13.5">
  202. <div class="w-[110px] h-[110px] bg-[#f6f6f6] rounded-2xl">
  203. <wd-img width="100%" height="100%" :src="data?.productCoverImgUrl"></wd-img>
  204. </div>
  205. <div class="flex flex-col justify-between flex-1">
  206. <div class="text-black/40 text-base font-normal font-['PingFang_SC'] leading-normal">
  207. {{ data?.prodcutName }}
  208. </div>
  209. <div class="flex items-end gap-1">
  210. <div class="text-[#ef4343] text-[22px] font-normal font-['D-DIN_Exp'] leading-4">
  211. <!-- {{ data?.points }}-->
  212. {{ data?.showFavourable ? data?.favourablePoints : data?.points }}
  213. </div>
  214. <div class="text-black/40 text-sm font-normal font-['PingFang_SC'] leading-3">
  215. 积分
  216. </div>
  217. <div class="flex-1"></div>
  218. <wd-input-number
  219. v-model="nums"
  220. :max="
  221. data?.isRestrict === 1 && data?.purchaseLimit
  222. ? Math.min(data?.purchaseQuantity, data?.productRepertory)
  223. : data?.isRestrict === 1 && !data?.purchaseLimit
  224. ? data?.productRepertory
  225. : data?.isRestrict === 2 && data?.purchaseLimit
  226. ? data?.purchaseQuantity
  227. : 100
  228. "
  229. />
  230. </div>
  231. </div>
  232. </div>
  233. <wd-button block :round="false" @click="handleConfirm">确认</wd-button>
  234. </view>
  235. </wd-action-sheet>
  236. </view>
  237. </template>
  238. <style scoped lang="scss"></style>