Browse Source

修改成果收藏

zs 1 năm trước cách đây
mục cha
commit
73630390ae
2 tập tin đã thay đổi với 60 bổ sung9 xóa
  1. 5 0
      src/store/api/platform/achievement.js
  2. 55 9
      src/views/achievement/detail.vue

+ 5 - 0
src/store/api/platform/achievement.js

@@ -17,6 +17,10 @@ export const AchievementStore = defineStore('achievement', () => {
     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 AchievementStore = defineStore('achievement', () => {
   return {
     query,
     fetch,
+    detail,
     create,
     update,
     del

+ 55 - 9
src/views/achievement/detail.vue

@@ -6,11 +6,19 @@
           <el-col :span="24" class="one">
             <el-row :span="24" class="one_1">
               <el-col :span="20" class="title">{{ info.name || '暂无标题' }}</el-col>
-              <el-col :span="4" class="file" @click="toFile" v-if="info.status == '1'">
+              <el-col :span="2" class="file" @click="toCollection(0)" v-if="info.is_collection">
+                <el-icon :size="16"><StarFilled /></el-icon>
+                <span>已收藏</span>
+              </el-col>
+              <el-col :span="2" class="file" @click="toCollection(1)" v-else>
+                <el-icon :size="16"><Star /></el-icon>
+                <span>收藏</span>
+              </el-col>
+              <el-col :span="2" class="file" @click="toFile" v-if="info.status == '1'">
                 <el-icon>
                   <Download />
                 </el-icon>
-                附件下载
+                <span>附件下载</span>
               </el-col>
             </el-row>
             <el-row :span="24" class="one_2"> {{ getDict(info.sell, 'sell') }} </el-row>
@@ -56,11 +64,11 @@
             <el-row :span="24" class="thr_2">
               <el-col :span="16" 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="8" class="right" v-if="info.status == '1'">
@@ -135,14 +143,18 @@
 
 <script setup>
 // 基础
+import moment from 'moment'
 import { MessageOutlined } from '@ant-design/icons-vue'
 import { get } from 'lodash-es'
 const $checkRes = inject('$checkRes')
 // 接口
 import { AchievementStore } from '@/store/api/platform/achievement'
+import { CollectionStore } from '@/store/api/platform/collection'
 import { DictDataStore } from '@/store/api/system/dictData'
 const store = AchievementStore()
 const dictDataStore = DictDataStore()
+const collectionStore = CollectionStore()
+
 import { UserStore } from '@/store/user'
 const userStore = UserStore()
 const user = computed(() => userStore.user)
@@ -152,7 +164,7 @@ const router = useRouter()
 // 加载中
 const loading = ref(false)
 const info = ref({})
-const unit = ref({ name: '吉林大学', contacts: '陈老师' })
+const userInfo = ref({})
 // 字典表
 const fieldList = ref([])
 const attributeList = ref([])
@@ -175,8 +187,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 }) => {
@@ -246,8 +261,36 @@ const toUnit = () => {
   router.push({ path: '/company/detail', 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: 'achievement',
+      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) => {
@@ -292,6 +335,9 @@ const sizeChange = (limits) => {
         font-size: 14px;
         color: #2374ff;
         text-align: right;
+        span {
+          margin: 0 0 0 5px;
+        }
       }
     }