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

263 lines
6.8 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" v-if="s_item.full_minus">
  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?id='+ g_item.com_id)"></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.qty}};{{g_item.color}};{{g_item.size}}</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.qty)
  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. let data = res.data.data;
  121. let list = [];
  122. for(let i in data){
  123. let goods = data[i].goods.map(item => {
  124. item.checked = false;
  125. return item;
  126. })
  127. list.push({
  128. name: data[i].name,
  129. full_minus: '',
  130. goods: goods
  131. })
  132. }
  133. this.list = list;
  134. })
  135. },
  136. // 商品被勾选
  137. goodsCheckChange(event, parentIndex, childIndex) {
  138. this.list[parentIndex].goods[childIndex].checked = event.value;
  139. let check_list = this.list.map(item => {
  140. return item.goods.every(g => g.checked);
  141. });
  142. this.allChecked = check_list.every(a => a);
  143. },
  144. // 全选被改变
  145. allCheckChange(event){
  146. this.allChecked = event.value;
  147. this.list.forEach(s => {
  148. s.goods.forEach(g => {
  149. g.checked = event.value;
  150. })
  151. })
  152. },
  153. // 结算
  154. submit(){
  155. if(this.total_count){
  156. let brand = [];
  157. let cart_ids = [];
  158. this.list.map(item => {
  159. let checked = item.goods.every(g => g.checked);
  160. item.goods.map(g => {
  161. if(g.checked){
  162. cart_ids.push(g.__raw_id);
  163. }
  164. })
  165. if(checked){
  166. brand.push(item.name);
  167. }
  168. })
  169. if(brand.length > 1){
  170. this.$msg('只支持单个店铺结算哦');
  171. }else{
  172. let par = {
  173. cart_ids: cart_ids,
  174. type: "normal",
  175. wechat_group_id: ""
  176. };
  177. this.$cookieStorage.set('order_confirm', par);
  178. this.$url('/pages/order/confirm/confirm');
  179. }
  180. }else{
  181. this.$msg('您未选择需要结算的商品');
  182. }
  183. },
  184. // 滑动组件,按钮被点击
  185. onButton(event, parentIndex){
  186. console.log("event", event, parentIndex);
  187. if(event.buttonIndex == 0){
  188. uni.showModal({
  189. title: '温馨提示',
  190. content: '确定移除该商品吗?',
  191. success: result => {
  192. }
  193. })
  194. }
  195. }
  196. }
  197. }
  198. </script>
  199. <style>
  200. page {
  201. background-color: #F8F8F8;
  202. }
  203. </style>
  204. <style scoped lang="scss">
  205. .cart-btn {
  206. display: flex;
  207. justify-content: center;
  208. align-items: center;
  209. width: 200rpx;
  210. height: 80rpx;
  211. background: #15716E;
  212. border-radius: 40rpx;
  213. color: #FFFFFF;
  214. font-size: 28rpx;
  215. }
  216. .cart-bottom {
  217. display: flex;
  218. justify-content: space-between;
  219. width: 750rpx;
  220. height: 120rpx;
  221. background: #FFFFFF;
  222. position: fixed;
  223. bottom: 0;
  224. padding: 32rpx;
  225. }
  226. .gray-tag {
  227. border-radius: 2rpx;
  228. border: 1rpx solid #979797;
  229. color: #777;
  230. padding: 0 6rpx;
  231. font-size: 20rpx;
  232. width: max-content;
  233. }
  234. .red-tag {
  235. font-size: 20rpx;
  236. color: #F63434;
  237. }
  238. .content-img {
  239. width: 130rpx;
  240. height: 130rpx;
  241. border-radius: 5rpx;
  242. }
  243. .content-info{
  244. width: 410rpx;
  245. }
  246. .online-card {
  247. width: 686rpx;
  248. height: auto;
  249. background: #FFFFFF;
  250. border-radius: 20rpx;
  251. // margin-bottom: 30rpx;
  252. padding: 30rpx;
  253. margin: 30rpx auto;
  254. overflow: hidden;
  255. &:last-child {
  256. margin-bottom: 150rpx;
  257. }
  258. }
  259. </style>