leave-unused/pagesA/goods/detail.vue

243 lines
6.5 KiB
Vue
Raw Normal View History

<template>
2022-10-20 13:07:14 +00:00
<view :class="type==''?'':'pad-x120'" v-if="isLoading">
<!-- 头部 -->
<status-nav :ifReturn="true" navBarTitle="商品详情"></status-nav>
<!-- 提示 -->
<view class="notice-tips color-orange font26 border-box pad-all20 flex"><image src="/static/icon-notice.png" mode="widthFix"></image>交易前请务必核实对方的身份及信息!</view>
<!-- 商品详情 -->
<view class="goods-detail">
<view class="goods-info background-white pad-zy20 border-box">
<view class="item font28 flex">
<view class="title color-8c">商品名称</view>
<view class="msg">{{goodsDetail.name}}</view>
</view>
<view class="item font28 flex">
<view class="title color-8c">商品分类</view>
<view class="msg">{{goodsDetail.category_name}}</view>
</view>
<view class="item font28 flex">
<view class="title color-8c">商品售价</view>
2022-12-02 10:12:31 +00:00
<view class="msg">
<text class="color-8c font24" v-if="parseFloat(goodsDetail.original_price)>0" style="text-decoration:line-through;margin-right: 6rpx;">{{goodsDetail.original_price}}</text>
<text class="color-red">{{goodsDetail.price}}</text>
</view>
</view>
<view class="item font28 flex">
<view class="title color-8c">联系方式</view>
<view class="msg" v-if="showPhone" @tap="this.$toolAll.tools.countCustomer(goodsDetail.phone)">{{goodsDetail.phone}}</view>
<view class="msg" v-else>
2022-12-07 07:39:02 +00:00
<view class="see-phone color-ff font24 background-blue radius20 flex" @tap="getPhone"></view>
</view>
</view>
</view>
<view class="goods-content background-white pad-all20 mar-s20 font28 border-box">
<view class="goods-describe color-8c">{{goodsDetail.msg}}</view>
<view class="goods-img">
<image :src="item" mode="widthFix" v-for="(item,index) in goodsImg" :key="index"></image>
</view>
</view>
</view>
2022-10-20 13:07:14 +00:00
<view class="detail-btns background-white border-box flex" v-if="type=='release'">
2022-11-28 07:21:53 +00:00
<view class="btn font30 color-ff radius35 flex" :class="goodsDetail.status==0?'background-orange':'background-8c'" @tap="changeStateEv(goodsDetail.id)">
2022-11-28 07:27:37 +00:00
{{goodsDetail.status==0?'已上架':'已下架'}}
2022-11-28 07:21:53 +00:00
</view>
<view class="btn background-blue font30 color-ff radius35 flex" @tap="editEv(goodsDetail.id)"></view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
statusHeight:uni.getSystemInfoSync().statusBarHeight, //状态栏高度
goodsDetail:{}, //商品详情
goodsImg:[], //商品图片
showPhone:false, //显示电话号码
2022-10-20 13:07:14 +00:00
isLoading:false, //是否加载完成
type:'', //是否自己发布
2022-11-02 06:15:55 +00:00
goods_id: 0,// 商品id
2022-12-02 10:12:31 +00:00
flag:true, //能否上下架
}
},
2022-10-20 13:07:14 +00:00
onLoad(op) {
if(op.type=='release'){
this.type = op.type;
}
if(op.id){
2022-11-02 06:15:55 +00:00
// 获取商品id
this.goods_id = op.id;
2022-10-20 13:07:14 +00:00
}
2022-11-02 06:15:55 +00:00
},
onShow() {
// 查询商品详情
this.getGoodsDetail(this.goods_id);
},
onShareAppMessage(res) {
let shareObj = {
2022-11-02 06:15:55 +00:00
title:this.goodsDetail.name,
path: this.type=='release'?uni.getStorageSync('page-path-options').substring(0,uni.getStorageSync('page-path-options').indexOf("&")):uni.getStorageSync('page-path-options'),
imageUrl:this.goodsDetail.cover,
}
// 返回shareObj
return shareObj;
},
onShareTimeline(res){
let shareObj = {
2022-11-02 06:15:55 +00:00
title:this.goodsDetail.name,
path: this.type=='release'?uni.getStorageSync('page-path-options').substring(0,uni.getStorageSync('page-path-options').indexOf("&")):uni.getStorageSync('page-path-options'),
imageUrl:this.goodsDetail.cover,
}
// 返回shareObj
return shareObj;
},
methods: {
// 查询商品详情
2022-10-20 13:07:14 +00:00
getGoodsDetail(id){
uni.showLoading({
title:'加载中'
})
this.$requst.get('/api/v1/goods/detail',{id:id}).then(res=>{
if(res.code == 0){
console.log(res,'闲置商品详情');
this.goodsDetail = {
id:res.data.id,
cover:res.data.cover,
name:res.data.title,
category_name:res.data.category_name,
original_price:res.data.original_price,
price:res.data.price,
phone:res.data.phone,
images:res.data.images,
2022-11-28 07:21:53 +00:00
msg:res.data.content,
status:res.data.status
2022-10-20 13:07:14 +00:00
};
// 获取图片
this.goodsImg = this.goodsDetail.images;
}
uni.hideLoading();
this.isLoading = true;
})
},
// 编辑
editEv(id){
uni.navigateTo({
2022-12-05 02:35:44 +00:00
url:`/pagesA/release/release?id=${id}`,
})
},
2022-12-07 07:39:02 +00:00
// 查看联系方式
getPhone(){
if(this.$toolAll.tools.judgeAuth()) {
this.showPhone = true;
}
},
2022-11-28 07:21:53 +00:00
// 更改显示状态
changeStateEv(id){
if(this.flag){
this.flag =false;
this.$requst.post('/api/v1/goods/set-status',{id:id,status:this.goodsDetail.status}).then(res=>{
if(res.code == 0){
console.log(res,'改变状态');
if(this.goodsDetail.status==0){
this.goodsDetail.status = 1;
this.$toolAll.tools.showToast('已下架');
}else{
this.goodsDetail.status = 0;
2022-11-28 07:27:37 +00:00
this.$toolAll.tools.showToast('已上架');
2022-11-28 07:21:53 +00:00
}
}
})
setTimeout(()=>{
this.flag = true;
},500)
}
},
// 删除
2022-10-20 13:07:14 +00:00
delEv(id){
this.$requst.post('/api/v1/goods/del',{id:id}).then(res=>{
if(res.code == 0){
this.$toolAll.tools.showToast('删除成功');
2022-11-02 06:15:55 +00:00
setTimeout(()=>{
uni.navigateTo({
2022-12-05 02:35:44 +00:00
url:`/pagesA/goods/goods`,
2022-11-02 06:15:55 +00:00
})
},500)
2022-10-20 13:07:14 +00:00
}
})
},
}
}
</script>
<style scoped>
.notice-tips{
align-items: center;
background-color: rgba(255,133,0,.2);
height: 70rpx;
line-height: 36rpx;
}
.notice-tips>image{
width: 40rpx;
height: 40rpx;
margin-right: 8rpx;
animation: opacity_name 0.8s linear alternate infinite;
}
@keyframes opacity_name {
from {
opacity: .1;
transform: scale(.8);
}
to {
opacity: 1;
transform: scale(1.2);
}
}
.goods-info .item{
align-items: center;
height: 90rpx;
border-bottom: 2rpx solid #f4f5f6;
}
.goods-info .item:last-child{
border: 0;
}
.goods-info .title{
width: 200rpx;
}
.goods-info .msg{
width: calc(100% - 200rpx);
}
.see-phone{
justify-content: center;
align-items: center;
width: 90px;
height: 54rpx;
}
.goods-describe{
line-height: 1.5;
}
.goods-img>image{
width: 100%;
margin-top: 20rpx;
border-radius: 10rpx;
}
/* 删除按钮 */
.detail-btns{
justify-content: space-around;
align-items: center;
width: 100%;
height: 100rpx;
position: fixed;
left: 0;
bottom: 0;
z-index: 99;
}
.detail-btns .btn{
justify-content: center;
align-items: center;
width: 40%;
height: 66rpx;
}
</style>