|
|
|
|
@ -35,7 +35,7 @@
|
|
|
|
|
</van-cell-group>
|
|
|
|
|
<main class="main-wrap address2-page mb-xxl" v-show="active === 1">
|
|
|
|
|
<div class="add-btn">
|
|
|
|
|
<van-button type="success" plain hairline block @click="showOffcanvas = true">+新增公司資料</van-button>
|
|
|
|
|
<van-button type="success" plain hairline block @click="handleAddUserCompany">+新增公司資料</van-button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="address-wrap">
|
|
|
|
|
<div class="address-box"
|
|
|
|
|
@ -50,8 +50,8 @@
|
|
|
|
|
<span class="badges-round font-white bg-theme-theme font-xs" v-if="uc.is_default">預設</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="heading-right">
|
|
|
|
|
<!-- <i class="icon-pencil" @click.stop="handleEdit(uc.id)"></i> -->
|
|
|
|
|
<i class="icon-trash" style="color: red;" @click.stop="handleDelete(uc.id)" v-if="!uc.is_default"></i>
|
|
|
|
|
<i class="icon-pencil" @click.stop="handleEdit(uc.id)"></i>
|
|
|
|
|
<i class="icon-trash" style="color: red;" @click.stop="handleDelete(uc.id)"></i>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<h3 class="title-color font-sm">{{ uc.uc_title }}</h3>
|
|
|
|
|
@ -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,6 +203,7 @@ export default {
|
|
|
|
|
const userCompany = ref([])
|
|
|
|
|
|
|
|
|
|
const ucForm = ref({
|
|
|
|
|
action: 'insert',
|
|
|
|
|
uc_name: '',
|
|
|
|
|
uc_title: '',
|
|
|
|
|
uc_tel: '',
|
|
|
|
|
@ -300,6 +311,7 @@ export default {
|
|
|
|
|
if (userCompRes.code === 200) {
|
|
|
|
|
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,8 +358,29 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onUCSumbit = async () => {
|
|
|
|
|
if(ucForm.value.action ==='insert'){
|
|
|
|
|
if(userCompany.length === 0){
|
|
|
|
|
ucForm.value.is_default = true
|
|
|
|
|
}
|
|
|
|
|
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: ''
|
|
|
|
|
}
|
|
|
|
|
showOffcanvas.value = false
|
|
|
|
|
userCompany.value = res.data
|
|
|
|
|
}else{
|
|
|
|
|
Toast('操作失敗')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
let res = await updateUserCompany(ucForm.value)
|
|
|
|
|
|
|
|
|
|
if(res.code === 200){
|
|
|
|
|
ucForm.value={
|
|
|
|
|
uc_name: '',
|
|
|
|
|
@ -352,6 +394,8 @@ export default {
|
|
|
|
|
}else{
|
|
|
|
|
Toast('操作失敗')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleDelete = async (id)=>{
|
|
|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|