cart.vue 9.6 KB

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