cart.vue 9.1 KB

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