通訊錄 - 設定用戶類別及部份修正

main
Wayne 2 years ago
parent b406125e5d
commit 8033a7f261

@ -14,7 +14,7 @@ export const getUserInfo = async () =>
ajax(`/user/getUserInfo`); ajax(`/user/getUserInfo`);
export const updateUserInfo = async (params) => export const updateUserInfo = async (params) =>
ajax(`/user/updateUserInfo`,params, 'POST'); ajax(`/user/updateUserInfo`, params, 'POST');
export const setUserLevel = async (level) => export const setUserLevel = async (level) =>
ajax(`/user/setUserLevel`, { level }, "POST"); ajax(`/user/setUserLevel`, { level }, "POST");
@ -57,13 +57,13 @@ export const updateSendCount = async (userid) =>
//授權使用者 //授權使用者
export const setAuthUser = async (params) => export const setAuthUser = async (params) =>
ajax(`/user/setAuthUser`, params , "POST"); ajax(`/user/setAuthUser`, params, "POST");
export const getAuthUsers = async () => export const getAuthUsers = async () =>
ajax(`/user/getAuthUsers`); ajax(`/user/getAuthUsers`);
export const delAuthUser = async (id) => export const delAuthUser = async (id) =>
ajax(`/user/delAuthUser`,{id}); ajax(`/user/delAuthUser`, { id });
export const getAuthList = async () => export const getAuthList = async () =>
ajax(`/user/getAuthList`); ajax(`/user/getAuthList`);
@ -79,15 +79,18 @@ export const getFlexcard = async () =>
ajax(`/ads/getFlexcard`); ajax(`/ads/getFlexcard`);
//通訊錄 //通訊錄
export const getUserFaviList = async (params) => export const getUserFaviList = async (cate_id) =>
ajax(`/UserFavi/getUserFaviList`, params , "GET"); ajax(`/UserFavi/getUserFaviList`, { cate_id }, "GET");
export const addUserFavi = async (params) => export const addUserFavi = async (params) =>
ajax(`/UserFavi/addUserFavi`, params , "POST"); ajax(`/UserFavi/addUserFavi`, params, "POST");
export const setUserFaviCate = async (params) =>
ajax(`/UserFavi/setUserFaviCate`, params , "POST");
export const getUserCateList = async () => export const getUserCateList = async () =>
ajax(`/UserCate/getUserCateList`); ajax(`/UserCate/getUserCateList`);
export const updateUserCate = async (params) => export const updateUserCate = async (params) =>
ajax(`/UserCate/updateUserCate`, params , "POST"); ajax(`/UserCate/updateUserCate`, params, "POST");

