cart.vue 18 KB

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