freight-web/src/pagesApp/user.vue

205 lines
4.9 KiB
Vue
Raw Normal View History

2024-03-18 06:17:04 +00:00
<template>
<view class="c-card">
<view class="search">
<u-search
placeholder="请输入人员名称"
v-model="state.name"
:showAction="false"
:bgColor="'#fff'"
:borderColor="'rgba(0, 0, 0, 0.1)'"
:placeholderColor="'#C1C1C1'"
@search="handleSearch()"
@clear="handleSearch()"
2024-03-18 06:17:04 +00:00
></u-search>
</view>
2024-03-19 06:29:27 +00:00
2024-03-20 02:43:46 +00:00
<page-view
@loadList="
(v) => {
getList(v);
}
"
:noMoreData="pageList.noMoreData"
2024-03-21 05:52:15 +00:00
:list="pageList.list"
2024-03-28 08:55:03 +00:00
:height="100"
:isLoading="pageList.isLoading"
2024-03-20 02:43:46 +00:00
>
2024-03-19 06:29:27 +00:00
<view class="box">
<view v-for="(item, index) in pageList.list" :key="index">
<view>
2024-03-20 02:43:46 +00:00
<view>{{ item.name || item.userName }}</view>
2024-07-15 06:15:49 +00:00
<view>手机号{{ item.phone || "-" }}</view>
<view>关联角色{{
2024-03-19 06:29:27 +00:00
item.roleVos.length > 0 ? item.roleVos[0].roleName : "-"
}}</view>
</view>
<view class="op-box">
<view class="btn" @click="edit(item)"> 编辑 </view>
<view class="btn" @click="handleModal(true, item.id)"> 删除 </view>
2024-03-19 06:29:27 +00:00
</view>
2024-03-18 06:17:04 +00:00
</view>
</view>
2024-03-19 06:29:27 +00:00
</page-view>
2024-03-18 06:17:04 +00:00
</view>
2024-07-15 06:15:49 +00:00
<view class="btn-box-fix-btn">
<u-button type="primary" text="新增" @click="add" shape="circle"></u-button>
</view>
<SmallModal
:title="'确认删除吗?'"
:content="'确认删除后,不能恢复!'"
:okText="'确认删除'"
:isMain="true"
:show="isShowCancelModal"
@handleModal="(v:boolean) => {handleModal(v, deleteId)}"
@handleOk="handleOk()"
/>
2024-03-18 06:17:04 +00:00
</template>
<script setup lang="ts">
2024-03-19 06:29:27 +00:00
import PageView from "@/components/PageView/index.vue";
import { ProfileApi } from "@/services";
import type { User } from "@/types/user";
import SmallModal from "@/components/Modal/smallModal.vue";
2024-04-25 08:30:50 +00:00
import { onShow } from "@dcloudio/uni-app";
2024-03-18 06:17:04 +00:00
const isShowCancelModal = ref(false);
const deleteId = ref(0);
const handleModal = (v: boolean, id: number) => {
isShowCancelModal.value = v;
deleteId.value = id;
};
const handleOk = () => {
deleteCustomer({id: deleteId.value})
};
2024-03-18 06:17:04 +00:00
const state = reactive<any>({
name: "",
});
const pageList: PageResult<User> = reactive({
2024-03-19 06:29:27 +00:00
noMoreData: false,
2024-03-18 06:17:04 +00:00
total: 0,
list: [],
pageNum: 1,
pageSize: 10,
});
const add = () => {
uni.navigateTo({
url: "/pagesApp/components/addUser", // 要跳转到的页面路径
});
};
const edit = (item: any) => {
uni.navigateTo({
url:
"/pagesApp/components/addUser?title=编辑人员&item=" +
JSON.stringify(item), // 要跳转到的页面路径
});
};
const deleteCustomer = (item: any) => {
2024-03-20 02:43:46 +00:00
ProfileApi.updateUserByIdOffline({ id: item.id }).then((res) => {
2024-03-18 06:17:04 +00:00
if (res.code === 200) {
resetPageList();
2024-03-18 06:17:04 +00:00
getList();
}
});
};
2024-03-20 02:43:46 +00:00
const resetPageList = () => {
pageList.noMoreData = false;
pageList.total = 0;
pageList.list = [];
pageList.pageNum = 1;
2024-07-15 06:15:49 +00:00
pageList.pageSize = 100;
2024-03-20 02:43:46 +00:00
};
2024-03-18 06:17:04 +00:00
const handleSearch = () => {
2024-03-20 02:43:46 +00:00
resetPageList();
2024-03-18 06:17:04 +00:00
getList();
};
2024-03-19 06:29:27 +00:00
const getList = (v?: boolean) => {
if (v) {
if (Math.ceil(pageList.total / pageList.pageSize) > pageList.pageNum) {
2024-03-20 02:43:46 +00:00
pageList.pageNum++;
if (Math.ceil(pageList.total / pageList.pageSize) <= pageList.pageNum) {
pageList.noMoreData = true;
}
2024-03-19 06:29:27 +00:00
} else {
2024-03-20 02:43:46 +00:00
pageList.noMoreData = true;
return;
2024-03-19 06:29:27 +00:00
}
}
2024-03-18 06:17:04 +00:00
let params: any = {
2024-03-19 06:29:27 +00:00
pageSize: pageList.pageSize,
pageNum: pageList.pageNum,
2024-03-18 06:17:04 +00:00
name: state.name,
};
2024-03-28 08:55:03 +00:00
pageList.isLoading = true;
2024-03-18 06:17:04 +00:00
ProfileApi.getUserListByPage(params).then((res) => {
2024-03-28 08:55:03 +00:00
if (res.code === 200) {
pageList.isLoading = false;
(pageList as any).list = (pageList as any).list.concat(
(res.data as any).list
);
pageList.total = (res.data as any).total;
}
2024-03-18 06:17:04 +00:00
});
};
2024-04-25 08:30:50 +00:00
onShow(() => {
resetPageList()
2024-03-18 06:17:04 +00:00
getList();
});
</script>
<style lang="scss" scoped>
.c-card {
margin: 30rpx 25rpx;
.search {
display: flex;
align-items: center;
justify-content: space-between;
.btn {
background: #00dcee;
border-radius: 24rpx;
border: 1px solid #00dcee;
font-weight: 500;
font-size: 26rpx;
color: #ffffff;
margin-left: 50rpx;
padding: 6rpx 30rpx;
}
}
.box {
background: #ffffff;
box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(5, 68, 37, 0.12);
border-radius: 13rpx;
2024-03-21 05:52:15 +00:00
padding: 0rpx 20rpx;
2024-03-18 06:17:04 +00:00
font-weight: 400;
font-size: 26rpx;
color: #000000;
line-height: 41rpx;
margin-top: 30rpx;
> view {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 0rpx;
.op-box {
display: flex;
.btn + .btn {
margin-left: 20rpx;
}
.btn {
background: #ff9d55;
border-radius: 24rpx;
font-weight: 500;
font-size: 26rpx;
color: #ffffff;
padding: 6rpx 30rpx;
}
}
}
> view + view {
border-top: 1px solid rgba(233, 233, 233, 0.76);
}
}
}
</style>