@ -1,121 +1,151 @@
<script setup> <script setup>
import _ from 'lodash';
import { showToast,showSuccessToast , showLoadingToast } from 'vant'; import { showToast, showSuccessToast, showLoadingToast } from 'vant';
import { getUserFaviList, getUserCateList, updateUserCate } from '@/api' import { getUserFaviList, getUserCateList, updateUserCate, setUserFaviCate } from '@/api'
import { onMounted, reactive, ref, toRefs, computed, watch } from 'vue' import { onMounted, reactive, ref, toRefs, computed, watch } from 'vue'
const setShowPicker = ref(false); const setShowPicker = ref(false);
const selectVal1 = ref('all'); const selectVal1 = ref('all');
const selectVal2 = ref('普通'); const selectVal2 = ref('普通');
const selectOpt1 = ref([{ text: '全部', value: 'all' }]); const selectOpt1 = ref([{ text: '全部', value: 'all' }]);
const selectOpt2 = ref([{ text: '重要', value: '重要' },{ text: '普通', value: '普通' }]); const selectOpt2 = ref([{ text: '重要', value: '重要' }, { text: '普通', value: '普通' }]);
const addressList = ref({
data:[
{
id:"a1",
real_name:"樹林李敏鎬",
line:"test",
user_cate_id:''
},
{
id:"a2",
real_name:"五條悟",
line:"test",
user_cate_id:''
},
{
id:"a3",
real_name:"機哩瓜啦",
line:"test",
user_cate_id:''
},
]
});
const modalForm = ref({ const addressList = ref([]);
page: 1,
sort:[ onMounted(async () => {
{ let res = await getUserFaviList(0);
"id": 1, if (res.code === 200) {
"name": "第一類", addressList.value = res.data;
"children": [ }
{"id": 4,"name": "普通"},
{"id": 5,"name": "重要"} res = await getUserCateList();
] if (res.code === 200) {
}, console.log('res.data', res.data)
{ columns.value = [columns.value[0], ...res.data];
"id": 2, columns2.value = [columns2.value[0], ...res.data];
"name": "第二類", if(res.data.length > 0){
"children": [ modalForm.value.sort = res.data;
{"id": 6,"name": "普通"}, }else{
{"id": 7,"name": "重要"} modalForm.value.sort = [_.cloneDeep(defaultCate)];
]
},
{
"id": 3,
"name": "第三類",
"children": [
{"id": 8,"name": "普通"},
{"id": 9,"name": "重要"},
{"name": "特殊"}
]
} }
] }
}); });
onMounted(async() => { // START:
let res = await getUserFaviList(); const fieldValue = ref('全部-全部');
const showCatePicker = ref(false);
const customFieldName = {
text: 'name',
value: 'id',
children: 'children',
};
const columns = ref([
{
id: 0,
name: '全部',
children: [
{
id: 0,
name: '全部'
}
]
},
]);
const onCateConfirm = async (value) => {
let res = await getUserFaviList(value.selectedValues[1]);
if (res.code === 200) { if (res.code === 200) {
addressList.value.data = res.data; addressList.value = res.data;
} }
res = await getUserCateList(); showCatePicker.value = false;
};
const onCateChange = (value) => {
fieldValue.value = value.selectedOptions.map((item) => item.name).join('-');
};
// END:
// START:
const columns2 = ref([
{
id: 0,
name: '未分類',
children: [
{
id: 0,
name: '未分類'
}
]
},
]);
const showChangeCatePicker = ref(false);
const changeUserId = ref('');
const handleChangeCate = (userId) => {
changeUserId.value = userId;
showChangeCatePicker.value = true;
};
const onChangeCateConfirm = async (value) => {
let res = await setUserFaviCate({ uf_user_id: changeUserId.value,cate_id : value.selectedValues[1] });
if (res.code === 200) { if (res.code === 200) {
let sort = modalForm.value.sort; showSuccessToast('更新成功')
sort.forEach((item, i) => { } else {
selectOpt1.value.push({ showToast('更新失敗')
text:item.name,
value:i
})
});
} }
showChangeCatePicker.value = false;
};
const onChangeCateChange = (value) => {
console.log('Change Category');
};
// END:
// START:
const defaultCate = {
"id": 0,
"name": ""
};
const modalForm = ref({
page: 1,
sort: [_.cloneDeep(defaultCate)]
}); });
const sel1Change = (value) => { const sel1Change = (value) => {
if(value != 'all'){ if (value != 'all') {
let child = modalForm.value.sort[value].children; let child = modalForm.value.sort[value].children;
let ary = []; let ary = [];
child.forEach((item, i) => { child.forEach((item, i) => {
ary.push({ ary.push({
text:item.name, text: item.name,
value:item.name value: item.name
}) })
}); });
selectOpt2.value = ary; selectOpt2.value = ary;
selectVal2.value = child[0].name; selectVal2.value = child[0].name;
}else{ } else {
selectOpt2.value = []; selectOpt2.value = [];
selectVal2.value = ''; selectVal2.value = '';
} }
}; };
const addCard = () => { const addCard = () => {
modalForm.value.sort.push( modalForm.value.sort.push(_.cloneDeep(defaultCate));
{
"name": "",
"children": [
{
"name": "普通"
}
]
}
);
modalForm.value.page = modalForm.value.sort.length; modalForm.value.page = modalForm.value.sort.length;
}; };
@ -131,10 +161,7 @@ const addBtn = (page) => {
modalForm.value.sort[page - 1].children = []; modalForm.value.sort[page - 1].children = [];
} }
modalForm.value.sort[page - 1].children.push({ modalForm.value.sort[page - 1].children.push(_.cloneDeep(defaultCate));
"id": '',
"name": ""
});
}; };
const moveCard = (type, page) => { const moveCard = (type, page) => {
@ -171,9 +198,9 @@ const moveBtn = (type, index) => {
modalForm.value.sort[modalForm.value.page - 1].children[index], modalForm.value.sort[modalForm.value.page - 1].children[index],
modalForm.value.sort[modalForm.value.page - 1].children[index - 1], modalForm.value.sort[modalForm.value.page - 1].children[index - 1],
] = [ ] = [
modalForm.value.sort[modalForm.value.page - 1].children[index - 1], modalForm.value.sort[modalForm.value.page - 1].children[index - 1],
modalForm.value.sort[modalForm.value.page - 1].children[index], modalForm.value.sort[modalForm.value.page - 1].children[index],
]; ];
} }
} else { } else {
if (index + 1 !== modalForm.value.sort[modalForm.value.page - 1].children.length) { if (index + 1 !== modalForm.value.sort[modalForm.value.page - 1].children.length) {
@ -181,15 +208,16 @@ const moveBtn = (type, index) => {
modalForm.value.sort[modalForm.value.page - 1].children[index + 1], modalForm.value.sort[modalForm.value.page - 1].children[index + 1],
modalForm.value.sort[modalForm.value.page - 1].children[index], modalForm.value.sort[modalForm.value.page - 1].children[index],
] = [ ] = [
modalForm.value.sort[modalForm.value.page - 1].children[index], modalForm.value.sort[modalForm.value.page - 1].children[index],
modalForm.value.sort[modalForm.value.page - 1].children[index + 1], modalForm.value.sort[modalForm.value.page - 1].children[index + 1],
]; ];
} }
} }
}; };
const onSubmit = async () => { const onSubmit = async () => {
let res = await updateUserCate(modalForm.value.sort) let res = await updateUserCate({ category: modalForm.value.sort })
if (res.code === 200) { if (res.code === 200) {
showSuccessToast('更新成功') showSuccessToast('更新成功')
// router.push('/member') // router.push('/member')
@ -203,46 +231,43 @@ const onSubmit = async () => {
<template> <template>
<div class="address page"> <div class="address page">
<van-nav-bar <van-nav-bar class="bg-skyBlue py-1" left-arrow right-arrow @click-left="$router.push('/')"
class="bg-skyBlue py-1" @click-right="setShowPicker = true">
left-arrow
right-arrow
@click-left="$router.push('/')"
@click-right="setShowPicker = true"
>
<template #title> <template #title>
<h5 class="text-white mb-1"><strong>通訊錄</strong></h5> <h5 class="text-white mb-1"><strong>通訊錄</strong></h5>
</template> </template>
<template #left> <template #left>
<h4><i class="fa-solid fa-angle-left text-white" :style="{opacity:0.5}"></i></h4> <h4><i class="fa-solid fa-angle-left text-white" :style="{ opacity: 0.5 }"></i></h4>
</template> </template>
<template #right> <template #right>
<h4><i class="fa-solid fa-gear text-white" :style="{opacity:0.5}"></i></h4> <h4><i class="fa-solid fa-gear text-white" :style="{ opacity: 0.5 }"></i></h4>
</template> </template>
</van-nav-bar> </van-nav-bar>
<div class="content"> <div class="content">
<!-- START: 通訊錄類別 -->
<van-cell-group inset> <van-cell-group inset>
<van-dropdown-menu> <van-field v-model="fieldValue" is-link readonly label="類別" placeholder="通訊錄類別" @click="showCatePicker = true" />
<van-dropdown-item v-model="selectVal1" :options="selectOpt1" @change="sel1Change"/> <van-popup v-model:show="showCatePicker" round position="bottom">
<van-dropdown-item v-model="selectVal2" :options="selectOpt2" /> <van-picker :columns="columns" :columns-field-names="customFieldName" confirm-button-text=""
</van-dropdown-menu> cancel-button-text="取消" @cancel="showCatePicker = false" @confirm="onCateConfirm" @change="onCateChange" />
</van-popup>
</van-cell-group> </van-cell-group>
<!-- END: 通訊錄類別 -->
<van-cell-group inset> <van-cell-group inset>
<van-list> <van-list>
<div class="list-item" v-for="(item, index) in addressList" :data-cateid="item.user_cate_id" :key="index">
<div class="list-item" v-for="(item, index) in addressList.data" :data-cateid="item.user_cate_id" :key="index">
<div class="left"> <div class="left">
<div class="avatar"><img :src="`https://fakeimg.pl/350x200/?text=${item.id}`"></div> <div class="avatar"><img :src="item.avatar"></div>
<div class="text"> <div class="text">
<h5 class="name ellipsis">{{ item.real_name }}</h5> <h5 class="name ellipsis">{{ item.real_name }}</h5>
<div class="desc ellipsis">@{{ item.line }}</div> <div class="desc ellipsis">@{{ item.line }}</div>
</div> </div>
</div> </div>
<div class="right"> <div class="right">
<van-button size="small" class="border-0"> <van-button size="small" class="border-0" @click="handleChangeCate(item.user_id)">
<h5><i class="fa-solid fa-heart text-darkBlue"></i></h5> <h5><i class="fa-solid fa-heart text-darkBlue"></i></h5>
</van-button> </van-button>
<van-button size="small" class="border-0" :url="`line://ti/p/@${item.line}`"> <van-button size="small" class="border-0" :url="`line://ti/p/@${item.line}`">
@ -255,145 +280,85 @@ const onSubmit = async () => {
</van-cell-group> </van-cell-group>
</div> </div>
<!-- START: 編輯通訊錄 -->
<van-dialog <van-dialog v-model:show="setShowPicker" width="400" showCancelButton confirm-button-text="" @confirm="onSubmit">
v-model:show="setShowPicker"
width="400"
showCancelButton
confirm-button-text="確認修改"
@confirm="onSubmit"
>
<van-form @submit="onSubmit"> <van-form @submit="onSubmit">
<keep-alive> <div id="app">
<div id="app"> <div class="bg-lightPink px-2 pt-3">
<ul class="nav nav-tabs">
<div class="bg-lightPink px-2 pt-3"> <li class="nav-item" v-for="(card, index) in modalForm.sort" :key="index"
<ul class="nav nav-tabs"> @click="modalForm.page = index + 1">
<li <button type="button" class="nav-link" :class="{ active: modalForm.page === index + 1 }">
class="nav-item" {{ index + 1 }}
v-for="(card, index) in modalForm.sort" </button>
:key="index" </li>
@click="modalForm.page = index + 1" <li class="nav-item" @click="addCard" v-if="modalForm.sort.length < 10">
> <button type="button" class="nav-link">
<button <i class="fa fa-plus-circle"></i>
type="button" </button>
class="nav-link" </li>
:class="{ active: modalForm.page === index + 1 }" </ul>
> </div>
{{ index + 1 }}
</button>
</li>
<li
class="nav-item"
@click="addCard"
v-if="modalForm.sort.length < 10"
>
<button type="button" class="nav-link">
<i class="fa fa-plus-circle"></i>
</button>
</li>
</ul>
</div>
<van-cell-group class="m-0 pt-2"> <van-cell-group class="m-0 pt-2">
<van-field <van-field label="調整卡片順序" :border="false" v-if="modalForm.sort.length > 1">
label="調整卡片順序" <template #button>
:border="false" <van-button size="small" class="ml-1 btn-skyBlue" icon="arrow-left"
v-if="modalForm.sort.length > 1" @click="moveCard(0, modalForm.page)">前移</van-button>
> <van-button size="small" class="ml-1 btn-skyBlue" icon="arrow"
<template #button> @click="moveCard(1, modalForm.page)">後移</van-button>
<van-button <van-button size="small" class="ml-1 btn-tomatoRed" icon="delete-o"
size="small" @click="delCard(modalForm.page)"></van-button>
class="ml-1 btn-skyBlue" </template>
icon="arrow-left" </van-field>
@click="moveCard(0, modalForm.page)"
>前移</van-button <van-field v-model="modalForm.sort[modalForm.page - 1].name" label="分類名稱" id="vcard-title" input-align="right"
> placeholder="請輸入分類名稱" />
<van-button
size="small" <div class="listCnt">
class="ml-1 btn-skyBlue" <div class="item" v-for="(btn, index) in modalForm.sort[modalForm.page - 1].children" :key="index">
icon="arrow" <van-field v-model="btn.name" id="cardbtn-text-0" placeholder="請輸入子項目名稱" class="bg-transparent">
@click="moveCard(1, modalForm.page)" <template #button>
>後移</van-button <van-button size="small" class="bg-transparent border-0" icon="arrow-up" @click="moveBtn(0, index)"
> v-if="modalForm.sort[modalForm.page - 1].children.length > 1"></van-button>
<van-button <van-button size="small" class="bg-transparent border-0" icon="arrow-down" @click="moveBtn(1, index)"
size="small" v-if="modalForm.sort[modalForm.page - 1].children.length > 1"></van-button>
class="ml-1 btn-tomatoRed" <van-button size="small" class="bg-transparent border-0" icon="delete-o"
icon="delete-o" @click="delBtn(index)"></van-button>
@click="delCard(modalForm.page)" </template>
></van-button> </van-field>
</template>
</van-field>
<van-field
v-model="modalForm.sort[modalForm.page - 1].name"
label="分類名稱"
id="vcard-title"
input-align="right"
placeholder="請輸入分類名稱"
/>
<div class="listCnt">
<div
class="item"
v-for="(btn, index) in modalForm.sort[modalForm.page - 1].children"
:key="index"
>
<van-field
v-model="btn.name"
id="cardbtn-text-0"
placeholder="請輸入子項目名稱"
class="bg-transparent"
>
<template #button>
<van-button
size="small"
class="bg-transparent border-0"
icon="arrow-up"
@click="moveBtn(0, index)"
v-if="modalForm.sort[modalForm.page - 1].children.length > 1"
></van-button>
<van-button
size="small"
class="bg-transparent border-0"
icon="arrow-down"
@click="moveBtn(1, index)"
v-if="modalForm.sort[modalForm.page - 1].children.length > 1"
></van-button>
<van-button
size="small"
class="bg-transparent border-0"
icon="delete-o"
@click="delBtn(index)"
></van-button>
</template>
</van-field>
</div>
<van-button
block
class="btn-tomatoRed"
icon="add-o"
@click="addBtn(modalForm.page)"
>
<h6>新增按鈕</h6>
</van-button>
</div> </div>
<van-button block class="btn-tomatoRed" icon="add-o" @click="addBtn(modalForm.page)">
<h6>新增按鈕</h6>
</van-button>
</div>
</van-cell-group> </van-cell-group>
</div> </div>
</keep-alive>
</van-form> </van-form>
</van-dialog> </van-dialog>
<!-- END: 編輯通訊錄 -->
<van-popup v-model:show="showChangeCatePicker" round position="bottom">
<van-picker
:columns="columns2"
:columns-field-names="customFieldName"
confirm-button-text="確認"
cancel-button-text="取消"
@cancel="showChangeCatePicker = false"
@confirm="onChangeCateConfirm"
@change="onChangeCateChange" />
</van-popup>
</div> </div>
</template> </template>
<style lang="less" scoped> <style lang="less" scoped>
.address {
.address{ .content {
.content{
min-height: calc(100vh - 54px); min-height: calc(100vh - 54px);
} }
.van-list { .van-list {
.list-item { .list-item {
display: flex; display: flex;
@ -447,29 +412,31 @@ const onSubmit = async () => {
} }
} }
} }
.nav-tabs{
.nav-link{ .nav-tabs {
.nav-link {
color: #4a677d; color: #4a677d;
background-color: #fff; background-color: #fff;
border-color: transparent; border-color: transparent;
margin-right: 4px; margin-right: 4px;
} }
.nav-item.show .nav-link, .nav-item.show .nav-link,
.nav-link.active { .nav-link.active {
color: #fff; color: #fff;
background-color: #4a677d; background-color: #4a677d;
border-color: #4a677d #4a677d #4a677d; border-color: #4a677d #4a677d #4a677d;
} }
} }
.listCnt{ .listCnt {
padding: 15px; padding: 15px;
.item{
margin-bottom: 15px; .item {
border: 1px #ddd solid; margin-bottom: 15px;
border-radius: 5px; border: 1px #ddd solid;
border-radius: 5px;
} }
} }
} }
</style> </style>

@ -803,7 +803,7 @@ const handleSubmit = async () => {
.flex-section { .flex-section {
width: 100%; width: 100%;
} }
:deep .van-field__control{ :deep(.van-field__control){
justify-content: center; justify-content: center;
.upload-main { .upload-main {
flex-direction: column; flex-direction: column;

Loading…
Cancel
Save