2025-02-19 20:12:42 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<button type="button" class="btn btn-primary" @click="add_company">
|
|
|
|
|
新增企業
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<br /><br />
|
|
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div v-for="company in companies" :key="company.guid" class="col-xl-3 col-md-6 mb-4">
|
2025-02-22 17:03:42 +08:00
|
|
|
|
<div :class="['card', 'shadow', 'h-100', 'py-2', company.level == '8' ? 'border-left-primary' : 'border-left-warning']" @click="edit_company(company.guid)">
|
2025-02-19 20:12:42 +08:00
|
|
|
|
<div class="card-body">
|
|
|
|
|
<div class="row no-gutters align-items-center">
|
|
|
|
|
<div class="col mr-2">
|
|
|
|
|
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
|
|
|
|
|
企業名稱:
|
|
|
|
|
</div>
|
2025-02-20 21:27:24 +08:00
|
|
|
|
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ company.company_name }}</div>
|
2025-02-19 20:12:42 +08:00
|
|
|
|
</div>
|
|
|
|
|
<div class="col-auto">
|
|
|
|
|
<i class="fas fa-building fa-2x text-gray-300"></i> <!-- 改為企業圖標 -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
2025-02-22 12:26:58 +08:00
|
|
|
|
|
2025-02-19 20:12:42 +08:00
|
|
|
|
|
|
|
|
|
<!--新增企業-彈跳視窗-->
|
|
|
|
|
<div>
|
|
|
|
|
<dialog ref="add_Company_view" class="dialog-box">
|
|
|
|
|
<div><button class="btn btn-danger" style="float:right" @click="close_add_Company_view">關閉</button>
|
|
|
|
|
<h2>新增企業</h2>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 表單內容 -->
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label for="companyName">企業名稱:</label>
|
|
|
|
|
<input id="companyName" v-model="companyName" type="text" class="form-control" placeholder="請輸入企業名稱">
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label for="companyPhone">聯絡電話:</label>
|
|
|
|
|
<input id="companyPhone" v-model="companyPhone" type="tel" class="form-control" placeholder="請輸入聯絡電話">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label for="companyPhone">預設帳號:</label>
|
|
|
|
|
<input id="companyPhone" v-model="companyaccount" type="text" class="form-control"
|
|
|
|
|
placeholder="請輸入預設帳號">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label for="companyPhone">預設密碼:</label>
|
|
|
|
|
<input id="companyPhone" v-model="companypassword" type="text" class="form-control"
|
|
|
|
|
placeholder="請輸入預設密碼">
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 操作按鈕 -->
|
|
|
|
|
<div class="button-group">
|
|
|
|
|
<button class="btn btn-success" @click="submitCompany">確認</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2025-02-22 12:26:58 +08:00
|
|
|
|
<script setup>
|
2025-02-19 20:12:42 +08:00
|
|
|
|
import { ref, onMounted } from 'vue'
|
|
|
|
|
import { useRouter } from "vue-router"; //匯入路徑
|
2025-02-25 20:49:51 +08:00
|
|
|
|
const config = useRuntimeConfig();
|
|
|
|
|
const $api_host = config.public.apiHost;
|
2025-02-19 20:12:42 +08:00
|
|
|
|
const router = useRouter(); // 匯入
|
2025-02-22 12:26:58 +08:00
|
|
|
|
// 🔐 定義全域 token
|
|
|
|
|
const authToken = ref("");
|
2025-02-19 20:12:42 +08:00
|
|
|
|
|
|
|
|
|
|
2025-02-22 12:26:58 +08:00
|
|
|
|
|
|
|
|
|
const add_Company_view = ref(null);
|
2025-02-19 20:12:42 +08:00
|
|
|
|
//新增企業
|
2025-02-22 12:26:58 +08:00
|
|
|
|
const add_company = async () => {
|
|
|
|
|
companyName.value = "";
|
2025-02-19 20:12:42 +08:00
|
|
|
|
companyPhone.value = "";
|
2025-02-22 12:26:58 +08:00
|
|
|
|
companyaccount.value = "";
|
2025-02-19 20:12:42 +08:00
|
|
|
|
companypassword.value = "";
|
|
|
|
|
add_Company_view.value?.showModal();
|
|
|
|
|
}
|
|
|
|
|
//關閉 <新增企業-彈跳視窗>
|
2025-02-22 12:26:58 +08:00
|
|
|
|
const close_add_Company_view = () => {
|
2025-02-19 20:12:42 +08:00
|
|
|
|
add_Company_view.value?.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 上傳企業基本資料
|
|
|
|
|
const companyName = ref("");
|
|
|
|
|
const companyPhone = ref("");
|
|
|
|
|
const companyaccount = ref("");
|
|
|
|
|
const companypassword = ref("");
|
2025-02-22 12:26:58 +08:00
|
|
|
|
const submitCompany = async () => {
|
|
|
|
|
|
2025-02-19 20:12:42 +08:00
|
|
|
|
try {
|
|
|
|
|
const companyData = {
|
2025-02-22 12:26:58 +08:00
|
|
|
|
lastname: companyName.value,
|
|
|
|
|
username: companyaccount.value,
|
|
|
|
|
password: companypassword.value
|
2025-02-19 20:12:42 +08:00
|
|
|
|
};
|
|
|
|
|
console.log(companyData)
|
|
|
|
|
|
|
|
|
|
const response = await fetch(`${$api_host}/api/Company_detail_table/Add_campany`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
2025-02-22 12:26:58 +08:00
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: authToken.value,
|
2025-02-19 20:12:42 +08:00
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(companyData)
|
|
|
|
|
});
|
|
|
|
|
add_Company_view.value?.close();
|
|
|
|
|
alert('上傳成功!');
|
|
|
|
|
get_data();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
alert('上傳失敗,請檢查後端!');
|
|
|
|
|
}
|
2025-02-22 12:26:58 +08:00
|
|
|
|
|
2025-02-19 20:12:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-22 12:26:58 +08:00
|
|
|
|
|
2025-02-19 20:12:42 +08:00
|
|
|
|
//獲取資料
|
|
|
|
|
const get_data = async () => {
|
2025-02-22 12:26:58 +08:00
|
|
|
|
const All_Companies = await get_All_Companies();//獲取公司資訊
|
|
|
|
|
set_All_Companies_data(All_Companies);
|
|
|
|
|
}
|
2025-02-19 20:12:42 +08:00
|
|
|
|
|
2025-02-22 12:26:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 📌 獲取公司資訊
|
|
|
|
|
const get_All_Companies = async () => {
|
|
|
|
|
if (!process.client) return; // 確保只在 client-side 執行
|
|
|
|
|
|
|
|
|
|
//const token = localStorage.getItem("token_TCM");
|
|
|
|
|
try {
|
|
|
|
|
const response = await $fetch(`${$api_host}/api/Company_detail_table/get_all_campany`, {
|
|
|
|
|
method: "GET",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
Authorization: authToken.value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log("✅ 獲取成功", response);
|
|
|
|
|
return response
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("🔴 獲取公司資料失敗", error);
|
|
|
|
|
}
|
2025-02-19 20:12:42 +08:00
|
|
|
|
};
|
|
|
|
|
|
2025-02-22 12:26:58 +08:00
|
|
|
|
|
|
|
|
|
// 設定資料
|
|
|
|
|
const companies = ref([]);
|
|
|
|
|
const set_All_Companies_data = (data) => {
|
|
|
|
|
console.log(data)
|
|
|
|
|
companies.value = data; // 更新公司列表
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-19 20:12:42 +08:00
|
|
|
|
//編輯資料
|
2025-02-22 12:26:58 +08:00
|
|
|
|
const edit_company = async (guid) => {
|
2025-02-19 20:12:42 +08:00
|
|
|
|
console.log(guid)
|
2025-02-22 12:26:58 +08:00
|
|
|
|
router.push("/Lamiter_pages/Company-" + guid);
|
2025-02-19 20:12:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 自啟
|
2025-02-22 12:26:58 +08:00
|
|
|
|
// 🚀 在 mounted 時獲取 token
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
if (process.client) {
|
|
|
|
|
// 讀取 localStorage 並將 token 設置到 reactive 變數中
|
|
|
|
|
authToken.value = localStorage.getItem("token_TCM") || "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_data(); // 確保 token 讀取後再調用 API
|
|
|
|
|
});
|
2025-02-19 20:12:42 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
/* 簡單美化對話框 */
|
|
|
|
|
.dialog-box {
|
|
|
|
|
width: 50%;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-group {
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-control {
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding: 8px;
|
|
|
|
|
margin-top: 5px;
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.button-group {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
/* 讓按鈕水平置中 */
|
|
|
|
|
margin-top: 15px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|