cart.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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" style="margin-bottom: 150upx;">
  6. <scroll-view style="height: 88vh;" class="floor-list"
  7. :scroll-top="scrollTop" scroll-y="true" @scroll="scroll" @scrolltoupper="upper" @scrolltolower="lower"
  8. :refresher-enabled="false">
  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.descire+'X'+item.goods_num"
  28. :title="item.desarray"
  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;border-top:1px solid #eee;height: 8vh;">
  55. <!-- :price-class="isdelete? '':'isdiaplay' " -->
  56. <van-submit-bar
  57. v-if="isdelete"
  58. :price="prices"
  59. :button-text="listip"
  60. @submit="onClickButton"
  61. :tip="true"
  62. >
  63. <van-checkbox checked-color="#D9332E" :value="isAll" shape="round" @change="onChange">
  64. 全选
  65. </van-checkbox>
  66. </van-submit-bar>
  67. <van-submit-bar
  68. bar-class="betweenclass"
  69. v-if="!isdelete"
  70. :button-text="listip"
  71. @submit="onClickButton"
  72. :tip="true"
  73. >
  74. <van-checkbox checked-color="#D9332E" :value="isAll" shape="round" @change="onChange">
  75. 全选
  76. </van-checkbox>
  77. </van-submit-bar>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import uniNavBar from '@/component/uni-nav-bar/uni-nav-bar.vue'
  83. import uninumberbox from '@/component/uinNumberCart.vue'
  84. export default {
  85. components: {
  86. uniNavBar,
  87. uninumberbox
  88. },
  89. data() {
  90. return {
  91. ismax: 0,
  92. lengthnumber: 0,
  93. pricelist:[],
  94. pictureUrl: this.pictureUrl,
  95. scrollTop: 0,
  96. old: {
  97. scrollTop: 0
  98. },
  99. nums: 0,
  100. store: {},
  101. ispull: true,
  102. page: 1,
  103. store_id: 0,
  104. prices: 0,
  105. listip: '',
  106. isdelete: true,
  107. isAll: false,
  108. checkboxList:[],
  109. list:[]
  110. }
  111. },
  112. // 隐藏分享菜单
  113. onLoad: function (options) {
  114. this.store_id = options.store_id;
  115. this.listip = "结算" + '(' + this.nums + ')';
  116. this.getshoplist();
  117. },
  118. methods: {
  119. onClickButton(e) {
  120. let array = [];
  121. if(this.pricelist.length == 0) {
  122. this.$msg('请选择商品');
  123. return;
  124. }
  125. this.pricelist.forEach(item => {
  126. array.push(item.goods_id)
  127. })
  128. let ids = array.toString();
  129. if(this.isdelete) {
  130. // 结算
  131. this.getorderId(); // 保存订单生成订单id
  132. uni.navigateTo({
  133. // url: `/pages/index/sureBuy?store=${store}&pricelist=${pricelist}&prices=${prices}`
  134. });
  135. }else {
  136. if(ids == '') {
  137. this.$msg('请选择删除商品');
  138. return;
  139. }
  140. // 删除
  141. this.deleteshop(ids);
  142. }
  143. },
  144. // 保存订单生成订单id
  145. getorderId() {
  146. let goods = [];
  147. let prices = this.prices;
  148. this.pricelist.forEach((item,index) => {
  149. goods.push({});
  150. goods[index].goods_id = item.goods_id;
  151. goods[index].buy_num = item.goods_num;
  152. })
  153. this.request({
  154. url:'/v1/order/save_og',
  155. method: 'post',
  156. data: {
  157. store_id: this.store.store_id,
  158. goods: JSON.stringify(goods)
  159. },
  160. success:(res) => {
  161. let order_id = res.data.data.order_id;
  162. let store = this.store.store_id;
  163. uni.navigateTo({
  164. url: `/pages/index/sureBuy?store=${store}&prices=${prices}&order_id=${order_id}`
  165. });
  166. }
  167. })
  168. },
  169. deleteshop(ids) {
  170. this.request({
  171. url: '/v2/order/cart_drop',
  172. method: 'post',
  173. data: {
  174. ids: ids,
  175. store_id: this.store_id
  176. },
  177. success: () => {
  178. this.getshoplist();
  179. }
  180. })
  181. },
  182. // 滚动到顶部
  183. upper(e) {
  184. console.log("顶部")
  185. },
  186. // 滚到底部
  187. lower(e) {
  188. this.page = this.page + 1;
  189. if(this.ispull) {
  190. this.getshoplist();
  191. }
  192. },
  193. // 滚动时触发
  194. scroll(e) {
  195. this.old.scrollTop = e.detail.scrollTop
  196. },
  197. changeShop() {
  198. this.isdelete = !this.isdelete;
  199. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  200. },
  201. getshoplist() {
  202. this.request({
  203. url: '/v2/order/cart',
  204. method: 'post',
  205. data: {
  206. store_id: this.store_id,
  207. page: this.page
  208. },
  209. success: (res) => {
  210. let { data } = res.data;
  211. data.cart_list.forEach(item => {
  212. let arr = item.goods_name.split(' ');
  213. item.desarray = arr[0];
  214. item.descire = item.goods_name.replace(arr[0], '');
  215. })
  216. this.list = data.cart_list;
  217. this.store = data.store;
  218. //console.log(data.cart_list[0].goods_name.split(' '));
  219. }
  220. })
  221. },
  222. // 返回上层
  223. goback() {
  224. uni.navigateBack();
  225. },
  226. // 编辑
  227. deleteShop() {
  228. },
  229. // 数量累加
  230. bindChange(e) {
  231. this.list[e.index].goods_num = e.number;
  232. this.checkoutprice();
  233. },
  234. // 单选
  235. checkboxChange(e) {
  236. this.checkboxList = []
  237. e.detail.forEach((item, idx) => {
  238. this.$set(this.checkboxList, idx, item)
  239. })
  240. let array = this.list;
  241. let price = [];
  242. this.checkboxList.forEach(item => {
  243. price.push(array[item])
  244. })
  245. this.pricelist = price;
  246. let num = 0
  247. this.pricelist.forEach(item => {
  248. num += item.goods_num;
  249. })
  250. this.nums = num;
  251. this.lengthnumber = this.pricelist.length;
  252. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  253. this.checkoutprice();
  254. },
  255. // 计算价格
  256. checkoutprice() {
  257. let total = 0;
  258. let num = 0
  259. this.pricelist.forEach(item => {
  260. total += item.goods_price * item.goods_num;
  261. num += item.goods_num;
  262. })
  263. this.nums = num;
  264. this.prices = Number(total.toFixed(2))*100;
  265. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  266. },
  267. // 全选
  268. onChange(a) {
  269. this.isAll = !this.isAll;
  270. let items = this.list;
  271. if(this.isAll) {
  272. items.forEach((item, idx) => {
  273. this.$set(this.checkboxList, idx, idx.toString())
  274. })
  275. this.pricelist = this.list;
  276. let num = 0
  277. this.pricelist.forEach(item => {
  278. num += item.goods_num;
  279. })
  280. this.nums = num;
  281. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  282. this.checkoutprice();
  283. }else {
  284. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  285. this.checkboxList = [];
  286. this.pricelist = [];
  287. this.nums = 0;
  288. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  289. this.checkoutprice();
  290. }
  291. }
  292. }
  293. }
  294. }
  295. </script>
  296. <style>
  297. .betweenclass {
  298. display: flex;
  299. justify-content: space-between!important;
  300. }
  301. .uniNavBar {
  302. height: 100%;
  303. }
  304. .cart-list {
  305. background-color: #fff;
  306. /* padding: 0 36upx; */
  307. }
  308. .titleright {
  309. text-align: right;
  310. padding: 10upx 30upx;
  311. background: #fff;
  312. border-bottom: 1px solid #eee;
  313. height: 4vh;
  314. }
  315. .changewidth {
  316. color: #303133;
  317. font-size: 32upx;
  318. font-weight: 100!important;
  319. width: 70%;
  320. white-space: nowrap;
  321. overflow: hidden;
  322. text-overflow: ellipsis;
  323. }
  324. .van-card {
  325. background-color: #fff!important;
  326. }
  327. .shoplist {
  328. display: flex;
  329. padding: 0 35upx;
  330. justify-content: space-between;
  331. align-items: center;
  332. padding-bottom: 25upx;
  333. }
  334. .checklabel {
  335. transform:scale(0.7);
  336. border-radius: 100%;
  337. }
  338. .checkboxteil {
  339. transform:scale(0.7);
  340. border-radius: 100%;
  341. }
  342. .uni-numbox {
  343. position: static!important;
  344. float: right;
  345. }
  346. .isdiaplay .van-submit-bar__text {
  347. visibility: hidden;
  348. }
  349. .isdiaplay {
  350. visibility: hidden;
  351. }
  352. </style>