condition-popup.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <u-popup v-model="visible" mode="bottom" border-radius="24" :safe-area-inset-bottom="true" :mask-close-able="true"
  3. @close="close">
  4. <view class="condition-popup">
  5. <!-- 头部 -->
  6. <view class="header">
  7. <text class="title">切换品相</text>
  8. <image src="/pages-sell/static/select-good/icon-close.png" class="close-icon" @click="close"></image>
  9. </view>
  10. <!-- SKU 列表 (新样式) -->
  11. <view class="options-list" v-if="skuList.length > 0">
  12. <view class="option-item" v-for="(opt, index) in skuList" :key="index"
  13. :class="{ active: currentCondition === opt.conditionType, disabled: isStockEmpty(opt) }"
  14. @click="selectSku(opt)">
  15. <!-- 选中背景图 -->
  16. <image v-if="currentCondition === opt.conditionType"
  17. src="/pages-sell/static/select-good/selected.png" class="bg-image"></image>
  18. <view class="left">
  19. <text class="opt-name">{{ getConditionName(opt.conditionType) }}</text>
  20. <!-- 折扣标签 -->
  21. <view class="opt-discount" :class="{ active: currentCondition === opt.conditionType }"
  22. v-if="opt.discount">
  23. <text>{{ opt.discount }}折</text>
  24. </view>
  25. </view>
  26. <view class="right">
  27. <text v-if="!isStockEmpty(opt)">¥{{ opt.price }} <text v-if="opt.balanceMoney"
  28. style="font-size: 24rpx; color: #999;">( 余额价 ¥{{ opt.balanceMoney }} )</text></text>
  29. <text v-else class="no-stock">暂无库存</text>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="empty-list" v-else>
  34. <u-loading mode="circle"></u-loading>
  35. </view>
  36. </view>
  37. </u-popup>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. visible: false,
  44. currentCondition: null,
  45. skuList: []
  46. };
  47. },
  48. methods: {
  49. open(skuList, currentCondition) {
  50. this.skuList = skuList || [];
  51. // 确保类型一致,通常 API 返回 number
  52. this.currentCondition = Number(currentCondition);
  53. this.visible = true;
  54. },
  55. close() {
  56. this.visible = false;
  57. },
  58. getConditionName(type) {
  59. return this.$conditionMap[type] || '-';
  60. },
  61. isStockEmpty(sku) {
  62. return !sku.stockNum || sku.stockNum <= 0;
  63. },
  64. selectSku(sku) {
  65. if (this.isStockEmpty(sku)) return;
  66. if (this.currentCondition === sku.conditionType) return;
  67. this.$emit('select', sku);
  68. this.close();
  69. }
  70. }
  71. };
  72. </script>
  73. <style lang="scss" scoped>
  74. .condition-popup {
  75. background-color: #fff;
  76. padding: 30rpx;
  77. min-height: 400rpx;
  78. .header {
  79. display: flex;
  80. justify-content: center;
  81. align-items: center;
  82. position: relative;
  83. margin-bottom: 30rpx;
  84. padding-bottom: 30rpx;
  85. border-bottom: 2rpx dashed #eee;
  86. .title {
  87. font-size: 34rpx;
  88. font-weight: bold;
  89. color: #333;
  90. }
  91. .close-icon {
  92. position: absolute;
  93. right: 0;
  94. top: 0;
  95. width: 24rpx;
  96. height: 24rpx;
  97. padding: 10rpx;
  98. box-sizing: content-box;
  99. }
  100. }
  101. .options-list {
  102. margin-bottom: 40rpx;
  103. .option-item {
  104. position: relative;
  105. display: flex;
  106. justify-content: space-between;
  107. align-items: center;
  108. background: #F8F8F8;
  109. border-radius: 12rpx;
  110. padding: 24rpx 30rpx;
  111. margin-bottom: 24rpx;
  112. border: 2rpx solid #dfdfdf;
  113. transition: all 0.2s;
  114. &.active {
  115. border-color: transparent;
  116. }
  117. &.disabled {
  118. opacity: 0.6;
  119. background: #f0f0f0;
  120. }
  121. .bg-image {
  122. position: absolute;
  123. top: -6rpx;
  124. left: -1%;
  125. width: 102%;
  126. height: 110rpx;
  127. z-index: 0;
  128. }
  129. .left,
  130. .right {
  131. position: relative;
  132. z-index: 1;
  133. }
  134. .left {
  135. display: flex;
  136. align-items: center;
  137. .opt-name {
  138. font-size: 30rpx;
  139. font-weight: bold;
  140. color: #333;
  141. margin-right: 16rpx;
  142. }
  143. .opt-discount {
  144. background: #D8D8D8;
  145. padding: 0 20rpx;
  146. border-radius: 0 20rpx 0 20rpx;
  147. text {
  148. color: #fff;
  149. font-size: 24rpx;
  150. display: inline-block;
  151. }
  152. &.active {
  153. background: linear-gradient(0deg, #30E030 0%, #28C445 100%);
  154. }
  155. }
  156. }
  157. .right {
  158. font-size: 28rpx;
  159. color: #D81A00;
  160. font-weight: bold;
  161. .no-stock {
  162. color: #999;
  163. font-weight: normal;
  164. font-size: 24rpx;
  165. }
  166. }
  167. }
  168. }
  169. .empty-list {
  170. display: flex;
  171. justify-content: center;
  172. padding: 50rpx 0;
  173. }
  174. }
  175. </style>