my_cart.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view>
  3. <!--标题栏-->
  4. <bar-title bgColor='bg-white' @rightTap="barEditTap">
  5. <block slot="content">购物车</block>
  6. <!-- <block slot="right">
  7. <text v-if="goods_checked">完成</text>
  8. <text v-else>编辑</text>
  9. </block> -->
  10. </bar-title>
  11. <view class="bg-white zaiui-cart-list-view">
  12. <block v-for="(items,indexs) in cartList" :key="items.id">
  13. <view class="light goods-list-item-view">
  14. <checkbox class='round red sm zaiui-checked' :class="items.status == 1?'checked':''"
  15. :checked="items.status == 1?true:false" :data-item="items" @click="CheckboxChange" />
  16. <view class="cu-avatar radius lg" :style="[{backgroundImage:'url('+ items.pic +')'}]"/>
  17. <view class="goods-info-view">
  18. <view class="text-cut text-black">{{items.name}}</view>
  19. <view class="text-sm text-gray">{{items.sku_name}}</view>
  20. <view class="zaiui-tag-view">
  21. <text class="cu-tag line-red sm radius" v-if="items.tag">{{items.tag}}</text>
  22. </view>
  23. <view class="goods-price-view">
  24. <view class="text-price-view">
  25. <text class="text-price text-red text-lg">{{items.price.value}}</text>
  26. <text class="cu-tag bg-red sm radius" v-if="items.price_tag">{{items.price_tag}}</text>
  27. </view>
  28. <view class="step-btn-view">
  29. <button class="zaiui-btn text-gray" @click="handleCartNum" :data-item="items" :data-plus="-1" >-</button>
  30. <input class="zaiui-input" type='number' :value="items.num" @blur="handleCartNum" :data-item="items" :data-plus="0"></input>
  31. <button class="zaiui-btn" style="line-height: 44upx;" @click="handleCartNum" :data-item="items" :data-plus="1" >+</button>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </block>
  37. </view>
  38. <!--占位底部距离-->
  39. <view class="cu-tabbar-height"/>
  40. <!--底部操作-->
  41. <view class="bg-white zaiui-footer-fixed zaiui-foot-padding-bottom">
  42. <view class="cu-bar padding-lr">
  43. <view class="checked-view" @tap="tapChecked">
  44. <!-- <checkbox class='round red sm zaiui-checked' :class="checkAll?'checked':''" :checked="checkAll"></checkbox>
  45. <text class="text-black text-lg text-bold">全选</text> -->
  46. </view>
  47. <view class="price-view" style="padding-left: 0;">
  48. <view class="text-black text-bold">合计:¥{{totalInfo.price}}</view>
  49. <view class="text-sm">总额:¥{{totalInfo.price}} 优惠:¥0.00</view>
  50. </view>
  51. <view class="btn-view">
  52. <button class="cu-btn radius bg-red" @tap="tapBtn">去结算({{totalInfo.count}})</button>
  53. </view>
  54. </view>
  55. </view>
  56. <!--小程序端显示-->
  57. <!-- #ifdef MP -->
  58. <!--编辑-->
  59. <view class="zaiui-add-btn-view-box" @tap="barEditTap">
  60. <button class="cu-btn cuIcon-check bg-red" v-if="goods_checked"></button>
  61. <button class="cu-btn cuIcon-write bg-red" v-else></button>
  62. </view>
  63. <!-- #endif -->
  64. </view>
  65. </template>
  66. <script>
  67. import barTitle from '@/components/zaiui-common/basics/bar-title';
  68. import _my_cart_data from '@/static/zaiui/data/my_cart.js'; //虚拟数据
  69. import _tool from '@/static/zaiui/util/tools.js'; //工具函数
  70. export default {
  71. components: {
  72. barTitle,
  73. },
  74. data() {
  75. return {
  76. cartList: [], checkAll: false, goods_checked: false,
  77. }
  78. },
  79. onLoad() {
  80. // this.goodsList = _my_cart_data.goodsListData();
  81. this.loadCartList()
  82. },
  83. onReady() {
  84. _tool.setBarColor(true);
  85. uni.pageScrollTo({
  86. scrollTop: 0,
  87. duration: 0
  88. });
  89. },
  90. computed: {
  91. totalInfo() {
  92. if(!this.cartList.length) {
  93. return 0
  94. }
  95. return this.cartList.filter(item => item.status == 1).reduce((prev, curr) => {
  96. let count = prev.count + curr.num
  97. let price = prev.price + curr.price.value
  98. return {
  99. count,
  100. price
  101. }
  102. }, {
  103. count: 0,
  104. price: 0
  105. })
  106. }
  107. },
  108. methods: {
  109. loadCartList() {
  110. this.reqByuser({
  111. url: '?l=cart.list',
  112. data: {},
  113. success: res => {
  114. if(res.data.status == 1) {
  115. // console.log(res.data.data)
  116. // this.cartInfo = res.data.data.info;
  117. this.cartList = res.data.data.list
  118. // this.checkAll = !this.cartList.find(item => item.status != 1)
  119. }else {
  120. this.error = res.data.msg
  121. }
  122. }
  123. })
  124. },
  125. handleCartNum(e) {
  126. let {info_id, sku_id, num} = e.currentTarget.dataset.item;
  127. let {plus} = e.currentTarget.dataset;
  128. this.reqByuser({
  129. url: '?l=cart.up',
  130. // method: 'POST',
  131. data: {
  132. type_id: info_id,
  133. sku_id,
  134. num: plus == 0 ? e.target.value : (num + plus)
  135. },
  136. success: res => {
  137. if(res.data.status == 1) {
  138. uni.showToast({
  139. icon: 'success',
  140. title: '操作成功'
  141. })
  142. this.cartList = res.data.data
  143. }else {
  144. uni.showToast({
  145. icon: 'error',
  146. title: '添加失败'
  147. })
  148. }
  149. }
  150. })
  151. },
  152. CheckboxChange(e, _values) {
  153. // let items = this.cartList, values = e ? e.detail.value : _values;
  154. // this.cartList = this.cartList.map(item => {
  155. // return {...item, checked: values.includes(item.id + '')}
  156. // })
  157. let {id, sku_id, status} = e.currentTarget.dataset.item;
  158. this.reqByuser({
  159. url: '?l=cart.edit',
  160. data: {
  161. type_id: id,
  162. sku_id,
  163. status: status == 1 ? 2 : 1
  164. },
  165. success: res => {
  166. if(res.data.status == 1) {
  167. // console.log(res.data.data)
  168. // this.cartInfo = res.data.data.info;
  169. this.cartList = res.data.data
  170. // this.checkAll = !this.cartList.find(item => item.status != 1)
  171. }else {
  172. this.error = res.data.msg
  173. }
  174. }
  175. })
  176. },
  177. tapChecked() {
  178. if (this.checkAll) {
  179. this.checkAll = false;
  180. } else {
  181. this.checkAll = true;
  182. }
  183. this.CheckboxChange('', this.checkAll ? this.cartList.map(item => item.id + '') : [''])
  184. },
  185. barEditTap() {
  186. if (this.goods_checked) {
  187. this.goods_checked = false;
  188. } else {
  189. this.goods_checked = true;
  190. }
  191. },
  192. tapBtn() {
  193. uni.navigateTo({
  194. url: '/pages/goods/settlement'
  195. });
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss">
  201. /* #ifdef APP-PLUS */
  202. @import "../../static/colorui/main.css";
  203. @import "../../static/colorui/icon.css";
  204. @import "../../static/zaiui/style/app.scss";
  205. /* #endif */
  206. @import "../../static/zaiui/style/my_cart.scss";
  207. </style>