shop_car.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <view class="pageBg">
  3. <block v-if="emptyType==0">
  4. <block v-if="isLogin">
  5. <view v-if="!(dataList.length<=0 && invalidList.length<=0)" class="coupon">
  6. <view class="coupon_count">
  7. <!-- 您当前有<text class="count">{{0}}</text>张优惠券 -->
  8. </view>
  9. <view @tap="tapShowEdit" class="coupon_handle">{{isEdit?'删除完成':'批量删除'}}</view>
  10. </view>
  11. <DtShopCarGoods ref="dtShopCarGoods" :isEdit="isEdit"
  12. :dataList.sync="dataList"
  13. :invalidList.sync="invalidList"
  14. :flag.sync="flag"
  15. @wxchecked="onWxChecked"
  16. @wxdelchecked="onWxDelChecked"
  17. @delete="onDeteleItem"
  18. />
  19. <view v-if="dataList.length<=0 && invalidList.length<=0" class="no-data-wrap">
  20. <image class="no-data" src="http://139.9.103.171:1888/img/image/noData.png" mode="widthFix"></image>
  21. <view class="no-data-tips">购物车空空如也,快去逛逛</view>
  22. <button @tap="tapToIndex" class="btn-base">去逛逛</button>
  23. </view>
  24. <view v-if="recomendList.length>0" clsss="recommend">
  25. <DtRecommendWrap title="新邻推荐" />
  26. <DtRecommendGoodsList :dataList="recomendList" />
  27. </view>
  28. <block v-if="!(dataList.length<=0 && invalidList.length<=0)">
  29. <view class="bottomHeight"></view>
  30. <view class="bottom">
  31. <view v-if="isEdit" @tap="tapCheckAll" class="bottomLeft">
  32. <image v-if="wxDelCheckAll" class="operation_icon" src="http://139.9.103.171:1888/img/image/selected_icon.png"></image>
  33. <image v-else class="operation_icon" src="http://139.9.103.171:1888/img/image/no_selected_icon.png"></image>
  34. <text class="hasSelected">已选({{wxDelCheckedNum}})</text>
  35. </view>
  36. <view v-else @tap="tapCheckAll" class="bottomLeft">
  37. <image v-if="wxCheckAll" class="operation_icon" src="http://139.9.103.171:1888/img/image/selected_icon.png"></image>
  38. <image v-else class="operation_icon" src="http://139.9.103.171:1888/img/image/no_selected_icon.png"></image>
  39. <text class="hasSelected">已选({{wxCheckedNum}})</text>
  40. </view>
  41. <view class="bottomRight">
  42. <view v-if="isEdit" @tap="tapClearCheck" class="settlement">删除</view>
  43. <block v-else>
  44. <view class="price"><text class="sign">¥</text>{{totalPrice|moneyEx}}</view>
  45. <view @tap="tapCheckCart" class="settlement">结算</view>
  46. </block>
  47. </view>
  48. </view>
  49. </block>
  50. </block>
  51. <view v-else class="no-data-wrap" style="height:100vh;padding:0">
  52. <image class="no-data" src="http://139.9.103.171:1888/img/image/noData.png" mode="widthFix"></image>
  53. <view class="no-data-tips">购物车空空如也,快去逛逛</view>
  54. <button @tap="tapToIndex" class="btn-base">去逛逛</button>
  55. </view>
  56. </block>
  57. <!-- 登录弹窗 -->
  58. <DtLogin ref="dialogLogin" @signIn="onSignIn" />
  59. </view>
  60. </template>
  61. <script>
  62. import DtRecommendWrap from '../comps//dt_recommend_wrap.vue'
  63. import DtRecommendGoodsList from '../comps//dt_recommend_goods_list.vue'
  64. import DtShopCarGoods from '../comps//dt_shop_car_goods.vue'
  65. import DtLogin from '../comps//dt_login.vue'
  66. export default {
  67. components: {
  68. DtRecommendWrap,
  69. DtRecommendGoodsList,
  70. DtShopCarGoods,
  71. DtLogin
  72. },
  73. data() {
  74. return {
  75. totalPrice: 0,
  76. wxDelCheckedNum: 0,
  77. wxCheckedNum: 0,
  78. wxCheckAll: false,
  79. wxDelCheckAll: false,
  80. respDetail: {},
  81. dataList: [],
  82. invalidList: [],
  83. recomendList: [],
  84. isEdit: false,
  85. memberId: 0,
  86. isLogin: false,
  87. flag:false,
  88. }
  89. },
  90. methods: {
  91. tapToIndex() {
  92. uni.switchTab({
  93. url:"/pages/life/life"
  94. })
  95. },
  96. // 登录成功响应事件
  97. onSignIn(resp) {
  98. console.log(143, resp)
  99. this.$util.refreshPage(['/pages/home', '/pagesM/pages/mine'])
  100. this.onPullDownRefreshPage()
  101. },
  102. onWxChecked(total, wxCheckedNum) {
  103. this.totalPrice = total
  104. this.wxCheckedNum = wxCheckedNum
  105. this.wxCheckAll = wxCheckedNum == this.dataList.length
  106. },
  107. onWxDelChecked(wxDelCheckedNum) {
  108. console.log(117,wxDelCheckedNum)
  109. this.wxDelCheckedNum = wxDelCheckedNum
  110. this.wxDelCheckAll = wxDelCheckedNum == this.dataList.length
  111. },
  112. onDeteleItem({ totalPrice, wxCheckedNum, wxDelCheckedNum, wxCheckAll, wxDelCheckAll }){
  113. console.log(118,{totalPrice, wxCheckedNum, wxDelCheckedNum, wxCheckAll, wxDelCheckAll})
  114. this.totalPrice = totalPrice
  115. this.wxCheckedNum = wxCheckedNum
  116. this.wxDelCheckedNum = wxDelCheckedNum
  117. this.wxCheckAll = wxCheckAll
  118. this.wxDelCheckAll = wxDelCheckAll
  119. },
  120. tapCheckAll() {
  121. if(this.flag){
  122. return
  123. }
  124. let list = this.dataList.slice(0)
  125. let totalPrice = 0
  126. list.map((item) => {
  127. totalPrice += item.skuDetail.price * item.skuDetail.quantity
  128. if (this.isEdit) {
  129. item.wxdelChecked = !this.wxDelCheckAll
  130. } else {
  131. item.wxChecked = !this.wxCheckAll
  132. }
  133. return item
  134. })
  135. // console.log(125,totalPrice)
  136. if (this.isEdit) {
  137. this.wxDelCheckedNum = !this.wxDelCheckAll ? list.length : 0
  138. this.wxDelCheckAll = !this.wxDelCheckAll
  139. } else {
  140. this.wxCheckedNum = !this.wxCheckAll ? list.length : 0
  141. this.wxCheckAll = !this.wxCheckAll
  142. if (this.wxCheckAll) { // 选择全部
  143. this.totalPrice = totalPrice
  144. } else {// 全不选
  145. this.totalPrice = 0
  146. }
  147. }
  148. this.dataList = list
  149. },
  150. // 显示管理
  151. tapShowEdit() {
  152. this.isEdit = !this.isEdit
  153. },
  154. // 批量删除
  155. async tapClearCheck() {
  156. if(this.flag){
  157. return
  158. }
  159. let skuIds = []
  160. let list = this.dataList.slice(0)
  161. list.forEach((item) => {
  162. if (item.wxdelChecked && item.skuDetail.id) {
  163. skuIds.push(item.skuDetail.id)
  164. }
  165. })
  166. let resp = await this.$api.cartRemoves({
  167. _isShowLoading: true,
  168. skuIds: skuIds
  169. })
  170. this.$dialog.success('删除成功')
  171. let newList = []
  172. let totalPrice = 0, wxCheckedNum = 0
  173. list.forEach((item) => {
  174. if (item.wxdelChecked && item.skuDetail.id) {
  175. return
  176. }
  177. if(item.wxChecked){
  178. totalPrice += item.skuDetail.price * item.skuDetail.quantity
  179. wxCheckedNum++
  180. }
  181. newList.push(item)
  182. })
  183. this.totalPrice = totalPrice
  184. this.wxCheckedNum = wxCheckedNum
  185. this.wxDelCheckedNum = 0
  186. this.wxCheckAll = wxCheckedNum == newList.length
  187. this.wxDelCheckAll = false
  188. this.dataList = newList
  189. },
  190. // 结算.校验购物车商品
  191. async tapCheckCart() {
  192. if(this.flag){
  193. return
  194. }
  195. let cartItemIds = [], skuIds = [];
  196. let dtos = []
  197. let list = this.dataList.slice(0)
  198. let storeId = this.$global.server.storeId
  199. list.forEach((item) => {
  200. if (item.wxChecked) {
  201. cartItemIds.push(item.skuDetail.cartItemId)
  202. skuIds.push(item.skuDetail.id)
  203. }
  204. })
  205. dtos.push({
  206. storeId: storeId,
  207. memo: '',
  208. skuIds: skuIds,
  209. codes: []
  210. })
  211. let resp = await this.$api.checkCart({
  212. _isShowLoading: true,
  213. cartItemIds: cartItemIds
  214. })
  215. let params = {
  216. cartItemIds: JSON.stringify(cartItemIds),
  217. dtos: JSON.stringify(dtos),
  218. flag: this.$global.orderFlag.card
  219. }
  220. uni.navigateTo({
  221. url: '/pagesM/pages/order_confirm?' + this.$util.serialize(params)
  222. })
  223. },
  224. // 推荐商品列表
  225. async queryRecomendList() {
  226. if (this.isPull) {
  227. this.isNoMore = false
  228. this.pageIndex = 0
  229. this.recomendList.length = 0
  230. }
  231. let params = [
  232. {
  233. t: 3,
  234. v: -1,
  235. k: "hits"
  236. },
  237. {
  238. t: 1,
  239. v: this.$global.server.storeId,
  240. k: "storeId"
  241. }
  242. ]
  243. let resp = await this.$api.searchProduct({
  244. memberId: this.memberId,
  245. pageNo: this.pageIndex,
  246. pageSize: 10,
  247. params: params
  248. })
  249. let list = this.getDataList(resp)
  250. this.recomendList = this.recomendList.concat(list)
  251. },
  252. // 购物车列表
  253. async queryDataList() {
  254. if (this.isPull) {
  255. this.dataList.length = 0
  256. this.invalidList.length = 0
  257. this.recomendList.length = 0
  258. this.isEdit = false
  259. }
  260. let resp = await this.$api.cartSkuList({
  261. _isShowLoading: true
  262. })
  263. this.emptyType==0
  264. let list = resp || []
  265. this.respDetail = list[0] || {}
  266. if (list[0] && list[0].cartItems) {
  267. let cartItems = list[0].cartItems || []
  268. let newCartItems = []
  269. cartItems.forEach((item) => {
  270. item.skus.forEach(skuItem => {
  271. let newItem = Object.assign({}, item)
  272. newItem.skuDetail = Object.assign({}, skuItem)
  273. let specList = skuItem.specificationValues || []
  274. let specificationDescArr = []
  275. specList.forEach((spec) => {
  276. specificationDescArr.push(spec.value)
  277. })
  278. // newItem.specificationValues = skuItem.specificationValues
  279. newItem.specificationDesc = specificationDescArr.join('+')
  280. newCartItems.push(newItem)
  281. })
  282. })
  283. let datalist = [], invalidList = []
  284. if (!list[0].isEnabled) {
  285. invalidList = cartItems
  286. } else {
  287. newCartItems.forEach((item) => {
  288. if (!item.isMarketable || !item.isActive) {
  289. invalidList.push(item)
  290. } else {
  291. datalist.push(item)
  292. }
  293. })
  294. }
  295. this.invalidList = this.invalidList.concat(invalidList)
  296. this.dataList = this.dataList.concat(datalist)
  297. }
  298. },
  299. onLoadPage() {
  300. // wx.hideShareMenu();
  301. if (this.isPull || this.isLoad) {
  302. this.isLogin = this.$auth.isAuth
  303. if (!this.$auth.isAuth) {
  304. this.emptyType = 0
  305. this.$refs.dialogLogin.show()
  306. return
  307. }else{
  308. this.$refs.dialogLogin.hide()
  309. }
  310. this.totalPrice = 0
  311. this.wxDelCheckedNum = 0
  312. this.wxCheckedNum = 0
  313. this.wxCheckAll = false
  314. this.wxDelCheckAll = false
  315. this.memberId = this.$auth.getMemberId()
  316. this.queryDataList()
  317. this.queryRecomendList()
  318. }
  319. if (this.isReach) {
  320. this.queryRecomendList()
  321. }
  322. },
  323. },
  324. onShow() {
  325. this.onShowPage()
  326. },
  327. onReachBottom() {
  328. this.onReachBottomPage()
  329. }
  330. }
  331. </script>
  332. <style lang="scss" scoped>
  333. .coupon {
  334. height: 80upx;
  335. display: flex;
  336. flex-direction: row;
  337. align-items: center;
  338. justify-content: space-between;
  339. padding: 0 30upx;
  340. background: #fff;
  341. .coupon_count {
  342. font-size: 26upx;
  343. color: #999999;
  344. .count {
  345. display: inline-block;
  346. padding: 0 10upx;
  347. color: #F3993A;
  348. }
  349. }
  350. .coupon_handle {
  351. font-size: 26upx;
  352. border-radius: 25px;
  353. background-color: $dt-color-primary;
  354. color: #fff;
  355. padding: 10upx 20upx;
  356. }
  357. }
  358. .bottomHeight {
  359. height: 100upx;
  360. }
  361. .bottom {
  362. height: 98upx;
  363. background: white;
  364. position: fixed;
  365. bottom: 0;
  366. width: 100%;
  367. font-size: 30upx;
  368. display: flex;
  369. flex-direction: row;
  370. justify-content: space-between;
  371. align-items: center;
  372. border-top: 2upx solid rgb(238, 238, 238);
  373. z-index:90;
  374. .bottomLeft {
  375. display: flex;
  376. flex-direction: row;
  377. align-items: center;
  378. color: #666666;
  379. font-size: 26upx;
  380. image {
  381. width: 40upx;
  382. height: 40upx;
  383. padding: 20upx 20upx 20upx 30upx;
  384. }
  385. }
  386. .bottomRight {
  387. display: flex;
  388. flex-direction: row;
  389. align-items: center;
  390. box-sizing: border-box;
  391. .settlement {
  392. background: $dt-color-primary;
  393. width: 210upx;
  394. text-align: center;
  395. height: 98upx;
  396. line-height: 98upx;
  397. color: white;
  398. box-sizing: border-box;
  399. font-size: 30upx;
  400. }
  401. .price {
  402. padding-right: 40upx;
  403. text-align: right;
  404. color: #ee1515;
  405. font-size: 34upx;
  406. .sign {
  407. font-size: 24upx;
  408. text-align: right;
  409. display: inline-block;
  410. margin-right: 10upx;
  411. }
  412. }
  413. }
  414. }
  415. .no-data-wrap {
  416. padding: 100upx 0;
  417. text-align: center;
  418. display: flex;
  419. flex-direction: column;
  420. align-items: center;
  421. justify-content: center;
  422. .no-data {
  423. width: 180upx;
  424. }
  425. .no-data-tips {
  426. color: #999;
  427. text-align: center;
  428. font-size: 24upx;
  429. padding: 30upx 0 40upx;
  430. }
  431. .btn-base {
  432. position: relative;
  433. width: 160rpx;
  434. height: 60rpx;
  435. line-height: 60upx;
  436. text-align: center;
  437. color: $dt-color-primary;
  438. border-radius: 6rpx;
  439. background-color: transparent;
  440. }
  441. .btn-base:before {
  442. position: absolute;
  443. top: 0;
  444. left: 0;
  445. width: 100%;
  446. height: 100%;
  447. border-radius: 6upx;
  448. box-sizing: border-box;
  449. border: 1upx solid $dt-color-primary;
  450. content: "";
  451. }
  452. }
  453. </style>