specPopup.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <uni-popup ref="popup" background-color="#fff" mode="bottom" @change="change">
  3. <view class="s-box padding-sm">
  4. <view class="s-img">
  5. <image mode="aspectFit" class="wh-full" :src="cardMsg.src"></image>
  6. </view>
  7. <view class="g-info">
  8. <view class="s-name">{{cardMsg.goods_name}}</view>
  9. <view class="s-price">{{cardMsg.goods_price}}</view>
  10. </view>
  11. </view>
  12. <uni-section title="规格">
  13. <view class="spec-box padding-lr-sm">
  14. <view class="spec-item padding-lr-sm" :class="{'on-spec': spec.selected}" :key="spec.id"
  15. @click="selectSpec1(spec)" v-for="spec in specs1">{{ spec.name }}</view>
  16. </view>
  17. </uni-section>
  18. <uni-section title="口味">
  19. <view class="spec-box padding-lr-sm">
  20. <view class="spec-item padding-lr-sm" :class="{'on-spec': spec.selected}" :key="spec.id"
  21. @click="selectSpec2(spec)" v-for="spec in specs2">{{ spec.name }}</view>
  22. </view>
  23. </uni-section>
  24. <uni-section title="购买数量">
  25. <view class="purchase-num padding-lr-sm">
  26. <view class="num">剩余562件</view>
  27. <uni-number-box v-model="vModelValue" @change="changeValue(value)" />
  28. </view>
  29. </uni-section>
  30. <view class="btn-box">
  31. <view class="btn reset" @click="toShop">加入购物车</view>
  32. <view class="btn confirm" @click="toBuy">立即购买</view>
  33. </view>
  34. </uni-popup>
  35. </template>
  36. <script>
  37. export default {
  38. name: "specPopup",
  39. props: {
  40. cardMsg: {
  41. type: Object,
  42. required: true
  43. }
  44. },
  45. data() {
  46. return {
  47. vModelValue: 1,
  48. shopMsg: {
  49. id: '',
  50. spec: '',
  51. specs: '',
  52. num: ''
  53. },
  54. specs1: [{
  55. id: 1,
  56. name: '规格1',
  57. selected: false
  58. },
  59. {
  60. id: 2,
  61. name: '规格2',
  62. selected: false
  63. },
  64. {
  65. id: 3,
  66. name: '规格3',
  67. selected: false
  68. },
  69. {
  70. id: 4,
  71. name: '规格4',
  72. selected: false
  73. },
  74. {
  75. id: 5,
  76. name: '规格5',
  77. selected: false
  78. }
  79. ],
  80. specs2: [{
  81. id: 1,
  82. name: '大份1',
  83. selected: false
  84. },
  85. {
  86. id: 2,
  87. name: '大份2',
  88. selected: false
  89. },
  90. {
  91. id: 3,
  92. name: '大份3',
  93. selected: false
  94. },
  95. {
  96. id: 4,
  97. name: '大份4',
  98. selected: false
  99. },
  100. {
  101. id: 5,
  102. name: '大份5',
  103. selected: false
  104. }
  105. ]
  106. }
  107. },
  108. methods: {
  109. changeValue(e) {
  110. console.log('vModelValue', e)
  111. },
  112. change(e) {
  113. if (!e.show) { // 当弹出层关闭时
  114. // 重置规格选择
  115. this.specs1.forEach(spec => {
  116. spec.selected = false;
  117. });
  118. this.specs2.forEach(spec => {
  119. spec.selected = false;
  120. });
  121. // 重置购买数量
  122. this.vModelValue = 1;
  123. }
  124. },
  125. selectSpec1(item) {
  126. console.log('点击了规格:', item);
  127. item.selected = !item.selected;
  128. this.shopMsg.spec = item.name
  129. // 在这里添加您的点击处理逻辑
  130. },
  131. selectSpec2(item) {
  132. console.log('点击了大份:', item);
  133. item.selected = !item.selected;
  134. this.shopMsg.specs = item.name
  135. // 在这里添加您的点击处理逻辑
  136. },
  137. open() {
  138. console.log('cardMsg', this.cardMsg)
  139. this.$refs.popup.open('bottom')
  140. },
  141. toShop() {
  142. this.shopMsg.id = this.cardMsg.id
  143. this.shopMsg.num = this.vModelValue
  144. console.log('this.shopMsg', this.shopMsg)
  145. this.$emit('update-shopmsg', this.shopMsg);
  146. // 关闭弹出层
  147. this.$refs.popup.close();
  148. },
  149. toBuy() {
  150. uni.navigateTo({
  151. url: `/pages/order/submitOrder/submitOrder`
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. .btn-box {
  159. width: 100%;
  160. display: flex;
  161. justify-content: space-around;
  162. align-items: center;
  163. padding-top: 80upx;
  164. .btn {
  165. width: 45%;
  166. height: 80upx;
  167. text-align: center;
  168. line-height: 80upx;
  169. border-radius: 40upx;
  170. }
  171. .reset {
  172. border: solid 1px #EEE;
  173. box-sizing: border-box;
  174. box-sizing: border-box;
  175. border: solid 1px #FF0000;
  176. font-size: 14px;
  177. color: #FF0000;
  178. }
  179. .confirm {
  180. background-image: $base-bg-gradient-color;
  181. color: #FFF;
  182. }
  183. }
  184. .spec-box {
  185. width: 100%;
  186. display: flex;
  187. flex-wrap: wrap;
  188. .spec-item {
  189. height: 60upx;
  190. line-height: 60upx;
  191. border: solid 1px #EEE;
  192. box-sizing: border-box;
  193. text-align: center;
  194. margin-left: 20upx;
  195. border-radius: 3px;
  196. margin-bottom: 20upx;
  197. font-size: 12px;
  198. }
  199. .spec-item:first-child {
  200. margin-left: 0;
  201. }
  202. .on-spec {
  203. background-image: $base-bg-gradient-color;
  204. color: #FFF;
  205. }
  206. }
  207. .s-box {
  208. width: 100%;
  209. display: flex;
  210. border-bottom: solid 1px #EEE;
  211. .s-img {
  212. width: 140upx;
  213. height: 140upx;
  214. background-color: #EEE;
  215. border-radius: 4px;
  216. }
  217. .g-info {
  218. padding-left: 20upx;
  219. .s-name {
  220. padding-bottom: 4px;
  221. }
  222. .s-price {
  223. color: #F00;
  224. font-size: 14px;
  225. }
  226. }
  227. }
  228. .purchase-num {
  229. width: 100%;
  230. display: flex;
  231. justify-content: space-between;
  232. align-items: center;
  233. border-bottom: solid 1px #EEE;
  234. padding-bottom: 30upx;
  235. .num {
  236. font-size: 12px;
  237. }
  238. }
  239. </style>