CXBSkuPopup.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <script setup lang="ts">
  2. import FPopup from "~/components/FPopup/FPopup.vue";
  3. import { CANCEL_EVENT, CONFIRM_EVENT } from "~/constants/event";
  4. import FPrice from "~/components/FPrice/FPrice.vue";
  5. import { SkuModel } from "~/apis/model/product.model";
  6. import { computed } from "vue";
  7. import { PopupProps } from "~/components/FPopup";
  8. import { CLOSE_EVENT, OPEN_EVENT, UPDATE_SHOW_EVENT } from "~/components/constants";
  9. import CXBButton from "~/components/CXBButton/CXBButton.vue";
  10. import FButton from "~/components/FButton/FButton.vue";
  11. import { findLast } from "lodash-es";
  12. const emit = defineEmits()
  13. const props = defineProps({
  14. show: {
  15. type: Boolean,
  16. default: false
  17. },
  18. detail: {
  19. type: Object,
  20. required: true
  21. },
  22. sku: {
  23. type: Array,
  24. default: () => {
  25. return []
  26. }
  27. },
  28. isTo: {
  29. type: Number,
  30. required: true
  31. }
  32. })
  33. const show = ref(props.show || false)
  34. const showValue = computed<PopupProps['show']>({
  35. get: () => props.show || show.value,
  36. set(val) {
  37. if (val)
  38. emit(OPEN_EVENT)
  39. else
  40. emit(CLOSE_EVENT)
  41. show.value = val
  42. emit(UPDATE_SHOW_EVENT, val)
  43. },
  44. })
  45. const currentSku = ref(null)
  46. const onConfirm = () => {
  47. show.value = false
  48. showValue.value = false
  49. console.log(showValue.value)
  50. emit(CONFIRM_EVENT)
  51. }
  52. const onCancel = () => {
  53. // show.value = false
  54. showValue.value = false
  55. emit(CANCEL_EVENT)
  56. }
  57. const count = ref(1)
  58. const skuList = computed(() => {
  59. const skuData = []
  60. if (props.detail && props.detail.sku) {
  61. for (let key in props.detail.sku) {
  62. const skuItem: SkuModel = props.detail.sku[key]
  63. skuData.push(skuItem)
  64. if (skuItem.unique === props.detail.unique) {
  65. currentSku.value = skuItem
  66. }
  67. }
  68. }
  69. return skuData
  70. })
  71. // currentSku.value = findLast(skuList, (item) => {
  72. // return item.unique === props.detail.unique
  73. // })
  74. onMounted(() => {
  75. emit('selected:item', currentSku)
  76. })
  77. function handleSelectedSku(skuItem: any) {
  78. console.log(skuItem);
  79. currentSku.value = skuItem
  80. console.log('我是数据', currentSku.value);
  81. emit('selected:item', currentSku)
  82. }
  83. function handleClose() {
  84. showValue.value = false
  85. emit(CLOSE_EVENT)
  86. }
  87. function handleAddCart() {
  88. emit('submit')
  89. }
  90. function handleBuyNow() {
  91. emit('subBuy')
  92. }
  93. function handleJiaCart() {
  94. emit('subAdd')
  95. }
  96. function handleSubQg() {
  97. emit('subQg')
  98. }
  99. function handleCountChange(value) {
  100. emit('count-change', value)
  101. }
  102. </script>
  103. <template>
  104. <FPopup v-model:show="showValue" @close="onCancel" position="bottom"
  105. exClass="rounded-rt-xl rounded-lt-xl flex flex-col pb-safe min-h-[55%] max-h-[70%] h-full">
  106. <div class="flex flex-col justify-between h-full">
  107. <div class="flex-1">
  108. <div class="p-3 flex flex-col gap-3">
  109. <div class="flex flex-row gap-3">
  110. <image :src="currentSku.image" v-if="currentSku" mode="aspectFit" class="w-25 h-25 rounded"></image>
  111. <div class="flex flex-col w-full">
  112. <div class="flex gap-2 justify-between w-full">
  113. <div class="text-overflow text-xs flex-1 line-clamp-2 h-fit" v-if="detail && detail.store_name">
  114. {{ detail.store_name }}
  115. </div>
  116. <div @tap="handleClose" class="i-tabler-x w-5 h-5 text-gray-500"></div>
  117. </div>
  118. <div class="flex flex-col" v-if="currentSku">
  119. <div class="text-[12px] text-right text-gray-500 ">
  120. 剩余库存{{ currentSku.stock }}
  121. </div>
  122. <div class="flex items-end gap-2" v-if="detail.mer_id === '148'">
  123. {{ Math.round(currentSku.price * 30) }} 积分
  124. </div>
  125. <div class="flex items-end gap-2" v-else>
  126. <FPrice :price="detail.seckill_s==0? currentSku.price:currentSku.dacang" />
  127. <FPrice v-if="currentSku.ot_price" :price="currentSku.ot_price"
  128. :ex-class="'!text-black text-xs font-bold'" need-symbol strike-through />
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. <!-- <template v-if="skuList && skuList.length > 0"></template>-->
  134. <!-- <scroll-view-->
  135. <!-- :scroll-y="true"-->
  136. <!-- class="h-20"-->
  137. <!-- >-->
  138. <div class="text-xs flex" v-if="skuList && skuList.length > 0">规格</div>
  139. <div class="flex flex-row gap-2 flex-wrap ">
  140. <div v-for="(item, index) in skuList" :key="index" @tap="handleSelectedSku(item)">
  141. <div v-if="item.sku && item.sku !== ''" class="text-[11px] border border-solid rounded p-1 px-1 "
  142. :class="currentSku.unique === item.unique ? 'border-primary text-primary' : 'border-gray-500 text-gray-500'">
  143. {{ item.sku }}
  144. </div>
  145. </div>
  146. </div>
  147. <!-- </scroll-view>-->
  148. </div>
  149. <div class="p-3">
  150. <div class="flex justify-between text-sm">
  151. 数量
  152. <nut-input-number v-model="count" @change="handleCountChange" />
  153. </div>
  154. </div>
  155. </div>
  156. <div class="px-3 pb-12" v-if="isTo == 1">
  157. <FButton @click="handleAddCart" size="small" :exClass="['!bg-primary', 'rounded-full', 'text-white']" block>
  158. 确定
  159. </FButton>
  160. </div>
  161. <div class="px-3 pb-10" v-if="isTo == 4">
  162. <FButton @click="handleSubQg" size="small" :exClass="['!bg-primary', 'rounded-full', 'text-white']" block>
  163. 立即抢购
  164. </FButton>
  165. </div>
  166. <div class="px-3 pb-10" v-if="isTo == 5">
  167. <FButton @click="handleAddCart" size="small" :exClass="['!bg-primary', 'rounded-full', 'text-white']" block>
  168. 立即抢购
  169. </FButton>
  170. </div>
  171. <div class="px-3 pb-10" v-if="isTo == 3">
  172. <FButton @click="handleAddCart" size="small" :exClass="['!bg-primary', 'rounded-full', 'text-white']" block>
  173. 立即兑换
  174. </FButton>
  175. </div>
  176. <div class="px-4 flex box_1 flex-row justify-between text-sm text-white gap-3 " v-if="isTo == 2">
  177. <button @click="handleJiaCart" size="small"
  178. class="bg-[#FFA319] rounded-full w-50 flex justify-center items-center h-9 clor">
  179. 加入购物车
  180. </button>
  181. <button @click="handleBuyNow" size="small"
  182. class="bg-[#F94032] rounded-full w-50 flex justify-center items-center h-9 clor ">
  183. 立即购买
  184. </button>
  185. </div>
  186. </div>
  187. </FPopup>
  188. </template>
  189. <style scoped>
  190. .box_1 {
  191. padding-top: 10rpx;
  192. padding-bottom: 30rpx;
  193. border-top: 1px solid rgba(182, 185, 192, 50%);
  194. }
  195. .clor {
  196. color: aliceblue;
  197. font-size: 28rpx;
  198. }
  199. </style>