index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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=${encodeURIComponent(JSON.stringify(idArr))}`).then(res => {
  362. this.$http.delete(`/trade/cart/deleteById?ids=%5B${idArr}%5D`).then(res => {
  363. this.isChange = true
  364. this.page = 1
  365. this.reloadList()
  366. this.setRemindText(successStr)
  367. }, err => {
  368. this.setRemindText(err.response.data || '系统错误')
  369. })
  370. },
  371. onSearch (searchObj) {
  372. if (searchObj.keyword) {
  373. this.$router.push(`/mobile/center/user/cart/${searchObj.keyword}`)
  374. }
  375. }
  376. }
  377. }
  378. </script>
  379. <style lang="scss" scoped>
  380. .mobile-cart {
  381. margin-bottom: 3rem;
  382. padding-top:1.26rem;
  383. &.empty-mobile-cart {
  384. bottom: .98rem;
  385. }
  386. .store-list {
  387. .store-item {
  388. background: #fff;
  389. margin: .19rem 0;
  390. .store-info {
  391. height: .9rem;
  392. line-height: .9rem;
  393. padding: 0 .25rem;
  394. .store-tag {
  395. width: .54rem;
  396. height: .3rem;
  397. line-height: .3rem;
  398. text-align: center;
  399. font-size: .24rem;
  400. color: #fff;
  401. background: #15b262;
  402. border-radius: .04rem;
  403. margin-left: .18rem;
  404. }
  405. .store-name {
  406. font-size: .28rem;
  407. margin-left: .08rem;
  408. max-width: 4rem;
  409. }
  410. }
  411. .goods-list {
  412. .goods-item {
  413. border-top: 1px solid #e4e4e4;
  414. .single-count {
  415. height: .61rem;
  416. line-height: .61rem;
  417. background: #ebebeb;
  418. font-size: .28rem;
  419. color: #666;
  420. text-align: right;
  421. padding: 0 .21rem 0 .72rem;
  422. .ol-price {
  423. font-size: .26rem;
  424. }
  425. .title {
  426. float: left;
  427. font-size: .3rem;
  428. }
  429. }
  430. .params {
  431. margin-left: .17rem;
  432. width: 3.03rem;
  433. .param {
  434. margin-top: .22rem;
  435. &:first-child {
  436. margin-top: 0;
  437. }
  438. .title {
  439. color: #666;
  440. }
  441. }
  442. }
  443. .param-operate {
  444. width: 3.23rem;
  445. .input-line {
  446. $group-height: .5rem;
  447. input {
  448. width: .98rem;
  449. height: $group-height;
  450. border-top: 1px solid #ddd;
  451. border-bottom: 1px solid #ddd;
  452. vertical-align: middle;
  453. border-radius: 0;
  454. padding: 0 .05rem;
  455. text-align: center;
  456. line-height: $group-height;
  457. /* position: relative;
  458. top: .01rem;*/
  459. }
  460. span {
  461. width: .35rem;
  462. height: $group-height;
  463. line-height: .48rem;
  464. text-align: center;
  465. border: 1px solid #ddd;
  466. font-size: .24rem;
  467. &:first-child {
  468. border-top-left-radius: .05rem;
  469. border-bottom-left-radius: .05rem;
  470. }
  471. &:last-child {
  472. border-top-right-radius: .05rem;
  473. border-bottom-right-radius: .05rem;
  474. }
  475. &.disab {
  476. background: #e8e8e8;
  477. }
  478. }
  479. }
  480. /*.price-line {
  481. font-size: .32rem;
  482. color: #f43938;
  483. margin-top: .2rem;
  484. span {
  485. margin-right: .06rem;
  486. font-size: .24rem;
  487. }
  488. }*/
  489. }
  490. }
  491. }
  492. }
  493. }
  494. .buy-wrap {
  495. position: fixed;
  496. bottom: .98rem;
  497. background: #fff;
  498. width: 100%;
  499. .line {
  500. border-top: .02rem solid #ccc;
  501. height: 1.02rem;
  502. line-height: 1.02rem;
  503. padding-left: .27rem;
  504. }
  505. .wrap-count {
  506. /* .fare {
  507. font-size: .24rem;
  508. color: #999;
  509. margin-right: .15rem;
  510. font-style: normal;
  511. display: inline-block;
  512. vertical-align: middle;
  513. }*/
  514. text-align: right;
  515. .title {
  516. font-size: .28rem;
  517. margin-right: .1rem;
  518. vertical-align: middle;
  519. }
  520. .price {
  521. font-size: .28rem;
  522. color: #fc2706;
  523. display: inline-block;
  524. max-width: 3.6rem;
  525. overflow: hidden;
  526. text-overflow: ellipsis;
  527. white-space: nowrap;
  528. vertical-align: middle;
  529. span {
  530. font-size: .24rem;
  531. margin-right: .08rem;
  532. }
  533. margin-right: .25rem;
  534. }
  535. .buy-btn {
  536. width: 2.08rem;
  537. height: 1.04rem;
  538. line-height: 1.04rem;
  539. text-align: center;
  540. font-size: .28rem;
  541. color: #fff;
  542. background: #3f84f6;
  543. vertical-align: middle;
  544. }
  545. }
  546. .wrap-select {
  547. padding-right: .15rem;
  548. .operate-btn {
  549. display: inline-block;
  550. font-size: .26rem;
  551. padding: .16rem .12rem;
  552. color: #3f84f6;
  553. border: 1px solid #3f84f6;
  554. margin-left: .28rem;
  555. border-radius: .04rem;
  556. line-height: normal;
  557. margin-top: .16rem;
  558. }
  559. }
  560. }
  561. .ol-price {
  562. font-size: .28rem;
  563. color: #f43938 !important;
  564. span {
  565. color: #f43938 !important;
  566. font-size: .24rem;
  567. }
  568. }
  569. }
  570. </style>