This commit is contained in:
木瓜一块八 2025-08-22 11:24:29 +08:00
parent f0032a3fe8
commit 2c18f68f2e
3 changed files with 105 additions and 16 deletions

View File

@ -220,3 +220,22 @@ export function reqSupplyAndDemandSecondCategory(data){
data data
}) })
} }
//收藏 /product/publish_product_collect.dspy
export function reqPublishProductCollect(data){
return request({
url: '/user/favorite_add.dspy',
method: 'post',
headers: { 'Content-Type': 'application/json' },
data
})
}
//取消收藏 /user/favorite_delete.dspy
export function reqFavoriteDelete(data){
return request({
url: '/user/favorite_delete.dspy',
method: 'post',
headers: { 'Content-Type': 'application/json' },
data
})
}

View File

@ -52,13 +52,29 @@
</div> </div>
<div class="product-price"> <div class="product-price">
<span class="price">¥{{ item.discount_price }}</span> <span class="price">¥{{ item.discount_price }}</span>
<span class="price-unit">{{ item.unit }} {{ item.short_term === '1' ? '(可短租)' : '' }} </span> <span class="price-unit">{{ item.unit }} {{ item.short_term === '1' ? '(可短租)' : '' }} </span> <el-tag v-if="item.favorite=='1'" type="success">已收藏</el-tag>
</div>
<div style="display: flex;justify-content: flex-start;align-items: center;gap: 16px;">
<el-button :disabled="loadingStates[item.id]" class="consult-btn" @click="openTalk">立即咨询</el-button>
<span @click="openDetail(item)" class="detail-btn">
详情 <i v-if="loadingStates[item.id]" class="el-icon-loading"></i> <span v-else>>></span>
</span>
<span
:style="{ color: item.favorite === '1' ? 'red' : 'green' }"
@click="collect(item)"
class="detail-btn"
style="cursor: pointer;"
>
{{ item.favorite === '1' ? '取消收藏' : '收藏' }}
<i v-if="collectLoadingStates[item.id]" class="el-icon-loading"></i>
<i
v-else
:class="item.favorite === '1' ? 'el-icon-star-off' : 'el-icon-star-on'"
style="width: 14px;height: 14px;margin-left: 2px;"
></i>
</span>
</div> </div>
<div style="display: flex;justify-content: space-between;align-items: center;">
<el-button :disabled="loadingStates[item.id]" class="consult-btn" @click="openTalk">立即咨询</el-button> <span @click="openDetail(item)"
class="detail-btn">详情 <i v-if="loadingStates[item.id]" class="el-icon-loading"></i> <span v-else>>></span> </span>
</div>
</div> </div>
</li> </li>
</ul> </ul>
@ -94,10 +110,25 @@
<span class="price">¥{{ item.discount_price }}</span> <span class="price">¥{{ item.discount_price }}</span>
<span class="price-unit">{{ item.unit }} {{ item.short_term === '1' ? '(可短租)' : '' }} </span> <span class="price-unit">{{ item.unit }} {{ item.short_term === '1' ? '(可短租)' : '' }} </span>
</div> </div>
<div style="display: flex;justify-content: space-between;align-items: center;"> <div style="display: flex;justify-content: flex-start;align-items: center;gap: 16px;">
<el-button :disabled="loadingStates[item.id]" class="consult-btn" @click="openTalk">立即咨询</el-button>
<el-button :disabled="loadingStates[item.id]" class="consult-btn" @click="openTalk">立即咨询</el-button> <span @click="openDetail(item)" <span @click="openDetail(item)" class="detail-btn">
class="detail-btn">详情 <i v-if="loadingStates[item.id]" class="el-icon-loading"></i> <span v-else>>></span> </span> 详情 <i v-if="loadingStates[item.id]" class="el-icon-loading"></i> <span v-else>>></span>
</span>
<span
:style="{ color: item.favorite === '1' ? 'red' : 'green' }"
@click="collect(item)"
class="detail-btn"
style="cursor: pointer;"
>
{{ item.favorite === '1' ? '取消收藏' : '收藏' }}
<i v-if="collectLoadingStates[item.id]" class="el-icon-loading"></i>
<i
v-else
:class="item.favorite === '1' ? 'el-icon-star-off' : 'el-icon-star-on'"
style="width: 14px;height: 14px;margin-left: 2px;"
></i>
</span>
</div> </div>
</div> </div>
</li> </li>
@ -107,7 +138,7 @@
</template> </template>
<script> <script>
import Talk from '@/views/homePage/dialog/talk/index.vue' import Talk from '@/views/homePage/dialog/talk/index.vue'
import { reqGetProductDetail } from '@/api/ncmatch' import { reqGetProductDetail,reqPublishProductCollect,reqFavoriteDelete } from '@/api/ncmatch'
export default { export default {
name: 'productCard', name: 'productCard',
components: { components: {
@ -129,10 +160,43 @@ export default {
}, },
data(){ data(){
return{ return{
loadingStates: {} loadingStates: {},
collectLoadingStates: {}
} }
}, },
methods: { methods: {
collect(item){
this.$set(this.collectLoadingStates, item.id, true);
// /
console.log("收藏",item);
if(item.favorite=='1'){
reqFavoriteDelete({
id:item.id,
}).then(res=>{
if(res.status){
this.$message.success(res.msg);
this.$set(this.collectLoadingStates, item.id, false);
}else{
this.$message.error(res.msg);
this.$set(this.collectLoadingStates, item.id, false);
}
})
}else if(item.favorite=='0'){
reqPublishProductCollect({
productid:item.id,
favorite_type:item.publish_type
}).then(res=>{
if(res.status){
this.$message.success(res.msg);
this.$set(this.collectLoadingStates, item.id, false);
}else{
this.$message.error(res.msg);
this.$set(this.collectLoadingStates, item.id, false);
}
})
}
},
openTalk() { openTalk() {
this.$store.commit('setShowTalk', true); this.$store.commit('setShowTalk', true);
}, },
@ -276,16 +340,18 @@ export default {
} }
.consult-btn { .consult-btn {
width: 100%;
background: linear-gradient(90deg, #275AFF 0%, #2EBDFA 100%); background: linear-gradient(90deg, #275AFF 0%, #2EBDFA 100%);
color: white; color: white;
border: none; border: none;
padding: 12px 24px; padding: 12px 32px;
border-radius: 8px; border-radius: 8px;
font-size: 16px; font-size: 16px;
font-weight: 500; font-weight: 500;
cursor: pointer; cursor: pointer;
transition: all 0.3s ease; transition: all 0.3s ease;
white-space: nowrap;
min-width: 120px;
flex-shrink: 0;
&:hover { &:hover {
box-shadow: 0 4px 12px rgba(39, 90, 255, 0.3); box-shadow: 0 4px 12px rgba(39, 90, 255, 0.3);

View File

@ -13,11 +13,15 @@
</el-table-column> </el-table-column>
<el-table-column prop="content" label="内容" min-width="180"> <el-table-column prop="content" label="内容" min-width="180">
</el-table-column> </el-table-column>
<el-table-column prop="create_time" label="创建时间" min-width="180"> <el-table-column prop="create_time" label="咨询时间" min-width="180">
</el-table-column> </el-table-column>
<el-table-column prop="update_time" label="更新时间" min-width="180"> <el-table-column prop="update_time" label="联系时间" min-width="180">
</el-table-column>
<el-table-column prop="update_time" label="操作" min-width="180">
<template slot-scope="scope">
<el-button type="text" @click="handleEdit(scope.row)">已回复</el-button>
</template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
</template> </template>