金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
6.0 KiB

  1. <template>
  2. <view>
  3. <lf-nav :spreadOut="true" :showIcon="true" bgColor="white" title="购物车"></lf-nav>
  4. <view style="height: 1rpx;"></view>
  5. <view>
  6. <view v-for="(s_item, s_index) in list" :key="s_index" class="online-card">
  7. <view class="lf-m-b-20" @click="$url('/pages/shop/shopdetail')">
  8. <text class="lf-iconfont icon-Group- lf-font-28"></text>
  9. <text class="lf-color-black lf-font-28 lf-font-bold lf-m-l-10">{{ s_item.name }}</text>
  10. <text class="lf-iconfont icon-xiangyou lf-font-24 lf-m-l-10"></text>
  11. </view>
  12. <view class="lf-row-between">
  13. <view class="lf-flex">
  14. <view class="gray-tag">满减</view>
  15. <view class="lf-m-l-15 lf-font-24 lf-color-333">{{s_item.full_minus}}</view>
  16. </view>
  17. <view class="red-tag" @click="$msg('敬请期待')">去凑单</view>
  18. </view>
  19. <view v-for="(g_item, g_index) in s_item.goods" :key="g_index" class="lf-row-between">
  20. <u-checkbox-group>
  21. <u-checkbox shape="circle" active-color="#15716E" @change="goodsCheckChange($event, s_index, g_index)" v-model="g_item.checked"></u-checkbox>
  22. </u-checkbox-group>
  23. <view class="lf-m-t-30" style="display: flex;">
  24. <image class="content-img" :src="g_item.img" mode="aspectFill" @click="$url('/pages/shop/goodsdetail')"></image>
  25. <view class="lf-m-l-15 content-info">
  26. <view class="lf-color-333 lf-font-26 lf-line-2" style="max-width: 480rpx;">{{g_item.name}}</view>
  27. <view class="lf-font-24 lf-color-777 lf-m-t-14 lf-row-between">
  28. <view>{{g_item.count}}{{g_item.spec}}</view>
  29. <view class="lf-font-32 lf-color-price">{{ g_item.price }}</view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view style="height: 60rpx;"></view>
  37. <view class="cart-bottom">
  38. <u-checkbox-group>
  39. <u-checkbox shape="circle" active-color="#15716E" @change="allCheckChange" v-model="allChecked">
  40. <text class="lf-font-28 lf-color-777">全选</text>
  41. </u-checkbox>
  42. </u-checkbox-group>
  43. <view class="lf-row-between">
  44. <view class="lf-font-32 lf-color-222 lf-font-bold lf-m-r-30">
  45. 合计: {{ total_price || 0 }}
  46. </view>
  47. <view class="cart-btn" hover-class="lf-opacity" @click="submit">
  48. <text>结算</text>
  49. <text v-if="total_count">({{ total_count }})</text>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. export default {
  57. data() {
  58. return {
  59. token: '', // 用户token
  60. allChecked: false, // 全选
  61. list: [], // 购物车列表
  62. total_price: '', // 总金额
  63. total_count: '' // 总数量
  64. }
  65. },
  66. watch: {
  67. list: {
  68. deep: true,
  69. handler: function(val){
  70. let total_count = 0;
  71. let total_price = 0;
  72. // TODO 真正对接接口时,使用精度计算
  73. val.map(s => {
  74. s.goods.map(g => {
  75. if(g.checked){
  76. total_count++;
  77. total_price += (g.price * g.count)
  78. }
  79. })
  80. })
  81. this.total_count = total_count;
  82. this.total_price = total_price;
  83. }
  84. }
  85. },
  86. onLoad(){
  87. this.token = this.$cookieStorage.get('user_token');
  88. this.getCartList();
  89. },
  90. methods: {
  91. getCartList(){
  92. this.$http.get({
  93. api: 'api/cart',
  94. header: {
  95. Authorization: this.token
  96. }
  97. }).then(res => {
  98. console.log("===", res);
  99. // TODO 此处为假数据 ------------------
  100. let list = [{
  101. name: '精品超市',
  102. full_minus: '母婴产品教师节满1200减200',
  103. goods: [{
  104. checked: false,
  105. img: 'https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png',
  106. name: '爱他美较大婴儿配方奶粉较大婴儿配方奶粉较大婴儿配方奶粉2段 900g',
  107. count: 1,
  108. spec: '900g',
  109. price: '385'
  110. },{
  111. checked: false,
  112. img: 'https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png',
  113. name: '基尼泰煤2000G',
  114. count: 2,
  115. spec: '900g',
  116. price: '197'
  117. }]
  118. },{
  119. name: '精品超市',
  120. full_minus: '母婴产品教师节满1200减200',
  121. goods: [{
  122. checked: false,
  123. img: 'https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png',
  124. name: '爱他美较大婴儿配方奶粉较大婴儿配方奶粉较大婴儿配方奶粉2段 900g',
  125. count: 4,
  126. spec: '900g',
  127. price: '99'
  128. }]
  129. }]
  130. this.list = list;
  131. // TODO 此处为假数据 end --------------
  132. })
  133. },
  134. // 商品被勾选
  135. goodsCheckChange(event, parentIndex, childIndex) {
  136. this.list[parentIndex].goods[childIndex].checked = event.value;
  137. let check_list = this.list.map(item => {
  138. return item.goods.every(g => g.checked);
  139. });
  140. this.allChecked = check_list.every(a => a);
  141. },
  142. // 全选被改变
  143. allCheckChange(event){
  144. this.allChecked = event.value;
  145. this.list.forEach(s => {
  146. s.goods.forEach(g => {
  147. g.checked = event.value;
  148. })
  149. })
  150. },
  151. // 结算
  152. submit(){
  153. if(this.total_count){
  154. this.$url('/pages/order/confirm/confirm');
  155. }else{
  156. this.$msg('您未选择需要结算的商品');
  157. }
  158. }
  159. }
  160. }
  161. </script>
  162. <style>
  163. page {
  164. background-color: #F8F8F8;
  165. }
  166. </style>
  167. <style scoped lang="scss">
  168. .cart-btn {
  169. display: flex;
  170. justify-content: center;
  171. align-items: center;
  172. width: 200rpx;
  173. height: 80rpx;
  174. background: #15716E;
  175. border-radius: 40rpx;
  176. color: #FFFFFF;
  177. font-size: 28rpx;
  178. }
  179. .cart-bottom {
  180. display: flex;
  181. justify-content: space-between;
  182. width: 750rpx;
  183. height: 120rpx;
  184. background: #FFFFFF;
  185. position: fixed;
  186. bottom: 0;
  187. padding: 32rpx;
  188. }
  189. .gray-tag {
  190. border-radius: 2rpx;
  191. border: 1rpx solid #979797;
  192. color: #777;
  193. padding: 0 6rpx;
  194. font-size: 20rpx;
  195. width: max-content;
  196. }
  197. .red-tag {
  198. font-size: 20rpx;
  199. color: #F63434;
  200. }
  201. .content-img {
  202. width: 130rpx;
  203. height: 130rpx;
  204. border-radius: 5rpx;
  205. }
  206. .content-info{
  207. width: 410rpx;
  208. }
  209. .online-card {
  210. width: 686rpx;
  211. height: auto;
  212. background: #FFFFFF;
  213. border-radius: 20rpx;
  214. // margin-bottom: 30rpx;
  215. padding: 30rpx;
  216. margin: 30rpx auto;
  217. &:last-child {
  218. margin-bottom: 150rpx;
  219. }
  220. }
  221. </style>