金诚优选前端代码
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.

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