cart.vue 15 KB

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