shopcar.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view>
  3. <!--列表数据-->
  4. <view class="list" v-if="list.length > 0">
  5. <view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
  6. <view class="icon" :class="{ active: item.check }" @click.stop="check(item)">&#xe61b;</view>
  7. <image :src="ip + item.goods.pic" class="pic" mode="aspectFill"></image>
  8. <view class="con">
  9. <view class="title">{{ item.goods.title }}</view>
  10. <view class="price">
  11. <text>¥{{ item.goods.price }}</text>
  12. <text class="day">/天</text>
  13. </view>
  14. </view>
  15. <view class="clear"></view>
  16. </view>
  17. </view>
  18. <view class="noData" v-else>
  19. <text class="icon">&#xe60c;</text>
  20. <view class="title">购物车是空的</view>
  21. </view>
  22. <view class="footer">
  23. <view class="lfx">
  24. <view class="f">
  25. <view class="check" @click="check_all()">
  26. <text class="icon" :class="{ active: checkAll && check_list.length > 0 }">&#xe61b;</text>
  27. <text>全选</text>
  28. </view>
  29. <view class="del" v-if="check_list.length > 0" @click="del()">删除已选</view>
  30. <view class="hej">
  31. <text class="hj">合计:</text>
  32. <text class="price">¥{{ total_price }}</text>
  33. </view>
  34. </view>
  35. <view class="f js" @click="buy()">结算</view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. ip: this.$http.urls.ip,
  45. list: [],
  46. checkAll: false, //全选
  47. check_list: [], //选中
  48. total_price: '0.00' //合计
  49. };
  50. },
  51. onShow() {
  52. this.getData();
  53. },
  54. methods: {
  55. //获取数据
  56. getData() {
  57. this.$http.request({
  58. url: this.$http.urls.cart_list,
  59. data: { userId: this.$getUser().id },
  60. success: res => {
  61. this.list = res.data.data;
  62. this.calcul();
  63. }
  64. });
  65. },
  66. //选中
  67. check(item) {
  68. item.check = !item.check;
  69. this.calcul();
  70. },
  71. //全选
  72. check_all() {
  73. this.checkAll = !this.checkAll;
  74. this.list.forEach(item => {
  75. item.check = this.checkAll;
  76. });
  77. this.calcul();
  78. },
  79. //计算价格和选中
  80. calcul() {
  81. this.check_list = this.list.filter(item => {
  82. return item.check;
  83. });
  84. this.checkAll = this.check_list.length == this.list.length ? true : false;
  85. this.total_price = 0;
  86. this.check_list.forEach(item => {
  87. this.total_price = this.$util.accAdd(this.total_price, item.goods.price);
  88. });
  89. this.$forceUpdate();
  90. },
  91. del() {
  92. let ids = this.check_list.map(item => item.id);
  93. uni.showModal({
  94. title: '提示',
  95. content: '是否删除选中服务?',
  96. success: res => {
  97. if (res.confirm) {
  98. this.$http.request({
  99. url: this.$http.urls.cart_del + ids,
  100. method: 'delete',
  101. success: res => {
  102. uni.showToast({ title: '删除成功' });
  103. this.getData();
  104. }
  105. });
  106. }
  107. }
  108. });
  109. },
  110. //详情
  111. detail(item) {
  112. uni.navigateTo({ url: 'detail?id=' + item.goodsId });
  113. },
  114. //结算
  115. buy() {
  116. if (this.check_list == 0) {
  117. uni.showModal({ content: '请勾选服务', showCancel: false });
  118. return;
  119. }
  120. console.log(JSON.stringify(this.check_list));
  121. uni.navigateTo({ url: 'pay?list=' + JSON.stringify(this.check_list) });
  122. }
  123. }
  124. };
  125. </script>
  126. <style lang="scss">
  127. page {
  128. background-color: $page;
  129. }
  130. .list {
  131. padding: 0px 10px 70px 10px;
  132. .item {
  133. background-color: white;
  134. padding: 15px 8px 15px 8px;
  135. border-bottom: 1px solid #e5e5e5;
  136. border-radius: 5px;
  137. margin-top: 10px;
  138. .icon {
  139. width: 10%;
  140. float: left;
  141. padding-left: 3px;
  142. font-size: 17px;
  143. margin-top: 30px;
  144. font-weight: bold;
  145. &.active {
  146. color: $red;
  147. }
  148. }
  149. .pic {
  150. float: left;
  151. width: 30%;
  152. border-radius: 3px;
  153. height:80px;
  154. background-color: #dcdcdc;
  155. }
  156. .con {
  157. padding-left: 10px;
  158. width: 60%;
  159. float: left;
  160. .title {
  161. font-size: 13px;
  162. text-align: left;
  163. color: #252525;
  164. }
  165. .price {
  166. color: $theme-color;
  167. margin-top: 5px;
  168. }
  169. }
  170. }
  171. }
  172. .footer {
  173. /* #ifdef MP-WEIXIN */
  174. bottom: 0px;
  175. /* #endif */
  176. /* #ifdef H5 */
  177. bottom: 40px;
  178. /* #endif */
  179. }
  180. </style>