154 lines
4.3 KiB
Vue
154 lines
4.3 KiB
Vue
<template>
|
||
<div>
|
||
<h1>健管師資料 - {{ healther_name }}</h1>
|
||
<!-- 你可以根據這個 name 來顯示詳細資料 -->
|
||
<div class="d-flex align-items-center">
|
||
<label for="enableSelect" > 是否啟用 </label>
|
||
<select class="form-control" id="enableSelect" @change="enable_change" v-model="healtherenable"
|
||
style="width: 80px ;">
|
||
<option value="Y">Y</option>
|
||
<option value="N">N</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<!--確認是否啟用-->
|
||
<div>
|
||
<dialog ref="check_enable_view" class="dialog-box" style="width: 20%;" >
|
||
<label>{{ healtherenable === 'Y' ? '確認啟用?' : '確認關閉?' }}</label>
|
||
<!-- 操作按鈕 -->
|
||
<div class="button-group">
|
||
<button class="btn btn-danger" @click = "enable_view_close">返回</button>
|
||
<button class="btn btn-success" @click="submit_edit_enable">確認</button>
|
||
</div>
|
||
</dialog>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, onMounted } from 'vue'
|
||
import { useRouter } from "vue-router"; //匯入路徑
|
||
const config = useRuntimeConfig();//匯入 API
|
||
const $api_host = config.public.apiHost;
|
||
const router = useRouter(); // 匯入
|
||
const authToken = ref("");// 🔐 定義全域 token
|
||
|
||
const add_Health_view = ref(null);
|
||
|
||
definePageMeta({
|
||
layout: 'defaultmanager' // 指定自定義的佈局名稱
|
||
})
|
||
|
||
//關閉確認啟用視窗
|
||
const enable_view_close = async() =>{
|
||
check_enable_view.value?.close();
|
||
}
|
||
|
||
|
||
//獲取資料
|
||
const get_data = async () => {
|
||
const Healther_data = await get_healther_data();
|
||
set_Healther(Healther_data);
|
||
|
||
};
|
||
|
||
const get_healther_data =async()=>{
|
||
const route = useRoute(); // 取得當前路由資訊
|
||
const health_guid = route.params.guid; // 提取路由中的 guid 參數
|
||
// 確保 company_guid 存在
|
||
if (!health_guid) {
|
||
console.error("沒有找到公司 GUID!");
|
||
return;
|
||
}
|
||
try {
|
||
const response = await $fetch(`${$api_host}/api/Health_detail_table/get_health_person-${health_guid}`, {
|
||
method: "GET",
|
||
headers: {
|
||
"Content-Type": "application/json",
|
||
Authorization: authToken.value, // 假設 authToken 已經在其他地方定義
|
||
},
|
||
});
|
||
return response
|
||
} catch (error) {
|
||
console.error("獲取健管師資料失敗:", error);
|
||
}
|
||
}
|
||
|
||
//設置資料
|
||
const healther_name=ref('');
|
||
const healtherenable = ref("");
|
||
let level =ref()
|
||
const set_Healther = (data) =>{
|
||
console.log(data)
|
||
healther_name.value = data.health_name
|
||
level = parseInt(data.level, 10);
|
||
if (level % 2 == 0) {
|
||
healtherenable.value = 'Y'
|
||
}
|
||
else {
|
||
healtherenable.value = 'N'
|
||
}
|
||
}
|
||
|
||
|
||
//編輯資料
|
||
//編輯是否啟動
|
||
const check_enable_view = ref(null);
|
||
const enable_change = async () => {
|
||
if (healtherenable.value == 'Y'){
|
||
if (level % 2 != 0){
|
||
level = level + 1;
|
||
check_enable_view.value?.showModal();
|
||
}
|
||
}
|
||
if (healtherenable.value == 'N'){
|
||
if (level % 2 == 0){
|
||
level = level - 1;
|
||
check_enable_view.value?.showModal();
|
||
}
|
||
}
|
||
//console.log(level)
|
||
}
|
||
|
||
//上傳編輯啟用訊息
|
||
const submit_edit_enable = async () => {
|
||
console.log(level)
|
||
const route = useRoute(); // 取得當前路由資訊
|
||
const health_guid = route.params.guid; // 提取路由中的 guid 參數
|
||
try {
|
||
const enable_data = {
|
||
guid: health_guid,
|
||
level:level.toString()
|
||
};
|
||
const response = await fetch(`${$api_host}/api/Health_detail_table/healther_enable`, {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json',
|
||
Authorization: authToken.value,
|
||
},
|
||
body: JSON.stringify(enable_data)
|
||
});
|
||
check_enable_view.value?.close();
|
||
alert('編輯成功!');
|
||
get_data();
|
||
|
||
} catch (error) {
|
||
console.error( error);
|
||
}
|
||
}
|
||
|
||
// 自啟
|
||
// 🚀 在 mounted 時獲取 token
|
||
onMounted(() => {
|
||
if (process.client) {
|
||
// 讀取 localStorage 並將 token 設置到 reactive 變數中
|
||
authToken.value = localStorage.getItem("token_TCM") || "";
|
||
}
|
||
|
||
get_data(); // 確保 token 讀取後再調用 API
|
||
});
|
||
</script> |