用戶公司增加修改功能,剩下一筆也可刪除

main
Wayne Hsu 3 years ago
parent 99e8f7bd53
commit 7978fb3bc6

@ -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');

@ -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,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
}
}
}

@ -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: {

Loading…
Cancel
Save