cart.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view style="height: 100vh;background-color: #F5F5F5;">
  3. <view class="titleright" @click="changeShop" v-if="isdelete">编辑</view>
  4. <view class="titleright" @click="changeShop" v-else>取消</view>
  5. <view v-if="list.length>0">
  6. <scroll-view style="height: 100vh;" class="floor-list"
  7. :scroll-top="scrollTop" scroll-y="true" @scroll="scroll" @scrolltoupper="upper" @scrolltolower="lower"
  8. refresher-enabled="true">
  9. <view class="cart-list">
  10. <view style="display: flex;align-items: center;padding: 20upx 36upx;
  11. border-bottom: 1px solid #F5F5F5;">
  12. <image :src="pictureUrl+'/uploads/home/store/'+store.store_id+'/'+store.store_logo" style="border-radius: 50%;
  13. width: 50upx;height: 50upx;"></image>
  14. <span style="padding-left: 8upx;">{{store.store_name}}</span>
  15. </view>
  16. <view v-for="(item,index) in list" :key="index" class="shoplist" style="background-color: #fff;">
  17. <view style="flex: 1;border-radius: 100%;">
  18. <van-checkbox-group :value="checkboxList" @change="checkboxChange()">
  19. <van-checkbox checked-color="#D9332E" :name="index"></van-checkbox>
  20. </van-checkbox-group>
  21. </view>
  22. <view style="flex: 15;">
  23. <van-card
  24. title-class="changewidth"
  25. price-class ="priceClass"
  26. :price="item.goods_price"
  27. :desc="item.desarray[1]+'X'+item.goods_num"
  28. :title="item.desarray[0]"
  29. :thumb="pictureUrl + '/uploads/home/store/goods/' + item.goods_image.substr(0, item.goods_image.indexOf('\_')) + '/' + item.goods_image"
  30. >
  31. <view slot="footer">
  32. <!-- <uninumberbox :min="1":isMax="item.number>=item.stock?true:false"
  33. :isMin="item.number===1":max="item.stock" :value="item.goods_num" @change="bindChange(item)"/> -->
  34. <uninumberbox
  35. class="step"
  36. :min="1"
  37. :value="item.goods_num"
  38. :index="index"
  39. @eventChange="bindChange"
  40. ></uninumberbox>
  41. </view>
  42. </van-card>
  43. </view>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. <view v-else>
  49. <view style="margin: 120upx auto;text-align: center;">
  50. <van-icon size="160rpx" color="#909399" name="cart-o" />
  51. <view style="text-align: center;color: #909399;"> 去买点什么</view>
  52. </view>
  53. </view>
  54. <view style="position: fixed;bottom: 0;">
  55. <van-submit-bar
  56. :price="prices"
  57. :button-text="listip"
  58. @submit="onClickButton"
  59. :tip="true"
  60. >
  61. <van-checkbox checked-color="#D9332E" :value="isAll" shape="round" @change="onChange">
  62. 全选
  63. </van-checkbox>
  64. </van-submit-bar>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. import uniNavBar from '@/component/uni-nav-bar/uni-nav-bar.vue'
  70. import uninumberbox from '@/component/uinNumberCart.vue'
  71. export default {
  72. components: {
  73. uniNavBar,
  74. uninumberbox
  75. },
  76. data() {
  77. return {
  78. ismax: 0,
  79. lengthnumber: 0,
  80. pricelist:[],
  81. pictureUrl: this.pictureUrl,
  82. scrollTop: 0,
  83. old: {
  84. scrollTop: 0
  85. },
  86. store: {},
  87. ispull: true,
  88. page: 1,
  89. store_id: 0,
  90. prices: 0,
  91. listip: '',
  92. isdelete: true,
  93. isAll: false,
  94. checkboxList:[],
  95. list:[]
  96. }
  97. },
  98. // 隐藏分享菜单
  99. onLoad: function (options) {
  100. console.log(options)
  101. this.store_id = options.store_id;
  102. this.listip = '结算'+ (this.lengthnumber);
  103. this.getshoplist();
  104. },
  105. methods: {
  106. onClickButton(e) {
  107. let array = [];
  108. this.pricelist.forEach(item => {
  109. array.push(item.goods_id)
  110. })
  111. let ids = array.toString();
  112. if(this.isdelete) {
  113. if(this.pricelist.length == 0) {
  114. this.$msg('请选择商品');
  115. return;
  116. }
  117. // 结算
  118. uni.navigateTo({
  119. url: './sureBuy' // 确认订单
  120. })
  121. }else {
  122. if(ids == '') {
  123. this.$msg('请选择删除商品');
  124. return;
  125. }
  126. // 删除
  127. this.deleteshop(ids);
  128. }
  129. },
  130. deleteshop(ids) {
  131. this.request({
  132. url: '/v2/order/cart_drop',
  133. method: 'post',
  134. data: {
  135. ids: ids,
  136. store_id: this.store_id
  137. },
  138. success: () => {
  139. this.getshoplist();
  140. }
  141. })
  142. },
  143. // 滚动到顶部
  144. upper(e) {
  145. console.log("顶部")
  146. },
  147. // 滚到底部
  148. lower(e) {
  149. this.page = this.page + 1;
  150. if(this.ispull) {
  151. this.getshoplist();
  152. }
  153. },
  154. // 滚动时触发
  155. scroll(e) {
  156. this.old.scrollTop = e.detail.scrollTop
  157. },
  158. changeShop() {
  159. this.isdelete = !this.isdelete;
  160. console.log(this.lengthnumber)
  161. this.listip = this.isdelete ? "结算" + (this.lengthnumber) :'删除'+ (this.lengthnumber);
  162. },
  163. getshoplist() {
  164. this.request({
  165. url: '/v2/order/cart',
  166. method: 'post',
  167. data: {
  168. store_id: this.store_id,
  169. page: this.page
  170. },
  171. success: (res) => {
  172. let { data } = res.data;
  173. data.cart_list.forEach(item => {
  174. item.desarray = item.goods_name.split(' ')
  175. })
  176. this.list = data.cart_list;
  177. this.store = data.store;
  178. //console.log(data.cart_list[0].goods_name.split(' '));
  179. }
  180. })
  181. },
  182. // 返回上层
  183. goback() {
  184. uni.navigateBack();
  185. },
  186. // 编辑
  187. deleteShop() {
  188. },
  189. // 数量累加
  190. bindChange(e) {
  191. console.log(e);
  192. this.list[e.index].goods_num = e.number;
  193. this.checkoutprice();
  194. },
  195. // 单选
  196. checkboxChange(e) {
  197. this.checkboxList = []
  198. e.detail.forEach((item, idx) => {
  199. this.$set(this.checkboxList, idx, item)
  200. })
  201. let array = this.list;
  202. let price = [];
  203. this.checkboxList.forEach(item => {
  204. price.push(array[item])
  205. })
  206. this.pricelist = price
  207. this.lengthnumber = this.pricelist.length;
  208. this.listip = this.isdelete ? "结算" + (this.lengthnumber) :'删除'+ (this.lengthnumber);
  209. this.checkoutprice();
  210. },
  211. // 计算价格
  212. checkoutprice() {
  213. let total = 0;
  214. console.log(this.pricelist)
  215. this.pricelist.forEach(item => {
  216. total += item.goods_price * item.goods_num;
  217. })
  218. this.prices = Number(total.toFixed(2))*100;
  219. },
  220. // 全选
  221. onChange(a) {
  222. this.isAll = !this.isAll;
  223. let items = this.list;
  224. if(this.isAll) {
  225. items.forEach((item, idx) => {
  226. this.$set(this.checkboxList, idx, idx.toString())
  227. })
  228. this.pricelist = this.list;
  229. this.lengthnumber = this.pricelist.length;
  230. this.listip = this.isdelete ? "结算" + (this.lengthnumber) :'删除'+ (this.lengthnumber);
  231. this.checkoutprice();
  232. }else {
  233. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  234. this.checkboxList = []
  235. this.pricelist = this.list;
  236. this.lengthnumber = 0;
  237. this.listip = this.isdelete ? "结算" + (this.lengthnumber) :'删除'+ (this.lengthnumber);
  238. this.checkoutprice();
  239. }
  240. }
  241. }
  242. }
  243. }
  244. </script>
  245. <style>
  246. .uniNavBar {
  247. height: 100%;
  248. }
  249. .cart-list {
  250. background-color: #fff;
  251. /* padding: 0 36upx; */
  252. }
  253. .titleright {
  254. text-align: right;
  255. padding: 10upx 30upx;
  256. background: #fff;
  257. border-bottom: 1px solid #eee;
  258. }
  259. .changewidth {
  260. color: #303133;
  261. font-size: 32upx;
  262. font-weight: 100!important;
  263. width: 70%;
  264. white-space: nowrap;
  265. overflow: hidden;
  266. text-overflow: ellipsis;
  267. }
  268. .priceClass {
  269. color:#303133!important;
  270. font-weight: 100!important;
  271. font-size: 36upx;
  272. }
  273. .van-card {
  274. background-color: #fff!important;
  275. }
  276. .shoplist {
  277. display: flex;
  278. padding: 0 35upx;
  279. justify-content: space-between;
  280. align-items: center;
  281. padding-bottom: 25upx;
  282. }
  283. .checklabel {
  284. transform:scale(0.7);
  285. border-radius: 100%;
  286. }
  287. .checkboxteil {
  288. transform:scale(0.7);
  289. border-radius: 100%;
  290. }
  291. .uni-numbox {
  292. position: static!important;
  293. float: right;
  294. }
  295. </style>