zs пре 1 година
родитељ
комит
3b626c9d61

+ 45 - 0
src/store/api/platform/collection.js

@@ -0,0 +1,45 @@
+import { defineStore } from 'pinia'
+import { AxiosWrapper } from '@/utils/axios-wrapper'
+import { get } from 'lodash-es'
+const url = '/collection'
+const axios = new AxiosWrapper()
+
+export const CollectionStore = defineStore('collection', () => {
+  const query = async ({ skip = 0, limit = undefined, ...info } = {}) => {
+    let cond = {}
+    if (skip) cond.skip = skip
+    if (limit) cond.limit = limit
+    cond = { ...cond, ...info }
+    const res = await axios.$get(`${url}`, cond)
+    return res
+  }
+  const fetch = async (payload) => {
+    const res = await axios.$get(`${url}/${payload}`)
+    return res
+  }
+  const create = async (payload) => {
+    const res = await axios.$post(`${url}`, payload)
+    return res
+  }
+  const cancel = async (payload) => {
+    const res = await axios.$post(`${url}/cancel`, payload)
+    return res
+  }
+  const update = async (payload) => {
+    const id = get(payload, 'id', get(payload, '_id'))
+    const res = await axios.$post(`${url}/${id}`, payload)
+    return res
+  }
+  const del = async (payload) => {
+    const res = await axios.$delete(`${url}/${payload}`)
+    return res
+  }
+  return {
+    query,
+    fetch,
+    create,
+    update,
+    cancel,
+    del
+  }
+})

+ 14 - 0
src/store/api/platform/demand.js

