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

283 lines
7.5 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. this.$http.ajax({
  195. api: 'api/shopping/cart/'+ __raw_id,
  196. method: 'DELETE',
  197. header: {
  198. Authorization: this.token
  199. }
  200. }).then(res => {
  201. if(res.data.code == 200){
  202. this.$msg('删除成功', {icon: 'success'}).then(() => {
  203. this.list[parentIndex].goods.splice(childIndex, 1);
  204. if(this.list[parentIndex].goods.length <= 0){
  205. this.list.splice(parentIndex, 1);
  206. }
  207. })
  208. }else{
  209. this.$msg('删除失败', {icon: 'error'});
  210. }
  211. })
  212. }
  213. }
  214. })
  215. }
  216. }
  217. }
  218. }
  219. </script>
  220. <style>
  221. page {
  222. background-color: #F8F8F8;
  223. }
  224. </style>
  225. <style scoped lang="scss">
  226. .cart-btn {
  227. display: flex;
  228. justify-content: center;
  229. align-items: center;
  230. width: 200rpx;
  231. height: 80rpx;
  232. background: #15716E;
  233. border-radius: 40rpx;
  234. color: #FFFFFF;
  235. font-size: 28rpx;
  236. }
  237. .cart-bottom {
  238. display: flex;
  239. justify-content: space-between;
  240. width: 750rpx;
  241. height: 120rpx;
  242. background: #FFFFFF;
  243. position: fixed;
  244. bottom: 0;
  245. padding: 32rpx;
  246. }
  247. .gray-tag {
  248. border-radius: 2rpx;
  249. border: 1rpx solid #979797;
  250. color: #777;
  251. padding: 0 6rpx;
  252. font-size: 20rpx;
  253. width: max-content;
  254. }
  255. .red-tag {
  256. font-size: 20rpx;
  257. color: #F63434;
  258. }
  259. .content-img {
  260. width: 130rpx;
  261. height: 130rpx;
  262. border-radius: 5rpx;
  263. }
  264. .content-info{
  265. width: 410rpx;
  266. }
  267. .online-card {
  268. width: 686rpx;
  269. height: auto;
  270. background: #FFFFFF;
  271. border-radius: 20rpx;
  272. // margin-bottom: 30rpx;
  273. padding: 30rpx;
  274. margin: 30rpx auto;
  275. overflow: hidden;
  276. &:last-child {
  277. margin-bottom: 150rpx;
  278. }
  279. }
  280. </style>