index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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/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. const levelIds = product.memberLevelIds.split(',')
  78. if (!levelIds.includes(String(userInfo.value.level.level))) {
  79. toast.show('您当前会员等级不符合兑换条件')
  80. return null
  81. }
  82. // 否则,执行原来的点击逻辑
  83. clickByPermission('mallExchange', () => {
  84. show.value = true
  85. type.value = 'orderNow'
  86. })
  87. }
  88. onLoad(async (query: { id: string }) => {
  89. id.value = query.id
  90. await setData()
  91. })
  92. onShareAppMessage(() => ({
  93. title: data.value?.prodcutName,
  94. }))
  95. onShareTimeline(() => ({
  96. title: data.value?.prodcutName,
  97. }))
  98. </script>
  99. <template>
  100. <view class="flex-grow flex flex-col">
  101. <div class="aspect-[1.34/1] relative">
  102. <div class="absolute aspect-[1.26/1] top-0 w-full">
  103. <swiper>
  104. <wd-swiper
  105. custom-class="rounded-1xl overflow-hidden aspect-[1.29/1]"
  106. width="100%"
  107. height="100%"
  108. :list="data?.productDetailsImgUrl?.split(',')"
  109. autoplay
  110. v-model:current="current"
  111. :indicator="{ type: 'dots-bar' } as any"
  112. @click="handleClick"
  113. ></wd-swiper>
  114. </swiper>
  115. </div>
  116. </div>
  117. <div class="relative flex-1 bg-white p-4 flex flex-col gap-4 rounded-tl-2xl rounded-tr-2xl">
  118. <div class="flex items-end gap-1">
  119. <div class="text-[#ef4343] text-[26px] font-normal font-['D-DIN_Exp'] leading-[20px]">
  120. <!-- 1000 -->
  121. {{ data?.showFavourable ? data?.favourablePoints : data?.points }}
  122. </div>
  123. <template v-if="String(data?.needPoints) === '0'">
  124. <div class="text-black/60 text-base font-normal font-['PingFang_SC'] leading-4">积分</div>
  125. </template>
  126. <template v-if="String(data?.needPoints) === '1'">
  127. <div class="text-black/60 text-base font-normal font-['PingFang_SC'] leading-4">
  128. 折(积分结算)
  129. </div>
  130. </template>
  131. <div
  132. v-if="Number(data?.productPrice)"
  133. class="w-[66px] text-black/30 text-xs font-normal font-['PingFang_SC'] leading-3"
  134. >
  135. <!-- ¥60 -->
  136. <span style="text-decoration: line-through">¥{{ data?.productPrice }}</span>
  137. </div>
  138. <div class="flex-1"></div>
  139. <template v-if="String(data?.needPoints) !== '1'">
  140. <div class="text-[#999999] text-xs font-normal font-['PingFang_SC']">
  141. {{ data?.isRestrict === 0 ? '不限库存' : `库存:${data?.productRepertory || 0}` }}
  142. </div>
  143. </template>
  144. </div>
  145. <div class="text-black text-xl font-normal font-['PingFang_SC']">
  146. <!-- 阿芙佳朵 -->
  147. {{ data?.prodcutName }}
  148. </div>
  149. <div class="h-0.25 bg-[#f6f6f6]"></div>
  150. <div class="text-black/90 text-base font-normal font-['PingFang_SC'] leading-normal">
  151. 积分兑换说明:
  152. </div>
  153. <div
  154. class="text-black/40 text-xs font-normal font-['PingFang_SC'] leading-[23px] whitespace-pre-wrap"
  155. >
  156. {{ data?.exchangeDesc }}
  157. <!-- · 不限制兑换个数-->
  158. <!-- <br />-->
  159. <!-- · 兑换后不支持退换货,如有问题可联系官方客户-->
  160. <!-- <br />-->
  161. <!-- · 规格:件-->
  162. <!-- <br />-->
  163. <!-- · 配送方式:到店自取-->
  164. </div>
  165. <div class="mx--4 h-2.5 bg-neutral-100"></div>
  166. <wd-divider>
  167. <div
  168. class="text-center text-black/40 text-xs font-normal font-['PingFang_SC'] leading-normal"
  169. >
  170. 商品详情
  171. </div>
  172. </wd-divider>
  173. <mpHtml :content="data?.contentDesc"></mpHtml>
  174. </div>
  175. <template v-if="String(data?.needPoints) === '0'">
  176. <BottomAppBar fixed placeholder>
  177. <div class="h-[63px] bg-white backdrop-blur-[20px] flex items-center justify-between gap-2">
  178. <div class="flex-1">
  179. <ButtonEvo
  180. block
  181. color="white"
  182. location="right"
  183. @click="((show = true), (type = 'add2Cart'))"
  184. >
  185. <span class="text-black/80">加入购物车</span>
  186. </ButtonEvo>
  187. </div>
  188. <div class="flex-1">
  189. <ButtonEvo
  190. block
  191. size="lg"
  192. :disabled="
  193. (data?.isRestrict === 1 && data?.productRepertory == 0) ||
  194. !data?.memberLevelIds.split(',').includes(String(userInfo.level.level))
  195. ? 'isDisabled'
  196. : null
  197. "
  198. @click="handleClick(data)"
  199. >
  200. 立即兑换
  201. </ButtonEvo>
  202. </div>
  203. </div>
  204. </BottomAppBar>
  205. </template>
  206. <wd-action-sheet v-model="show">
  207. <view class="px-7 py-11">
  208. <div class="flex gap-3 mb-13.5">
  209. <div class="w-[110px] h-[110px] bg-[#f6f6f6] rounded-2xl">
  210. <wd-img width="100%" height="100%" :src="data?.productCoverImgUrl"></wd-img>
  211. </div>
  212. <div class="flex flex-col justify-between flex-1">
  213. <div class="text-black/40 text-base font-normal font-['PingFang_SC'] leading-normal">
  214. {{ data?.prodcutName }}
  215. </div>
  216. <div class="flex items-end gap-1">
  217. <div class="text-[#ef4343] text-[22px] font-normal font-['D-DIN_Exp'] leading-4">
  218. <!-- {{ data?.points }}-->
  219. {{ data?.showFavourable ? data?.favourablePoints : data?.points }}
  220. </div>
  221. <div class="text-black/40 text-sm font-normal font-['PingFang_SC'] leading-3">
  222. 积分
  223. </div>
  224. <div class="flex-1"></div>
  225. <wd-input-number
  226. v-model="nums"
  227. :max="
  228. data?.isRestrict === 1 && data?.purchaseLimit
  229. ? Math.min(data?.purchaseQuantity, data?.productRepertory)
  230. : data?.isRestrict === 1 && !data?.purchaseLimit
  231. ? data?.productRepertory
  232. : data?.isRestrict === 2 && data?.purchaseLimit
  233. ? data?.purchaseQuantity
  234. : 100
  235. "
  236. />
  237. </div>
  238. </div>
  239. </div>
  240. <wd-button block :round="false" @click="handleConfirm">确认</wd-button>
  241. </view>
  242. </wd-action-sheet>
  243. </view>
  244. </template>
  245. <style scoped lang="scss"></style>