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

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