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

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