cart.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. <template>
  2. <div class="mobile-cart" :class="{'empty-mobile-cart': !cartList.length}" id="mobileFixContent" @touchmove="blurEvent()">
  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>{{goods.currencyName | currencyFilter}}{{baseUtils.getPriceByLevel(goods.goods.prices, goods.number, goods.currencyName) | priceFilter}}</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" ref="numberInput" v-model="goods.goods.purchaseNumber" @blur="blurEvent('set', goods)" @focus="focusEvent()">
  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 | priceFilter}}</span></div>
  43. </li>
  44. </ul>
  45. </li>
  46. </ul>
  47. <div class="buy-wrap" ref="buyWrap">
  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 | priceFilter}}</span>
  59. <button class="buy-btn" @click="submit">去结算</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 :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. // 失去焦点事件
  176. blurEvent (type, obj) {
  177. this.$refs.buyWrap.hidden = false
  178. this.$store.commit('option/SET_SHOW_MOBILE_FOOTER', true)
  179. this.$refs.numberInput.forEach((value) => {
  180. value.blur()
  181. })
  182. if (type && obj) {
  183. this.setGoods(type, obj)
  184. }
  185. },
  186. // 获得焦点事件
  187. focusEvent () {
  188. this.$refs.buyWrap.hidden = true
  189. this.$store.commit('option/SET_SHOW_MOBILE_FOOTER', false)
  190. },
  191. getStoreTypeColor: function (type) {
  192. let tmp = null
  193. switch (type) {
  194. case 'CONSIGNMENT':
  195. tmp = '#f3393a'
  196. break
  197. case 'DISTRIBUTION':
  198. tmp = '#4083f6'
  199. break
  200. case 'AGENCY':
  201. tmp = '#15b262'
  202. break
  203. case 'ORIGINAL_FACTORY':
  204. tmp = '#ff6300'
  205. break
  206. }
  207. if (tmp) {
  208. return `background: ${tmp};`
  209. } else {
  210. return ''
  211. }
  212. },
  213. setRemindText: function (str) {
  214. this.remindText = str
  215. this.timeoutCount++
  216. },
  217. checkCurrency: function (currency, callback) {
  218. if (currency === this.allCurrency) {
  219. callback.call()
  220. } else {
  221. this.setRemindText('所选产品币别与已选产品不是同一币别')
  222. }
  223. },
  224. setActive (type, storeIndex, goodsIndex, goodsCheckFlag) {
  225. if (type === 'store') {
  226. let storeActive = this.cartList[storeIndex].$active
  227. for (let i = 0; i < this.cartList[storeIndex].goods.length; i++) {
  228. this.setActive('goods', storeIndex, i, !storeActive)
  229. }
  230. // this.cartList[storeIndex].goods.forEach(item => {
  231. // this.checkCurrency(item.goods.currencyName, () => {
  232. // item.$active = !this.cartList[storeIndex].$active
  233. // })
  234. // })
  235. this.checkAll()
  236. } else if (type === 'goods') {
  237. if (!this.allActiveObj[0]) {
  238. this.allCurrency = this.cartList[storeIndex].goods[goodsIndex].currencyName
  239. }
  240. this.checkCurrency(this.cartList[storeIndex].goods[goodsIndex].currencyName, () => {
  241. this.cartList[storeIndex].goods[goodsIndex].$active = typeof goodsCheckFlag === 'undefined' ? !this.cartList[storeIndex].goods[goodsIndex].$active : goodsCheckFlag
  242. // this.cartList[storeIndex].$active = !this.cartList[storeIndex].goods.find(item => {
  243. // return !item.$active
  244. // })
  245. this.checkAll()
  246. })
  247. } else if (type === 'all') {
  248. let activeFlag = true
  249. this.cartList.forEach(item => {
  250. item.goods.forEach(goodsItem => {
  251. if (!goodsItem.$active) {
  252. activeFlag = false
  253. }
  254. })
  255. })
  256. for (let i = 0; i < this.cartList.length; i++) {
  257. this.cartList[i].$active = activeFlag
  258. this.setActive('store', i)
  259. }
  260. this.checkAll()
  261. }
  262. },
  263. // 总勾选校验
  264. checkAll: function () {
  265. let activeFlag = true
  266. this.cartList.forEach(item => {
  267. let itemActive = true
  268. item.goods.forEach(goodsItem => {
  269. if (!goodsItem.$active) {
  270. activeFlag = false
  271. itemActive = false
  272. }
  273. })
  274. item.$active = itemActive
  275. })
  276. this.isAllChecked = activeFlag
  277. },
  278. onPullUpAction: function () {
  279. this.page++
  280. this.reloadList()
  281. },
  282. reloadList: function () {
  283. this.$store.dispatch('userCenter/loadCartList', {page: this.page, count: this.count})
  284. },
  285. submit: function () {
  286. if (!this.allCount) {
  287. this.setRemindText('请勾选要生成订单的批次')
  288. return
  289. }
  290. let arrOD = []
  291. this.allActiveObj.forEach(item => {
  292. arrOD.push({
  293. batchCode: item.goods.batchCode,
  294. minPackQty: item.goods.minPackQty,
  295. number: item.goods.purchaseNumber,
  296. storeid: item.storeUuid
  297. })
  298. })
  299. console.log(arrOD)
  300. this.$http.post('/trade/order/saveByGroup', {
  301. arrOD: arrOD,
  302. currency: this.allCurrency
  303. }).then(res => {
  304. console.log(res.data)
  305. if (res.data.code === 1) {
  306. if (res.data.message) {
  307. this.setRemindText(res.data.message)
  308. }
  309. this.$router.push(`/mobile/center/user/pay/${this.baseUtils.enidfilter(res.data.data.orderid)}`)
  310. } else if (res.data.code === 7) {
  311. this.setRemindText('选中的购物车信息已经失效,将为您刷新界面之后重新操作')
  312. setTimeout(() => {
  313. this.page = 1
  314. this.cartList = []
  315. this.reloadList()
  316. }, 1500)
  317. } else {
  318. this.setRemindText(res.data.message)
  319. }
  320. }, err => {
  321. console.log(err.response.data || '系统错误')
  322. this.setRemindText(err.response.data || '系统错误')
  323. })
  324. },
  325. linkSaler (item) {
  326. this.currentStoreInfo = item.enterprise
  327. this.showLink = true
  328. },
  329. removeInvalidGoods () {
  330. let arr = []
  331. this.allActiveObj.forEach(item => {
  332. if (item.status === 1) {
  333. arr.push(item.id)
  334. }
  335. })
  336. if (!arr.length) {
  337. this.setRemindText('购物车内目前没有失效的产品')
  338. } else {
  339. this.doDelete(arr, '成功清除购物车内的无效产品')
  340. }
  341. },
  342. batchDelete () {
  343. if (!this.allActiveObj.length) {
  344. this.setRemindText('请选择要删除的商品')
  345. } else {
  346. let arr = []
  347. this.allActiveObj.forEach(item => {
  348. arr.push(item.id)
  349. })
  350. this.doDelete(arr, '删除成功')
  351. }
  352. },
  353. doDelete (idArr, successStr) {
  354. this.$http.delete(`/trade/cart/deleteById?ids=${JSON.stringify(idArr)}`).then(res => {
  355. this.isChange = true
  356. this.page = 1
  357. this.reloadList()
  358. this.setRemindText(successStr)
  359. }, err => {
  360. this.setRemindText(err.response.data || '系统错误')
  361. })
  362. }
  363. }
  364. }
  365. </script>
  366. <style lang="scss" scoped>
  367. .mobile-cart {
  368. margin-bottom: 3rem;
  369. padding-top:1.26rem;
  370. &.empty-mobile-cart {
  371. bottom: .98rem;
  372. }
  373. .store-list {
  374. .store-item {
  375. background: #fff;
  376. margin: .19rem 0;
  377. .store-info {
  378. height: .9rem;
  379. line-height: .9rem;
  380. padding: 0 .25rem;
  381. .store-tag {
  382. width: .54rem;
  383. height: .3rem;
  384. line-height: .3rem;
  385. text-align: center;
  386. font-size: .24rem;
  387. color: #fff;
  388. background: #15b262;
  389. border-radius: .04rem;
  390. margin-left: .18rem;
  391. }
  392. .store-name {
  393. font-size: .28rem;
  394. margin-left: .08rem;
  395. max-width: 4rem;
  396. }
  397. }
  398. .goods-list {
  399. .goods-item {
  400. border-top: 1px solid #e4e4e4;
  401. .single-count {
  402. height: .61rem;
  403. line-height: .61rem;
  404. background: #ebebeb;
  405. font-size: .28rem;
  406. color: #666;
  407. text-align: right;
  408. padding: 0 .21rem 0 .72rem;
  409. .ol-price {
  410. font-size: .26rem;
  411. }
  412. .title {
  413. float: left;
  414. font-size: .3rem;
  415. }
  416. }
  417. .params {
  418. margin-left: .17rem;
  419. width: 3.03rem;
  420. .param {
  421. margin-top: .22rem;
  422. &:first-child {
  423. margin-top: 0;
  424. }
  425. .title {
  426. color: #666;
  427. }
  428. }
  429. }
  430. .param-operate {
  431. width: 3.23rem;
  432. .input-line {
  433. $group-height: .5rem;
  434. input {
  435. width: .98rem;
  436. height: $group-height;
  437. border-top: 1px solid #ddd;
  438. border-bottom: 1px solid #ddd;
  439. vertical-align: middle;
  440. border-radius: 0;
  441. padding: 0 .05rem;
  442. text-align: center;
  443. line-height: $group-height;
  444. /* position: relative;
  445. top: .01rem;*/
  446. }
  447. span {
  448. width: .35rem;
  449. height: $group-height;
  450. line-height: .48rem;
  451. text-align: center;
  452. border: 1px solid #ddd;
  453. font-size: .24rem;
  454. &:first-child {
  455. border-top-left-radius: .05rem;
  456. border-bottom-left-radius: .05rem;
  457. }
  458. &:last-child {
  459. border-top-right-radius: .05rem;
  460. border-bottom-right-radius: .05rem;
  461. }
  462. &.disab {
  463. background: #e8e8e8;
  464. }
  465. }
  466. }
  467. /*.price-line {
  468. font-size: .32rem;
  469. color: #f43938;
  470. margin-top: .2rem;
  471. span {
  472. margin-right: .06rem;
  473. font-size: .24rem;
  474. }
  475. }*/
  476. }
  477. }
  478. }
  479. }
  480. }
  481. .buy-wrap {
  482. position: fixed;
  483. bottom: .98rem;
  484. background: #fff;
  485. width: 100%;
  486. .line {
  487. border-top: .02rem solid #ccc;
  488. height: 1.02rem;
  489. line-height: 1.02rem;
  490. padding-left: .27rem;
  491. }
  492. .wrap-count {
  493. /* .fare {
  494. font-size: .24rem;
  495. color: #999;
  496. margin-right: .15rem;
  497. font-style: normal;
  498. display: inline-block;
  499. vertical-align: middle;
  500. }*/
  501. text-align: right;
  502. .title {
  503. font-size: .28rem;
  504. margin-right: .1rem;
  505. vertical-align: middle;
  506. }
  507. .price {
  508. font-size: .28rem;
  509. color: #fc2706;
  510. display: inline-block;
  511. max-width: 3.6rem;
  512. overflow: hidden;
  513. text-overflow: ellipsis;
  514. white-space: nowrap;
  515. vertical-align: middle;
  516. span {
  517. font-size: .24rem;
  518. margin-right: .08rem;
  519. }
  520. margin-right: .25rem;
  521. }
  522. .buy-btn {
  523. width: 2.08rem;
  524. height: 1.04rem;
  525. line-height: 1.04rem;
  526. text-align: center;
  527. font-size: .28rem;
  528. color: #fff;
  529. background: #3f84f6;
  530. vertical-align: middle;
  531. }
  532. }
  533. .wrap-select {
  534. padding-right: .15rem;
  535. .operate-btn {
  536. display: inline-block;
  537. font-size: .26rem;
  538. padding: .16rem .12rem;
  539. color: #3f84f6;
  540. border: 1px solid #3f84f6;
  541. margin-left: .28rem;
  542. border-radius: .04rem;
  543. line-height: normal;
  544. margin-top: .16rem;
  545. }
  546. }
  547. }
  548. .ol-price {
  549. font-size: .28rem;
  550. color: #f43938 !important;
  551. span {
  552. color: #f43938 !important;
  553. font-size: .24rem;
  554. }
  555. }
  556. }
  557. </style>