index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. const { clickByPermission } = usePermissions()
  20. const userStore = useUserStore()
  21. const router = useRouter()
  22. const { userInfo } = storeToRefs(userStore)
  23. const id = ref()
  24. const show = ref(false)
  25. const nums = ref(1)
  26. const type = ref<'add2Cart' | 'orderNow'>()
  27. const { data, run: setData } = useRequest(() => getProduct(id.value))
  28. const handleConfirm = async () => {
  29. // 积分
  30. const points = data.value?.showFavourable ? data.value?.favourablePoints : data.value?.points
  31. if (type.value === 'orderNow') {
  32. const body = {
  33. isShoppingCart: 0,
  34. userId: userInfo.value.userId,
  35. item: 3,
  36. list: [
  37. {
  38. productId: id.value,
  39. points,
  40. nums: nums.value,
  41. productName: data.value.prodcutName,
  42. orderImgUrl: data.value.productCoverImgUrl,
  43. vendorId: data.value.vendorId,
  44. },
  45. ],
  46. couponList: [],
  47. }
  48. const { data: res, code } = await requestToast(() => productPlacing(body))
  49. if (code !== 0) return
  50. await router.push(`/pages/home/mall/confirm-order/index?data=${JSON.stringify(body)}`)
  51. }
  52. if (type.value === 'add2Cart') {
  53. await requestToast(
  54. () =>
  55. createProductItemBuy({
  56. doList: [
  57. {
  58. userId: userInfo.value.userId,
  59. productId: data.value?.productId || '',
  60. points,
  61. nums: nums.value,
  62. },
  63. ],
  64. }),
  65. { success: true, successTitle: '加入购物车成功' },
  66. )
  67. show.value = false
  68. }
  69. }
  70. onLoad(async (query: { id: string }) => {
  71. id.value = query.id
  72. await setData()
  73. })
  74. onShareAppMessage(() => ({
  75. title: data.value?.prodcutName,
  76. }))
  77. onShareTimeline(() => ({
  78. title: data.value?.prodcutName,
  79. }))
  80. </script>
  81. <template>
  82. <view class="flex-grow flex flex-col">
  83. <div class="aspect-[1.34/1] relative">
  84. <div class="absolute aspect-[1.26/1] top-0 w-full">
  85. <swiper>
  86. <template v-for="(it, index) in data?.productDetailsImgUrl?.split(',')" :key="index">
  87. <swiper-item>
  88. <wd-img width="100%" height="100%" mode="aspectFill" :src="it" />
  89. </swiper-item>
  90. </template>
  91. </swiper>
  92. </div>
  93. </div>
  94. <div class="relative flex-1 bg-white p-4 flex flex-col gap-4 rounded-tl-2xl rounded-tr-2xl">
  95. <div class="flex items-end gap-1">
  96. <div class="text-[#ef4343] text-[26px] font-normal font-['D-DIN_Exp'] leading-[20px]">
  97. <!-- 1000 -->
  98. {{ data?.showFavourable ? data?.favourablePoints : data?.points }}
  99. </div>
  100. <template v-if="String(data?.needPoints) === '0'">
  101. <div class="text-black/60 text-base font-normal font-['PingFang_SC'] leading-4">积分</div>
  102. </template>
  103. <template v-if="String(data?.needPoints) === '1'">
  104. <div class="text-black/60 text-base font-normal font-['PingFang_SC'] leading-4">
  105. 折(积分结算)
  106. </div>
  107. </template>
  108. <div
  109. v-if="Number(data?.productPrice)"
  110. class="w-[66px] text-black/30 text-xs font-normal font-['PingFang_SC'] leading-3"
  111. >
  112. <!-- ¥60 -->
  113. ¥{{ data?.productPrice }}
  114. </div>
  115. <div class="flex-1"></div>
  116. <div class="text-[#999999] text-xs font-normal font-['PingFang_SC']">
  117. <!-- 已售5件 -->
  118. 库存:{{ data?.productRepertory || 0 }}
  119. </div>
  120. </div>
  121. <div class="text-black text-xl font-normal font-['PingFang_SC']">
  122. <!-- 阿芙佳朵 -->
  123. {{ data?.prodcutName }}
  124. </div>
  125. <div class="h-0.25 bg-[#f6f6f6]"></div>
  126. <div class="text-black/90 text-base font-normal font-['PingFang_SC'] leading-normal">
  127. 积分兑换说明:
  128. </div>
  129. <div class="text-black/40 text-xs font-normal font-['PingFang_SC'] leading-[23px]">
  130. {{ data?.exchangeDesc }}
  131. <!-- · 不限制兑换个数-->
  132. <!-- <br />-->
  133. <!-- · 兑换后不支持退换货,如有问题可联系官方客户-->
  134. <!-- <br />-->
  135. <!-- · 规格:件-->
  136. <!-- <br />-->
  137. <!-- · 配送方式:到店自取-->
  138. </div>
  139. <div class="mx--4 h-2.5 bg-neutral-100"></div>
  140. <wd-divider>
  141. <div
  142. class="text-center text-black/40 text-xs font-normal font-['PingFang_SC'] leading-normal"
  143. >
  144. 商品详情
  145. </div>
  146. </wd-divider>
  147. <mpHtml :content="data?.contentDesc"></mpHtml>
  148. </div>
  149. <template v-if="String(data?.needPoints) === '0'">
  150. <BottomAppBar fixed placeholder>
  151. <div class="h-[63px] bg-white backdrop-blur-[20px] flex items-center justify-between gap-2">
  152. <div class="flex-1">
  153. <ButtonEvo
  154. block
  155. color="white"
  156. location="right"
  157. @click="((show = true), (type = 'add2Cart'))"
  158. >
  159. <span class="text-black/80">加入购物车</span>
  160. </ButtonEvo>
  161. </div>
  162. <div class="flex-1">
  163. <ButtonEvo
  164. block
  165. size="lg"
  166. @click="
  167. clickByPermission('mallExchange', () => {
  168. show = true
  169. type = 'orderNow'
  170. })
  171. "
  172. >
  173. 立即兑换
  174. </ButtonEvo>
  175. </div>
  176. </div>
  177. </BottomAppBar>
  178. </template>
  179. <wd-action-sheet v-model="show">
  180. <view class="px-7 py-11">
  181. <div class="flex gap-3 mb-13.5">
  182. <div class="w-[110px] h-[110px] bg-[#f6f6f6] rounded-2xl">
  183. <wd-img width="100%" height="100%" :src="data?.productCoverImgUrl"></wd-img>
  184. </div>
  185. <div class="flex flex-col justify-between flex-1">
  186. <div class="text-black/40 text-base font-normal font-['PingFang_SC'] leading-normal">
  187. {{ data?.prodcutName }}
  188. </div>
  189. <div class="flex items-end gap-1">
  190. <div class="text-[#ef4343] text-[22px] font-normal font-['D-DIN_Exp'] leading-4">
  191. <!-- {{ data?.points }}-->
  192. {{ data?.showFavourable ? data?.favourablePoints : data?.points }}
  193. </div>
  194. <div class="text-black/40 text-sm font-normal font-['PingFang_SC'] leading-3">
  195. 积分
  196. </div>
  197. <div class="flex-1"></div>
  198. <!-- <wd-input-number v-model="a" /> -->
  199. <wd-input-number v-model="nums" />
  200. </div>
  201. </div>
  202. </div>
  203. <wd-button block :round="false" @click="handleConfirm">确认</wd-button>
  204. </view>
  205. </wd-action-sheet>
  206. </view>
  207. </template>
  208. <style scoped lang="scss"></style>