cart.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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;" @click.stop="checkboxChange()">
  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. if(res.data.code == 1000) {
  162. let order_id = res.data.data.order_id;
  163. let store = this.store.store_id;
  164. uni.navigateTo({
  165. url: `/pages/index/sureBuy?store=${store}&prices=${prices}&order_id=${order_id}`
  166. });
  167. }
  168. }
  169. })
  170. },
  171. deleteshop(ids) {
  172. this.request({
  173. url: '/v2/order/cart_drop',
  174. method: 'post',
  175. data: {
  176. ids: ids,
  177. store_id: this.store_id
  178. },
  179. success: () => {
  180. this.getshoplist();
  181. }
  182. })
  183. },
  184. // 滚动到顶部
  185. upper(e) {
  186. console.log("顶部")
  187. },
  188. // 滚到底部
  189. lower(e) {
  190. this.page = this.page + 1;
  191. if(this.ispull) {
  192. this.getshoplist();
  193. }
  194. },
  195. // 滚动时触发
  196. scroll(e) {
  197. this.old.scrollTop = e.detail.scrollTop
  198. },
  199. changeShop() {
  200. this.isdelete = !this.isdelete;
  201. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  202. },
  203. getshoplist() {
  204. this.request({
  205. url: '/v2/order/cart',
  206. method: 'post',
  207. data: {
  208. store_id: this.store_id,
  209. page: this.page
  210. },
  211. success: (res) => {
  212. let { data } = res.data;
  213. data.cart_list.forEach(item => {
  214. let arr = item.goods_name.split(' ');
  215. item.desarray = arr[0];
  216. item.descire = item.goods_name.replace(arr[0], '');
  217. })
  218. this.list = data.cart_list;
  219. this.store = data.store;
  220. //console.log(data.cart_list[0].goods_name.split(' '));
  221. }
  222. })
  223. },
  224. // 返回上层
  225. goback() {
  226. uni.navigateBack();
  227. },
  228. // 编辑
  229. deleteShop() {
  230. },
  231. // 数量累加
  232. bindChange(e) {
  233. this.list[e.index].goods_num = e.number;
  234. this.checkoutprice();
  235. },
  236. // 单选
  237. checkboxChange(e) {
  238. console.log("kkkk")
  239. this.checkboxList = []
  240. e.detail.forEach((item, idx) => {
  241. this.$set(this.checkboxList, idx, item)
  242. })
  243. let array = this.list;
  244. let price = [];
  245. this.checkboxList.forEach(item => {
  246. price.push(array[item])
  247. })
  248. this.pricelist = price;
  249. let num = 0
  250. this.pricelist.forEach(item => {
  251. num += item.goods_num;
  252. })
  253. this.nums = num;
  254. this.lengthnumber = this.pricelist.length;
  255. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  256. this.checkoutprice();
  257. },
  258. // 计算价格
  259. checkoutprice() {
  260. let total = 0;
  261. let num = 0
  262. this.pricelist.forEach(item => {
  263. total += item.goods_price * item.goods_num;
  264. num += item.goods_num;
  265. })
  266. this.nums = num;
  267. this.prices = Number(total.toFixed(2))*100;
  268. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  269. },
  270. // 全选
  271. onChange(a) {
  272. this.isAll = !this.isAll;
  273. let items = this.list;
  274. if(this.isAll) {
  275. items.forEach((item, idx) => {
  276. this.$set(this.checkboxList, idx, idx.toString())
  277. })
  278. this.pricelist = this.list;
  279. let num = 0
  280. this.pricelist.forEach(item => {
  281. num += item.goods_num;
  282. })
  283. this.nums = num;
  284. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  285. this.checkoutprice();
  286. }else {
  287. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  288. this.checkboxList = [];
  289. this.pricelist = [];
  290. this.nums = 0;
  291. this.listip = this.isdelete ? "结算" + '(' + this.nums + ')' :'删除'+ '(' + this.nums + ')';
  292. this.checkoutprice();
  293. }
  294. }
  295. }
  296. }
  297. }
  298. </script>
  299. <style>
  300. .betweenclass {
  301. display: flex;
  302. justify-content: space-between!important;
  303. }
  304. .uniNavBar {
  305. height: 100%;
  306. }
  307. .cart-list {
  308. background-color: #fff;
  309. /* padding: 0 36upx; */
  310. }
  311. .titleright {
  312. text-align: right;
  313. padding: 10upx 30upx;
  314. background: #fff;
  315. border-bottom: 1px solid #eee;
  316. height: 4vh;
  317. }
  318. .changewidth {
  319. color: #303133;
  320. font-size: 32upx;
  321. font-weight: 100!important;
  322. width: 70%;
  323. white-space: nowrap;
  324. overflow: hidden;
  325. text-overflow: ellipsis;
  326. }
  327. .van-card {
  328. background-color: #fff!important;
  329. }
  330. .shoplist {
  331. display: flex;
  332. padding: 0 35upx;
  333. justify-content: space-between;
  334. align-items: center;
  335. padding-bottom: 25upx;
  336. }
  337. .checklabel {
  338. transform:scale(0.7);
  339. border-radius: 100%;
  340. }
  341. .checkboxteil {
  342. transform:scale(0.7);
  343. border-radius: 100%;
  344. }
  345. .uni-numbox {
  346. position: static!important;
  347. float: right;
  348. }
  349. .isdiaplay .van-submit-bar__text {
  350. visibility: hidden;
  351. }
  352. .isdiaplay {
  353. visibility: hidden;
  354. }
  355. </style>