index.vue 19 KB

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