cart.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <view class="content">
  3. <view class="top hflex acenter jbetween">
  4. <view class="hflex acenter">
  5. <!-- <u-icon name="map-fill" color="#555555" size="13"></u-icon>
  6. <view class="top_text">{{city}}</view> -->
  7. </view>
  8. <view class="top_text" @click="manager">{{is_manager == 0?'管理':'取消'}}</view>
  9. </view>
  10. <view class="center" v-if="pageList.length>0">
  11. <block v-for="(item,index) in pageList" :key="index">
  12. <view class="box vflex">
  13. <view class="hflex acenter jbetween cell">
  14. <view class="hflex acenter">
  15. <u-checkbox-group placement="column" @change="checkboxAll(index)">
  16. <u-checkbox :value="all" :checked="isAllSelected" shape="circle"></u-checkbox>
  17. </u-checkbox-group>
  18. <view class="title text_hide" style="max-width: 450rpx;">{{item.nickname}}</view>
  19. </view>
  20. <view class="right_btn" @click="toShop(item.admin_id)">进店看看</view>
  21. </view>
  22. <block v-for="(item2,index2) in item.goods_item" :key="index2">
  23. <u-checkbox-group placement="column" @change="checkboxChange(index,index2)">
  24. <u-swipe-action :key="item2.id" :autoClose="true">
  25. <u-swipe-action-item :options="options2" @click="deleteCart(index,index2)" :autoClose="true">
  26. <view class="hflex acenter cell">
  27. <u-checkbox v-model="item2.id" :value="item2.id" :checked="item2.checked" shape="circle"></u-checkbox>
  28. <image :src="item2.show_image" mode="aspectFill" class="img"></image>
  29. <view class="vflex img_right">
  30. <view class="item_name text_hide" style="max-width: 450rpx;">{{item2.name}}</view>
  31. <view class="norm">{{item2.goods_spec}}</view>
  32. <view class="hflex acenter jbetween">
  33. <view class="text_red">¥{{item2.price_selling}}</view>
  34. <u-number-box buttonSize="25" :integer="true" :name="item2.id" v-model="item2.num" @change="valChange"></u-number-box>
  35. </view>
  36. </view>
  37. </view>
  38. </u-swipe-action-item>
  39. </u-swipe-action>
  40. </u-checkbox-group>
  41. </block>
  42. </view>
  43. </block>
  44. </view>
  45. <view class="center" v-else>
  46. <u-empty mode="car" icon="http://cdn.uviewui.com/uview/empty/car.png" text="购物车为空"></u-empty>
  47. </view>
  48. <view class="bottom hflex acenter jbetween">
  49. <view>
  50. <u-checkbox-group placement="column" @change="checkboxAll2">
  51. <u-checkbox :value="all" :checked="isAllSelected" shape="circle" label="全选"></u-checkbox>
  52. </u-checkbox-group>
  53. </view>
  54. <view class="hflex aend" v-if="is_manager == 0">
  55. <view class="bottom_num">已选{{num?num:0}}件</view>
  56. <view class="bottom_total hflex acenter jcenter">合计:<span class="text-blue">¥{{count}}</span></view>
  57. <view class="btn" @click="buy">一键结算</view>
  58. </view>
  59. <view class="hflex aend" v-if="is_manager == 1">
  60. <view class="btn2" @click="batchDelete">删除</view>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import $api from '@/static/js/api.js'
  67. var that = ''
  68. export default {
  69. data() {
  70. return {
  71. is_manager: 0,
  72. city: '北京市',
  73. pageList: [
  74. ],
  75. count: 0,
  76. num: 0,
  77. page: 1,
  78. limit: 10,
  79. total: 10,
  80. isAllSelected: false,
  81. options2: [{
  82. text: '删除'
  83. }]
  84. }
  85. },
  86. onLoad() {
  87. that = this
  88. var city = uni.getStorageSync('city')
  89. if(city) {
  90. that.city = city
  91. }
  92. that.getCart()
  93. },
  94. onShow() {
  95. var token = uni.getStorageSync('token')
  96. if(!token) {
  97. $api.info('请先登录')
  98. setTimeout(() =>{
  99. $api.jump('/pages/login/code_login')
  100. }, 1000)
  101. }
  102. },
  103. methods: {
  104. // 获取购物车列表
  105. getCart() {
  106. $api.req({
  107. url: '/data/api.Goods/goods_cart_list',
  108. data: {
  109. page: that.page
  110. }
  111. }, function(res) {
  112. if(that.page == 1) {
  113. that.pageList = res.data.list
  114. } else {
  115. that.pageList = that.pageList.concat(res.data.list)
  116. }
  117. that.total = res.data.page.total
  118. that.limit = res.data.page.limit
  119. for(var i=0;i<that.pageList.length;i++) {
  120. for(var j=0;j<that.pageList[i].goods_item.length;j++) {
  121. that.pageList[i].goods_item[j].goods_spec = $api.resetspec(that.pageList[i].goods_item[j].goods_spec)
  122. }
  123. }
  124. })
  125. },
  126. // 管理
  127. manager() {
  128. if(that.is_manager == 0) {
  129. that.is_manager = 1
  130. } else {
  131. that.is_manager = 0
  132. }
  133. },
  134. // 单个店铺全选
  135. checkboxAll(index) {
  136. // console.log(e);
  137. that.pageList[index].isAllSelected = !that.pageList[index].isAllSelected
  138. if(that.pageList[index].isAllSelected) {
  139. for(var i = 0;i<that.pageList[index].goods_item.length;i++) {
  140. that.$set(that.pageList[index].goods_item[i],'checked',true)
  141. // that.pageList[index].isAllSelected = true
  142. }
  143. } else {
  144. for(var i = 0;i<that.pageList[index].goods_item.length;i++) {
  145. that.$set(that.pageList[index].goods_item[i],'checked',false)
  146. // that.pageList[index].isAllSelected = false
  147. }
  148. }
  149. that.totalGood()
  150. },
  151. // 选择单个商品
  152. checkboxChange(index,index2) {
  153. if(that.pageList[index].goods_item[index2].checked) {
  154. that.pageList[index].goods_item[index2].checked = !that.pageList[index].goods_item[index2].checked
  155. } else {
  156. that.$set(that.pageList[index].goods_item[index2],'checked',true)
  157. }
  158. that.totalGood()
  159. },
  160. // 选择所有商品
  161. checkboxAll2() {
  162. that.isAllSelected = !that.isAllSelected
  163. if(that.isAllSelected) {
  164. for(var i = 0;i<that.pageList.length;i++) {
  165. that.pageList[i].isAllSelected = true
  166. for (var j=0;j<that.pageList[i].goods_item.length;j++) {
  167. that.$set(that.pageList[i].goods_item[j],'checked',true)
  168. }
  169. }
  170. } else {
  171. for(var i = 0;i<that.pageList.length;i++) {
  172. that.pageList[i].isAllSelected = false
  173. for (var j=0;j<that.pageList[i].goods_item.length;j++) {
  174. that.$set(that.pageList[i].goods_item[j],'checked',false)
  175. }
  176. }
  177. that.num = 0
  178. that.count = 0
  179. }
  180. that.totalGood()
  181. },
  182. // 进店看看
  183. toShop(id) {
  184. $api.jump('/page_shop/pages/good/shop?id=' + id)
  185. },
  186. // 计算选择数量和价格
  187. totalGood() {
  188. var count = 0
  189. that.count = 0
  190. that.num = 0
  191. var num = 0
  192. for(var i = 0;i<that.pageList.length;i++) {
  193. for (var j=0;j<that.pageList[i].goods_item.length;j++) {
  194. if(that.pageList[i].goods_item[j].checked) {
  195. num += that.pageList[i].goods_item[j].num
  196. count += that.pageList[i].goods_item[j].num * Number(that.pageList[i].goods_item[j].price_selling)
  197. that.count = count.toFixed(2)
  198. that.num = num
  199. }
  200. }
  201. }
  202. },
  203. // 数量
  204. valChange(e) {
  205. console.log(e.name);
  206. $api.req({
  207. url: '/data/api.Goods/goods_cart_save',
  208. data: {
  209. cart_id: e.name,
  210. num: e.value
  211. }
  212. }, function(res) {
  213. if(res.code == 1) {
  214. $api.info(res.info)
  215. // that.getCart()
  216. that.totalGood()
  217. }
  218. })
  219. },
  220. // 删除
  221. deleteCart(index,index2) {
  222. $api.req({
  223. url: '/data/api.Goods/goods_cart_del',
  224. data: {
  225. cart_ids: that.pageList[index].goods_item[index2].id
  226. }
  227. }, function(res) {
  228. if(res.code == 1) {
  229. $api.info(res.info)
  230. that.getCart()
  231. }
  232. })
  233. },
  234. batchDelete() {
  235. var cart_ids = []
  236. for(var i = 0;i<that.pageList.length;i++) {
  237. for (var j=0;j<that.pageList[i].goods_item.length;j++) {
  238. if(that.pageList[i].goods_item[j].checked) {
  239. cart_ids.push(that.pageList[i].goods_item[j].id)
  240. }
  241. }
  242. }
  243. cart_ids = cart_ids.toString()
  244. $api.req({
  245. url: '/data/api.Goods/goods_cart_del',
  246. data: {
  247. cart_ids: cart_ids
  248. }
  249. }, function(res) {
  250. if(res.code == 1) {
  251. $api.info(res.info)
  252. that.getCart()
  253. }
  254. })
  255. },
  256. buy() {
  257. var address_id = uni.getStorageSync('address_id')
  258. var url = ''
  259. var cart_ids = []
  260. var data = []
  261. var good_item = []
  262. for(var i = 0;i<that.pageList.length;i++) {
  263. for (var j=0;j<that.pageList[i].goods_item.length;j++) {
  264. if(that.pageList[i].goods_item[j].checked) {
  265. cart_ids.push(that.pageList[i].goods_item[j].id)
  266. good_item.push(that.pageList[i].goods_item[j])
  267. }
  268. }
  269. var item = {
  270. nickname: that.pageList[i].nickname,
  271. goods_item: good_item
  272. }
  273. if(good_item.length !== 0) {
  274. data.push(item)
  275. }
  276. good_item = []
  277. }
  278. if(cart_ids.length == 0) {
  279. $api.info('请先选择商品')
  280. return
  281. }
  282. cart_ids = cart_ids.toString()
  283. if(address_id) {
  284. url = '/page_shop/pages/good/submit?data=' + JSON.stringify(data) + '&cart_ids=' + cart_ids + '&address_id=' + address_id
  285. } else {
  286. url = '/page_shop/pages/good/submit?data=' + JSON.stringify(data) + '&cart_ids=' + cart_ids
  287. }
  288. $api.jump(url)
  289. /* for(var i = 0;i<that.pageList.length;i++) {
  290. for (var j=0;j<that.pageList[i].goods_item.length;j++) {
  291. if(that.pageList[i].goods_item[j].checked) {
  292. cart_ids.push(that.pageList[i].goods_item[j].id)
  293. good_item.push(that.pageList[i].goods_item[j])
  294. }
  295. }
  296. var item = {
  297. nickname: that.pageList[i].nickname,
  298. goods_item: good_item
  299. }
  300. if(good_item.length !== 0) {
  301. data.push(item)
  302. }
  303. good_item = []
  304. }
  305. cart_ids = cart_ids.toString()
  306. $api.jump('/page_shop/pages/good/submit?pay_no=' + pay_no + '&data=' + JSON.stringify(data) + '&address_id=' + address_id)
  307. $api.req({
  308. url: '/data/api.Order/crat_create',
  309. method: 'POST',
  310. data: {
  311. cart_ids: cart_ids,
  312. address_id: address_id
  313. }
  314. }, function(res) {
  315. if(res.code == 1) {
  316. $api.info(res.info)
  317. var pay_no = res.data
  318. $api.jump('/page_shop/pages/good/submit?pay_no=' + pay_no + '&data=' + JSON.stringify(data) + '&address_id=' + address_id)
  319. }
  320. }) */
  321. },
  322. onReachBottom() {
  323. if (Number(that.page) * Number(that.limit) >= Number(that.total)) {
  324. // $api.info("没有更多了")
  325. } else {
  326. that.page++
  327. that.getCart()
  328. }
  329. }
  330. },
  331. }
  332. </script>
  333. <style lang="scss" scoped>
  334. .content::v-deep {
  335. background: #F5F5F5;
  336. .top {
  337. width: 100%;
  338. height: 80rpx;
  339. background: #FFFFFF;
  340. box-sizing: border-box;
  341. padding: 20rpx 30rpx;
  342. .top_text {
  343. font-size: 28rpx;
  344. font-weight: 400;
  345. color: #555555;
  346. line-height: 40rpx;
  347. padding-left: 6rpx;
  348. }
  349. }
  350. .center {
  351. width: 100%;
  352. box-sizing: border-box;
  353. padding: 0 30rpx;
  354. margin-bottom: 186rpx;
  355. .box {
  356. width: 100%;
  357. background: #FFFFFF;
  358. border-radius: 14px;
  359. margin-top: 20rpx;
  360. box-sizing: border-box;
  361. padding: 10rpx 20rpx;
  362. .cell {
  363. padding: 10rpx 0;
  364. }
  365. .title {
  366. font-size: 30rpx;
  367. font-weight: 500;
  368. color: #222222;
  369. line-height: 42rpx;
  370. }
  371. .right_btn {
  372. width: 112rpx;
  373. height: 36rpx;
  374. background: #EDF0FF;
  375. border-radius: 18rpx;
  376. text-align: center;
  377. font-size: 20rpx;
  378. font-weight: 400;
  379. color: #506DFF;
  380. line-height: 36rpx;
  381. }
  382. .img {
  383. width: 128rpx;
  384. height: 128rpx;
  385. border-radius: 12rpx;
  386. margin: 0 20rpx 0 16rpx;
  387. }
  388. .img_right {
  389. width: calc(100% - 188rpx);
  390. }
  391. .item_name {
  392. font-size: 28rpx;
  393. font-weight: 400;
  394. color: #222222;
  395. line-height: 40rpx;
  396. // padding-bottom: 32rpx;
  397. }
  398. .norm {
  399. max-width: 400rpx;
  400. width: max-content;
  401. margin: 12rpx 0;
  402. background: #F5F5F5;
  403. border-radius: 2px;
  404. box-sizing: border-box;
  405. padding: 8rpx 24rpx 8rpx 12rpx;
  406. font-size: 20rpx;
  407. font-weight: 400;
  408. color: #888888;
  409. line-height: 28rpx;
  410. text-overflow: ellipsis;
  411. overflow: hidden;
  412. display: -webkit-box;
  413. -webkit-box-orient: vertical;
  414. box-orient: vertical;
  415. line-clamp: 2;
  416. -webkit-line-clamp: 2;
  417. }
  418. .text_red {
  419. font-size: 28rpx;
  420. font-weight: bold;
  421. color: #FF4747;
  422. line-height: 32rpx;
  423. }
  424. .u-number-box {
  425. // width: 152rpx;
  426. // height: 40rpx !important;
  427. .input {
  428. // min-height: 40rpx !important;
  429. }
  430. .u-number-box__minus {
  431. border-radius: 20rpx 0 0 20rpx;
  432. }
  433. .u-number-box__input {
  434. margin: 0 !important;
  435. min-height: 40rpx !important;
  436. }
  437. .u-number-box__plus {
  438. border-radius: 0 20rpx 20rpx 0;
  439. }
  440. }
  441. }
  442. }
  443. .bottom {
  444. width: 100%;
  445. z-index: 9999;
  446. position: fixed;
  447. bottom: 0;
  448. height: 166rpx;
  449. background: #FFFFFF;
  450. box-sizing: border-box;
  451. padding: 8rpx 30rpx 74rpx;
  452. .bottom_num {
  453. font-size: 20rpx;
  454. font-weight: 400;
  455. color: #939393;
  456. line-height: 34rpx;
  457. padding-bottom: 16rpx;
  458. }
  459. .bottom_total {
  460. font-size: 24rpx;
  461. font-weight: 400;
  462. color: #222222;
  463. line-height: 34rpx;
  464. padding-bottom: 16rpx;
  465. }
  466. .text-blue {
  467. font-size: 34rpx;
  468. font-weight: 400;
  469. color: #5270FF;
  470. }
  471. .btn {
  472. width: 232rpx;
  473. height: 88rpx;
  474. background: #506DFF;
  475. border-radius: 44rpx;
  476. font-size: 36rpx;
  477. font-weight: 500;
  478. color: #FFFFFF;
  479. line-height: 88rpx;
  480. text-align: center;
  481. }
  482. .btn2 {
  483. width: 200rpx;
  484. height: 80rpx;
  485. border-radius: 44rpx;
  486. border: 1px solid #506DFF;
  487. font-size: 36rpx;
  488. font-weight: 500;
  489. color: #506DFF;
  490. line-height: 80rpx;
  491. text-align: center;
  492. }
  493. }
  494. .u-page {
  495. padding: 0;
  496. }
  497. .u-demo-block__title {
  498. padding: 10px 0 2px 15px;
  499. }
  500. .swipe-action {
  501. &__content {
  502. padding: 25rpx 0;
  503. &__text {
  504. font-size: 15px;
  505. color: $u-main-color;
  506. padding-left: 30rpx;
  507. }
  508. }
  509. }
  510. .u-swipe-action-item__right__button__wrapper {
  511. background-color: #FF4C4C !important;
  512. }
  513. .u-swipe-action-item__right {
  514. width: 114rpx;
  515. height: 128rpx;
  516. margin: 0 0 30rpx;
  517. }
  518. }
  519. </style>