From 7978fb3bc6441eb33e5b9b8a174a653b992b9090 Mon Sep 17 00:00:00 2001 From: Wayne Hsu Date: Fri, 17 Feb 2023 19:20:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B6=E5=85=AC=E5=8F=B8=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=89=A9?= =?UTF-8?q?=E4=B8=8B=E4=B8=80=E7=AD=86=E4=B9=9F=E5=8F=AF=E5=88=AA=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.js | 3 +- src/views/Member/index.vue | 96 +++++++++++++++++++++++++++++--------- vue.config.js | 2 +- 3 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/api/user.js b/src/api/user.js index 234ebc4..485a7df 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -13,5 +13,6 @@ export const updateCard = async (userInfo) => export const getUserCompany = async () => ajax(`/user/getUserCompany`); export const addUserCompany = async (params) => ajax(`/user/addUserCompany`,params,'POST'); -export const updateUserCompany = async (id) => ajax(`/user/updateUserCompany`,{id},'POST'); +export const updateUserCompany = async (params) => ajax(`/user/updateUserCompany`,params,'POST'); export const deleteUserCompany = async (id) => ajax(`/user/deleteUserCompany`,{id},'POST'); +export const setUCDefault = async (id) => ajax(`/user/setUCDefault`,{id},'POST'); diff --git a/src/views/Member/index.vue b/src/views/Member/index.vue index c006cdb..f07baac 100644 --- a/src/views/Member/index.vue +++ b/src/views/Member/index.vue @@ -35,7 +35,7 @@
- +新增公司資料 + +新增公司資料
預設
- - + +

{{ uc.uc_title }}

@@ -174,7 +174,17 @@ import { useStore } from 'vuex' import { useRouter } from 'vue-router' import { Toast } from 'vant' -import { getUserInfo, updateCard, getUserCompany, addUserCompany, updateUserCompany, deleteUserCompany } from '@/api/user' + +import { + getUserInfo, + updateCard, + getUserCompany, + addUserCompany, + updateUserCompany, + deleteUserCompany, + setUCDefault + } from '@/api/user' +import { is } from '@babel/types'; const URL = window.URL || window.webkitURL; @@ -193,10 +203,11 @@ export default { const userCompany = ref([]) const ucForm = ref({ + action: 'insert', uc_name: '', uc_title: '', uc_tel: '', - uc_address: '', + uc_address: '', uc_url: '', }) @@ -298,8 +309,9 @@ export default { //公司資料 let userCompRes = await getUserCompany() if (userCompRes.code === 200) { - userCompany.value = userCompRes.data + userCompany.value = userCompRes.data } + console.log(userCompany.value) //增加連結 const onAddBtn = () => { @@ -327,8 +339,17 @@ export default { } + const handleAddUserCompany = () => { + ucForm.value = {action: 'insert'} + console.log(userCompany.value.length,userCompany.value) + if(userCompany.value.length ==0){ + ucForm.value.is_default = true + } + showOffcanvas.value = true + } + const handleSetDefault = async (id) => { - let res = await updateUserCompany(id) + let res = await setUCDefault(id) if(res.code === 200){ userCompany.value = res.data }else{ @@ -337,20 +358,43 @@ export default { } const onUCSumbit = async () => { - let res = await addUserCompany(ucForm.value) - console.log('res',res) - if(res.code === 200){ - ucForm.value={ - uc_name: '', - uc_title: '', - uc_tel: '', - uc_address: '', - uc_url: '' + if(ucForm.value.action ==='insert'){ + if(userCompany.length === 0){ + ucForm.value.is_default = true } - showOffcanvas.value = false - userCompany.value = res.data + let res = await addUserCompany(ucForm.value) + + if(res.code === 200){ + ucForm.value={ + uc_name: '', + uc_title: '', + uc_tel: '', + uc_address: '', + uc_url: '' + } + showOffcanvas.value = false + userCompany.value = res.data + }else{ + Toast('操作失敗') + } + }else{ - Toast('操作失敗') + let res = await updateUserCompany(ucForm.value) + + if(res.code === 200){ + ucForm.value={ + uc_name: '', + uc_title: '', + uc_tel: '', + uc_address: '', + uc_url: '' + } + showOffcanvas.value = false + userCompany.value = res.data + }else{ + Toast('操作失敗') + } + } } @@ -363,8 +407,15 @@ export default { } } - const handleEdit = (id)=>{ - console.log('edit') + const handleEdit = async (id)=>{ + showOffcanvas.value = true + let t_data = {action:'update',...userCompany.value.find(item => item.id == id)} + if(t_data.is_default==1){ + t_data.is_default=true + }else{ + t_data.is_default=false + } + ucForm.value = t_data } const onSubmit = async () => { @@ -406,7 +457,8 @@ export default { onUCSumbit, handleEdit, handleDelete, - handleSetDefault + handleSetDefault, + handleAddUserCompany } } } diff --git a/vue.config.js b/vue.config.js index 0ca5764..11ef3d6 100644 --- a/vue.config.js +++ b/vue.config.js @@ -6,7 +6,7 @@ module.exports = { ? "/home" : "/home", outputDir: - ["production", "u168", "slash"].includes(process.env.VUE_ENV) + ["production", "u168"].includes(process.env.VUE_ENV) ? "../api/public/home" : "./dist", pwa: {