CXBSkuPopup.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. const emit = defineEmits()
  12. const props = defineProps({
  13. show: {
  14. type: Boolean,
  15. default: false
  16. },
  17. detail: {
  18. type: Object,
  19. required: true
  20. },
  21. sku: {
  22. type: Array,
  23. default: () => {
  24. return []
  25. }
  26. }
  27. })
  28. const show = ref(props.show || false)
  29. const showValue = computed<PopupProps['show']>({
  30. get: () => props.show || show.value,
  31. set(val) {
  32. // console.log(val + 'xxxx')
  33. if (val)
  34. emit(OPEN_EVENT)
  35. else
  36. emit(CLOSE_EVENT)
  37. show.value = val
  38. emit(UPDATE_SHOW_EVENT, val)
  39. },
  40. })
  41. const currentSku = ref(null)
  42. const onConfirm = () => {
  43. show.value = false
  44. showValue.value = false
  45. console.log(showValue.value)
  46. emit(CONFIRM_EVENT)
  47. }
  48. const onCancel = () => {
  49. // show.value = false
  50. showValue.value = false
  51. emit(CANCEL_EVENT)
  52. }
  53. const count = ref(1)
  54. const skuList = computed(() => {
  55. const skuData = []
  56. if (props.detail && props.detail.sku) {
  57. for (let key in props.detail.sku) {
  58. const skuItem: SkuModel = props.detail.sku[key]
  59. // if (skuItem.sku !== '') {
  60. skuData.push(skuItem)
  61. // }
  62. currentSku.value = skuData[0]
  63. }
  64. }
  65. return skuData
  66. })
  67. onMounted(() => {
  68. emit('selected:item', currentSku)
  69. })
  70. function handleSelectedSku(skuItem) {
  71. currentSku.value = skuItem
  72. emit('selected:item', currentSku)
  73. }
  74. function handleClose() {
  75. showValue.value = false
  76. emit(CLOSE_EVENT)
  77. }
  78. function handleAddCart() {
  79. emit('submit')
  80. }
  81. // function handleSelectedSku(item) {
  82. //
  83. // }
  84. function handleCountChange(value) {
  85. emit('count-change', value)
  86. }
  87. </script>
  88. <template>
  89. <FPopup
  90. v-model:show="showValue"
  91. @close="onCancel"
  92. position="bottom"
  93. exClass="rounded-rt-xl rounded-lt-xl flex flex-col pb-safe min-h-[40%] max-h-[80%]"
  94. >
  95. <div class="flex flex-col justify-between h-full">
  96. <div class="flex-1">
  97. <div class="p-3 flex flex-col gap-3">
  98. <div class="flex flex-row gap-3">
  99. <image :src="detail.image"
  100. v-if="currentSku"
  101. mode="aspectFit" class="w-25 h-25 rounded"></image>
  102. <div class="flex flex-col w-full">
  103. <div class="flex gap-2 justify-between w-full">
  104. <div class="text-overflow text-xs flex-1" v-if="detail && detail.store_name">
  105. {{ detail.store_name }}
  106. </div>
  107. <div
  108. @tap="handleClose"
  109. class="i-tabler-x w-5 h-5 text-gray-500"></div>
  110. </div>
  111. <div class="flex flex-col" v-if="currentSku">
  112. <div class="text-[12px] text-right text-gray-500 ">
  113. 剩余库存{{currentSku.stock}}
  114. </div>
  115. <div class="flex items-end gap-2" v-if="detail.mer_id === '148'">
  116. {{ currentSku.ot_price * 30 }} 积分
  117. </div>
  118. <div class="flex items-end gap-2" v-else>
  119. <FPrice :price="currentSku.price"/>
  120. <FPrice v-if="currentSku.ot_price" :price="currentSku.ot_price" :ex-class="'!text-black text-xs font-bold'" need-symbol strike-through/>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <!-- <template v-if="skuList && skuList.length > 0"></template>-->
  126. <!-- <scroll-view-->
  127. <!-- :scroll-y="true"-->
  128. <!-- class="h-20"-->
  129. <!-- >-->
  130. <div class="text-xs flex" v-if="skuList && skuList.length > 0">规格</div>
  131. <div class="flex flex-row gap-2 flex-wrap ">
  132. <div
  133. v-for="(item, index) in skuList"
  134. :key="index"
  135. @tap="handleSelectedSku(item)"
  136. >
  137. <div
  138. v-if="item.sku && item.sku !== ''"
  139. class="text-[12px] border border-solid rounded p-1 px-2 "
  140. :class="currentSku.unique === item.unique ? 'border-primary text-primary' : 'border-gray-500 text-gray-500'"
  141. >
  142. {{ item.sku }}
  143. </div>
  144. </div>
  145. </div>
  146. <!-- </scroll-view>-->
  147. </div>
  148. <div class="p-3">
  149. <div class="flex justify-between text-sm">
  150. 数量
  151. <nut-input-number v-model="count" @change="handleCountChange"/>
  152. </div>
  153. </div>
  154. </div>
  155. <div class="px-3 ">
  156. <FButton
  157. @click="handleAddCart"
  158. size="small"
  159. :exClass="['!bg-primary', 'rounded-full', 'text-white']"
  160. block
  161. >
  162. 确定
  163. </FButton>
  164. </div>
  165. </div>
  166. </FPopup>
  167. </template>