@@ -13,10 +13,22 @@ export const DemandStore = defineStore('demand', () => {
     const res = await axios.$get(`${url}`, cond)
     return res
   }
+  const list = async ({ skip = 0, limit = undefined, ...info } = {}) => {
+    let cond = {}
+    if (skip) cond.skip = skip
+    if (limit) cond.limit = limit
+    cond = { ...cond, ...info }
+    const res = await axios.$get(`${url}/list`, cond)
+    return res
+  }
   const fetch = async (payload) => {
     const res = await axios.$get(`${url}/${payload}`)
     return res
   }
+  const detail = async (payload) => {
+    const res = await axios.$get(`${url}/detail/${payload}`)
+    return res
+  }
   const create = async (payload) => {
     const res = await axios.$post(`${url}`, payload)
     return res
@@ -32,8 +44,10 @@ export const DemandStore = defineStore('demand', () => {
   }
   return {
     query,
+    list,
     fetch,
     create,
+    detail,
     update,
     del
   }

+ 5 - 0
src/store/api/user/expert.js

@@ -17,6 +17,10 @@ export const ExpertStore = defineStore('expert', () => {
     const res = await axios.$get(`${url}/${payload}`)
     return res
   }
+  const detail = async (payload) => {
+    const res = await axios.$get(`${url}/detail/${payload}`)
+    return res
+  }
   const create = async (payload) => {
     const res = await axios.$post(`${url}`, payload)
     return res
@@ -33,6 +37,7 @@ export const ExpertStore = defineStore('expert', () => {
   return {
     query,
     fetch,
+    detail,
     create,
     update,
     del

+ 55 - 13
src/views/demand/detail.vue

@@ -5,10 +5,14 @@
         <div class="w_1200">
           <el-col :span="24" class="one">
             <el-row :span="24" class="one_1">
-              <el-col :span="23" class="title">{{ info.name || '暂无标题' }}</el-col>
-              <el-col :span="1" class="file" @click="toCollection" v-if="info.status == '1'">
-                <el-icon><Star /></el-icon>
-                收藏
+              <el-col :span="22" class="title">{{ info.name || '暂无标题' }}</el-col>
+              <el-col :span="2" class="file" @click="toCollection(0)" v-if="info.is_collection">
+                <el-icon :size="18"><StarFilled /></el-icon>
+                <span>已收藏</span>
+              </el-col>
+              <el-col :span="2" class="file" @click="toCollection(1)" v-else>
+                <el-icon :size="18"><Star /></el-icon>
+                <span>收藏</span>
               </el-col>
             </el-row>
           </el-col>
@@ -49,11 +53,11 @@
             <el-row :span="24" class="thr_2">
               <el-col :span="17" class="left">
                 <el-col :span="24" class="name">
-                  {{ unit.name || '暂无' }}
+                  {{ userInfo.name || '暂无单位' }}
                 </el-col>
                 <el-col :span="24" class="other">
                   <span>联系人</span>
-                  {{ unit.contacts || '暂无' }}
+                  {{ userInfo.name || '暂无联系人' }}
                 </el-col>
               </el-col>
               <el-col :span="4" class="right" v-if="info.status == '1'">
@@ -125,15 +129,19 @@
 </template>
 
 <script setup>
+import moment from 'moment'
 // 基础
 import { MessageOutlined } from '@ant-design/icons-vue'
 import { get } from 'lodash-es'
 const $checkRes = inject('$checkRes')
 // 接口
 import { DemandStore } from '@/store/api/platform/demand'
+import { CollectionStore } from '@/store/api/platform/collection'
 import { DictDataStore } from '@/store/api/system/dictData'
 const store = DemandStore()
 const dictDataStore = DictDataStore()
+const collectionStore = CollectionStore()
+
 import { UserStore } from '@/store/user'
 const userStore = UserStore()
 const user = computed(() => userStore.user)
@@ -143,7 +151,7 @@ const router = useRouter()
 // 加载中
 const loading = ref(false)
 const info = ref({})
-const unit = ref({ name: '吉林大学', contacts: '陈老师' })
+const userInfo = ref({})
 // 字典表
 const methodList = ref([])
 const urgentList = ref([])
@@ -165,8 +173,11 @@ onMounted(async () => {
 const search = async () => {
   let id = route.query.id
   if (id) {
-    let res = await store.fetch(id)
-    if (res.errcode == '0') info.value = res.data
+    let res = await store.detail(id)
+    if (res.errcode == '0') {
+      info.value = res.data
+      userInfo.value = res.data.userInfo
+    }
   }
 }
 const searchAchieve = async (query = { skip: 0, limit }) => {
@@ -221,8 +232,36 @@ const toDocking = () => {
   console.log('我要对接')
 }
 // 收藏
-const toCollection = () => {
-  console.log('收藏')
+const toCollection = async (status) => {
+  if (user.value._id) {
+    let res
+    let message
+    const data = {
+      user: user.value._id,
+      source: info.value._id,
+      type: 'demand',
+      time: moment().format('YYYY-MM-DD')
+    }
+    if (status == '1') {
+      message = '收藏成功'
+      res = await collectionStore.create(data)
+    } else {
+      message = '取消收藏成功'
+      res = await collectionStore.cancel(data)
+    }
+    if (res.errcode === 0) {
+      ElMessage({
+        message,
+        type: 'success'
+      })
+      await search()
+    }
+  } else {
+    ElMessage({
+      message: '未登录无法进行收藏 请登录',
+      type: 'warning'
+    })
+  }
 }
 // 查看
 const toView = (item) => {
@@ -262,11 +301,14 @@ const sizeChange = (limits) => {
       .file {
         display: flex;
         align-items: center;
-        justify-content: space-between;
+        justify-content: flex-end;
         font-family: PingFangSC-Regular;
         font-size: 14px;
         color: #2374ff;
         text-align: right;
+        span {
+          margin: 0 0 0 5px;
+        }
       }
     }
 
@@ -352,7 +394,7 @@ const sizeChange = (limits) => {
             color: #7e8288;
             line-height: 14px;
             font-weight: 400;
-            margin-right: 16px;
+            margin-right: 10px;
           }
         }
       }

+ 2 - 2
src/views/demand/index.vue

@@ -92,7 +92,7 @@
                 </el-col>
                 <el-col :span="8" class="other_1">
                   <span>单位:</span>
-                  {{ item.user || '暂无单位' }}
+                  {{ item.userName || '暂无单位' }}
                 </el-col>
               </el-row>
               <el-col :span="24" class="brief textOver">
@@ -241,7 +241,7 @@ const search = async (query = { skip: 0, limit }) => {
     is_use: '0',
     status: '1'
   }
-  const res = await store.query(info)
+  const res = await store.list(info)
   if (res.errcode == '0') {
     list.value = res.data
     total.value = res.total

+ 47 - 6
src/views/expert/detail.vue

@@ -29,9 +29,13 @@
                 <div class="other"><span> 工作单位:</span>{{ info.work || '暂无' }}</div>
               </el-col>
               <el-col :span="6" class="one_3">
-                <el-col :span="10" class="file" @click="toCollection">
-                  <el-icon><Star /></el-icon>
-                  收藏
+                <el-col :span="10" class="file" @click="toCollection(0)" v-if="info.is_collection">
+                  <el-icon :size="18"><StarFilled /></el-icon>
+                  <span>已收藏</span>
+                </el-col>
+                <el-col :span="10" class="file" @click="toCollection(1)" v-else>
+                  <el-icon :size="18"><Star /></el-icon>
+                  <span>收藏</span>
                 </el-col>
                 <el-col :span="14">
                   <a-button type="primary" @click="toChat"> 在线洽谈 </a-button>
@@ -93,16 +97,19 @@
 </template>
 
 <script setup>
+import moment from 'moment'
 // 基础
 import { get } from 'lodash-es'
 const $checkRes = inject('$checkRes')
 // 接口
 import { ExpertStore } from '@/store/api/user/expert'
 import { AchievementStore } from '@/store/api/platform/achievement'
+import { CollectionStore } from '@/store/api/platform/collection'
 import { DictDataStore } from '@/store/api/system/dictData'
 const achievementStore = AchievementStore()
 const store = ExpertStore()
 const dictDataStore = DictDataStore()
+const collectionStore = CollectionStore()
 import { UserStore } from '@/store/user'
 const userStore = UserStore()
 const user = computed(() => userStore.user)
@@ -134,7 +141,7 @@ onMounted(async () => {
 const search = async () => {
   let id = route.query.id
   if (id) {
-    let res = await store.fetch(id)
+    let res = await store.detail(id)
     if (res.errcode == '0') info.value = res.data
   }
 }
@@ -181,8 +188,36 @@ const toChat = () => {
   router.push({ path: '/chat', query: { id: info.value.id || info.value._id } })
 }
 // 收藏
-const toCollection = () => {
-  console.log('收藏')
+const toCollection = async (status) => {
+  if (user.value._id) {
+    let res
+    let message
+    const data = {
+      user: user.value._id,
+      source: info.value._id,
+      type: 'expert',
+      time: moment().format('YYYY-MM-DD')
+    }
+    if (status == '1') {
+      message = '收藏成功'
+      res = await collectionStore.create(data)
+    } else {
+      message = '取消收藏成功'
+      res = await collectionStore.cancel(data)
+    }
+    if (res.errcode === 0) {
+      ElMessage({
+        message,
+        type: 'success'
+      })
+      await search()
+    }
+  } else {
+    ElMessage({
+      message: '未登录无法进行收藏 请登录',
+      type: 'warning'
+    })
+  }
 }
 // 查看
 const toView = (item) => {
@@ -265,6 +300,12 @@ const sizeChange = (limits) => {
           display: flex;
           align-items: center;
           justify-content: center;
+          font-family: PingFangSC-Regular;
+          font-size: 14px;
+          color: #2374ff;
+          span {
+            margin: 0 0 0 5px;
+          }
         }
       }
     }