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

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