| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656 |
- <template>
- <view class="content">
- <!-- 购物车 -->
- <view v-if="dataList.length !== 0">
- <view class="cart-bg">
- <view class="cart-num-box">
- <image src="https://ceres.zkthink.com/static/images/logoTop.png"></image>
- <text class="btn-box"
- @click="btnTypeClick(1)"
- v-if="btnType == 0">管理
- </text>
- <text class="btn-box"
- @click="btnTypeClick(0)"
- v-if="btnType == 1">完成
- </text>
- </view>
- <view>
- <text class="num-box">共
- <text class="num">{{ allNum }}</text>
- 件宝贝
- </text>
- </view>
- </view>
- <view class="cart-list-box">
- <view class="itemBox"
- v-for="(item, index) in dataList"
- :key="item.shopId">
- <view class="item"
- v-if="item.skus.length !== 0">
- <view class="shop-box">
- <image mode="aspectFill"
- v-if="item.selected === 1"
- src="https://ceres.zkthink.com/static/images/selectActive.png"
- class="cart-select-img"
- @click.stop="updateShopSel(index,0)"></image>
- <image mode="aspectFill"
- v-else
- src="https://ceres.zkthink.com/static/images/selectEmpty.png"
- class="cart-select-img"
- @click.stop="updateShopSel(index,1)"></image>
- <view class="shop-name-box"
- @click="goStore(index)">
- <image src="https://ceres.zkthink.com/static/images/orderStoreIcon.png"
- class="shop-img"></image>
- <text class="shop-name">{{ item.shopName }}</text>
- <image src="https://ceres.zkthink.com/static/images/arrowRight.png"
- class="arrow-right-img"></image>
- </view>
- </view>
- <view class="rulesBox flex-items"
- v-if="item.currentRules.number">
- <image class="mar-right-20"
- src="https://ceres.zkthink.com/static/images/zuheIcon.png"></image>
- <view class="fs24 font-color-C83732">
- 已满足【{{ item.currentRules.price }}元任选{{ item.currentRules.number }}件】!
- </view>
- </view>
- <view v-for="(skuItem, cIndex) in dataList[index].skus"
- class="product-list-box">
- <view class="pro-item"
- @click="goodsDateils(item.shopId,skuItem.productId,skuItem.skuId)">
- <image mode="aspectFill"
- v-if="skuItem.selected == 1"
- src="https://ceres.zkthink.com/static/images/selectActive.png"
- @click.stop="cartItemSel(index,cIndex,0)"
- class="cart-select-img"></image>
- <image mode="aspectFill"
- v-else
- src="https://ceres.zkthink.com/static/images/selectEmpty.png"
- @click.stop="cartItemSel(index,cIndex,1)"
- class="cart-select-img"></image>
- <view class="pro-r">
- <image :src="skuItem.image"
- class="pro-img"></image>
- <view class="pro-r-r">
- <view class="pro-name">{{ skuItem.productName }}</view>
- <view class="sku-box">
- <text v-if="skuItem.value">{{ skuItem.value }}</text>
- <text v-else>默认规格</text>
- <!-- <text></text> -->
- </view>
- <view class="pro-price-num-box">
- <view class="pro-price-box">
- <text class="fuhao">¥</text>
- <text>{{ skuItem.price }}</text>
- </view>
- <view class="pro-num-box">
- <text class="num-btn r"
- @click.stop="numSub(index,cIndex)">-
- </text>
- <text class="num">{{ skuItem.number }}</text>
- <text class="num-btn l"
- @click.stop="numAdd(index,cIndex)">+
- </text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 商品详情 -->
- <u-popup v-model="goodsDetailShowFlag"
- mode="bottom"
- border-radius="14">
- <view class="goosDetailshow-box">
- <view class="detailImg-box flex-row-plus">
- <image class="detailImg"
- :src="selectedSku.image"></image>
- <view class="flex-column-plus mar-left-40">
- <view class="font-color-C5AA7B">
- <label class="fs24">¥</label>
- <label class="fs36 mar-left-10"
- v-text="selectedSku.activityType === 1 && btnType === 4 ? selectedSku.originalPrice : selectedSku.price"></label>
- </view>
- <label class="fs24 font-color-999 mar-top-20">库存 {{ selectedSku.stockNumber }} 件</label>
- <label class="fs24 mar-top-20">已选</label>
- </view>
- </view>
- <view class="color-box flex-column-plus">
- <view v-for="(attritem,index) in productData.names"
- :key="index"
- class="skuStyle">
- <label class="fs24 font-color-999">{{ attritem.skuName }}</label>
- <view class="colorName-box">
- <view class="pad-bot-30"
- v-for="(attrRes, resIndex) in attritem.values"
- :key="resIndex">
- <view class="colorName"
- :class="{'colorName-on' : selectedAttr[attritem.nameCode] == attrRes.valueCode}"
- @click="nameCodeValueCodeClick(attritem.nameCode, attrRes.valueCode, true)">
- {{ attrRes.skuValue }}
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="goodsNum-box flex-row-plus flex-sp-between"
- :class="{'bottom-line' :supportHuabei}">
- <label class="font-color-999 fs24">数量</label>
- <view class="goodsNum">
- <text class="subtract"
- @click="updateNumSub()">-
- </text>
- <text class="goodsNumber"
- v-model="buyNum">{{ buyNum }}
- </text>
- <text class="add"
- @click.stop="updateNumAdd()">+
- </text>
- </view>
- </view>
- <view class="goosDetailbut-box flex-items-plus">
- <button type="default"
- @click="goodsDateils(shopId,productId,skuId)">查看详情
- </button>
- <button type="default"
- class="submitBtn"
- @click="submitBtn()">确认
- </button>
- </view>
- </view>
- </u-popup>
- <!-- #ifdef H5 -->
- <view class="cart-bottom-box-h5">
- <!-- #endif -->
- <!-- #ifndef H5 -->
- <view class="cart-bottom-box-app">
- <!-- #endif -->
- <view class="cart-bottom">
- <view class="left">
- <image mode="aspectFill"
- v-if="isAllCheck"
- src="https://ceres.zkthink.com/static/images/selectActive.png"
- class="cart-select-img"
- @click="allSel(0)"></image>
- <image mode="aspectFill"
- v-else
- src="https://ceres.zkthink.com/static/images/selectEmpty.png"
- class="cart-select-img"
- @click="allSel(1)"></image>
- <text>全选</text>
- </view>
- <view class="right"
- v-if="btnType == 0">
- <view class="price-box">
- <text>合计:</text>
- <text class="price">¥{{ checkMoney }}</text>
- </view>
- <view class="btn-confirm"
- @click="settlementTap">结算({{ checkNum }})
- </view>
- </view>
- <view class="right"
- v-if="btnType == 1">
- <view class="btn-delete"
- @click="cartDel">删除
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 购物车为空 -->
- <view v-if="isEmpty"
- class="emptyCart-box flex-items-plus flex-column">
- <image class="emptyCart-img"
- src="https://ceres.zkthink.com/static/images/cartEmpty.png"></image>
- <label class="font-color-999 fs26 mar-top-30">你的购物车还没有宝贝哦</label>
- <label class="font-color-999 fs26 mar-top-10">快去首页选一个吧~</label>
- <view class="goToShopping"
- @click="goToShopping">去购物
- </view>
- </view>
- <!-- 热门推荐 -->
- <HotTemplate/>
- <view style="width: 100%;height: 100rpx;background-color:#efefef;"></view>
- <!-- 删除确认弹窗 -->
- <tui-modal :show="cardModal"
- :custom="true"
- :fadein="true">
- <view class="Put-box1">
- <view class="text-align fs34 fs-bold">
- 温馨提示
- </view>
- <view class="mar-top-40 text-align">
- 您确定删除选中的商品吗?
- </view>
- <view class="flex-display flex-sp-between">
- <view class="btn"
- @click="cardModal = false">
- 点错了
- </view>
- <view class="btn submit"
- @click="doDelete">
- 确认删除
- </view>
- </view>
- </view>
- </tui-modal>
- </view>
- </view>
- </template>
- <script>
- import tuiModal from "@/components/modal/modal";
- import HotTemplate from '@/components/hoteRecommed/index.vue'
- import api from "../../../components/canvasShow/config/api";
- const NET = require('../../../utils/request')
- const API = require('../../../config/api')
- export default {
- components: {
- tuiModal,
- HotTemplate
- },
- data() {
- return {
- goodsDetailShowFlag: false,
- OriginalSelectedSku: {},
- selectedSku: {},
- productData: [],
- shopId: 0,
- productId: 0,
- skuId: 0,
- selectedAttr: {},
- supportHuabei: false,
- title: 'Hello',
- btnType: 0,
- dataList: [],
- goosDetailshowFlag: false,
- colorActiveId: 1,
- colorList: [{
- id: 1,
- color: '复古蓝色'
- }, {
- id: 2,
- color: '马卡龙粉色'
- }],
- modelNumActiveId: 1,
- modelNumList: [{
- id: 1,
- modelNum: '小号'
- }, {
- id: 2,
- modelNum: '中号'
- }, {
- id: 3,
- modelNum: '大号'
- }],
- skuItemList: [],
- buyNum: 1,
- allNum: 0,
- checkNum: 0,
- checkMoney: 0,
- isAllCheck: true,
- skuProdList: {},
- item: {},
- cardModal: false,
- isEmpty: false
- }
- },
- computed: {
- // 计算显示tabBar购物车数量
- getCartNum() {
- let cartNum = 0
- this.updateMoneyAndNum()
- cartNum = this.allNum
- if (cartNum > 0) {
- uni.setTabBarBadge({
- index: 2,
- text: cartNum.toString()
- })
- } else {
- uni.removeTabBarBadge({
- index: 2
- })
- }
- uni.setStorageSync('allCartNum', cartNum)
- console.log(uni.getStorageSync('allCartNum'), '1111')
- }
- },
- onLoad() {
- },
- onShow() {
- //判断是否登录
- /* let item = {}
- if(uni.getStorageSync('storage_key')){
- item = uni.getStorageSync('storage_key');
- }
- console.dir(item) */
- /* if(JSON.stringify(item) == '{}'){
- uni.navigateTo({
- url:'../../../pages_category_page2/userModule/login'
- })
- }else{ */
- this.isEmpty = false
- this.dataList = []
- this.getDataList()
- /* } */
- },
- methods: {
- // 提交更换商品规格
- submitBtn() {
- console.log(this.selectedSku.skuId, 'this.selectedSku.skuId')
- console.log(this.skuId, 'this.skuId')
- NET.request(API.UpdateSkuCart, {
- skuId: this.skuId,
- newSkuId: this.selectedSku.skuId,
- number: this.buyNum
- },
- "POST").then(res => {
- this.goodsDetailShowFlag = false
- this.getDataList()
- })
- },
- // 购物车修改属性样式时:数量减
- updateNumSub() {
- if (this.buyNum > 1) {
- this.buyNum = this.buyNum - 1
- } else {
- uni.showToast({
- title: '亲!至少一件哦!',
- icon: "none"
- })
- }
- },
- // 获取匹配组合定价价格
- getData(item) {
- return new Promise(((resolve, reject) => {
- if (item.ids) {
- NET.request(api.getPrices, {
- shopId: item.shopId,
- ids: item.ids,
- page: 1,
- pageSize: 10
- }, 'GET').then(res => {
- resolve(res)
- })
- } else {
- resolve([])
- }
- }))
- },
- // 购物车修改属性样式时:数量加
- updateNumAdd() {
- if (this.buyNum < this.selectedSku.stockNumber) {
- this.buyNum = this.buyNum + 1
- } else {
- uni.showToast({
- title: '库存不足!',
- icon: "none"
- })
- }
- },
- //获取商品详情
- queryProductDetail() {
- uni.showLoading({
- mask: true,
- title: '加载中...'
- })
- NET.request(API.QueryProductDetail, {
- shopId: this.shopId,
- productId: this.productId,
- skuId: this.skuId,
- terminal: 1
- },
- "GET").then(res => {
- uni.hideLoading()
- this.productData = res.data
- this.markTools = res.data.markTools //平台优惠券
- this.shopMarkTools = res.data.shopMarkTools //店铺优惠券
- //如果是单款式商品,需要特殊处理productData.names
- const mapKeys = Object.keys(this.productData.map)
- if (mapKeys.length === 1 && mapKeys[0] === '单款项') {
- this.productData.names[0].values.push({
- skuValue: '单款项',
- valueCode: '单款项'
- })
- }
- //如果sku的图像为空,设置为商品的图像
- for (var key in this.productData.map) {
- let skuImage = this.productData.map[key].image
- if (!skuImage) {
- this.productData.map[key].image = this.productData.images[0]
- }
- }
- //评价
- this.commentList = res.data.comments
- this.commentListLength = this.commentList.length
- this.sellDescList = res.data.text.replace(/\<img/gi,
- '<img style="max-width:100%;height:auto" ')
- this.couponListLength = res.data.couponImages.length
- this.showVOList = res.data.couponImages
- this.couponList = res.data.markTools
- //渲染商详之后,如果参数传了skuId,则选中该skuId,否则选中第一个规格
- if (this.skuId) {
- this.selectBySkuId(this.skuId)
- console.log(this.skuId, 'this.skuId2222')
- } else {
- for (var attr in this.productData.names) {
- this.nameCodeValueCodeClick(attr.nameCode, attr.values[0].valueCode, true)
- }
- }
- this.beginTimer();
- }).catch(res => {
- uni.hideLoading()
- })
- },
- selectBySkuId(skuId) {
- if (skuId) {
- let mapinfo = this.productData.map
- for (var key in mapinfo) {
- if (parseInt(mapinfo[key].skuId) === parseInt(skuId)) {
- this.selectedSku = mapinfo[key]
- // 选中sku对应的规格
- const valueCodeList = key.split(',')
- this.productData.names.forEach(attr => {
- for (var index in attr.values) {
- let valueCode = attr.values[index].valueCode
- if (valueCodeList.includes(valueCode)) {
- this.nameCodeValueCodeClick(attr.nameCode, valueCode, false)
- break
- }
- }
- })
- break
- }
- }
- }
- },
- nameCodeValueCodeClick(nameCode, valueCode, reSelectSku) {
- this.selectedAttr[nameCode] = valueCode
- if (reSelectSku) {
- let attrList = []
- for (var key in this.selectedAttr) {
- attrList.push(this.selectedAttr[key])
- }
- const attrkey = attrList.join(',')
- let mapinfo = this.productData.map
- for (var key in mapinfo) {
- if (attrkey === key) {
- this.selectedSku = mapinfo[key]
- }
- }
- }
- // 选中sku之后,做一些相应的操作
- // this.selectSkuPostProcessor()
- this.$forceUpdate(); // 重绘
- },
- selectSkuPostProcessor() {
- const ifEnable = this.selectedSku.ifEnable
- if (this.selectedSku.activityType === 1 && ifEnable === 0) {
- this.topThreeCollageOrders = this.selectedSku.collageOrders.slice(0, 3)
- }
- if ([1, 2, 3, 4, 5].includes(this.selectedSku.activityType) && ifEnable === 0) {
- this.dateformat(this.selectedSku.endTime)
- this.countDown();
- }
- this.timeActivetype = ifEnable === 0;
- this.shopDiscountId = this.selectedSku.shopDiscountId
- this.shopSeckillId = this.selectedSku.shopSeckillId
- },
- // 更换商品样式
- changeSkuItemValue(skuItem, shopId) {
- this.OriginalSelectedSku = skuItem
- this.shopId = shopId
- this.productId = skuItem.productId
- this.skuId = skuItem.skuId
- this.buyNum = this.OriginalSelectedSku.number
- this.queryProductDetail()
- setTimeout(() => {
- this.goodsDetailShowFlag = true
- }, 1000)
- },
- //逛店铺
- goStore(index) {
- uni.navigateTo({
- url: '../../../pages_category_page1/store/index?storeId=' + this.dataList[index].shopId
- })
- },
- //商品详情
- goodsDateils(shopId, productId, skuId) {
- uni.navigateTo({
- url: '../../../pages_category_page1/goodsModule/goodsDetails?shopId=' + shopId +
- '&productId=' + productId + '&skuId=' + skuId
- })
- },
- // 去首页
- goToShopping() {
- uni.switchTab({
- url: '../../../pages/tabbar/index/index'
- })
- },
- btnTypeClick(type) {
- this.btnType = type
- },
- getDataList() {
- uni.showLoading({
- mask: true,
- title: '加载中...',
- })
- NET.request(API.ShoppingCart, {}, 'GET').then(res => {
- uni.hideLoading()
- this.dataList = res.data
- this.allNum = this.dataList.length
- if (this.dataList.length === 0) {
- this.isEmpty = true
- uni.setStorageSync('allCartNum', 0)
- uni.removeTabBarBadge({
- index: 2
- })
- }
- let recheck = false
- this.dataList.forEach((item, index) => {
- item['currentIds'] = []
- item['priceNumber'] = 0
- item['rules'] = []
- item['currentRules'] = {}
- item['ids'] = 0
- for (let i = item.skus.length - 1; i >= 0; i--) {
- if (item.skus[i].shelveState === 0) {
- item.skus.splice(i, 1)
- if (item.skus.length === 0) {
- recheck = true
- }
- } else {
- if (item.skus[i].activityType === 6 && item.skus[i].selected === 1) {
- item.currentIds.push(item.skus[i].priceId)
- item.priceNumber += item.skus[i].number
- }
- }
- }
- for (let i = 0; i < item.skus.length; i++) {
- if (item.skus[i].activityType === 6) {
- item.ids = item.skus[i].priceId
- break
- }
- }
- this.getData(item).then(res => {
- let rules = []
- rules = res.data
- this.dataList[index].rules = rules ? rules[0].rules : {}
- for (let i = 0; i < this.dataList[index].rules.length; i++) {
- // console.log(this.dataList[index].rules[i].number, this.dataList[index].priceNumber, 'fsdfsdfsdfs')
- if (this.dataList[index].rules[i].number === this.dataList[index].priceNumber) {
- this.dataList[index].currentRules = this.dataList[index].rules[i]
- console.log(this.dataList[index].currentRules, '==', this.dataList[index].rules[i])
- this.$forceUpdate()
- break
- } else if (this.dataList[index].rules[this.dataList[index].rules.length - 1].number < this.dataList[index].priceNumber) {
- this.dataList[index].currentRules = this.dataList[index].rules[this.dataList[index].rules.length - 1]
- this.$forceUpdate()
- break
- }
- }
- // 重新检查是不是全为空
- if (recheck) {
- let isEmpty = true
- this.dataList.forEach((item, index) => {
- if (item.skus.length !== 0) {
- isEmpty = false
- }
- })
- this.isEmpty = isEmpty
- }
- this.updateMoneyAndNum()
- })
- })
- }).catch(res => {
- uni.hideLoading()
- })
- },
- // 数量减
- numSub(index, cIndex) {
- this.dataList[index].priceNumber = 0
- if (this.dataList[index].skus[cIndex].number > 1) {
- this.dataList[index].skus[cIndex].number = this.dataList[index].skus[cIndex].number - 1
- this.dataList[index].priceNumber = 0
- this.priceFn(index)
- this.updateCart(this.dataList[index].skus[cIndex].skuId, this.dataList[index].skus[cIndex].number)
- } else {
- uni.showToast({
- title: '亲!至少一件哦!',
- icon: "none"
- })
- }
- },
- // 数量加
- numAdd(index, cIndex) {
- this.dataList[index].priceNumber = 0
- if (this.dataList[index].skus[cIndex].number >= this.dataList[index].skus[cIndex].stockNumber) {
- this.dataList[index].skus[cIndex].number = this.dataList[index].skus[cIndex].stockNumber
- wx.showToast({
- title: '库存不足!',
- icon: 'none'
- })
- return;
- }
- if (this.dataList[index].skus[cIndex].number <= this.dataList[index].skus[cIndex].stockNumber) {
- this.dataList[index].skus[cIndex].number = this.dataList[index].skus[cIndex].number + 1
- this.dataList[index].priceNumber = 0
- this.priceFn(index)
- this.updateCart(this.dataList[index].skus[cIndex].skuId, this.dataList[index].skus[cIndex].number)
- }
- },
- updateMoneyAndNum() {
- this.isAllCheck = true
- this.allNum = 0
- this.checkNum = 0
- // this.checkMoney = 0
- for (let i = 0; i < this.dataList.length; i++) {
- /** 判断是否存在组合促销*/
- // 当前店铺
- let shopObj = this.dataList[i]
- // 当前店铺的组合优惠ID
- let groupPriceId = shopObj.currentIds
- // 当前店铺的组合优惠规则
- let groupRule = shopObj.currentRules
- let selectGroupSku = []
- for (let j = 0; j < this.dataList[i].skus.length; j++) {
- let item = this.dataList[i].skus[j]
- this.allNum += item.number
- if (item.selected == 1) {
- // 是否在组合商品中
- if (groupPriceId.includes(item.priceId)) {
- selectGroupSku.push(item)
- }
- this.checkNum = this.checkNum + item.number
- // this.checkMoney += parseFloat(item.price * item.number)
- } else {
- if (this.isAllCheck) {
- this.isAllCheck = false
- }
- }
- }
- }
- // 算钱
- this.getPriceBySelect()
- uni.setStorageSync('allCartNum', this.allNum)
- if (this.allNum > 0) {
- uni.setTabBarBadge({
- index: 2,
- text: (this.allNum).toString()
- })
- } else {
- uni.removeTabBarBadge({
- index: 2
- })
- }
- },
- updateShopSel(index, type) {
- this.dataList[index].currentRules = {}
- this.dataList[index].priceNumber = null
- console.log(index, 'index', type, 'type')
- let shopCarts = [{
- shopId: '',
- skus: []
- }]
- this.dataList[index].selected = type
- let len = this.dataList[index].skus.length
- for (let i = 0; i < len; i++) {
- this.dataList[index].skus[i].selected = type
- var skusobj = {};
- skusobj["skuId"] = this.dataList[index].skus[i].skuId;
- skusobj["selected"] = this.dataList[index].skus[i].selected
- shopCarts[0].skus.push(skusobj);
- }
- shopCarts[0].shopId = this.dataList[index].shopId
- this.priceFn(index)
- this.updateSelected(shopCarts)
- this.$forceUpdate()
- },
- //选中商品
- updateSelected(shopCarts) {
- this.updateMoneyAndNum()
- NET.request(API.SelectedCart, {
- shopCarts
- }, 'POST').then(res => {
- }).catch(res => {
- })
- },
- updateCart(skuId, number) {
- NET.request(API.UpdateNumberCart, {
- skuId: skuId,
- number: number
- }, 'POST').then(res => {
- this.updateMoneyAndNum()
- }).catch(res => {
- })
- },
- cartItemSel(index, cIndex, type) {
- console.log(this.dataList)
- this.dataList[index].currentRules = {}
- this.dataList[index].priceNumber = 0
- let shopCarts = [{
- shopId: 0,
- skus: []
- }]
- this.dataList[index].skus[cIndex].selected = type
- if (type == 1) {
- let len = this.dataList[index].skus.length
- let shopType = 1
- for (let i = 0; i < len; i++) {
- if (this.dataList[index].skus[i].selected == 0) {
- shopType = 0
- break
- }
- }
- this.dataList[index].selected = shopType
- } else {
- this.dataList[index].selected = type
- }
- this.priceFn(index)
- shopCarts[0].shopId = this.dataList[index].shopId
- var skusobj = {};
- skusobj["skuId"] = this.dataList[index].skus[cIndex].skuId;
- skusobj["selected"] = this.dataList[index].skus[cIndex].selected;
- shopCarts[0].skus.push(skusobj);
- this.updateSelected(shopCarts)
- },
- // 组合定价
- priceFn(shopIndex) {
- this.dataList[shopIndex].currentRules = {}
- this.dataList[shopIndex].skus.forEach((item) => {
- if (item.activityType === 6 && item.selected === 1) {
- this.dataList[shopIndex].priceNumber += item.number
- }
- })
- for (let i = 0; i < this.dataList[shopIndex].rules.length; i++) {
- if (this.dataList[shopIndex].rules[i].number === this.dataList[shopIndex].priceNumber) {
- this.dataList[shopIndex].currentRules = this.dataList[shopIndex].rules[i]
- console.log(this.dataList[shopIndex].currentRules, '==', this.dataList[shopIndex].rules[i])
- this.$forceUpdate()
- break
- } else if (this.dataList[shopIndex].rules[this.dataList[shopIndex].rules.length - 1].number < this.dataList[shopIndex].priceNumber) {
- this.dataList[shopIndex].currentRules = this.dataList[shopIndex].rules[this.dataList[shopIndex].rules.length - 1]
- this.$forceUpdate()
- break
- }
- }
- },
- //全选
- allSel(type) {
- this.updateAllSel(type)
- },
- updateAllSel(type) {
- console.log(type, 'type')
- let len = this.dataList.length
- for (let i = 0; i < len; i++) {
- let len2 = this.dataList[i].skus.length
- this.dataList[i].selected = type
- let priceNum = 0
- for (let j = 0; j < len2; j++) {
- this.dataList[i].skus[j].selected = type
- if (this.dataList[i].skus[j].selected === 1 && this.dataList[i].skus[j].activityType === 6) {
- priceNum += this.dataList[i].skus[j].number
- }
- }
- this.dataList[i].priceNumber = priceNum
- if (JSON.stringify(this.dataList[i].rules) !== "{}" && this.dataList[i].rules.length > 0) {
- this.dataList[i].rules.forEach((item => {
- if (item.number <= this.dataList[i].priceNumber) {
- this.dataList[i].currentRules = item
- }
- }))
- }
- }
- if (type === 0) {
- this.dataList.forEach((item) => {
- item.currentRules = {}
- })
- }
- let shopCarts = []
- this.updateSelected(shopCarts)
- },
- //点击删除
- cartDel() {
- if (!this.checkNum) {
- uni.showToast({
- title: '请先选择对应商品',
- icon: 'none'
- })
- return;
- }
- this.cardModal = true
- },
- //删除购物车
- doDelete() {
- this.cardModal = false
- let cartList = []
- let n = 0
- let skus = []
- let len = this.dataList.length
- for (let i = 0; i < len; i++) {
- let item = {}
- let len2 = this.dataList[i].skus.length
- for (let j = 0; j < len2; j++) {
- let itemGoods = this.dataList[i].skus[j]
- if (itemGoods.selected == 1) {
- skus[n] = itemGoods.skuId
- n = n + 1
- }
- }
- }
- NET.request(API.DeleteCart, {
- ids: skus
- }, 'POST').then(res => {
- this.getDataList()
- }).catch(res => {
- })
- },
- /**
- * 获取结算数组(计算价格)
- * @param needReturn 是否需要返回数组
- * @returns {*[]}
- */
- getPriceBySelect(needReturn=false){
- uni.showLoading({
- title:"计算中..."
- })
- let addCart = []
- let len = this.dataList.length
- for (let i = 0; i < len; i++) {
- let shopObj = {}
- shopObj["shopId"] = this.dataList[i].shopId
- shopObj["skus"] = []
- let len2 = this.dataList[i].skus.length
- for (let j = 0; j < len2; j++) {
- let skusObj = {}
- skusObj["ifLogistics"] = this.dataList[i].skus[j].ifLogistics
- skusObj["number"] = this.dataList[i].skus[j].number
- skusObj["selected"] = this.dataList[i].skus[j].selected
- skusObj["skuId"] = this.dataList[i].skus[j].skuId
- shopObj.skus.push(skusObj)
- }
- addCart.push(shopObj)
- }
- let newArray = []
- addCart.forEach((item, index) => {
- newArray[index] = item
- newArray[index].skus = item.skus.filter((item) => {
- return item.selected == 1
- })
- if (item.skus.length == 0) {
- newArray.splice(index, 1);
- }
- })
- newArray = newArray.filter(d => d)
- let postData = {
- type: 2,
- shops: newArray
- }
- if(!needReturn){
- NET.request(API.Settlement, postData, 'POST').then(res => {
- let money = 0;
- res.data.shops.forEach(item=>{
- money+=item.total
- })
- this.checkMoney = money.toFixed(2)
- uni.hideLoading()
- })
- }else{
- return newArray
- }
- },
- //结算购物车
- settlementTap() {
- let newArray = this.getPriceBySelect(true)
- uni.setStorageSync('skuItemDTOList', newArray)
- uni.navigateTo({
- url: '../../../pages_category_page1/orderModule/orderConfirm?type=2'
- })
- },
- //商品尺寸弹窗
- goosDetailshowClick(storeId, skuItemId) {
- this.goosDetailshowFlag = true
- this.colorActiveClick(storeId, skuItemId)
- },
- //颜色选中事件
- colorActiveClick(storeId, attrItemId) {
- this.colorActiveId = attrItemId
- NET.request(API.QueryProductSku, {
- productId: storeId,
- skuValueIdList: [attrItemId]
- }, 'POST').then(res => {
- if (res.code === 0) {
- this.skuProdList = res.data
- this.skuProdId = res.data.id
- this.skuImg = res.data.skuImg
- this.skuNameStr = res.data.skuNameStr
- this.skuPrice = res.data.skuPrice
- }
- }).catch(res => {
- })
- },
- }
- }
- </script>
- <style lang="scss"
- scoped>
- page {
- // background: #f7f7f7;
- }
- .content {
- overflow: hidden;
- .goosDetailshow-box {
- .detailImg-box {
- margin-top: 30upx;
- margin-left: 30upx;
- border-radius: 10upx;
- border-bottom: 1upx solid #EDEDED;
- padding-bottom: 20upx;
- width: 690upx;
- .detailImg {
- width: 180upx;
- height: 180upx;
- }
- }
- .color-box {
- padding: 30upx 30upx;
- border-bottom: 1upx solid #EDEDED;
- width: 690upx;
- .colorName-box {
- display: flex;
- flex-wrap: wrap;
- flex-direction: row;
- justify-content: flex-start;
- align-items: center;
- margin-top: 30upx;
- margin-left: -30upx;
- .colorName {
- background-color: #FFFFFF;
- margin-left: 30upx;
- padding: 10upx 32upx;
- font-size: 26upx;
- border: 2rpx solid #E4E5E6;
- z-index: 2;
- color: #333333;
- }
- .colorName-on {
- box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.1);
- color: #C5AA7B;
- margin-left: 30upx;
- padding: 10upx 32upx;
- font-size: 26upx;
- text-align: center;
- z-index: 1;
- border: none;
- }
- }
- }
- .modelNum-box {
- padding: 30upx 30upx;
- border-bottom: 1upx solid #EDEDED;
- width: 690upx;
- .modelNumName-box {
- display: flex;
- flex-wrap: wrap;
- flex-direction: row;
- justify-content: flex-start;
- align-items: center;
- margin-top: 30upx;
- margin-left: -30upx;
- .modelNumName-on {
- background-color: #FFE4D0;
- color: #FF7800;
- margin-left: 30upx;
- padding: 10upx 32upx;
- border-radius: 28upx;
- border: 1upx solid #FF7800;
- font-size: 26upx;
- text-align: center;
- }
- .modelNumName {
- background-color: #F5F5F5;
- margin-left: 30upx;
- padding: 10upx 32upx;
- border-radius: 28upx;
- font-size: 26upx;
- }
- }
- }
- .goodsNum-box {
- padding: 30upx 30upx;
- width: 100%;
- padding-bottom: 140upx;
- .goodsNum {
- height: 50upx;
- text {
- display: inline-block;
- width: 50upx;
- height: 50upx;
- border: 1upx solid #999999;
- text-align: center;
- // line-height: 50upx;
- }
- .subtract {
- border-right: 0upx;
- }
- .add {
- border-left: 0upx;
- }
- }
- }
- .bottom-line {
- border-bottom: 1upx solid #EDEDED;
- }
- .huabei-box {
- padding: 30upx 30upx;
- width: 690upx;
- .fenqi-box {
- margin-top: 15upx;
- width: 120%;
- .huabei-item {
- display: inline-block;
- background: #f3f3f3;
- padding: 16upx 24upx;
- margin: 5upx 10upx;
- border-radius: 15upx;
- text-align: center;
- font-size: 7upx;
- .huabei-period {
- display: block;
- }
- }
- .fenqi-on {
- border: 1px solid #EF7F93;
- color: #EF7F93;
- }
- .disabled {
- color: #cacaca;
- }
- }
- }
- .goosDetailbut-box {
- justify-content: center;
- margin-bottom: 48rpx;
- button {
- width: 342rpx;
- height: 100rpx;
- line-height: 100rpx;
- font-size: 28rpx;
- border: 1px solid;
- border-radius: 0;
- }
- .submitBtn {
- color: #FFEBC4;
- background: #333333;
- }
- }
- }
- .Put-box1 {
- .btn {
- text-align: center;
- margin-top: 40rpx;
- border: 1px solid #333333;
- height: 80upx;
- line-height: 80upx;
- width: 240upx;
- color: #333333;
- }
- .submit {
- background-color: #333333;
- color: #FFEBC4;
- }
- }
- .cart-bg {
- width: 100%;
- height: 180rpx;
- .cart-num-box {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- image {
- width: 286rpx;
- height: 72rpx;
- }
- .btn-box {
- font-size: 30rpx;
- color: #333333;
- padding: 30rpx;
- box-sizing: border-box;
- display: inline-block;
- }
- }
- .num-box {
- padding: 30rpx 0 30rpx 30rpx;
- box-sizing: border-box;
- font-size: 30rpx;
- color: #C5CACF;
- }
- }
- .cart-list-box {
- box-sizing: border-box;
- .itemBox {
- .item {
- background: #fff;
- border-bottom: 16rpx solid #F8F9FA;
- .shop-box {
- display: flex;
- flex-direction: row;
- align-items: center;
- border-bottom: 1px solid #eee;
- position: relative;
- .cart-select-img {
- width: 40rpx;
- height: 40rpx;
- margin: 30rpx;
- box-sizing: border-box;
- }
- .shop-name-box {
- display: flex;
- flex-direction: row;
- align-items: center;
- .shop-img {
- width: 36rpx;
- height: 36rpx;
- margin-right: 10rpx;
- }
- .shop-name {
- font-size: 30rpx;
- color: #333;
- font-weight: bold;
- display: inline-block;
- margin-left: 10rpx;
- }
- .arrow-right-img {
- width: 30rpx;
- height: 30rpx;
- box-sizing: border-box;
- margin-left: 30rpx;
- position: absolute;
- right: 30rpx;
- }
- }
- }
- .rulesBox {
- height: 86rpx;
- background: #F9F6F1;
- padding: 0 20rpx;
- image {
- width: 126rpx;
- height: 46rpx;
- }
- }
- .product-list-box {
- .pro-item {
- display: flex;
- flex-direction: row;
- align-items: center;
- .cart-select-img {
- width: 40rpx;
- height: 40rpx;
- margin: 30rpx;
- box-sizing: border-box;
- }
- .pro-r {
- flex: 1;
- border-bottom: 1px solid #eee;
- display: flex;
- flex-direction: row;
- padding: 30rpx 30rpx 30rpx 0;
- box-sizing: border-box;
- overflow: hidden;
- .pro-img {
- width: 180rpx;
- height: 180rpx;
- border-radius: 10rpx;
- margin-right: 30rpx;
- }
- .pro-r-r {
- flex: 1;
- font-size: 26rpx;
- color: #333;
- overflow: hidden;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- .pro-name {
- height: 66rpx;
- line-height: 33rpx;
- display: -webkit-box;
- overflow: hidden;
- text-overflow: ellipsis;
- word-break: break-all;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- }
- .sku-box {
- width: auto;
- display: inline;
- height: 40rpx;
- border-radius: 4rpx;
- padding: 0 0 0 10rpx;
- box-sizing: border-box;
- font-size: 24rpx;
- color: #999;
- text {
- border: 2rpx solid #E4E5E6;
- padding: 2rpx 10rpx;
- }
- }
- .pro-price-num-box {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- .pro-price-box {
- font-size: 36rpx;
- color: #333333;
- font-weight: 400;
- .fuhao {
- font-size: 24rpx;
- }
- }
- .pro-num-box {
- width: 140rpx;
- height: 40rpx;
- border: 1px solid #ddd;
- border-radius: 4rpx;
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- overflow: hidden;
- .num-btn {
- font-size: 34rpx;
- color: #999999;
- display: inline-block;
- width: 40rpx;
- text-align: center;
- line-height: 32rpx;
- height: 40rpx;
- }
- .num-btn.r {
- border-right: 1px solid #ddd;
- }
- .num-btn.l {
- border-left: 1px solid #ddd;
- }
- .num {
- font-size: 26rpx;
- color: #333;
- }
- }
- }
- }
- }
- }
- .pro-item:last-of-type .pro-r {
- border-bottom: none;
- }
- }
- }
- }
- .itemBox:first-child {
- .shop-box {
- border-top: 2rpx solid #eee;
- }
- }
- .itemBox:last-child {
- .item {
- border-bottom: none;
- }
- }
- }
- .emptyCart-box {
- margin: 100rpx 0;
- .emptyCart-img {
- width: 216rpx;
- height: 156rpx;
- }
- .goToShopping {
- width: 282rpx;
- height: 84rpx;
- line-height: 84rpx;
- text-align: center;
- background: #333333;
- margin-top: 40rpx;
- color: #FFEBC4;
- font-size: 28rpx;
- }
- }
- .cart-bottom-box-h5 {
- position: fixed;
- bottom: 74rpx;
- width: 100%;
- z-index: 99;
- }
- .cart-bottom-box-app {
- position: fixed;
- bottom: 0rpx;
- width: 100%;
- z-index: 99;
- }
- .cart-bottom {
- height: 120rpx;
- background: #fff;
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- border-top: 1rpx solid #eee;
- }
- .left {
- display: flex;
- flex-direction: row;
- align-items: center;
- font-size: 28rpx;
- color: #666;
- .cart-select-img {
- width: 40rpx;
- height: 40rpx;
- margin: 30rpx;
- box-sizing: border-box;
- }
- }
- .right {
- display: flex;
- flex-direction: row;
- align-items: center;
- box-sizing: border-box;
- .price-box {
- font-size: 30rpx;
- color: #333;
- .price {
- font-size: 40rpx;
- color: #C83732;
- font-weight: bold;
- }
- }
- .btn-confirm {
- width: 232rpx;
- height: 120rpx;
- background: #333333;
- margin-left: 18rpx;
- text-align: center;
- line-height: 120rpx;
- font-size: 28rpx;
- color: #FFEBC4;
- }
- .btn-delete {
- width: 232rpx;
- height: 120rpx;
- line-height: 120rpx;
- text-align: center;
- font-size: 28rpx;
- color: #FFFFFF;
- background: #C83732;
- }
- }
- .goosDetailshow-box {
- .detailImg-box {
- margin-top: 30rpx;
- margin-left: 30rpx;
- border-radius: 10rpx;
- border-bottom: 1rpx solid #EDEDED;
- padding-bottom: 20rpx;
- width: 690rpx;
- .detailImg {
- width: 180rpx;
- height: 180rpx;
- }
- }
- .color-box {
- padding: 30rpx 30rpx;
- border-bottom: 1rpx solid #EDEDED;
- width: 690rpx;
- .skuStyle {
- padding: 20rpx 0;
- }
- .skuStyle:nth-child(2) {
- border-top: 1px solid #F3F4F5;
- }
- .colorName-box {
- display: flex;
- flex-wrap: wrap;
- flex-direction: row;
- justify-content: flex-start;
- align-items: center;
- margin-top: 30rpx;
- margin-left: -30rpx;
- .colorName-on {
- background-color: #FFE5D0;
- color: #C5AA7B;
- margin-left: 30rpx;
- padding: 10rpx 32rpx;
- border-radius: 28rpx;
- border: 1rpx solid #C5AA7B;
- font-size: 26rpx;
- text-align: center;
- z-index: 1;
- }
- .colorName {
- background-color: #F5F5F5;
- margin-left: 30rpx;
- padding: 10rpx 32rpx;
- border-radius: 28rpx;
- font-size: 26rpx;
- z-index: 2;
- }
- }
- }
- .modelNum-box {
- padding: 30rpx 30rpx;
- border-bottom: 1rpx solid #EDEDED;
- width: 690rpx;
- .modelNumName-box {
- display: flex;
- flex-wrap: wrap;
- flex-direction: row;
- justify-content: flex-start;
- align-items: center;
- margin-top: 30rpx;
- margin-left: -30rpx;
- .modelNumName-on {
- background-color: #FFE4D0;
- color: #C5AA7B;
- margin-left: 30rpx;
- padding: 10rpx 32rpx;
- border-radius: 28rpx;
- border: 1rpx solid #C5AA7B;
- font-size: 26rpx;
- text-align: center;
- }
- .modelNumName {
- background-color: #F5F5F5;
- margin-left: 30rpx;
- padding: 10rpx 32rpx;
- border-radius: 28rpx;
- font-size: 26rpx;
- }
- }
- }
- .goodsNum-box {
- padding: 30rpx 30rpx;
- width: 690rpx;
- padding-bottom: 140rpx;
- .goodsNumber {
- text-align: center;
- border: 1rpx solid #999999;
- padding: 3rpx 20rpx;
- }
- .subtract {
- border: 1rpx solid #999999;
- padding: 3rpx 20rpx;
- margin-right: -1rpx;
- }
- .add {
- border: 1rpx solid #999999;
- padding: 3rpx 20rpx;
- margin-left: -1rpx;
- }
- }
- .goosDetailbut-box {
- .joinShopCartBut {
- width: 343rpx;
- height: 80rpx;
- background-color: #FFC300;
- color: #FFFEFE;
- font-size: 28rpx;
- line-height: 80rpx;
- text-align: center;
- margin-left: 30rpx;
- }
- .buyNowBut {
- width: 343rpx;
- height: 80rpx;
- border-radius: 0 40rpx 40rpx 0;
- background-color: #FF6F00;
- color: #FFFEFE;
- font-size: 28rpx;
- line-height: 80rpx;
- text-align: center;
- }
- }
- }
- }
- </style>
|