condition-popup.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. conditionMap: {
  47. 1: '良好',
  48. 2: '中等',
  49. 3: '次品',
  50. 4: '全新'
  51. }
  52. };
  53. },
  54. methods: {
  55. open(skuList, currentCondition) {
  56. this.skuList = skuList || [];
  57. // 确保类型一致,通常 API 返回 number
  58. this.currentCondition = Number(currentCondition);
  59. this.visible = true;
  60. },
  61. close() {
  62. this.visible = false;
  63. },
  64. getConditionName(type) {
  65. return this.conditionMap[type] || '未知';
  66. },
  67. isStockEmpty(sku) {
  68. return !sku.stockNum || sku.stockNum <= 0;
  69. },
  70. selectSku(sku) {
  71. if (this.isStockEmpty(sku)) return;
  72. if (this.currentCondition === sku.conditionType) return;
  73. this.$emit('select', sku);
  74. this.close();
  75. }
  76. }
  77. };
  78. </script>
  79. <style lang="scss" scoped>
  80. .condition-popup {
  81. background-color: #fff;
  82. padding: 30rpx;
  83. min-height: 400rpx;
  84. .header {
  85. display: flex;
  86. justify-content: center;
  87. align-items: center;
  88. position: relative;
  89. margin-bottom: 30rpx;
  90. padding-bottom: 30rpx;
  91. border-bottom: 2rpx dashed #eee;
  92. .title {
  93. font-size: 34rpx;
  94. font-weight: bold;
  95. color: #333;
  96. }
  97. .close-icon {
  98. position: absolute;
  99. right: 0;
  100. top: 0;
  101. width: 24rpx;
  102. height: 24rpx;
  103. padding: 10rpx;
  104. box-sizing: content-box;
  105. }
  106. }
  107. .options-list {
  108. margin-bottom: 40rpx;
  109. .option-item {
  110. position: relative;
  111. display: flex;
  112. justify-content: space-between;
  113. align-items: center;
  114. background: #F8F8F8;
  115. border-radius: 12rpx;
  116. padding: 24rpx 30rpx;
  117. margin-bottom: 24rpx;
  118. border: 2rpx solid #dfdfdf;
  119. transition: all 0.2s;
  120. &.active {
  121. border-color: transparent;
  122. }
  123. &.disabled {
  124. opacity: 0.6;
  125. background: #f0f0f0;
  126. }
  127. .bg-image {
  128. position: absolute;
  129. top: -6rpx;
  130. left: -1%;
  131. width: 102%;
  132. height: 110rpx;
  133. z-index: 0;
  134. }
  135. .left,
  136. .right {
  137. position: relative;
  138. z-index: 1;
  139. }
  140. .left {
  141. display: flex;
  142. align-items: center;
  143. .opt-name {
  144. font-size: 30rpx;
  145. font-weight: bold;
  146. color: #333;
  147. margin-right: 16rpx;
  148. }
  149. .opt-discount {
  150. background: #D8D8D8;
  151. padding: 0 20rpx;
  152. border-radius: 0 20rpx 0 20rpx;
  153. text {
  154. color: #fff;
  155. font-size: 24rpx;
  156. display: inline-block;
  157. }
  158. &.active {
  159. background: linear-gradient(0deg, #30E030 0%, #28C445 100%);
  160. }
  161. }
  162. }
  163. .right {
  164. font-size: 28rpx;
  165. color: #D81A00;
  166. font-weight: bold;
  167. .no-stock {
  168. color: #999;
  169. font-weight: normal;
  170. font-size: 24rpx;
  171. }
  172. }
  173. }
  174. }
  175. .empty-list {
  176. display: flex;
  177. justify-content: center;
  178. padding: 50rpx 0;
  179. }
  180. }
  181. </style>