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

292 lines
7.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?id='+ s_item.id)">
  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, g_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.qty+'件;' : ''}}{{g_item.color ? g_item.color+';' : ''}}{{g_item.size ? 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 class="loading-more" v-if="list.length == 0">
  41. {{list.length}}
  42. <lf-nocontent src="/static/images/empty-cart.png"></lf-nocontent>
  43. </view>
  44. </view>
  45. <view style="height: 60rpx;"></view>
  46. <view class="cart-bottom">
  47. <u-checkbox-group>
  48. <u-checkbox shape="circle" active-color="#15716E" @change="allCheckChange" v-model="allChecked">
  49. <text class="lf-font-28 lf-color-777">全选</text>
  50. </u-checkbox>
  51. </u-checkbox-group>
  52. <view class="lf-row-between">
  53. <view class="lf-font-32 lf-color-222 lf-font-bold lf-m-r-30">
  54. 合计: {{ total_price || 0 }}
  55. </view>
  56. <view class="cart-btn" hover-class="lf-opacity" @click="submit">
  57. <text>结算</text>
  58. <text v-if="total_count">({{ total_count }})</text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import lfSwipeAction from '@/components/lf-swipeAction/lf-swipeAction.vue';
  66. import Bigc from '@/common/js/bigc.js';
  67. export default {
  68. components: {
  69. lfSwipeAction
  70. },
  71. data() {
  72. return {
  73. token: '', // 用户token
  74. allChecked: false, // 全选
  75. list: [], // 购物车列表
  76. total_price: '', // 总金额
  77. total_count: '', // 总数量
  78. options: [{
  79. text: '删除',
  80. style: {
  81. backgroundColor: '#dd524d'
  82. }
  83. },{
  84. text: '取消',
  85. style: {
  86. backgroundColor: '#15716E'
  87. }
  88. }],
  89. show: false
  90. }
  91. },
  92. watch: {
  93. list: {
  94. deep: true,
  95. handler: function(val){
  96. let total_count = 0;
  97. let total_price = new Bigc(0);
  98. val.map(s => {
  99. s.goods.map(g => {
  100. if(g.checked){
  101. total_count++;
  102. let itemPrice = new Bigc(g.price).times(g.qty);
  103. total_price = total_price.plus(itemPrice);
  104. }
  105. })
  106. })
  107. this.total_count = total_count;
  108. this.total_price = total_price;
  109. }
  110. }
  111. },
  112. onLoad(){
  113. this.token = this.$cookieStorage.get('user_token');
  114. this.getCartList();
  115. },
  116. methods: {
  117. getCartList(){
  118. this.$http.get({
  119. api: 'api/cart',
  120. header: {
  121. Authorization: this.token
  122. }
  123. }).then(res => {
  124. console.log("===", res);
  125. let data = res.data.data;
  126. let list = [];
  127. for(let i in data){
  128. let goods = data[i].goods.map(item => {
  129. item.checked = false;
  130. return item;
  131. })
  132. list.push({
  133. name: data[i].name,
  134. full_minus: '',
  135. goods: goods,
  136. id: data[i].id
  137. })
  138. }
  139. this.list = list;
  140. })
  141. },
  142. // 商品被勾选
  143. goodsCheckChange(event, parentIndex, childIndex) {
  144. this.list[parentIndex].goods[childIndex].checked = event.value;
  145. let check_list = this.list.map(item => {
  146. return item.goods.every(g => g.checked);
  147. });
  148. this.allChecked = check_list.every(a => a);
  149. },
  150. // 全选被改变
  151. allCheckChange(event){
  152. this.allChecked = event.value;
  153. this.list.forEach(s => {
  154. s.goods.forEach(g => {
  155. g.checked = event.value;
  156. })
  157. })
  158. },
  159. // 结算
  160. submit(){
  161. if(this.total_count){
  162. let brand = [];
  163. let cart_ids = [];
  164. this.list.map(item => {
  165. let checked = item.goods.every(g => g.checked);
  166. item.goods.map(g => {
  167. if(g.checked){
  168. cart_ids.push(g.__raw_id);
  169. }
  170. })
  171. if(checked){
  172. brand.push(item.name);
  173. }
  174. })
  175. if(brand.length > 1){
  176. this.$msg('只支持单个店铺结算哦');
  177. }else{
  178. let par = {
  179. cart_ids: cart_ids,
  180. type: "normal",
  181. wechat_group_id: ""
  182. };
  183. this.$cookieStorage.set('order_confirm', par);
  184. this.$url('/pages/order/confirm/confirm');
  185. }
  186. }else{
  187. this.$msg('您未选择需要结算的商品');
  188. }
  189. },
  190. // 滑动组件,按钮被点击
  191. onButton(event, parentIndex, childIndex){
  192. if(event.buttonIndex == 0){
  193. let __raw_id = this.list[parentIndex].goods[childIndex].__raw_id;
  194. uni.showModal({
  195. title: '温馨提示',
  196. content: '确定移除该商品吗?',
  197. success: result => {
  198. if(result.confirm){
  199. uni.showLoading({
  200. title: '正在删除'
  201. })
  202. this.$http.ajax({
  203. api: 'api/shopping/cart/'+ __raw_id,
  204. method: 'DELETE',
  205. header: {
  206. Authorization: this.token
  207. }
  208. }).then(res => {
  209. if(res.data.code == 200){
  210. this.$msg('删除成功', {icon: 'success'}).then(() => {
  211. this.list[parentIndex].goods.splice(childIndex, 1);
  212. if(this.list[parentIndex].goods.length <= 0){
  213. this.list.splice(parentIndex, 1);
  214. }
  215. })
  216. }else{
  217. this.$msg('删除失败', {icon: 'error'});
  218. }
  219. uni.hideLoading();
  220. }).catch(err => uni.hideLoading())
  221. }
  222. }
  223. })
  224. }
  225. }
  226. }
  227. }
  228. </script>
  229. <style>
  230. page {
  231. background-color: #F8F8F8;
  232. }
  233. </style>
  234. <style scoped lang="scss">
  235. .cart-btn {
  236. display: flex;
  237. justify-content: center;
  238. align-items: center;
  239. width: 200rpx;
  240. height: 80rpx;
  241. background: #15716E;
  242. border-radius: 40rpx;
  243. color: #FFFFFF;
  244. font-size: 28rpx;
  245. }
  246. .cart-bottom {
  247. display: flex;
  248. justify-content: space-between;
  249. width: 750rpx;
  250. height: 120rpx;
  251. background: #FFFFFF;
  252. position: fixed;
  253. bottom: 0;
  254. padding: 32rpx;
  255. }
  256. .gray-tag {
  257. border-radius: 2rpx;
  258. border: 1rpx solid #979797;
  259. color: #777;
  260. padding: 0 6rpx;
  261. font-size: 20rpx;
  262. width: max-content;
  263. }
  264. .red-tag {
  265. font-size: 20rpx;
  266. color: #F63434;
  267. }
  268. .content-img {
  269. width: 130rpx;
  270. height: 130rpx;
  271. border-radius: 5rpx;
  272. }
  273. .content-info{
  274. width: 410rpx;
  275. }
  276. .online-card {
  277. width: 686rpx;
  278. height: auto;
  279. background: #FFFFFF;
  280. border-radius: 20rpx;
  281. // margin-bottom: 30rpx;
  282. padding: 30rpx;
  283. margin: 30rpx auto;
  284. overflow: hidden;
  285. &:last-child {
  286. margin-bottom: 150rpx;
  287. }
  288. }
  289. </style>