123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- <template>
- <view class="">
- <!-- 轮播图 1-->
- <view class="uni-margin-wrap">
- <swiper class="swiper" circular :indicator-dots="true" indicator-color="white" :autoplay="3000"
- :interval="2000" :duration="500">
- <swiper-item v-for="(item,index) in productList.imgs" :key="index">
- <image class="pictures" :src="item" mode=""></image>
- </swiper-item>
- </swiper>
- </view>
- <van-divider hairline />
- <!-- 商品信息 -->
- <view class="list">
- <van-row class="product_name">
- <van-col span="18">
- {{productList.prodName}}
- </van-col>
- <van-col span="6">
- <van-icon name="like-o" v-if="!isCollection" @click="addCollect" size="24" />
- <van-icon name="like" v-if="isCollection" @click="addCollect" size="24" />
- <text class="content_word">收藏</text>
- </van-col>
- </van-row>
- <van-row class="product_desc">
- <van-col span="20">
- {{productList.brief}}
- </van-col>
- <van-col span="4">
- </van-col>
- </van-row>
- <view class="price">
- ¥<text>{{productList.price}}</text>
- </view>
- </view>
- <van-divider hairline customStyle="border:12px solid #eee;" />
- <!-- 已选 -->
- <view class="choose" @click="showPart2">
- <view class="left">已选:<text>{{defaultStr.skuName}}</text></view>
- <view class="right">...</view>
- </view>
- <van-divider hairline customStyle="border:12px solid #eee;" />
- <!-- 好评 -->
- <!-- <view class="good">
- <view class="left">
- 评价:
- <text>好评{{common.positiveRating}}%</text>
- </view>
- <view class="right">共{{common.number}}条</view>
- </view> -->
- <van-cell-group>
- <van-cell value="共0条" is-link :border="true">
- <template #title>
- <view>评价:<text>好评:{{common.positiveRating}}%</text></view>
- </template>
- </van-cell>
- </van-cell-group>
- <!-- 评价 -->
- <view class="other">
- <view>
- <van-tag type="warning">全部{{common.number}}</van-tag>
- </view>
- <view>
- <van-tag type="warning">好评{{common.praiseNumber}}</van-tag>
- </view>
- <view>
- <van-tag type="warning">中评{{common.secondaryNumber}}</van-tag>
- </view>
- <view>
- <van-tag type="warning">差评{{common.negativeNumber}}</van-tag>
- </view>
- <view>
- <van-tag type="warning">有图{{common.picNumber}}</van-tag>
- </view>
- </view>
- <!-- 内容页 -->
- <view v-html="formatHtml(prodData.content)"></view>
- <!-- 立即购买 -->
- <van-action-sheet :show="showPart1" @click-overlay="cancelPart">
- <view class="shop_main">
- <!-- 商品信息 -->
- <van-card :num="comfirm.orderItem.prodCount" :price="defaultStr.price? defaultStr.price : productList.price" :desc="productList.brief"
- :title="defaultStr.skuName ? defaultStr.skuName : productList.prodName" :thumb="defaultStr.pic? defaultStr.pic : productList.pic">
- <template #footer>
- <view>
- <van-stepper :value="comfirm.orderItem.prodCount" @change="onChange" />
- </view>
- </template>
- </van-card>
- <!-- 商品选项 -->
- <view class="choice" v-if="tags[0].label != ''">
- <view class="main" v-for="(item,index) in tags" :key="index">
- <view class="news">
- {{item.label}}
- </view>
- <view class="select">
- <view class="word" v-for="(item1,index1) in item.options" :key="index1"
- @click="selectTag(item.label,item1.value)"
- :class="{'prop_select':selectedTag[item.label] === item1.value ? true : false}">
- {{item1.value}}
- </view>
- </view>
- </view>
- </view>
- <!-- 结单按钮 -->
- <view class="shopcart-button">
- <van-button class="left" :disabled="defaultStr.price ? false : true" type="danger"
- @click="shopcartAdd">加入购物车</van-button>
- <van-button class="right" :disabled="defaultStr.price ? false : true" type="danger" @click="buynow">
- 立即购买</van-button>
- </view>
- </view>
- </van-action-sheet>
- <!-- 型号选择 -->
- <van-action-sheet :show="showMain" @click-overlay="cancelMain" description="选择产品类别">
- <view class="choice">
- <view class="main" v-if="tags[0].label != ''" v-for="(item,index) in tags" :key="index">
- <view class="news">
- {{item.label}}
- </view>
- <view class="select">
- <view class="word" v-for="(item1,index1) in item.options" :key="index1"
- @click="selectTag(item.label,item1.value)"
- :class="{'prop_select':selectedTag[item.label] === item1.value ? true : false}">
- {{item1.value}}
- </view>
- </view>
- </view>
- <van-button class="submitBtn" :disabled="defaultStr.skuName ? false : true" type="danger" block
- @click="cancelMain">确定</van-button>
- </view>
- </van-action-sheet>
- <!-- 商品导航 -->
- <van-goods-action>
- <van-goods-action-icon icon="cart-o" text="购物车" @click="onClickIcon" />
- <van-goods-action-icon icon="shop-o" text="店铺" />
- <van-goods-action-button text="立即购买" @click="onClickBtn" />
- </van-goods-action>
- </view>
- </template>
- <script>
- import {
- prodInfo,
- isCollection,
- prodComm,
- confirm,
- changeItem
- } from '@/api/detail.js'
- import {
- formatHtml
- } from '../../utils/util.js';
- export default {
- data() {
- return {
- // 轮播列表
- bannerList: [],
- // 商品列表
- productList: [],
- // 是否收藏
- isCollection: false,
- defaultStr: {},
- prodCommList: [],
- prodData: [],
- common: {
- negativeNumber: 0, //差评
- number: 0, //全部
- picNumber: 0, //有图
- positiveRating: 0, //好评率
- praiseNumber: 0, //好评
- secondaryNumber: 0 //中评
- },
- skuList: [],
- selectedTag: {},
- // 购物面板
- showPart1: false,
- // 型号
- showMain: false,
- tags: [],
- defaultSku: [],
- // 购物车
- shopCar: {
- basketId: 0,
- prodId: 0,
- skuId: 0,
- shopId: 0,
- count: 0,
- distributionCardNo: "string"
- },
- // 结单
- comfirm: {
- basketIds: [
- 0
- ],
- orderItem: {
- prodId: 0,
- skuId: 0,
- prodCount: 1,
- shopId: 0,
- distributionCardNo: "string"
- },
- addrId: 0,
- userChangeCoupon: 0,
- couponIds: [
- 0
- ]
- }
- }
- },
- async onLoad(options) {
- let result = await prodInfo({
- prodId: options.id
- })
- this.bannerList = result.skuList;
- this.skuList = result.skuList;
- this.prodData = result;
- result.imgs = result.imgs.split(",")
- this.productList = result;
- isCollection({
- prodId: options.id
- }).then(res => {
- this.isCollection = res;
- })
- this.init(result.skuList);
- this.prodCommList = prodComm({
- prodId: options.id
- });
- },
- onShow() {
-
- },
- methods: {
- addCollect() {
- this.isCollection = !this.isCollection;
- },
- init(main) {
- const properties = [];
- const propObject = {};
- let defaultArr = [];
- for (var i = 0; i < main.length; i++) {
- properties.push(main[i].properties);
- }
- for (var i = 0; i < properties.length; i++) {
- let propArr = properties[i];
- let propStr = properties[i].split(";");
- if (defaultArr.length === 0) {
- defaultArr = propStr;
- }
- this.defaultStr = main[i];
- for (var j = 0; j < propStr.length; j++) {
- const valueArr = propStr[j];
- const valueStr = valueArr.split(":");
- if (!propObject[valueStr[0]]) {
- propObject[valueStr[0]] = new Set();
- }
- propObject[valueStr[0]].add(valueStr[1]);
- this.tags = Object.entries(propObject).map(([key, values]) => {
- return {
- label: key,
- options: Array.from(values).map(item => {
- return {
- value: item
- }
- })
- }
- })
- for (let x = defaultArr.length - 1; x >= 0; x--) {
- let valueStr1 = defaultArr[x];
- let valueArr1 = valueStr1.split(":");
- this.$set(this.selectedTag, valueArr1[0], valueArr1[1]);
- }
- }
- }
- },
- formatHtml(t) {
- return formatHtml(t);
- },
- onClickIcon() {
- uni.switchTab({
- url: "/pages/shop/shop"
- })
- },
- onClickBtn() {
- this.showPart1 = true;
- },
- cancelPart() {
- this.showPart1 = false;
- },
- showPart2() {
- this.showMain = true;
- },
- cancelMain() {
- this.showMain = false;
- },
- onChange(event) {
- this.comfirm.orderItem.prodCount = event.detail;
- },
- selectTag(propTitle, propValue) {
- this.$set(this.selectedTag, propTitle, propValue);
- let str = "";
- for (let item in this.selectedTag) {
- str = item + ":" + this.selectedTag[item] + ";" + str
- let str1 = str.substring(0, str.length - 1);
- for (var i = 0; i < this.skuList.length; i++) {
- if (this.skuList[i].properties === str1) {
- this.defaultStr = this.skuList[i];
- return;
- }
- }
- }
- },
- shopcartAdd() {
- this.shopCar.basketId = 0;
- this.shopCar.prodId = this.prodData.prodId;
- this.shopCar.skuId = this.defaultStr.skuId;
- this.shopCar.shopId = this.prodData.shopId;
- this.shopCar.count = this.comfirm.orderItem.prodCount;
- changeItem(this.shopCar).then(res => {
- uni.showToast({
- title: '添加成功!',
- icon: "success",
- duration: 2000
- });
- this.showPart1 = false;
- })
- },
- buynow() {
- this.comfirm.basketIds = [];
- this.comfirm.orderItem.prodId = this.prodData.prodId;
- this.comfirm.orderItem.skuId = this.defaultStr.skuId;
- this.comfirm.orderItem.shopId = this.prodData.shopId;
- this.comfirm.orderItem.distributionCardNo = "";
- this.comfirm.couponIds = [];
-
- uni.setStorageSync("confirm",JSON.stringify(this.comfirm))
- console.log(this.comfirm,'this')
- uni.navigateTo({
- url:"/pages/order/order"
- })
- }
- }
- }
- </script>
- <style lang="less">
- .uni-margin-wrap {
- .swiper {
- width: 100%;
- height: 600rpx;
- image {
- width: 100%;
- height: 100%;
- }
- }
- }
- .prop_select {
- color: #fff !important;
- background: #f00 !important;
- }
- .product_name {
- .van-col--18 {
- font-size: 39rpx;
- }
- }
- .content_word {
- font-size: 34rpx;
- }
- .product_desc {
- .van-col--20 {
- font-size: 24rpx;
- color: #333;
- margin-top: 20rpx;
- }
- }
- .price {
- color: #f00;
- font-size: 34rpx;
- margin-top: 20rpx;
- text {
- font-size: 48rpx;
- }
- }
- .choose {
- width: 100%;
- height: 100rpx;
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 36rpx;
- .left {
- text {
- font-size: 44rpx;
- }
- }
- }
- .other {
- width: 100%;
- height: 100rpx;
- display: flex;
- justify-content: space-around;
- align-items: center;
- view {
- .van-tag--warning {
- padding: 14rpx 20rpx;
- width: 50rpx;
- text-align: center;
- color: red;
- }
- }
- }
- .shopcart-button {
- width: 100%;
- position: absolute;
- bottom: 0;
- .shopcart-button {
- .left .van-button--normal {
- width: 50%;
- background-color: #595959;
- border: 1px solid #595959;
- }
- .right .van-button--normal {
- width: 50%;
- }
- }
- .left .van-button--normal {
- width: 50%;
- background-color: #595959;
- border: 1px solid #595959;
- }
- .right .van-button--normal {
- width: 50%;
- }
- }
- .shop_main {
- height: 600rpx;
- }
- .choice {
- .news {
- font-size: 32rpx;
- .news {
- font-size: 32rpx;
- padding: 29rpx;
- }
- }
- .select {
- width: 100%;
- height: 80rpx;
- display: flex;
- justify-content: space-around;
- align-items: center;
- .word {
- color: #f00;
- font-size: 25rpx;
- padding: 10rpx 20rpx;
- border: 1px solid #f00;
- }
- }
- }
- </style>
|