PricePopup.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <Popup
  3. ref="popupRef"
  4. title="上架"
  5. :isClose="true"
  6. mode="bottom"
  7. :round="20"
  8. @close="onClose"
  9. >
  10. <template #content>
  11. <view class="price-content">
  12. <view class="price-section">
  13. <view class="section-title">
  14. <trans _t="原价" />
  15. </view>
  16. <view class="price-input-wrapper">
  17. <view class="currency-symbol">{{ symbol }}</view>
  18. <Input
  19. v-model="originalPrice"
  20. type="number"
  21. :placeholder="t('请输入原价')"
  22. :clearable="true"
  23. border="none"
  24. class="price-input"
  25. />
  26. </view>
  27. <view class="price-tip">
  28. <text
  29. ><trans _t="建议原价" />:{{ symbol
  30. }}{{ suggestedOriginalPrice }}</text
  31. >
  32. </view>
  33. </view>
  34. <view class="price-section">
  35. <view class="section-title">
  36. <trans _t="销售价格" />
  37. </view>
  38. <view class="price-input-wrapper">
  39. <view class="currency-symbol">{{ symbol }}</view>
  40. <Input
  41. v-model="salePrice"
  42. type="number"
  43. :placeholder="t('请输入销售价格')"
  44. :focus="true"
  45. :clearable="true"
  46. border="none"
  47. class="price-input"
  48. />
  49. </view>
  50. <view class="price-tip">
  51. <text
  52. ><trans _t="建议销售价格" />:{{ symbol
  53. }}{{ suggestedPrice }}</text
  54. >
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <template #footer>
  60. <view class="btn-group">
  61. <view class="btn cancel-btn" @click="onClose">
  62. <trans _t="取消" />
  63. </view>
  64. <view class="btn submit-btn" @click="submitPrice">
  65. <trans _t="确认上架" />
  66. </view>
  67. </view>
  68. </template>
  69. </Popup>
  70. </template>
  71. <script setup>
  72. import { ref, computed, watch } from "vue";
  73. import Popup from "@/components/popup";
  74. import Input from "@/components/input";
  75. import { t } from "@/locale";
  76. import { useSystemStore } from "@/store";
  77. import { SELLER_GOODS_UP } from "@/api";
  78. import { Toast } from "@/utils";
  79. const props = defineProps({
  80. show: {
  81. type: Boolean,
  82. default: false,
  83. },
  84. item: {
  85. type: Object,
  86. default: () => ({}),
  87. },
  88. });
  89. const emit = defineEmits(["close", "confirm"]);
  90. const useSystem = useSystemStore();
  91. const symbol = computed(() => useSystem.getSymbol.symbol);
  92. const popupRef = ref(null);
  93. const salePrice = ref("");
  94. const originalPrice = ref("");
  95. // 建议价格(原价的1.3倍)
  96. const suggestedPrice = computed(() => {
  97. if (props.item?.price) {
  98. return (parseFloat(props.item.price) * 1.3).toFixed(2);
  99. }
  100. return "0.00";
  101. });
  102. // 建议原价(原价的40%)
  103. const suggestedOriginalPrice = computed(() => {
  104. if (props.item?.price) {
  105. return (parseFloat(props.item.price) * 1.4).toFixed(2);
  106. }
  107. return "0.00";
  108. });
  109. watch(
  110. () => props.show,
  111. (newVal) => {
  112. if (newVal) {
  113. salePrice.value = suggestedPrice.value;
  114. originalPrice.value = suggestedOriginalPrice.value;
  115. popupRef.value?.open();
  116. } else {
  117. popupRef.value?.close();
  118. }
  119. }
  120. );
  121. const onClose = () => {
  122. emit("close");
  123. };
  124. const submitPrice = async () => {
  125. if (!salePrice.value || parseFloat(salePrice.value) <= 0) {
  126. return Toast(t("请输入有效的销售价格"));
  127. }
  128. if (!originalPrice.value || parseFloat(originalPrice.value) <= 0) {
  129. return Toast(t("请输入有效的原价"));
  130. }
  131. try {
  132. const para = {
  133. id: props.item.id,
  134. price: parseFloat(salePrice.value),
  135. originalprice: parseFloat(originalPrice.value),
  136. };
  137. const res = await SELLER_GOODS_UP(para);
  138. emit("confirm");
  139. popupRef.value?.close();
  140. } catch (error) {
  141. Toast(error.msg);
  142. }
  143. };
  144. </script>
  145. <style lang="less" scoped>
  146. @import url("@/style.less");
  147. .price-content {
  148. width: 100%;
  149. .price-section {
  150. margin-bottom: 32rpx;
  151. &:last-child {
  152. margin-bottom: 0;
  153. }
  154. .section-title {
  155. font-size: 32rpx;
  156. font-weight: 600;
  157. color: var(--black);
  158. margin-bottom: 24rpx;
  159. }
  160. .price-input-wrapper {
  161. display: flex;
  162. align-items: center;
  163. background: var(--bg);
  164. border-radius: 16rpx;
  165. padding: 0 24rpx;
  166. margin-bottom: 16rpx;
  167. border: 2rpx solid var(--border);
  168. .currency-symbol {
  169. font-size: 32rpx;
  170. font-weight: bold;
  171. color: var(--primary);
  172. margin-right: 16rpx;
  173. }
  174. .price-input {
  175. flex: 1;
  176. :deep(.u-input) {
  177. // padding: 0 !important;
  178. // background: transparent !important;
  179. // border: none !important;
  180. .u-input__content__field-wrapper__field {
  181. font-size: 32rpx;
  182. font-weight: bold;
  183. color: var(--black);
  184. }
  185. }
  186. }
  187. }
  188. .price-tip {
  189. font-size: 24rpx;
  190. color: var(--text-01);
  191. text-align: center;
  192. }
  193. }
  194. }
  195. .btn-group {
  196. display: flex;
  197. gap: 20rpx;
  198. .btn {
  199. flex: 1;
  200. height: 80rpx;
  201. border-radius: 16rpx;
  202. display: flex;
  203. align-items: center;
  204. justify-content: center;
  205. font-size: 32rpx;
  206. font-weight: 600;
  207. transition: all 0.3s ease;
  208. &.cancel-btn {
  209. background: var(--bg);
  210. color: var(--text-01);
  211. border: 2rpx solid var(--border);
  212. }
  213. &.submit-btn {
  214. background: var(--primary);
  215. color: var(--light);
  216. }
  217. }
  218. }
  219. </style>