update: 更新用户分页问题

This commit is contained in:
admin 2024-03-20 10:43:46 +08:00
parent ee042a1b33
commit 8faf971040
9 changed files with 235 additions and 66 deletions

View File

@ -3,7 +3,7 @@
:scroll-y="true"
class="scroll-view-custom"
@scrolltolower="loadMore"
:style="{ height: clientHeight + 'px' }"
:style="{ 'max-height': clientHeight + 'px' }"
>
<slot></slot>
<!-- 加载更多提示 -->

View File

@ -344,7 +344,7 @@
{
"path": "supplierType",
"style": {
"navigationBarTitleText": "出货分类"
"navigationBarTitleText": "供应商分类"
}
},
{

View File

@ -162,10 +162,10 @@ const handleSelect = (key: string, v: any) => {
const save = () => {
if (model1.formData.id) {
StockCardApi.updateStockCard(model1.formData).then((res) => {
ProfileApi.updateUserById(model1.formData).then((res) => {
if (res.code === 200) {
uni.redirectTo({
url: "/pagesApp/stockCard", //
url: "/pagesApp/user", //
});
}
});
@ -181,7 +181,7 @@ const save = () => {
};
const getRoleList = () => {
ProfileApi.getRoleList().then((res) => {
ProfileApi.getRoleList({}).then((res) => {
if (res.code === 200) {
contrlModalParams.role.list = (res.data as any).map((item: any) => {
return { ...item, name: item.roleName };

View File

@ -12,23 +12,31 @@
></u-search>
<view class="btn" @click="add"> 新增 </view>
</view>
<view class="box">
<view v-for="(item, index) in pageList.list" :key="index">
<view>
<view>{{ item.roleName }}</view>
</view>
<view class="op-box">
<view class="btn" @click="edit(item)"> 编辑 </view>
<view class="btn" @click="deleteCustomer(item)"> 删除
</view>
<page-view
@loadList="
(v) => {
getList(v);
}
"
:noMoreData="pageList.noMoreData"
>
<view class="box">
<view v-for="(item, index) in pageList.list" :key="index">
<view>
<view>{{ item.roleName }}</view>
</view>
<view class="op-box">
<view class="btn" @click="edit(item)"> 编辑 </view>
<view class="btn" @click="deleteCustomer(item)"> 删除 </view>
</view>
</view>
</view>
</view>
</page-view>
</view>
</template>
<script setup lang="ts">
import { ProfileApi, StockCardApi } from "@/services";
import { StockCardType } from "@/utils/enum";
import PageView from "@/components/PageView/index.vue";
const keyword = ref("");
@ -36,8 +44,9 @@ const state = reactive<any>({
name: "",
});
const pageList: PageResult<{
roleName: string
roleName: string;
}> = reactive({
noMoreData: false,
total: 0,
list: [],
pageNum: 1,
@ -65,14 +74,23 @@ const deleteCustomer = (item: any) => {
const handleSearch = () => {
getList();
};
const getList = () => {
const getList = (v?: boolean) => {
if (v) {
if (Math.ceil(pageList.total / pageList.pageSize) > pageList.pageNum) {
pageList.pageNum++;
} else {
pageList.noMoreData = true;
return;
}
}
let params: any = {
roleName: state.name,
};
ProfileApi.getRoleList(params).then((res) => {
if (res.code === 200) {
if (res.code === 200) {
(pageList as any).list = (res.data as any);
(pageList as any).list = res.data as any;
pageList.total = (res.data as any).total
}
}
});

View File

@ -12,29 +12,40 @@
></u-search>
<view class="btn" @click="add"> 新增 </view>
</view>
<view class="box">
<view v-for="(item, index) in pageList.list" :key="index">
<view>
<view>{{ item.reCategoryName }}</view>
</view>
<view class="op-box">
<view class="btn" @click="edit(item)"> 编辑 </view>
<view class="btn" @click="deleteType(item)"> 删除 </view>
<page-view
@loadList="
(v) => {
getList(v);
}
"
:noMoreData="pageList.noMoreData"
>
<view class="box">
<view v-for="(item, index) in pageList.list" :key="index">
<view>
<view>{{ item.reCategoryName }}</view>
</view>
<view class="op-box">
<view class="btn" @click="edit(item)"> 编辑 </view>
<view class="btn" @click="deleteType(item)"> 删除 </view>
</view>
</view>
</view>
</view>
</page-view>
</view>
</template>
<script setup lang="ts">
import { GoodsApi } from "@/services";
import { StockCardType } from "@/utils/enum";
import PageView from "@/components/PageView/index.vue";
const keyword = ref("");
const state = reactive<any>({
name: "",
});
const pageList: PageResult<{reCategoryName: string}> = reactive({
const pageList: PageResult<{ reCategoryName: string }> = reactive({
noMoreData: false,
total: 0,
list: [],
pageNum: 1,
@ -62,10 +73,22 @@ const deleteType = (item: any) => {
const handleSearch = () => {
getList();
};
const getList = () => {
const getList = (v?: boolean) => {
if (v) {
if (Math.ceil(pageList.total / pageList.pageSize) > pageList.pageNum) {
pageList.pageNum ++
if ( Math.ceil(pageList.total / pageList.pageSize) <= pageList.pageNum) {
pageList.noMoreData = true
}
} else {
pageList.noMoreData = true
return
}
}
let params: any = {
pageSize: 10,
pageNum: 1,
pageSize: pageList.pageSize,
pageNum: pageList.pageNum,
reCategoryName: state.name,
};
if (state.supplierTypeId > -1) {
@ -74,7 +97,8 @@ const getList = () => {
GoodsApi.getPage(params).then((res) => {
if (res.code === 200) {
if (res.code === 200) {
(pageList as any).list = (res.data as any).list;
(pageList as any).list = (pageList as any).list.concat((res.data as any).list);
pageList.total = (res.data as any).total
}
}
});

View File

@ -12,22 +12,31 @@
></u-search>
<view class="btn" @click="add"> 新增 </view>
</view>
<view class="box">
<view v-for="(item, index) in pageList.list" :key="index">
<view>
<view>{{ item.name }}</view>
</view>
<view class="op-box">
<view class="btn" @click="edit(item)"> 编辑 </view>
<view class="btn" @click="deleteType(item)"> 删除 </view>
<page-view
@loadList="
(v) => {
getList(v);
}
"
:noMoreData="pageList.noMoreData"
>
<view class="box">
<view v-for="(item, index) in pageList.list" :key="index">
<view>
<view>{{ item.name }}</view>
</view>
<view class="op-box">
<view class="btn" @click="edit(item)"> 编辑 </view>
<view class="btn" @click="deleteType(item)"> 删除 </view>
</view>
</view>
</view>
</view>
</page-view>
</view>
</template>
<script setup lang="ts">
import { StockCardApi, SupplierApi } from "@/services";
import { StockCardType } from "@/utils/enum";
import PageView from "@/components/PageView/index.vue";
const keyword = ref("");
@ -35,6 +44,7 @@ const state = reactive<any>({
name: "",
});
const pageList: PageResult<StockCard> = reactive({
noMoreData: false,
total: 0,
list: [],
pageNum: 1,
@ -53,19 +63,32 @@ const edit = (item: any) => {
});
};
const deleteType = (item: any) => {
SupplierApi.updateSupplierType({ isDeleted: true, id: item.id }).then((res) => {
if (res.code === 200) {
getList();
SupplierApi.updateSupplierType({ isDeleted: true, id: item.id }).then(
(res) => {
if (res.code === 200) {
getList();
}
}
});
);
};
const handleSearch = () => {
getList();
};
const getList = () => {
const getList = (v?: boolean) => {
if (v) {
if (Math.ceil(pageList.total / pageList.pageSize) > pageList.pageNum) {
pageList.pageNum++;
if ( Math.ceil(pageList.total / pageList.pageSize) <= pageList.pageNum) {
pageList.noMoreData = true
}
} else {
pageList.noMoreData = true;
return;
}
}
let params: any = {
pageSize: 10,
pageNum: 1,
pageSize: pageList.pageSize,
pageNum: pageList.pageNum,
name: state.name,
};
if (state.supplierTypeId > -1) {
@ -75,6 +98,7 @@ const getList = () => {
if (res.code === 200) {
if (res.code === 200) {
(pageList as any).list = (res.data as any).list;
pageList.total = (res.data as any).total;
}
}
});

View File

@ -13,12 +13,19 @@
<view class="btn" @click="add"> 新增 </view>
</view>
<page-view @loadList="(v) => {getList(v)}" :noMoreData="pageList.noMoreData">
<page-view
@loadList="
(v) => {
getList(v);
}
"
:noMoreData="pageList.noMoreData"
>
<view class="box">
<view v-for="(item, index) in pageList.list" :key="index">
<view>
<view>{{ item.name }}</view>
<view>{{ item.phone }}</view>
<view>{{ item.name || item.userName }}</view>
<view>{{ item.phone || "-" }}</view>
<view>{{
item.roleVos.length > 0 ? item.roleVos[0].roleName : "-"
}}</view>
@ -35,6 +42,7 @@
<script setup lang="ts">
import PageView from "@/components/PageView/index.vue";
import { ProfileApi, StockCardApi } from "@/services";
import { pageListInit } from "@/utils";
import { StockCardType } from "@/utils/enum";
const keyword = ref("");
@ -62,22 +70,33 @@ const edit = (item: any) => {
});
};
const deleteCustomer = (item: any) => {
StockCardApi.updateStockCard({ isDeleted: true, id: item.id }).then((res) => {
ProfileApi.updateUserByIdOffline({ id: item.id }).then((res) => {
if (res.code === 200) {
getList();
}
});
};
const resetPageList = () => {
pageList.noMoreData = false;
pageList.total = 0;
pageList.list = [];
pageList.pageNum = 1;
pageList.pageSize = 10;
};
const handleSearch = () => {
resetPageList();
getList();
};
const getList = (v?: boolean) => {
if (v) {
if (Math.ceil(pageList.total / pageList.pageSize) > pageList.pageNum) {
pageList.pageNum ++
pageList.pageNum++;
if (Math.ceil(pageList.total / pageList.pageSize) <= pageList.pageNum) {
pageList.noMoreData = true;
}
} else {
pageList.noMoreData = true
return
pageList.noMoreData = true;
return;
}
}
let params: any = {
@ -88,8 +107,10 @@ const getList = (v?: boolean) => {
ProfileApi.getUserListByPage(params).then((res) => {
if (res.code === 200) {
if (res.code === 200) {
(pageList as any).list = (res.data as any).list;
pageList.total = (res.data as any).total
(pageList as any).list = (pageList as any).list.concat(
(res.data as any).list
);
pageList.total = (res.data as any).total;
}
}
});

View File

@ -216,3 +216,21 @@ export const getInventoryUserPage = (data: any) => {
});
};
// 用户下线
export const updateUserByIdOffline = (data: any) => {
return http<User>({
method: "POST",
url: "/api/user/updateUserByIdOffline",
data
});
};
// 用户编辑
export const updateUserById = (data: any) => {
return http<User>({
method: "POST",
url: "/api/user/updateUserById",
data
});
};

View File

@ -1,7 +1,7 @@
export function formatDate(time: any, cFormat: string) {
const format = cFormat || "{y}-{m}-{d}";
const date = new Date(time);
const formatObj:any = {
const formatObj: any = {
//年
y: date.getFullYear(),
//月
@ -39,8 +39,8 @@ export function getCurrentMonthStartAndEnd() {
let currentMonthEnd = new Date(now.getFullYear(), now.getMonth() + 1, 0);
return {
start: currentMonthStart,
end: currentMonthEnd
start: currentMonthStart,
end: currentMonthEnd,
};
}
@ -50,8 +50,8 @@ export function getCurrentYearStartAndEnd() {
let currentYearEnd = (new Date(now.getFullYear() + 1, 0, 1) as any) - 1; // 下一年的一月一日减一毫秒
return {
start: currentYearStart,
end: currentYearEnd
start: currentYearStart,
end: currentYearEnd,
};
}
@ -62,5 +62,69 @@ export function deleteBaseKey(obj: any) {
delete obj.updateTime;
delete obj.updateUserId;
delete obj.updateUserName;
return obj
return obj;
}
export function moneyFormat(num: number, decimal = 2, split = ",") {
/*
parameter
num
decimal2
split,
moneyFormat(123456789.87654321, 2, ',') // 123,456,789.88
*/
if (isFinite(num)) {
// num是数字
if (num === 0) {
// 为0
return num.toFixed(decimal);
} else {
// 非0
var res = "";
var dotIndex = String(num).indexOf(".");
if (dotIndex === -1) {
// 整数
if (decimal === 0) {
res = String(num).replace(/(\d)(?=(?:\d{3})+$)/g, `$1${split}`);
} else {
res =
String(num).replace(/(\d)(?=(?:\d{3})+$)/g, `$1${split}`) +
"." +
"0".repeat(decimal);
}
} else {
// 非整数
// js四舍五入 Math.round()正数时4舍5入负数时5舍6入
// Math.round(1.5) = 2
// Math.round(-1.5) = -1
// Math.round(-1.6) = -2
// 保留decimals位小数
const numStr = String(
(
Math.round(num * Math.pow(10, decimal)) / Math.pow(10, decimal)
).toFixed(decimal)
); // 四舍五入然后固定保留2位小数
const decimals = numStr.slice(dotIndex, dotIndex + decimal + 1); // 截取小数位
res =
String(numStr.slice(0, dotIndex)).replace(
/(\d)(?=(?:\d{3})+$)/g,
`$1${split}`
) + decimals;
}
return res;
}
} else {
return "--";
}
}
// 分页内容重置
export function pageListInit() {
return {
noMoreData: false,
total: 0,
list: [],
pageNum: 1,
pageSize: 10,
};
}