cart.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <div class="mobile-fix-content mobile-centerfix-content mobile-cart" :class="{'empty-mobile-cart': !cartList.length}" id="mobileFixContent">
  3. <template v-if="cartList.length">
  4. <ul class="store-list">
  5. <li class="store-item" v-for="(item, storeIndex) in cartList">
  6. <div class="store-info">
  7. <label class="mobile-cart-check" :class="{'active': item.$active}">
  8. <input type="checkbox" @change="setActive('store', storeIndex)">
  9. </label>
  10. <span class="store-tag inline-block" :style="getStoreTypeColor(item.storeType)">{{item.storeType | storeTypeFilter}}</span>
  11. <p class="store-name inline-block text-ellipse">卖&nbsp;&nbsp;家:{{item.storeName}}</p>
  12. <a class="com-mobile-link" @click="linkSaler(item)"><i class="iconfont icon-kefu1"></i>联系卖家</a>
  13. </div>
  14. <ul class="goods-list">
  15. <li class="goods-item" v-for="(goods, goodsIndex) in item.goods">
  16. <div style="padding: .3rem .25rem">
  17. <label class="mobile-cart-check" :class="{'active': goods.$active}">
  18. <input type="checkbox" @change="setActive('goods', storeIndex, goodsIndex)">
  19. </label>
  20. <div class="params inline-block">
  21. <p class="param text-ellipse"><span class="title">品牌:</span>{{goods.goods.brandNameEn || '-'}}</p>
  22. <p class="param text-ellipse"><span class="title">物料名称(类目):</span>{{goods.kiName || '-'}}</p>
  23. <p class="param text-ellipse"><span class="title">型号:</span>{{goods.code || '-'}}</p>
  24. <p class="param text-ellipse"><span class="title">规格:</span>{{goods.spec || '-'}}</p>
  25. </div>
  26. <div class="inline-block params param-operate">
  27. <p class="param text-ellipse"><span class="title">交期(天):</span>{{goods.goods.b2cMinDelivery + '-' + goods.goods.b2cMaxDelivery}}</p>
  28. <p class="param text-ellipse"><span class="title">单价:</span>{{baseUtils.getPriceByLevel(goods.goods.prices, goods.number, goods.currencyName)}}</p>
  29. <p class="param text-ellipse"><span class="title">起拍:</span>{{goods.goods.minBuyQty}}</p>
  30. <p class="param"><span class="title">数量(PCS):</span>
  31. <span class="input-line inline-block">
  32. <span class="inline-block" @click="setGoods('sub', goods)" :class="{disab: !goods.goods.canSub}">-</span>
  33. <input type="number" v-model="goods.goods.purchaseNumber" @blur="setGoods('set', goods)">
  34. <span class="inline-block" @click="setGoods('add', goods)" :class="{disab: !goods.goods.canAdd}">+</span>
  35. </span>
  36. </p>
  37. <!--<div class="price-line">
  38. <span>{{goods.currencyName | currencyFilter}}</span>{{goods.goods.currentPrice}}
  39. </div>-->
  40. </div>
  41. </div>
  42. <div class="single-count text-ellipse"><span class="title">小计:</span><span class="ol-price"><span>{{goods.currencyName | currencyFilter}}</span>{{goods.goods.currentPrice}}</span></div>
  43. </li>
  44. </ul>
  45. </li>
  46. </ul>
  47. <div class="buy-wrap">
  48. <div class="wrap-select line">
  49. <label class="mobile-cart-check" :class="{'active': isAllChecked}">
  50. <input type="checkbox" @change="setActive('all')">
  51. <span>全选</span>
  52. </label>
  53. <a class="operate-btn fr" @click="removeInvalidGoods">清空失效产品</a>
  54. <a class="operate-btn fr" @click="batchDelete">批量删除</a>
  55. </div>
  56. <div class="wrap-count line">
  57. <!--<i class="fare">不含运费</i>-->
  58. <span class="title">合计:</span><span class="price"><span v-show="allCount > 0">{{allCurrency | currencyFilter}}</span>{{allPrice}}</span>
  59. <button class="buy-btn" @click="submit">结算({{allCount}})</button>
  60. </div>
  61. </div>
  62. </template>
  63. <template v-else>
  64. <empty-status :text="'购物车空空如也,快去添加商品吧!'"></empty-status>
  65. </template>
  66. <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
  67. <pull-up :fixId="'mobileFixContent'" :searchMore="fetching" :allPage="allPage" :page="page" @pullUpAction="onPullUpAction"></pull-up>
  68. <link-user :infoObj="currentStoreInfo"
  69. :showLink="showLink"
  70. @closeAction="showLink = false"></link-user>
  71. </div>
  72. </template>
  73. <script>
  74. import {RemindBox, PullUp, EmptyStatus} from '~components/mobile/common'
  75. import {LinkUser} from '~components/mobile/base'
  76. import { goodsPurchaseOperate } from '~utils/mixin'
  77. export default {
  78. layout: 'mobile',
  79. middleware: 'authenticated',
  80. data () {
  81. return {
  82. cartList: [],
  83. remindText: '',
  84. timeoutCount: '',
  85. isAllChecked: false,
  86. page: 1,
  87. count: 10,
  88. allCurrency: 'RMB', // 选定币别
  89. currentStoreInfo: {},
  90. showLink: false,
  91. isChange: false
  92. }
  93. },
  94. mixins: [goodsPurchaseOperate],
  95. components: {
  96. RemindBox,
  97. PullUp,
  98. LinkUser,
  99. EmptyStatus
  100. },
  101. fetch ({ store }) {
  102. return Promise.all([
  103. store.dispatch('userCenter/loadCartList', {page: 1, count: 10})
  104. ])
  105. },
  106. watch: {
  107. '$store.state.userCenter.list.cart.data': {
  108. handler: function (val) {
  109. let tmpVal = this.baseUtils.deepCopy(val)
  110. // this.cartList = []
  111. if (this.isChange) {
  112. this.cartList = []
  113. }
  114. tmpVal.content.forEach(item => {
  115. let current = this.cartList.find(objItem => {
  116. return objItem.storeUuid === item.storeUuid
  117. })
  118. item.$active = false
  119. // 初始化购买数量及状态
  120. this.initGoodsStatus(item.goods)
  121. if (!current) {
  122. this.cartList.push({
  123. storeName: item.storeName,
  124. storeType: item.storeType,
  125. storeUuid: item.storeUuid,
  126. enterprise: item.storeEnterprise.enterpriseInfo,
  127. goods: [item],
  128. $active: false
  129. })
  130. } else {
  131. current.goods.push(item)
  132. }
  133. })
  134. this.checkAll()
  135. },
  136. immediate: true
  137. }
  138. },
  139. computed: {
  140. cartData () {
  141. return this.$store.state.userCenter.list.cart.data
  142. },
  143. fetching () {
  144. return this.$store.state.userCenter.list.cart.fetching
  145. },
  146. allPage () {
  147. return this.cartData.totalPages
  148. },
  149. // 已选goods
  150. allActiveObj () {
  151. let arr = []
  152. this.cartList.forEach(item => {
  153. item.goods.forEach(goodsItem => {
  154. if (goodsItem.$active) {
  155. arr.push(goodsItem)
  156. }
  157. })
  158. })
  159. return arr
  160. },
  161. // 统计价格
  162. allPrice () {
  163. let price = 0
  164. this.allActiveObj.forEach(item => {
  165. price += Number(item.goods.currentPrice)
  166. })
  167. return this.baseUtils.priceFixed(price)
  168. },
  169. // 统计数量
  170. allCount () {
  171. return this.allActiveObj.length
  172. }
  173. },
  174. methods: {
  175. getStoreTypeColor: function (type) {
  176. let tmp = null
  177. switch (type) {
  178. case 'CONSIGNMENT':
  179. tmp = '#f3393a'
  180. break
  181. case 'DISTRIBUTION':
  182. tmp = '#4083f6'
  183. break
  184. case 'AGENCY':
  185. tmp = '#15b262'
  186. break
  187. case 'ORIGINAL_FACTORY':
  188. tmp = '#ff6300'
  189. break
  190. }
  191. if (tmp) {
  192. return `background: ${tmp};`
  193. } else {
  194. return ''
  195. }
  196. },
  197. setRemindText: function (str) {
  198. this.remindText = str
  199. this.timeoutCount++
  200. },
  201. checkCurrency: function (currency, callback) {
  202. if (currency === this.allCurrency) {
  203. callback.call()
  204. } else {
  205. this.setRemindText('所选产品币别与已选产品不是同一币别')
  206. }
  207. },
  208. setActive (type, storeIndex, goodsIndex, goodsCheckFlag) {
  209. if (type === 'store') {
  210. let storeActive = this.cartList[storeIndex].$active
  211. for (let i = 0; i < this.cartList[storeIndex].goods.length; i++) {
  212. this.setActive('goods', storeIndex, i, !storeActive)
  213. }
  214. // this.cartList[storeIndex].goods.forEach(item => {
  215. // this.checkCurrency(item.goods.currencyName, () => {
  216. // item.$active = !this.cartList[storeIndex].$active
  217. // })
  218. // })
  219. this.checkAll()
  220. } else if (type === 'goods') {
  221. if (!this.allActiveObj[0]) {
  222. this.allCurrency = this.cartList[storeIndex].goods[goodsIndex].currencyName
  223. }
  224. this.checkCurrency(this.cartList[storeIndex].goods[goodsIndex].currencyName, () => {
  225. this.cartList[storeIndex].goods[goodsIndex].$active = typeof goodsCheckFlag === 'undefined' ? !this.cartList[storeIndex].goods[goodsIndex].$active : goodsCheckFlag
  226. // this.cartList[storeIndex].$active = !this.cartList[storeIndex].goods.find(item => {
  227. // return !item.$active
  228. // })
  229. this.checkAll()
  230. })
  231. } else if (type === 'all') {
  232. let activeFlag = true
  233. this.cartList.forEach(item => {
  234. item.goods.forEach(goodsItem => {
  235. if (!goodsItem.$active) {
  236. activeFlag = false
  237. }
  238. })
  239. })
  240. for (let i = 0; i < this.cartList.length; i++) {
  241. this.cartList[i].$active = activeFlag
  242. this.setActive('store', i)
  243. }
  244. this.checkAll()
  245. }
  246. },
  247. // 总勾选校验
  248. checkAll: function () {
  249. let activeFlag = true
  250. this.cartList.forEach(item => {
  251. let itemActive = true
  252. item.goods.forEach(goodsItem => {
  253. if (!goodsItem.$active) {
  254. activeFlag = false
  255. itemActive = false
  256. }
  257. })
  258. item.$active = itemActive
  259. })
  260. this.isAllChecked = activeFlag
  261. },
  262. onPullUpAction: function () {
  263. this.page++
  264. this.reloadList()
  265. },
  266. reloadList: function () {
  267. this.$store.dispatch('userCenter/loadCartList', {page: this.page, count: this.count})
  268. },
  269. submit: function () {
  270. if (!this.allCount) {
  271. this.setRemindText('请勾选要生成订单的批次')
  272. return
  273. }
  274. let arrOD = []
  275. this.allActiveObj.forEach(item => {
  276. arrOD.push({
  277. batchCode: item.goods.batchCode,
  278. minPackQty: item.goods.minPackQty,
  279. number: item.goods.purchaseNumber,
  280. storeid: item.storeUuid
  281. })
  282. })
  283. console.log(arrOD)
  284. this.$http.post('/trade/order/saveByGroup', {
  285. arrOD: arrOD,
  286. currency: this.allCurrency
  287. }).then(res => {
  288. console.log(res.data)
  289. if (res.data.code === 1) {
  290. if (res.data.message) {
  291. this.setRemindText(res.data.message)
  292. }
  293. this.$router.push(`/mobile/center/user/pay/${this.baseUtils.enidfilter(res.data.data.orderid)}`)
  294. } else if (res.data.code === 7) {
  295. this.setRemindText('选中的购物车信息已经失效,将为您刷新界面之后重新操作')
  296. setTimeout(() => {
  297. this.page = 1
  298. this.cartList = []
  299. this.reloadList()
  300. }, 1500)
  301. } else {
  302. this.setRemindText(res.data.message)
  303. }
  304. }, err => {
  305. console.log(err.response.data.data || '系统错误')
  306. this.setRemindText(err.response.data.data || '系统错误')
  307. })
  308. },
  309. linkSaler (item) {
  310. this.currentStoreInfo = item.enterprise
  311. this.showLink = true
  312. },
  313. removeInvalidGoods () {
  314. let arr = []
  315. this.allActiveObj.forEach(item => {
  316. if (item.status === 1) {
  317. arr.push(item.id)
  318. }
  319. })
  320. if (!arr.length) {
  321. this.setRemindText('购物车内目前没有失效的产品')
  322. } else {
  323. this.doDelete(arr, '成功清除购物车内的无效产品')
  324. }
  325. },
  326. batchDelete () {
  327. if (!this.allActiveObj.length) {
  328. this.setRemindText('请选择要删除的商品')
  329. } else {
  330. let arr = []
  331. this.allActiveObj.forEach(item => {
  332. arr.push(item.id)
  333. })
  334. this.doDelete(arr, '删除成功')
  335. }
  336. },
  337. doDelete (idArr, successStr) {
  338. this.$http.delete(`/trade/cart/deleteById?ids=${JSON.stringify(idArr)}`).then(res => {
  339. this.isChange = true
  340. this.page = 1
  341. this.reloadList()
  342. this.setRemindText(successStr)
  343. }, err => {
  344. this.setRemindText(err.response.data || '系统错误')
  345. })
  346. }
  347. }
  348. }
  349. </script>
  350. <style lang="scss" scoped>
  351. .mobile-cart {
  352. bottom: 3.02rem;
  353. &.empty-mobile-cart {
  354. bottom: .98rem;
  355. }
  356. .store-list {
  357. .store-item {
  358. background: #fff;
  359. margin: .19rem 0;
  360. .store-info {
  361. height: .9rem;
  362. line-height: .9rem;
  363. padding: 0 .25rem;
  364. .store-tag {
  365. width: .54rem;
  366. height: .3rem;
  367. line-height: .3rem;
  368. text-align: center;
  369. font-size: .24rem;
  370. color: #fff;
  371. background: #15b262;
  372. border-radius: .04rem;
  373. margin-left: .18rem;
  374. }
  375. .store-name {
  376. font-size: .28rem;
  377. margin-left: .08rem;
  378. max-width: 4rem;
  379. }
  380. }
  381. .goods-list {
  382. .goods-item {
  383. border-top: 1px solid #e4e4e4;
  384. .single-count {
  385. height: .61rem;
  386. line-height: .61rem;
  387. background: #ebebeb;
  388. font-size: .28rem;
  389. color: #666;
  390. text-align: right;
  391. padding: 0 .21rem 0 .25rem;
  392. .ol-price {
  393. font-size: .26rem;
  394. }
  395. .title {
  396. float: left;
  397. }
  398. }
  399. .params {
  400. margin-left: .17rem;
  401. width: 3.03rem;
  402. .param {
  403. margin-top: .22rem;
  404. &:first-child {
  405. margin-top: 0;
  406. }
  407. .title {
  408. color: #666;
  409. }
  410. }
  411. }
  412. .param-operate {
  413. width: 3.23rem;
  414. .input-line {
  415. $group-height: .4rem;
  416. input {
  417. width: .91rem;
  418. height: $group-height;
  419. border-top: 1px solid #ddd;
  420. border-bottom: 1px solid #ddd;
  421. vertical-align: middle;
  422. border-radius: 0;
  423. padding: 0 .05rem;
  424. text-align: center;
  425. line-height: $group-height;
  426. /* position: relative;
  427. top: .01rem;*/
  428. }
  429. span {
  430. width: .35rem;
  431. height: $group-height;
  432. line-height: .38rem;
  433. text-align: center;
  434. border: 1px solid #ddd;
  435. font-size: .24rem;
  436. &:first-child {
  437. border-top-left-radius: .05rem;
  438. border-bottom-left-radius: .05rem;
  439. }
  440. &:last-child {
  441. border-top-right-radius: .05rem;
  442. border-bottom-right-radius: .05rem;
  443. }
  444. &.disab {
  445. background: #e8e8e8;
  446. }
  447. }
  448. }
  449. /*.price-line {
  450. font-size: .32rem;
  451. color: #f43938;
  452. margin-top: .2rem;
  453. span {
  454. margin-right: .06rem;
  455. font-size: .24rem;
  456. }
  457. }*/
  458. }
  459. }
  460. }
  461. }
  462. }
  463. .buy-wrap {
  464. position: fixed;
  465. bottom: .98rem;
  466. background: #fff;
  467. width: 100%;
  468. .line {
  469. border-top: .02rem solid #ccc;
  470. height: 1.02rem;
  471. line-height: 1.02rem;
  472. padding-left: .27rem;
  473. }
  474. .wrap-count {
  475. /* .fare {
  476. font-size: .24rem;
  477. color: #999;
  478. margin-right: .15rem;
  479. font-style: normal;
  480. display: inline-block;
  481. vertical-align: middle;
  482. }*/
  483. text-align: right;
  484. .title {
  485. font-size: .28rem;
  486. margin-right: .1rem;
  487. vertical-align: middle;
  488. }
  489. .price {
  490. font-size: .28rem;
  491. color: #fc2706;
  492. display: inline-block;
  493. max-width: 1.6rem;
  494. overflow: hidden;
  495. text-overflow: ellipsis;
  496. white-space: nowrap;
  497. vertical-align: middle;
  498. span {
  499. font-size: .24rem;
  500. margin-right: .08rem;
  501. }
  502. margin-right: .25rem;
  503. }
  504. .buy-btn {
  505. width: 2.08rem;
  506. height: 1.02rem;
  507. line-height: 1.02rem;
  508. text-align: center;
  509. font-size: .28rem;
  510. color: #fff;
  511. background: #3f84f6;
  512. }
  513. }
  514. .wrap-select {
  515. padding-right: .15rem;
  516. .operate-btn {
  517. display: inline-block;
  518. font-size: .26rem;
  519. padding: .16rem .12rem;
  520. color: #3f84f6;
  521. border: 1px solid #3f84f6;
  522. margin-left: .28rem;
  523. border-radius: .04rem;
  524. line-height: normal;
  525. margin-top: .16rem;
  526. }
  527. }
  528. }
  529. .ol-price {
  530. font-size: .28rem;
  531. color: #f43938 !important;
  532. span {
  533. color: #f43938 !important;
  534. font-size: .24rem;
  535. }
  536. }
  537. }
  538. </style>