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

View File

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

View File

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

View File

@ -12,23 +12,31 @@
></u-search> ></u-search>
<view class="btn" @click="add"> 新增 </view> <view class="btn" @click="add"> 新增 </view>
</view> </view>
<view class="box"> <page-view
<view v-for="(item, index) in pageList.list" :key="index"> @loadList="
<view> (v) => {
<view>{{ item.roleName }}</view> getList(v);
</view> }
<view class="op-box"> "
<view class="btn" @click="edit(item)"> 编辑 </view> :noMoreData="pageList.noMoreData"
<view class="btn" @click="deleteCustomer(item)"> 删除 >
</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>
</view>
</view> </view>
</view> </view>
</view> </page-view>
</view> </view>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ProfileApi, StockCardApi } from "@/services"; import { ProfileApi, StockCardApi } from "@/services";
import { StockCardType } from "@/utils/enum"; import PageView from "@/components/PageView/index.vue";
const keyword = ref(""); const keyword = ref("");
@ -36,8 +44,9 @@ const state = reactive<any>({
name: "", name: "",
}); });
const pageList: PageResult<{ const pageList: PageResult<{
roleName: string roleName: string;
}> = reactive({ }> = reactive({
noMoreData: false,
total: 0, total: 0,
list: [], list: [],
pageNum: 1, pageNum: 1,
@ -65,14 +74,23 @@ const deleteCustomer = (item: any) => {
const handleSearch = () => { const handleSearch = () => {
getList(); 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 = { let params: any = {
roleName: state.name, roleName: state.name,
}; };
ProfileApi.getRoleList(params).then((res) => { ProfileApi.getRoleList(params).then((res) => {
if (res.code === 200) { if (res.code === 200) {
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> ></u-search>
<view class="btn" @click="add"> 新增 </view> <view class="btn" @click="add"> 新增 </view>
</view> </view>
<view class="box"> <page-view
<view v-for="(item, index) in pageList.list" :key="index"> @loadList="
<view> (v) => {
<view>{{ item.reCategoryName }}</view> getList(v);
</view> }
<view class="op-box"> "
<view class="btn" @click="edit(item)"> 编辑 </view> :noMoreData="pageList.noMoreData"
<view class="btn" @click="deleteType(item)"> 删除 </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>
</view>
</view> </view>
</view> </view>
</view> </page-view>
</view> </view>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { GoodsApi } from "@/services"; import { GoodsApi } from "@/services";
import { StockCardType } from "@/utils/enum"; import PageView from "@/components/PageView/index.vue";
const keyword = ref(""); const keyword = ref("");
const state = reactive<any>({ const state = reactive<any>({
name: "", name: "",
}); });
const pageList: PageResult<{reCategoryName: string}> = reactive({ const pageList: PageResult<{ reCategoryName: string }> = reactive({
noMoreData: false,
total: 0, total: 0,
list: [], list: [],
pageNum: 1, pageNum: 1,
@ -62,10 +73,22 @@ const deleteType = (item: any) => {
const handleSearch = () => { const handleSearch = () => {
getList(); 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 = { let params: any = {
pageSize: 10, pageSize: pageList.pageSize,
pageNum: 1, pageNum: pageList.pageNum,
reCategoryName: state.name, reCategoryName: state.name,
}; };
if (state.supplierTypeId > -1) { if (state.supplierTypeId > -1) {
@ -74,7 +97,8 @@ const getList = () => {
GoodsApi.getPage(params).then((res) => { GoodsApi.getPage(params).then((res) => {
if (res.code === 200) { if (res.code === 200) {
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> ></u-search>
<view class="btn" @click="add"> 新增 </view> <view class="btn" @click="add"> 新增 </view>
</view> </view>
<view class="box"> <page-view
<view v-for="(item, index) in pageList.list" :key="index"> @loadList="
<view> (v) => {
<view>{{ item.name }}</view> getList(v);
</view> }
<view class="op-box"> "
<view class="btn" @click="edit(item)"> 编辑 </view> :noMoreData="pageList.noMoreData"
<view class="btn" @click="deleteType(item)"> 删除 </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>
</view>
</view> </view>
</view> </view>
</view> </page-view>
</view> </view>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { StockCardApi, SupplierApi } from "@/services"; import { StockCardApi, SupplierApi } from "@/services";
import { StockCardType } from "@/utils/enum"; import PageView from "@/components/PageView/index.vue";
const keyword = ref(""); const keyword = ref("");
@ -35,6 +44,7 @@ const state = reactive<any>({
name: "", name: "",
}); });
const pageList: PageResult<StockCard> = reactive({ const pageList: PageResult<StockCard> = reactive({
noMoreData: false,
total: 0, total: 0,
list: [], list: [],
pageNum: 1, pageNum: 1,
@ -53,19 +63,32 @@ const edit = (item: any) => {
}); });
}; };
const deleteType = (item: any) => { const deleteType = (item: any) => {
SupplierApi.updateSupplierType({ isDeleted: true, id: item.id }).then((res) => { SupplierApi.updateSupplierType({ isDeleted: true, id: item.id }).then(
if (res.code === 200) { (res) => {
getList(); if (res.code === 200) {
getList();
}
} }
}); );
}; };
const handleSearch = () => { const handleSearch = () => {
getList(); 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 = { let params: any = {
pageSize: 10, pageSize: pageList.pageSize,
pageNum: 1, pageNum: pageList.pageNum,
name: state.name, name: state.name,
}; };
if (state.supplierTypeId > -1) { if (state.supplierTypeId > -1) {
@ -75,6 +98,7 @@ const getList = () => {
if (res.code === 200) { if (res.code === 200) {
if (res.code === 200) { if (res.code === 200) {
(pageList as any).list = (res.data as any).list; (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 class="btn" @click="add"> 新增 </view>
</view> </view>
<page-view @loadList="(v) => {getList(v)}" :noMoreData="pageList.noMoreData"> <page-view
@loadList="
(v) => {
getList(v);
}
"
:noMoreData="pageList.noMoreData"
>
<view class="box"> <view class="box">
<view v-for="(item, index) in pageList.list" :key="index"> <view v-for="(item, index) in pageList.list" :key="index">
<view> <view>
<view>{{ item.name }}</view> <view>{{ item.name || item.userName }}</view>
<view>{{ item.phone }}</view> <view>{{ item.phone || "-" }}</view>
<view>{{ <view>{{
item.roleVos.length > 0 ? item.roleVos[0].roleName : "-" item.roleVos.length > 0 ? item.roleVos[0].roleName : "-"
}}</view> }}</view>
@ -35,6 +42,7 @@
<script setup lang="ts"> <script setup lang="ts">
import PageView from "@/components/PageView/index.vue"; import PageView from "@/components/PageView/index.vue";
import { ProfileApi, StockCardApi } from "@/services"; import { ProfileApi, StockCardApi } from "@/services";
import { pageListInit } from "@/utils";
import { StockCardType } from "@/utils/enum"; import { StockCardType } from "@/utils/enum";
const keyword = ref(""); const keyword = ref("");
@ -62,22 +70,33 @@ const edit = (item: any) => {
}); });
}; };
const deleteCustomer = (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) { if (res.code === 200) {
getList(); getList();
} }
}); });
}; };
const resetPageList = () => {
pageList.noMoreData = false;
pageList.total = 0;
pageList.list = [];
pageList.pageNum = 1;
pageList.pageSize = 10;
};
const handleSearch = () => { const handleSearch = () => {
resetPageList();
getList(); getList();
}; };
const getList = (v?: boolean) => { const getList = (v?: boolean) => {
if (v) { if (v) {
if (Math.ceil(pageList.total / pageList.pageSize) > pageList.pageNum) { 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 { } else {
pageList.noMoreData = true pageList.noMoreData = true;
return return;
} }
} }
let params: any = { let params: any = {
@ -88,8 +107,10 @@ const getList = (v?: boolean) => {
ProfileApi.getUserListByPage(params).then((res) => { ProfileApi.getUserListByPage(params).then((res) => {
if (res.code === 200) { if (res.code === 200) {
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(
pageList.total = (res.data as any).total (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) { export function formatDate(time: any, cFormat: string) {
const format = cFormat || "{y}-{m}-{d}"; const format = cFormat || "{y}-{m}-{d}";
const date = new Date(time); const date = new Date(time);
const formatObj:any = { const formatObj: any = {
//年 //年
y: date.getFullYear(), y: date.getFullYear(),
//月 //月
@ -39,8 +39,8 @@ export function getCurrentMonthStartAndEnd() {
let currentMonthEnd = new Date(now.getFullYear(), now.getMonth() + 1, 0); let currentMonthEnd = new Date(now.getFullYear(), now.getMonth() + 1, 0);
return { return {
start: currentMonthStart, start: currentMonthStart,
end: currentMonthEnd end: currentMonthEnd,
}; };
} }
@ -50,8 +50,8 @@ export function getCurrentYearStartAndEnd() {
let currentYearEnd = (new Date(now.getFullYear() + 1, 0, 1) as any) - 1; // 下一年的一月一日减一毫秒 let currentYearEnd = (new Date(now.getFullYear() + 1, 0, 1) as any) - 1; // 下一年的一月一日减一毫秒
return { return {
start: currentYearStart, start: currentYearStart,
end: currentYearEnd end: currentYearEnd,
}; };
} }
@ -62,5 +62,69 @@ export function deleteBaseKey(obj: any) {
delete obj.updateTime; delete obj.updateTime;
delete obj.updateUserId; delete obj.updateUserId;
delete obj.updateUserName; 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,
};
} }