123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- <template>
- <view class="">
- <view class="page">
- <navBar :backType="navBarTitle" :title="navBarTitle?navBarTitle:'详情'" :back="true" color="black"
- background="white" />
- <view class="topImg">
- <u-swiper type='img' radius="0rpx 0rpx 0rpx 40rpx" :list="bannerList" keyName="image" indicator
- indicatorMode="line" :autoplay="true" height="850rpx" imgMode="heightFix" circular
- @change="bannerChange">
- <view slot="indicator">
- </view>
- </u-swiper>
- <view class="indicatorBox1">
- <view class="indicator1">
- <view class="indicator1__dot1" style="" v-for="(item, index) in bannerList" :key="index"
- :class="[index === currentNum ?'indicator1__dot1--active1':'']">
- </view>
- </view>
- </view>
- </view>
- <view class="cen">
- <image class="water" src="/static/index/water.png" mode=""></image>
- <image class="halfC" src="/static/index/halfCircle_275.png" mode=""></image>
- <image class="love" :src="lovePic" mode="" @click="handleCol"></image>
- <view class="txtBox">
- <view class="left" v-if="content.name">
- {{content.name}}
- </view>
- <view class="right">
- {{totalCount}}人已收藏
- </view>
- </view>
- </view>
- <view class="parmasBox" v-for="(item,index) in Object.keys(skuParams.attrs)">
- <view class="con">
- <view class="title">
- {{item}}
- </view>
- <view class="list">
- <view class="item" @click="handleC(item,index,item1)"
- v-for="(item1,index1) in skuParams.attrs[item]"
- :class="[item1==saveCheckedObj[item]?'act':'']">
- {{item1}}
- </view>
- </view>
- </view>
- </view>
- <!-- <view class="parmasBox" style="border-bottom: none;"> -->
- <view class="parmasBox" style="border-bottom:1rpx solid #EAEAEA">
- <view class="con" @click="handleOpenOrClose(1)">
- <view class="title1">
- <view class="txt">
- 商品描述
- </view>
- <image class="add" :src="addOrLessIcon1" mode="" :style="{height:addOrLessIcon1=='/static/index/shortLine.png'
- ?'2rpx':'22rpx'}"></image>
- </view>
- <view class="des" v-if="show1">
- <u-parse :content="content1"></u-parse>
- </view>
- </view>
- </view>
- </view>
- <view class="bot">
- <view class="left">
- <view class="price">
- ¥{{Number( totalPrice).toFixed(0)}}
- </view>
- <image src="/static/index/arrDown.png" mode=""></image>
- </view>
- <button open-type="share" class="right">
- 一键下单
- </button>
- </view>
- </view>
- </view>
- </template>
- <script>
- import {
- addCollReq,
- cancelCollReq,
- getGoodsPriceReq,
- getMyGoodsDetailReq,
- } from '@/api/test/index.js'
- export default {
- components: {
- },
- data() {
- return {
- currIndex1: 0,
- currentNum: 0,
- show1: true,
- addOrLessIcon1: '/static/index/shortLine.png',
- lovePic: '',
- content: null,
- picBase: this.$picBase,
- bannerList: [],
- content1: '',
- totalPrice: 0,
- totalCount: 0,
- navBarTitle: '',
- ids: [],
- cutdownRatio: 1,
- // sku
- skuParams: {
- "attrs": {},
- "sku": []
- },
- saveCheckedObj: null,
- fullCheckArr: [],
- watchValue: null,
- conditions: [],
- cutdownRatio: 1,
- }
- },
- async onLoad(o) {
- // o.id = 17
- this.cutdownRatio = this.$getCutDown()
- console.log('哪种折扣价格-商城详情', this.cutdownRatio);
- if (o.id) {
- // this.ids = JSON.parse(o.ids)
- this.navBarTitle = '首页'
- let res = await getMyGoodsDetailReq({
- id: o.id
- })
- if (res.code == 0) {
- console.log('回显商城详情返回值: ', res);
- // this.skuParams = res.data.sku_params
- this.skuParams = res.data.sku_params || {
- "attrs": {},
- "sku": []
- }
- // 动态生成判断条件对象数组
- let c = []
- Object.keys(this.skuParams.attrs).forEach((item, index) => {
- c.push({
- key: item,
- value: null
- })
- })
- this.conditions = c
- // 动态生成用于判断选中激活项的对象
- let saveCheckedObj = {}
- Object.keys(this.skuParams.attrs).forEach((item, index) => {
- // saveCheckedObj[item] = null
- saveCheckedObj[item] = this.skuParams.attrs[item][0]
- })
- this.saveCheckedObj = saveCheckedObj
- // 动态生成用于判断sku参数是否全部选中的中间数组
- this.fullCheckArr = new Array(Object.keys(this.skuParams.attrs).length).fill(0)
- //回显默认值
- Object.keys(this.skuParams.attrs).forEach((item, index) => {
- this.handleC(item, index, this.skuParams.attrs[item][0])
- })
- this.content = res.data
- this.bannerList = res.data.images
- this.totalCount = res.data.collect_total_count
- this.content1 = res.data.content
- if (this.content.isCollect) {
- this.lovePic = "/static/mall/love.png"
- } else {
- this.lovePic = "/static/mall/no_love.png"
- }
- } else {
- uni.showToast({
- title: res.message,
- icon: 'none'
- })
- }
- } else {
- let res = await getMyGoodsDetailReq({
- id: getApp().mallItem.id
- // id: 70
- })
- if (res.code == 0) {
- console.log('进入详情返回值666', res);
- // this.skuParams = res.data.sku_params
- this.skuParams = res.data.sku_params || {
- "attrs": {},
- "sku": []
- }
- // this.skuParams = {
- // "attrs": {
- // "颜色": ['红色', '绿色'],
- // "尺寸": ['1cm', '2cm'],
- // },
- // "sku": [{
- // '颜色': '红色',
- // '尺寸': '1cm',
- // "price": 1
- // },
- // {
- // '颜色': '红色',
- // '尺寸': '2cm',
- // "price": 2
- // },
- // {
- // '颜色': '绿色',
- // '尺寸': '1cm',
- // "price": 3
- // },
- // {
- // '颜色': '绿色',
- // '尺寸': '2cm',
- // "price": 4
- // },
- // ]
- // }
- // 动态生成判断条件对象数组
- let c = []
- Object.keys(this.skuParams.attrs).forEach((item, index) => {
- c.push({
- key: item,
- value: null
- })
- })
- this.conditions = c
- // 动态生成用于判断选中激活项的对象
- let saveCheckedObj = {}
- Object.keys(this.skuParams.attrs).forEach((item, index) => {
- // saveCheckedObj[item] = null
- saveCheckedObj[item] = this.skuParams.attrs[item][0]
- })
- console.log('this.skuParams-----', this.skuParams);
- this.saveCheckedObj = saveCheckedObj
- // 动态生成用于判断sku参数是否全部选中的中间数组
- this.fullCheckArr = new Array(Object.keys(this.skuParams.attrs).length).fill(0)
- //回显默认值
- Object.keys(this.skuParams.attrs).forEach((item, index) => {
- this.handleC(item, index, this.skuParams.attrs[item][0])
- })
- this.content = res.data
- this.bannerList = res.data.images
- this.totalCount = res.data.collect_total_count
- this.content1 = res.data.content
- if (this.content.isCollect) {
- this.lovePic = "/static/mall/love.png"
- } else {
- this.lovePic = "/static/mall/no_love.png"
- }
- } else {
- uni.showToast({
- title: res.message,
- icon: 'none'
- })
- }
- }
- },
- watch: {
- // watchValue: {
- // handler(n, o) {
- // let showPrice = this.fullCheckArr.every((item, index) => {
- // return item == 1
- // })
- // if (showPrice) {
- // this.calcPrice()
- // // console.log('所求价格:', filterResult[0].price);
- // }
- // },
- // immediate: true
- // }
- watchValue(n, o) {
- let showPrice = this.fullCheckArr.every((item, index) => {
- return item == 1
- })
- if (showPrice) {
- this.calcPrice()
- // console.log('所求价格:', filterResult[0].price);
- }
- }
- },
- onShow() {
- this.cutdownRatio = this.$getCutDown()
- },
- onShareAppMessage(params) {
- if (params.from === 'button' || params.from === 'menu') {
- return {
- title: this.content.name,
- imageUrl: this.$picBase + this.content.cover,
- path: '/pages/mall/detail/index?id=' + this.content.id,
- mpId: this.$appId,
- type: this.$shareType,
- }
- }
- },
- methods: {
- calcPrice() {
- const filterResult = this.skuParams.sku.filter(item => {
- return this.conditions.every(condition => {
- const attrValues = this.skuParams.attrs[condition.key];
- return attrValues.includes(item[condition.key]) && item[condition.key] ===
- condition.value;
- });
- });
- this.totalPrice = filterResult[0].price * this.cutdownRatio
- },
- testShare() {
- console.log('parmsList', this.parmsList);
- let ids = []
- this.parmsList.forEach((item, index) => {
- item.list.forEach((item1, index1) => {
- if (item1.isSelect) {
- ids.push(index1)
- }
- })
- })
- console.log('选中的二维iindex数组', ids);
- },
- handleC(item, index, item1) {
- console.log('handleC参数----------', item, index, item1);
- this.fullCheckArr[index] = 1
- // 声东击西强行触发监听
- this.watchValue = Date.now()
- this.saveCheckedObj[item] = item1
- //此处个条件对象数组条件赋值(key==外围数组key)
- this.conditions.forEach((item2, index2) => {
- if (item2.key == item) {
- item2.value = item1
- }
- })
- },
- bannerChange(e) {
- this.currentNum = e.current
- },
- async handleCol() {
- if (this.lovePic == "/static/mall/no_love.png") {
- let res = await addCollReq({
- id: this.content.id,
- })
- if (res.code == 0) {
- console.log('添加收藏返回值: ', res);
- this.$toast('收藏成功')
- this.totalCount += 1
- if (this.lovePic == "/static/mall/love.png") {
- this.lovePic = "/static/mall/no_love.png"
- } else {
- this.lovePic = "/static/mall/love.png"
- }
- } else {
- uni.showToast({
- title: res.message,
- icon: 'none'
- })
- }
- } else {
- let res = await cancelCollReq({
- id: this.content.id,
- })
- if (res.code == 0) {
- console.log('取消收藏返回值: ', res);
- this.$toast('取消收藏成功')
- this.totalCount -= 1
- if (this.lovePic == "/static/mall/love.png") {
- this.lovePic = "/static/mall/no_love.png"
- } else {
- this.lovePic = "/static/mall/love.png"
- }
- } else {
- uni.showToast({
- title: res.message,
- icon: 'none'
- })
- }
- }
- },
- handleOpenOrClose(i) {
- if (this['addOrLessIcon' + i] == '/static/index/shortLine.png') {
- this['addOrLessIcon' + i] = '/static/index/add.png'
- this['show' + i] = false
- } else if (this['addOrLessIcon' + i] == '/static/index/add.png') {
- this['addOrLessIcon' + i] = '/static/index/shortLine.png'
- this['show' + i] = true
- }
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "./index.scss";
- </style>
|