quantity_popup.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <popup
  3. @close="close"
  4. ref="popupRef"
  5. isClose
  6. iconSize="16px"
  7. zIndex="998"
  8. iconColor="var(--text)"
  9. >
  10. <template #title>
  11. <view class="product_info">
  12. <image
  13. :src="detail.picurl"
  14. class="cur_img"
  15. @click="previewImage(1, detail.picurl)"
  16. ></image>
  17. <view class="product_price">
  18. <rich-text
  19. class="texts"
  20. :nodes="MoneyAbouthtml(detail.price, true)"
  21. ></rich-text>
  22. </view>
  23. </view>
  24. </template>
  25. <template #content>
  26. <scroll-view class="sku_info" scroll-y>
  27. <view class="prop_wrapper">
  28. <view class="spec_title"><trans _t="数量" /></view>
  29. <view class="spec_items decrease">
  30. <up-number-box
  31. v-model="total"
  32. :min="1"
  33. @change="totalChange"
  34. ></up-number-box>
  35. <view class="inventory">
  36. <trans _t="库存" />:{{ detail.total }}
  37. </view>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. </template>
  42. <template #footer>
  43. <view class="footer_btn" @click="btnClick">
  44. <trans :_t="btnText == 'add' ? '加入购物车' : '立即购买'" />
  45. </view>
  46. </template>
  47. </popup>
  48. </template>
  49. <script setup>
  50. import popup from "@/components/popup";
  51. import { ref, computed } from "vue";
  52. import { useSystemStore } from "@/store";
  53. import { MoneyAbouthtml, Toast } from "@/utils";
  54. import { SELLER_ADD_CART, SHOP_CART_CONFIRM } from "@/api";
  55. import { useShopStore } from "@/store";
  56. const useShop = useShopStore();
  57. const props = defineProps({
  58. detail: {
  59. type: Object,
  60. default: () => ({}),
  61. },
  62. });
  63. const emit = defineEmits(["open", "close"]);
  64. const total = ref(1);
  65. const btnText = ref("add");
  66. const useSystem = useSystemStore();
  67. const popupRef = ref(null);
  68. const symbol = computed(() => useSystem.getSymbol);
  69. const totalChange = (e) => {};
  70. const btnClick = () => {
  71. addCart();
  72. };
  73. const close = () => {
  74. popupRef.value && popupRef.value.close();
  75. emit("close");
  76. };
  77. const open = (value = "add") => {
  78. btnText.value = value;
  79. total.value = 1; // 重置数量
  80. popupRef.value && popupRef.value.open();
  81. };
  82. const addCart = async () => {
  83. try {
  84. const res = await SELLER_ADD_CART({
  85. id: props.detail.id,
  86. total: total.value,
  87. });
  88. useShop.setSellerNum(res.data.cartCount);
  89. Toast(res.msg);
  90. if (btnText.value == "buy") {
  91. uni.navigateTo({
  92. url: `/pagesBuyer/shop/shopConfirm?comfirmId=${res.data.cartids}`,
  93. });
  94. } else {
  95. close();
  96. }
  97. } catch (error) {
  98. Toast(error.msg);
  99. }
  100. };
  101. function previewImage(index, urls) {
  102. uni.previewImage({
  103. current: index,
  104. urls: [urls],
  105. success() {},
  106. });
  107. }
  108. defineExpose({
  109. open,
  110. close,
  111. });
  112. </script>
  113. <style lang="less" scoped>
  114. @import url("@/style.less");
  115. /deep/ .pop {
  116. .top {
  117. align-items: unset;
  118. padding-bottom: 24rpx;
  119. }
  120. .conts {
  121. padding-top: 0;
  122. }
  123. }
  124. .uni-preview-container {
  125. z-index: 99999 !important;
  126. /* 确保高于其他元素 */
  127. }
  128. .product_info {
  129. .flex();
  130. .cur_img {
  131. width: 144rpx;
  132. height: 144rpx;
  133. border-radius: 8rpx;
  134. margin-right: 24rpx;
  135. }
  136. .product_price {
  137. color: var(--red);
  138. .size(40rpx);
  139. font-weight: 700;
  140. .flex();
  141. .texts {
  142. margin-left: 8rpx;
  143. /deep/ div {
  144. .ver(baseline);
  145. .decimal {
  146. .size(24rpx);
  147. }
  148. }
  149. }
  150. }
  151. }
  152. .sku_info {
  153. .prop_wrapper {
  154. margin-top: 8rpx;
  155. .spec_title {
  156. .ver();
  157. color: var(--text);
  158. .size(28rpx);
  159. font-weight: 700;
  160. line-height: 40rpx;
  161. min-height: 60rpx;
  162. }
  163. .spec_items {
  164. .flex();
  165. flex-wrap: wrap;
  166. gap: 16rpx;
  167. margin-top: 24rpx;
  168. .decrease {
  169. .ver();
  170. /deep/ .u-number-box {
  171. border: 1px solid #dcdfe6;
  172. border-radius: 16rpx;
  173. .u-number-box__minus,
  174. .u-number-box__plus {
  175. width: 76rpx !important;
  176. height: 76rpx !important;
  177. background-color: transparent !important;
  178. .u-icon__icon {
  179. .size(26rpx) !important;
  180. color: var(--text) !important;
  181. }
  182. &--hover {
  183. .u-icon__icon {
  184. color: var(--primary) !important;
  185. }
  186. }
  187. }
  188. .u-number-box__input {
  189. margin: 0;
  190. border-left: 1px solid #dcdfe6;
  191. border-right: 1px solid #dcdfe6;
  192. height: 76rpx !important;
  193. width: 160rpx !important;
  194. background-color: transparent !important;
  195. }
  196. }
  197. .inventory {
  198. color: var(--text);
  199. margin-left: 8rpx;
  200. .size(28rpx);
  201. line-height: 60rpx;
  202. }
  203. }
  204. }
  205. }
  206. }
  207. .footer_btn {
  208. background-color: var(--black);
  209. color: var(--light);
  210. border-radius: 20rpx;
  211. padding: 16rpx 30rpx;
  212. .flex_center();
  213. .size();
  214. font-weight: bold;
  215. height: 100rpx;
  216. }
  217. </style>