index.vue 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. <template>
  2. <view class="content">
  3. <!-- 购物车 -->
  4. <view v-if="!isEmpty">
  5. <view class="cart-bg">
  6. <view class="cart-num-box">
  7. <image src="../../../static/images/logoTop.png"></image>
  8. <text class="btn-box" @click="btnTypeClick(1)" v-if="btnType == 0">管理</text>
  9. <text class="btn-box" @click="btnTypeClick(0)" v-if="btnType == 1">完成</text>
  10. </view>
  11. <view>
  12. <text class="num-box">共<text class="num">{{allNum}}</text>件宝贝</text>
  13. </view>
  14. </view>
  15. <view class="cart-list-box">
  16. <view v-for="(item, index) in dataList" :key="item.shopId">
  17. <view class="item" v-if="item.skus.length !== 0">
  18. <view class="shop-box">
  19. <image mode="aspectFill" v-if="item.selected === 1" src="../../../static/images/selectActive.png" class="cart-select-img" @click.stop="updateShopSel(index,0)"></image>
  20. <image mode="aspectFill" v-else src="../../../static/images/selectEmpty.png" class="cart-select-img" @click.stop="updateShopSel(index,1)"></image>
  21. <view class="shop-name-box" @click="goStore(index)">
  22. <image src="../../../static/images/orderStoreIcon.png" class="shop-img"></image>
  23. <text class="shop-name">{{item.shopName}}</text>
  24. <image src="../../../static/images/arrowRight.png" class="arrow-right-img"></image>
  25. </view>
  26. </view>
  27. <view v-for="(skuItem, cIndex) in dataList[index].skus" class="product-list-box">
  28. <view class="pro-item" @click="goodsDateils(item.shopId,skuItem.productId,skuItem.skuId)">
  29. <image mode="aspectFill" v-if="skuItem.selected == 1"
  30. src="../../../static/images/selectActive.png"
  31. @click.stop="cartItemSel(index,cIndex,0)" class="cart-select-img"></image>
  32. <image mode="aspectFill" v-else src="../../../static/images/selectEmpty.png"
  33. @click.stop="cartItemSel(index,cIndex,1)" class="cart-select-img"></image>
  34. <view class="pro-r">
  35. <image :src="skuItem.image" class="pro-img"></image>
  36. <view class="pro-r-r">
  37. <view class="pro-name">{{skuItem.productName}}</view>
  38. <view class="sku-box">
  39. <text v-if="skuItem.value">{{skuItem.value}}</text>
  40. <text v-else>默认规格</text>
  41. <!-- <text></text> -->
  42. </view>
  43. <view class="pro-price-num-box">
  44. <view class="pro-price-box">
  45. <text class="fuhao">¥</text>
  46. <text>{{skuItem.price}}</text>
  47. </view>
  48. <view class="pro-num-box">
  49. <text class="num-btn r" @click.stop="numSub(index,cIndex)">-</text>
  50. <text class="num">{{skuItem.number}}</text>
  51. <text class="num-btn l" @click.stop="numAdd(index,cIndex)">+</text>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <!-- 商品详情 -->
  62. <u-popup v-model="goodsDetailShowFlag" mode="bottom" border-radius="14">
  63. <view class="goosDetailshow-box">
  64. <view class="detailImg-box flex-row-plus">
  65. <image class="detailImg" :src="selectedSku.image"></image>
  66. <view class="flex-column-plus mar-left-40">
  67. <view class="font-color-C5AA7B">
  68. <label class="fs24">¥</label>
  69. <label class="fs36 mar-left-10"
  70. v-text="selectedSku.activityType === 1 && btnType === 4 ? selectedSku.originalPrice : selectedSku.price"></label>
  71. </view>
  72. <label class="fs24 font-color-999 mar-top-20">库存 {{selectedSku.stockNumber}} 件</label>
  73. <label class="fs24 mar-top-20">已选</label>
  74. </view>
  75. </view>
  76. <view class="color-box flex-column-plus">
  77. <view v-for="(attritem,index) in productData.names" :key="index" class="skuStyle">
  78. <label class="fs24 font-color-999">{{attritem.skuName}}</label>
  79. <view class="colorName-box">
  80. <view class="pad-bot-30" v-for="(attrRes, resIndex) in attritem.values" :key="resIndex">
  81. <view class="colorName"
  82. :class="{'colorName-on' : selectedAttr[attritem.nameCode] == attrRes.valueCode}"
  83. @click="nameCodeValueCodeClick(attritem.nameCode, attrRes.valueCode, true)">
  84. {{attrRes.skuValue}}
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. <view class="goodsNum-box flex-row-plus flex-sp-between" :class="{'bottom-line' :supportHuabei}">
  91. <label class="font-color-999 fs24">数量</label>
  92. <view class="goodsNum">
  93. <text class="subtract" @click="updateNumSub()">-</text>
  94. <text class="goodsNumber" v-model="buyNum">{{buyNum}}</text>
  95. <text class="add" @click.stop="updateNumAdd()">+</text>
  96. </view>
  97. </view>
  98. <view class="goosDetailbut-box flex-items-plus">
  99. <button type="default" @click="goodsDateils(shopId,productId,skuId)" >查看详情</button>
  100. <button type="default" class="submitBtn" @click="submitBtn()">确认</button>
  101. </view>
  102. </view>
  103. </u-popup>
  104. <!-- #ifdef H5 -->
  105. <view class="cart-bottom-box-h5">
  106. <!-- #endif -->
  107. <!-- #ifndef H5 -->
  108. <view class="cart-bottom-box-app">
  109. <!-- #endif -->
  110. <view class="cart-bottom">
  111. <view class="left">
  112. <image mode="aspectFill" v-if="isAllCheck" src="../../../static/images/selectActive.png"
  113. class="cart-select-img" @click="allSel(0)"></image>
  114. <image mode="aspectFill" v-else src="../../../static/images/selectEmpty.png"
  115. class="cart-select-img" @click="allSel(1)"></image>
  116. <text>全选</text>
  117. </view>
  118. <view class="right" v-if="btnType == 0">
  119. <view class="price-box">
  120. <text>合计:</text>
  121. <text class="price">¥{{checkMoney}}</text>
  122. </view>
  123. <view class="btn-confirm" @click="settlementTap">结算({{checkNum}})</view>
  124. </view>
  125. <view class="right" v-if="btnType == 1">
  126. <view class="btn-delete" @click="cartDel">删除</view>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. <!-- 购物车为空 -->
  132. <view v-if="isEmpty" class="emptyCart-box flex-items-plus flex-column">
  133. <image class="emptyCart-img" src="../../../static/images/cartEmpty.png"></image>
  134. <label class="font-color-999 fs26 mar-top-30">你的购物车还没有宝贝哦</label>
  135. <label class="font-color-999 fs26 mar-top-10">快去首页选一个吧~</label>
  136. <view class="goToShopping" @click="goToShopping">去购物</view>
  137. </view>
  138. <!-- 删除确认弹窗 -->
  139. <tui-modal :show="cardModal" :custom="true" :fadein="true">
  140. <view class="Put-box1">
  141. <view class="text-align fs34 fs-bold">
  142. 温馨提示
  143. </view>
  144. <view class="mar-top-40 text-align">
  145. 您确定删除选中的商品吗?
  146. </view>
  147. <view class="flex-display flex-sp-between">
  148. <view class="btn" @click="cardModal = false">
  149. 点错了
  150. </view>
  151. <view class="btn submit" @click="doDelete">
  152. 确认删除
  153. </view>
  154. </view>
  155. </view>
  156. </tui-modal>
  157. </view>
  158. </template>
  159. <script>
  160. import tuiModal from "@/components/modal/modal";
  161. const NET = require('../../../utils/request')
  162. const API = require('../../../config/api')
  163. export default {
  164. components: {
  165. tuiModal
  166. },
  167. data() {
  168. return {
  169. goodsDetailShowFlag: false,
  170. OriginalSelectedSku: {},
  171. selectedSku: {},
  172. productData: [],
  173. shopId: 0,
  174. productId: 0,
  175. skuId: 0,
  176. selectedAttr: {},
  177. supportHuabei: false,
  178. title: 'Hello',
  179. btnType: 0,
  180. dataList: [],
  181. goosDetailshowFlag: false,
  182. colorActiveId: 1,
  183. colorList: [{
  184. id: 1,
  185. color: '复古蓝色'
  186. }, {
  187. id: 2,
  188. color: '马卡龙粉色'
  189. }],
  190. modelNumActiveId: 1,
  191. modelNumList: [{
  192. id: 1,
  193. modelNum: '小号'
  194. }, {
  195. id: 2,
  196. modelNum: '中号'
  197. }, {
  198. id: 3,
  199. modelNum: '大号'
  200. }],
  201. skuItemList: [],
  202. buyNum: 1,
  203. allNum: 0,
  204. checkNum: 0,
  205. checkMoney: 0,
  206. isAllCheck: true,
  207. skuProdList: {},
  208. item: {},
  209. cardModal: false,
  210. isEmpty: false
  211. }
  212. },
  213. computed: {
  214. // 计算显示tabBar购物车数量
  215. getCartNum() {
  216. let cartNum = 0
  217. this.updateMoneyAndNum()
  218. cartNum = this.allNum
  219. if (cartNum > 0) {
  220. uni.setTabBarBadge({
  221. index: 2,
  222. text: cartNum.toString()
  223. })
  224. } else {
  225. uni.removeTabBarBadge({
  226. index: 2
  227. })
  228. }
  229. uni.setStorageSync('allCartNum', cartNum)
  230. console.log(uni.getStorageSync('allCartNum'), '1111')
  231. }
  232. },
  233. onLoad() {
  234. },
  235. onShow() {
  236. //判断是否登录
  237. /* let item = {}
  238. if(uni.getStorageSync('storage_key')){
  239. item = uni.getStorageSync('storage_key');
  240. }
  241. console.dir(item) */
  242. /* if(JSON.stringify(item) == '{}'){
  243. uni.navigateTo({
  244. url:'../../../pages_category_page2/userModule/login'
  245. })
  246. }else{ */
  247. this.isEmpty = false
  248. this.dataList = []
  249. this.getDataList()
  250. /* } */
  251. },
  252. methods: {
  253. // 提交更换商品规格
  254. submitBtn() {
  255. console.log(this.selectedSku.skuId,'this.selectedSku.skuId')
  256. console.log(this.skuId,'this.skuId')
  257. NET.request(API.UpdateSkuCart, {
  258. skuId: this.skuId,
  259. newSkuId: this.selectedSku.skuId,
  260. number: this.buyNum
  261. },
  262. "POST").then(res => {
  263. this.goodsDetailShowFlag = false
  264. this.getDataList()
  265. })
  266. },
  267. // 购物车修改属性样式时:数量减
  268. updateNumSub() {
  269. if (this.buyNum > 1) {
  270. this.buyNum = this.buyNum - 1
  271. } else {
  272. uni.showToast({
  273. title: '亲!至少一件哦!',
  274. icon: "none"
  275. })
  276. }
  277. },
  278. // 购物车修改属性样式时:数量加
  279. updateNumAdd() {
  280. if (this.buyNum < this.selectedSku.stockNumber) {
  281. this.buyNum = this.buyNum + 1
  282. } else {
  283. uni.showToast({
  284. title: '库存不足!',
  285. icon: "none"
  286. })
  287. }
  288. },
  289. //获取商品详情
  290. queryProductDetail() {
  291. uni.showLoading({
  292. title: '加载中...'
  293. })
  294. NET.request(API.QueryProductDetail, {
  295. shopId: this.shopId,
  296. productId: this.productId,
  297. skuId: this.skuId,
  298. terminal: 1
  299. },
  300. "GET").then(res => {
  301. uni.hideLoading()
  302. this.productData = res.data
  303. this.markTools = res.data.markTools //平台优惠券
  304. this.shopMarkTools = res.data.shopMarkTools //店铺优惠券
  305. //如果是单款式商品,需要特殊处理productData.names
  306. const mapKeys = Object.keys(this.productData.map)
  307. if (mapKeys.length === 1 && mapKeys[0] === '单款项') {
  308. this.productData.names[0].values.push({
  309. skuValue: '单款项',
  310. valueCode: '单款项'
  311. })
  312. }
  313. //如果sku的图像为空,设置为商品的图像
  314. for (var key in this.productData.map) {
  315. let skuImage = this.productData.map[key].image
  316. if (!skuImage) {
  317. this.productData.map[key].image = this.productData.images[0]
  318. }
  319. }
  320. //评价
  321. this.commentList = res.data.comments
  322. this.commentListLength = this.commentList.length
  323. this.sellDescList = res.data.text.replace(/\<img/gi,
  324. '<img style="max-width:100%;height:auto" ')
  325. this.couponListLength = res.data.couponImages.length
  326. this.showVOList = res.data.couponImages
  327. this.couponList = res.data.markTools
  328. //渲染商详之后,如果参数传了skuId,则选中该skuId,否则选中第一个规格
  329. if (this.skuId) {
  330. this.selectBySkuId(this.skuId)
  331. console.log(this.skuId, 'this.skuId2222')
  332. } else {
  333. for (var attr in this.productData.names) {
  334. this.nameCodeValueCodeClick(attr.nameCode, attr.values[0].valueCode, true)
  335. }
  336. }
  337. this.beginTimer();
  338. }).catch(res => {
  339. uni.hideLoading()
  340. })
  341. },
  342. selectBySkuId(skuId) {
  343. if (skuId) {
  344. let mapinfo = this.productData.map
  345. for (var key in mapinfo) {
  346. if (parseInt(mapinfo[key].skuId) === parseInt(skuId)) {
  347. this.selectedSku = mapinfo[key]
  348. // 选中sku对应的规格
  349. const valueCodeList = key.split(',')
  350. this.productData.names.forEach(attr => {
  351. for (var index in attr.values) {
  352. let valueCode = attr.values[index].valueCode
  353. if (valueCodeList.includes(valueCode)) {
  354. this.nameCodeValueCodeClick(attr.nameCode, valueCode, false)
  355. break
  356. }
  357. }
  358. })
  359. break
  360. }
  361. }
  362. }
  363. },
  364. nameCodeValueCodeClick(nameCode, valueCode, reSelectSku) {
  365. this.selectedAttr[nameCode] = valueCode
  366. if (reSelectSku) {
  367. let attrList = []
  368. for (var key in this.selectedAttr) {
  369. attrList.push(this.selectedAttr[key])
  370. }
  371. const attrkey = attrList.join(',')
  372. let mapinfo = this.productData.map
  373. for (var key in mapinfo) {
  374. if (attrkey === key) {
  375. this.selectedSku = mapinfo[key]
  376. }
  377. }
  378. }
  379. // 选中sku之后,做一些相应的操作
  380. // this.selectSkuPostProcessor()
  381. this.$forceUpdate(); // 重绘
  382. },
  383. selectSkuPostProcessor() {
  384. const ifEnable = this.selectedSku.ifEnable
  385. if (this.selectedSku.activityType === 1 && ifEnable === 0) {
  386. this.topThreeCollageOrders = this.selectedSku.collageOrders.slice(0, 3)
  387. }
  388. if ([1, 2, 3, 4, 5].includes(this.selectedSku.activityType) && ifEnable === 0) {
  389. this.dateformat(this.selectedSku.endTime)
  390. this.countDown();
  391. }
  392. this.timeActivetype = ifEnable === 0;
  393. this.shopDiscountId = this.selectedSku.shopDiscountId
  394. this.shopSeckillId = this.selectedSku.shopSeckillId
  395. },
  396. // 更换商品样式
  397. changeSkuItemValue(skuItem, shopId) {
  398. this.OriginalSelectedSku = skuItem
  399. this.shopId = shopId
  400. this.productId = skuItem.productId
  401. this.skuId = skuItem.skuId
  402. this.buyNum = this.OriginalSelectedSku.number
  403. this.queryProductDetail()
  404. setTimeout(() => {
  405. this.goodsDetailShowFlag = true
  406. }, 1000)
  407. },
  408. //逛店铺
  409. goStore(index) {
  410. uni.navigateTo({
  411. url: '../../../pages_category_page1/store/index?storeId=' + this.dataList[index].shopId
  412. })
  413. },
  414. //商品详情
  415. goodsDateils(shopId, productId, skuId) {
  416. uni.navigateTo({
  417. url: '../../../pages_category_page1/goodsModule/goodsDetails?shopId=' + shopId +
  418. '&productId=' + productId + '&skuId=' + skuId
  419. })
  420. },
  421. // 去首页
  422. goToShopping() {
  423. uni.switchTab({
  424. url: '../../../pages/tabbar/index/index'
  425. })
  426. },
  427. btnTypeClick(type) {
  428. this.btnType = type
  429. },
  430. getDataList() {
  431. wx.showLoading({
  432. title: '加载中...',
  433. })
  434. NET.request(API.ShoppingCart, {}, 'GET').then(res => {
  435. wx.hideLoading()
  436. this.dataList = res.data
  437. this.dataList.forEach((item) => {
  438. for (let i = 0; i < item.skus.length; i++) {
  439. if (item.skus[i].shelveState === 0) {
  440. item.skus.splice(i, 1)
  441. }
  442. }
  443. })
  444. // this.dataList.forEach((item) => {
  445. // for (let i = 0; i < item.skus.length; i++) {
  446. // for (let j = 0; j < item.skus[i].map.length; j++) {
  447. // if (item.skus[i].map[j].skuId === item.skus.skuId) {}
  448. // }
  449. // }
  450. // })
  451. this.allNum = this.dataList.length
  452. if (this.dataList.length === 0) {
  453. this.isEmpty = true
  454. }
  455. this.updateMoneyAndNum()
  456. }).catch(res => {
  457. wx.hideLoading()
  458. })
  459. },
  460. // 数量减
  461. numSub(index, cIndex) {
  462. if (this.dataList[index].skus[cIndex].number > 1) {
  463. this.dataList[index].skus[cIndex].number = this.dataList[index].skus[cIndex].number - 1
  464. this.updateCart(this.dataList[index].skus[cIndex].skuId, this.dataList[index].skus[cIndex].number)
  465. } else {
  466. uni.showToast({
  467. title: '亲!至少一件哦!',
  468. icon: "none"
  469. })
  470. }
  471. },
  472. // 数量加
  473. numAdd(index, cIndex) {
  474. console.log('点击')
  475. if (this.dataList[index].skus[cIndex].number <= 100) {
  476. this.dataList[index].skus[cIndex].number = this.dataList[index].skus[cIndex].number + 1
  477. this.updateCart(this.dataList[index].skus[cIndex].skuId, this.dataList[index].skus[cIndex].number)
  478. } else {
  479. wx.showToast({
  480. title: '库存不足!',
  481. icon: 'none'
  482. })
  483. }
  484. },
  485. updateMoneyAndNum() {
  486. this.isAllCheck = true
  487. this.allNum = 0
  488. this.checkNum = 0
  489. this.checkMoney = 0
  490. let len = this.dataList.length
  491. for (let i = 0; i < len; i++) {
  492. let len2 = this.dataList[i].skus.length
  493. for (let j = 0; j < len2; j++) {
  494. let item = this.dataList[i].skus[j]
  495. this.allNum += item.number
  496. if (item.selected == 1) {
  497. this.checkNum++
  498. this.checkMoney += parseFloat(item.price * item.number)
  499. } else {
  500. if (this.isAllCheck) {
  501. this.isAllCheck = false
  502. }
  503. }
  504. }
  505. }
  506. this.checkMoney = parseFloat(this.checkMoney.toFixed(10))
  507. uni.setStorageSync('allCartNum', this.allNum)
  508. if (this.allNum > 0) {
  509. uni.setTabBarBadge({
  510. index: 2,
  511. text: (this.allNum).toString()
  512. })
  513. } else {
  514. uni.removeTabBarBadge({
  515. index: 2
  516. })
  517. }
  518. },
  519. updateShopSel(index, type) {
  520. console.log(index, 'index', type, 'type')
  521. console.log(this.dataList, 'dataList')
  522. let shopCarts = [{
  523. shopId: '',
  524. skus: []
  525. }]
  526. this.dataList[index].selected = type
  527. let len = this.dataList[index].skus.length
  528. for (let i = 0; i < len; i++) {
  529. this.dataList[index].skus[i].selected = type
  530. var skusobj = {};
  531. skusobj["skuId"] = this.dataList[index].skus[i].skuId;
  532. skusobj["selected"] = this.dataList[index].skus[i].selected
  533. shopCarts[0].skus.push(skusobj);
  534. }
  535. shopCarts[0].shopId = this.dataList[index].shopId
  536. this.updateSelected(shopCarts)
  537. },
  538. //选中商品
  539. updateSelected(shopCarts) {
  540. this.updateMoneyAndNum()
  541. NET.request(API.SelectedCart, {
  542. shopCarts
  543. }, 'POST').then(res => {}).catch(res => {
  544. })
  545. },
  546. updateCart(skuId, number) {
  547. NET.request(API.UpdateNumberCart, {
  548. skuId: skuId,
  549. number: number
  550. }, 'POST').then(res => {
  551. this.updateMoneyAndNum()
  552. }).catch(res => {
  553. })
  554. },
  555. cartItemSel(index, cIndex, type) {
  556. let shopCarts = [{
  557. shopId: 0,
  558. skus: []
  559. }]
  560. this.dataList[index].skus[cIndex].selected = type
  561. if (type == 1) {
  562. let len = this.dataList[index].skus.length
  563. let shopType = 1
  564. for (let i = 0; i < len; i++) {
  565. if (this.dataList[index].skus[i].selected == 0) {
  566. shopType = 0
  567. break
  568. }
  569. }
  570. this.dataList[index].selected = shopType
  571. } else {
  572. this.dataList[index].selected = type
  573. }
  574. shopCarts[0].shopId = this.dataList[index].shopId
  575. var skusobj = {};
  576. skusobj["skuId"] = this.dataList[index].skus[cIndex].skuId;
  577. skusobj["selected"] = this.dataList[index].skus[cIndex].selected
  578. shopCarts[0].skus.push(skusobj);
  579. this.updateSelected(shopCarts)
  580. },
  581. //全选
  582. allSel(type) {
  583. this.updateAllSel(type)
  584. },
  585. updateAllSel(type) {
  586. let len = this.dataList.length
  587. for (let i = 0; i < len; i++) {
  588. let len2 = this.dataList[i].skus.length
  589. this.dataList[i].selected = type
  590. for (let j = 0; j < len2; j++) {
  591. this.dataList[i].skus[j].selected = type
  592. }
  593. }
  594. let shopCarts = []
  595. this.updateSelected(shopCarts)
  596. },
  597. //点击删除
  598. cartDel() {
  599. if (!this.checkNum) {
  600. uni.showToast({
  601. title: '请先选择对应商品',
  602. icon: 'none'
  603. })
  604. return;
  605. }
  606. this.cardModal = true
  607. },
  608. //删除购物车
  609. doDelete() {
  610. this.cardModal = false
  611. let cartList = []
  612. let n = 0
  613. let skus = []
  614. let len = this.dataList.length
  615. for (let i = 0; i < len; i++) {
  616. let item = {}
  617. let len2 = this.dataList[i].skus.length
  618. for (let j = 0; j < len2; j++) {
  619. let itemGoods = this.dataList[i].skus[j]
  620. if (itemGoods.selected == 1) {
  621. skus[n] = itemGoods.skuId
  622. n = n + 1
  623. }
  624. }
  625. }
  626. NET.request(API.DeleteCart, {
  627. ids: skus
  628. }, 'POST').then(res => {
  629. this.getDataList()
  630. }).catch(res => {
  631. })
  632. },
  633. //结算购物车
  634. settlementTap() {
  635. if (!this.checkNum) {
  636. wx.showToast({
  637. title: '请先选择对应商品',
  638. icon: 'none'
  639. })
  640. return;
  641. }
  642. console.log(this.dataList, 222)
  643. let addCart = []
  644. let len = this.dataList.length
  645. for (let i = 0; i < len; i++) {
  646. let shopObj = {}
  647. shopObj["shopId"] = this.dataList[i].shopId
  648. shopObj["skus"] = []
  649. let len2 = this.dataList[i].skus.length
  650. for (let j = 0; j < len2; j++) {
  651. let skusObj = {}
  652. skusObj["ifLogistics"] = this.dataList[i].skus[j].ifLogistics
  653. skusObj["number"] = this.dataList[i].skus[j].number
  654. skusObj["selected"] = this.dataList[i].skus[j].selected
  655. skusObj["skuId"] = this.dataList[i].skus[j].skuId
  656. shopObj.skus.push(skusObj)
  657. }
  658. addCart.push(shopObj)
  659. }
  660. let newArray = []
  661. addCart.forEach((item, index) => {
  662. newArray[index] = item
  663. newArray[index].skus = item.skus.filter((item) => {
  664. return item.selected == 1
  665. })
  666. if (item.skus.length == 0) {
  667. newArray.splice(index, 1);
  668. }
  669. })
  670. newArray = newArray.filter(d => d)
  671. uni.setStorageSync('skuItemDTOList', newArray)
  672. uni.navigateTo({
  673. url: '../../../pages_category_page1/orderModule/orderConfirm?type=2'
  674. })
  675. },
  676. //商品尺寸弹窗
  677. goosDetailshowClick(storeId, skuItemId) {
  678. this.goosDetailshowFlag = true
  679. this.colorActiveClick(storeId, skuItemId)
  680. },
  681. //颜色选中事件
  682. colorActiveClick(storeId, attrItemId) {
  683. this.colorActiveId = attrItemId
  684. NET.request(API.QueryProductSku, {
  685. productId: storeId,
  686. skuValueIdList: [attrItemId]
  687. }, 'POST').then(res => {
  688. if (res.code === 0) {
  689. this.skuProdList = res.data
  690. this.skuProdId = res.data.id
  691. this.skuImg = res.data.skuImg
  692. this.skuNameStr = res.data.skuNameStr
  693. this.skuPrice = res.data.skuPrice
  694. }
  695. }).catch(res => {
  696. })
  697. },
  698. }
  699. }
  700. </script>
  701. <style lang="scss">
  702. page {
  703. // background: #f7f7f7;
  704. }
  705. .content {
  706. padding: 0 0 110rpx;
  707. overflow: hidden;
  708. .goosDetailshow-box {
  709. .detailImg-box {
  710. margin-top: 30upx;
  711. margin-left: 30upx;
  712. border-radius: 10upx;
  713. border-bottom: 1upx solid #EDEDED;
  714. padding-bottom: 20upx;
  715. width: 690upx;
  716. .detailImg {
  717. width: 180upx;
  718. height: 180upx;
  719. }
  720. }
  721. .color-box {
  722. padding: 30upx 30upx;
  723. border-bottom: 1upx solid #EDEDED;
  724. width: 690upx;
  725. .colorName-box {
  726. display: flex;
  727. flex-wrap: wrap;
  728. flex-direction: row;
  729. justify-content: flex-start;
  730. align-items: center;
  731. margin-top: 30upx;
  732. margin-left: -30upx;
  733. .colorName {
  734. background-color: #FFFFFF;
  735. margin-left: 30upx;
  736. padding: 10upx 32upx;
  737. font-size: 26upx;
  738. border: 2rpx solid #E4E5E6;
  739. z-index: 2;
  740. color: #333333;
  741. }
  742. .colorName-on {
  743. box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.1);
  744. color: #C5AA7B;
  745. margin-left: 30upx;
  746. padding: 10upx 32upx;
  747. font-size: 26upx;
  748. text-align: center;
  749. z-index: 1;
  750. border: none;
  751. }
  752. }
  753. }
  754. .modelNum-box {
  755. padding: 30upx 30upx;
  756. border-bottom: 1upx solid #EDEDED;
  757. width: 690upx;
  758. .modelNumName-box {
  759. display: flex;
  760. flex-wrap: wrap;
  761. flex-direction: row;
  762. justify-content: flex-start;
  763. align-items: center;
  764. margin-top: 30upx;
  765. margin-left: -30upx;
  766. .modelNumName-on {
  767. background-color: #FFE4D0;
  768. color: #FF7800;
  769. margin-left: 30upx;
  770. padding: 10upx 32upx;
  771. border-radius: 28upx;
  772. border: 1upx solid #FF7800;
  773. font-size: 26upx;
  774. text-align: center;
  775. }
  776. .modelNumName {
  777. background-color: #F5F5F5;
  778. margin-left: 30upx;
  779. padding: 10upx 32upx;
  780. border-radius: 28upx;
  781. font-size: 26upx;
  782. }
  783. }
  784. }
  785. .goodsNum-box {
  786. padding: 30upx 30upx;
  787. width: 690upx;
  788. padding-bottom: 140upx;
  789. .goodsNum {
  790. height: 50upx;
  791. text {
  792. display: inline-block;
  793. width: 50upx;
  794. height: 50upx;
  795. border: 1upx solid #999999;
  796. text-align: center;
  797. // line-height: 50upx;
  798. }
  799. .subtract {
  800. border-right: 0upx;
  801. }
  802. .add {
  803. border-left: 0upx;
  804. }
  805. }
  806. }
  807. .bottom-line {
  808. border-bottom: 1upx solid #EDEDED;
  809. }
  810. .huabei-box {
  811. padding: 30upx 30upx;
  812. width: 690upx;
  813. .fenqi-box {
  814. margin-top: 15upx;
  815. width: 120%;
  816. .huabei-item {
  817. display: inline-block;
  818. background: #f3f3f3;
  819. padding: 16upx 24upx;
  820. margin: 5upx 10upx;
  821. border-radius: 15upx;
  822. text-align: center;
  823. font-size: 7upx;
  824. .huabei-period {
  825. display: block;
  826. }
  827. }
  828. .fenqi-on {
  829. border: 1px solid #EF7F93;
  830. color: #EF7F93;
  831. }
  832. .disabled {
  833. color: #cacaca;
  834. }
  835. }
  836. }
  837. .goosDetailbut-box {
  838. justify-content: center;
  839. margin-bottom: 48rpx;
  840. button {
  841. width: 342rpx;
  842. height: 100rpx;
  843. line-height: 100rpx;
  844. font-size: 28rpx;
  845. border: 1px solid;
  846. border-radius: 0;
  847. }
  848. .submitBtn {
  849. color: #FFEBC4;
  850. background: #333333;
  851. }
  852. }
  853. }
  854. .Put-box1 {
  855. .btn {
  856. text-align: center;
  857. margin-top: 40rpx;
  858. border: 1px solid #333333;
  859. height: 80upx;
  860. line-height: 80upx;
  861. width: 240upx;
  862. color: #333333;
  863. }
  864. .submit {
  865. background-color: #333333;
  866. color: #FFEBC4;
  867. }
  868. }
  869. .cart-bg {
  870. width: 100%;
  871. height: 180rpx;
  872. .cart-num-box {
  873. display: flex;
  874. flex-direction: row;
  875. align-items: center;
  876. justify-content: space-between;
  877. image {
  878. width: 286rpx;
  879. height: 72rpx;
  880. }
  881. .btn-box {
  882. font-size: 30rpx;
  883. color: #333333;
  884. padding: 30rpx;
  885. box-sizing: border-box;
  886. display: inline-block;
  887. }
  888. }
  889. .num-box {
  890. padding: 30rpx 0 30rpx 30rpx;
  891. box-sizing: border-box;
  892. font-size: 30rpx;
  893. color: #C5CACF;
  894. }
  895. }
  896. .cart-list-box {
  897. box-sizing: border-box;
  898. .item {
  899. background: #fff;
  900. border-radius: 10rpx;
  901. margin-bottom: 20rpx;
  902. .shop-box {
  903. display: flex;
  904. flex-direction: row;
  905. align-items: center;
  906. border-bottom: 1px solid #eee;
  907. border-top: 1px solid #eee;
  908. position: relative;
  909. .cart-select-img {
  910. width: 40rpx;
  911. height: 40rpx;
  912. margin: 30rpx;
  913. box-sizing: border-box;
  914. }
  915. .shop-name-box {
  916. display: flex;
  917. flex-direction: row;
  918. align-items: center;
  919. .shop-img {
  920. width: 36rpx;
  921. height: 36rpx;
  922. margin-right: 10rpx;
  923. }
  924. .shop-name {
  925. font-size: 30rpx;
  926. color: #333;
  927. font-weight: bold;
  928. display: inline-block;
  929. margin-left: 10rpx;
  930. }
  931. .arrow-right-img {
  932. width: 30rpx;
  933. height: 30rpx;
  934. box-sizing: border-box;
  935. margin-left: 30rpx;
  936. position: absolute;
  937. right: 30rpx;
  938. }
  939. }
  940. }
  941. .product-list-box {
  942. .pro-item {
  943. display: flex;
  944. flex-direction: row;
  945. align-items: center;
  946. .cart-select-img {
  947. width: 40rpx;
  948. height: 40rpx;
  949. margin: 30rpx;
  950. box-sizing: border-box;
  951. }
  952. .pro-r {
  953. flex: 1;
  954. border-bottom: 1px solid #eee;
  955. display: flex;
  956. flex-direction: row;
  957. padding: 30rpx 30rpx 30rpx 0;
  958. box-sizing: border-box;
  959. overflow: hidden;
  960. .pro-img {
  961. width: 180rpx;
  962. height: 180rpx;
  963. border-radius: 10rpx;
  964. margin-right: 30rpx;
  965. }
  966. .pro-r-r {
  967. flex: 1;
  968. font-size: 26rpx;
  969. color: #333;
  970. overflow: hidden;
  971. display: flex;
  972. flex-direction: column;
  973. justify-content: space-between;
  974. .pro-name {
  975. height: 66rpx;
  976. line-height: 33rpx;
  977. display: -webkit-box;
  978. overflow: hidden;
  979. text-overflow: ellipsis;
  980. word-break: break-all;
  981. -webkit-box-orient: vertical;
  982. -webkit-line-clamp: 2;
  983. }
  984. .sku-box {
  985. width: auto;
  986. display: inline;
  987. height: 40rpx;
  988. border-radius: 4rpx;
  989. padding: 0 0 0 10rpx;
  990. box-sizing: border-box;
  991. font-size: 24rpx;
  992. color: #999;
  993. text {
  994. border: 2rpx solid #E4E5E6;
  995. padding: 2rpx 10rpx;
  996. }
  997. }
  998. .pro-price-num-box {
  999. display: flex;
  1000. flex-direction: row;
  1001. align-items: center;
  1002. justify-content: space-between;
  1003. .pro-price-box {
  1004. font-size: 36rpx;
  1005. color: #333333;
  1006. font-weight: 400;
  1007. .fuhao {
  1008. font-size: 24rpx;
  1009. }
  1010. }
  1011. .pro-num-box {
  1012. width: 140rpx;
  1013. height: 40rpx;
  1014. border: 1px solid #ddd;
  1015. border-radius: 4rpx;
  1016. display: flex;
  1017. flex-direction: row;
  1018. justify-content: space-between;
  1019. .num-btn {
  1020. font-size: 34rpx;
  1021. color: #999999;
  1022. display: inline-block;
  1023. width: 40rpx;
  1024. text-align: center;
  1025. line-height: 32rpx;
  1026. height: 40rpx;
  1027. }
  1028. .num-btn.r {
  1029. border-right: 1px solid #ddd;
  1030. }
  1031. .num-btn.l {
  1032. border-left: 1px solid #ddd;
  1033. }
  1034. .num {
  1035. font-size: 26rpx;
  1036. color: #333;
  1037. }
  1038. }
  1039. }
  1040. }
  1041. }
  1042. }
  1043. .pro-item:last-of-type .pro-r {
  1044. border-bottom: none;
  1045. }
  1046. }
  1047. }
  1048. }
  1049. .emptyCart-box {
  1050. margin-top: 70rpx;
  1051. .emptyCart-img {
  1052. width: 216rpx;
  1053. height: 156rpx;
  1054. }
  1055. .goToShopping {
  1056. width: 282rpx;
  1057. height: 84rpx;
  1058. line-height: 84rpx;
  1059. text-align: center;
  1060. background: #333333;
  1061. margin-top: 40rpx;
  1062. color: #FFEBC4;
  1063. font-size: 28rpx;
  1064. }
  1065. }
  1066. .cart-bottom-box-h5 {
  1067. position: fixed;
  1068. bottom: 100rpx;
  1069. width: 100%;
  1070. }
  1071. .cart-bottom-box-app {
  1072. position: fixed;
  1073. bottom: 0rpx;
  1074. width: 100%;
  1075. }
  1076. .cart-bottom {
  1077. height: 120rpx;
  1078. background: #fff;
  1079. display: flex;
  1080. flex-direction: row;
  1081. align-items: center;
  1082. justify-content: space-between;
  1083. border-top: 1rpx solid #eee;
  1084. }
  1085. .left {
  1086. display: flex;
  1087. flex-direction: row;
  1088. align-items: center;
  1089. font-size: 28rpx;
  1090. color: #666;
  1091. .cart-select-img {
  1092. width: 40rpx;
  1093. height: 40rpx;
  1094. margin: 30rpx;
  1095. box-sizing: border-box;
  1096. }
  1097. }
  1098. .right {
  1099. display: flex;
  1100. flex-direction: row;
  1101. align-items: center;
  1102. box-sizing: border-box;
  1103. .price-box {
  1104. font-size: 30rpx;
  1105. color: #333;
  1106. .price {
  1107. font-size: 40rpx;
  1108. color: #C83732;
  1109. font-weight: bold;
  1110. }
  1111. }
  1112. .btn-confirm {
  1113. width: 232rpx;
  1114. height: 120rpx;
  1115. background: #333333;
  1116. margin-left: 18rpx;
  1117. text-align: center;
  1118. line-height: 120rpx;
  1119. font-size: 28rpx;
  1120. color: #FFEBC4;
  1121. }
  1122. .btn-delete {
  1123. width: 232rpx;
  1124. height: 120rpx;
  1125. line-height: 120rpx;
  1126. text-align: center;
  1127. font-size: 28rpx;
  1128. color: #FFFFFF;
  1129. background: #C83732;
  1130. }
  1131. }
  1132. .goosDetailshow-box {
  1133. .detailImg-box {
  1134. margin-top: 30rpx;
  1135. margin-left: 30rpx;
  1136. border-radius: 10rpx;
  1137. border-bottom: 1rpx solid #EDEDED;
  1138. padding-bottom: 20rpx;
  1139. width: 690rpx;
  1140. .detailImg {
  1141. width: 180rpx;
  1142. height: 180rpx;
  1143. }
  1144. }
  1145. .color-box {
  1146. padding: 30rpx 30rpx;
  1147. border-bottom: 1rpx solid #EDEDED;
  1148. width: 690rpx;
  1149. .skuStyle{
  1150. padding: 20rpx 0;
  1151. }
  1152. .skuStyle:nth-child(2) {
  1153. border-top: 1px solid #F3F4F5;
  1154. }
  1155. .colorName-box {
  1156. display: flex;
  1157. flex-wrap: wrap;
  1158. flex-direction: row;
  1159. justify-content: flex-start;
  1160. align-items: center;
  1161. margin-top: 30rpx;
  1162. margin-left: -30rpx;
  1163. .colorName-on {
  1164. background-color: #FFE5D0;
  1165. color: #C5AA7B;
  1166. margin-left: 30rpx;
  1167. padding: 10rpx 32rpx;
  1168. border-radius: 28rpx;
  1169. border: 1rpx solid #C5AA7B;
  1170. font-size: 26rpx;
  1171. text-align: center;
  1172. z-index: 1;
  1173. }
  1174. .colorName {
  1175. background-color: #F5F5F5;
  1176. margin-left: 30rpx;
  1177. padding: 10rpx 32rpx;
  1178. border-radius: 28rpx;
  1179. font-size: 26rpx;
  1180. z-index: 2;
  1181. }
  1182. }
  1183. }
  1184. .modelNum-box {
  1185. padding: 30rpx 30rpx;
  1186. border-bottom: 1rpx solid #EDEDED;
  1187. width: 690rpx;
  1188. .modelNumName-box {
  1189. display: flex;
  1190. flex-wrap: wrap;
  1191. flex-direction: row;
  1192. justify-content: flex-start;
  1193. align-items: center;
  1194. margin-top: 30rpx;
  1195. margin-left: -30rpx;
  1196. .modelNumName-on {
  1197. background-color: #FFE4D0;
  1198. color: #C5AA7B;
  1199. margin-left: 30rpx;
  1200. padding: 10rpx 32rpx;
  1201. border-radius: 28rpx;
  1202. border: 1rpx solid #C5AA7B;
  1203. font-size: 26rpx;
  1204. text-align: center;
  1205. }
  1206. .modelNumName {
  1207. background-color: #F5F5F5;
  1208. margin-left: 30rpx;
  1209. padding: 10rpx 32rpx;
  1210. border-radius: 28rpx;
  1211. font-size: 26rpx;
  1212. }
  1213. }
  1214. }
  1215. .goodsNum-box {
  1216. padding: 30rpx 30rpx;
  1217. width: 690rpx;
  1218. padding-bottom: 140rpx;
  1219. .goodsNumber {
  1220. text-align: center;
  1221. border: 1rpx solid #999999;
  1222. padding: 3rpx 20rpx;
  1223. }
  1224. .subtract {
  1225. border: 1rpx solid #999999;
  1226. padding: 3rpx 20rpx;
  1227. margin-right: -1rpx;
  1228. }
  1229. .add {
  1230. border: 1rpx solid #999999;
  1231. padding: 3rpx 20rpx;
  1232. margin-left: -1rpx;
  1233. }
  1234. }
  1235. .goosDetailbut-box {
  1236. .joinShopCartBut {
  1237. width: 343rpx;
  1238. height: 80rpx;
  1239. background-color: #FFC300;
  1240. color: #FFFEFE;
  1241. font-size: 28rpx;
  1242. line-height: 80rpx;
  1243. text-align: center;
  1244. margin-left: 30rpx;
  1245. }
  1246. .buyNowBut {
  1247. width: 343rpx;
  1248. height: 80rpx;
  1249. border-radius: 0 40rpx 40rpx 0;
  1250. background-color: #FF6F00;
  1251. color: #FFFEFE;
  1252. font-size: 28rpx;
  1253. line-height: 80rpx;
  1254. text-align: center;
  1255. }
  1256. }
  1257. }
  1258. }
  1259. </style>