更新 pages/deal/saleOrder/kanban/saleOrderKanban.js
This commit is contained in:
parent
d6bbef06ba
commit
33e0afd799
@ -1,119 +1,142 @@
|
|||||||
|
// 从 '../../../ulti/jsonrpc' 路径导入 jsonrpcFunc 函数
|
||||||
import jsonrpcFunc from '../../../ulti/jsonrpc'
|
import jsonrpcFunc from '../../../ulti/jsonrpc'
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
|
// 页面的数据对象,存储页面中需要使用的各种数据
|
||||||
data: {
|
data: {
|
||||||
loginInfo: '', //权限验证信息
|
loginInfo: '', // 权限验证信息,用于后续的接口调用身份验证
|
||||||
combinedOrders: [], //销售数据汇总
|
combinedOrders: [], // 销售数据汇总,存储销售订单及其相关的订单行数据
|
||||||
currentPage: 1, //当前第几页
|
currentPage: 1, // 当前显示的页码,初始为第一页
|
||||||
pageSize: 10, //一页多少数据
|
pageSize: 10, // 每页显示的数据数量,即每页显示 10 条记录
|
||||||
totalRecords: 0, //整个模型目前有多少条记录
|
totalRecords: 0, // 整个模型目前的记录总数,用于分页计算
|
||||||
orderlineIDs: [], //销售订单行数据
|
orderlineIDs: [], // 销售订单行数据的 ID 集合,方便后续获取订单行详细信息
|
||||||
isloading: 50 //加载进度条百分比
|
isloading: 50 // 加载进度条的百分比,初始为 50%
|
||||||
},
|
},
|
||||||
|
// 页面加载时触发的生命周期函数
|
||||||
onLoad(query) {
|
onLoad(query) {
|
||||||
// 页面加载
|
// 页面加载
|
||||||
|
// 从本地存储中同步获取登录信息
|
||||||
const loginInfo = dd.getStorageSync({
|
const loginInfo = dd.getStorageSync({
|
||||||
key: 'loginInfo'
|
key: 'loginInfo'
|
||||||
}).data;
|
}).data;
|
||||||
|
// 检查登录信息是否完整
|
||||||
if (loginInfo && loginInfo.apiurl && loginInfo.databaseName && loginInfo.username && loginInfo.password && loginInfo.uid > 0) {
|
if (loginInfo && loginInfo.apiurl && loginInfo.databaseName && loginInfo.username && loginInfo.password && loginInfo.uid > 0) {
|
||||||
|
// 如果登录信息完整,将其设置到页面数据中
|
||||||
this.setData({
|
this.setData({
|
||||||
loginInfo
|
loginInfo
|
||||||
});
|
});
|
||||||
// console.log('销售页得到的本地信息', loginInfo);
|
// console.log('销售页得到的本地信息', loginInfo);
|
||||||
//执行获取销售订单第一页数据分页第一页默认
|
// 执行获取销售订单第一页数据的操作,默认显示第一页
|
||||||
this.fetchData(1);
|
this.fetchData(1);
|
||||||
} else {
|
} else {
|
||||||
|
// 如果本地缓存中未获取到完整的登录信息,可进行相应提示
|
||||||
// console.log('本地缓存中未获取到登录信息');
|
// console.log('本地缓存中未获取到登录信息');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 页面初次渲染完成时触发的生命周期函数
|
||||||
onReady() {
|
onReady() {
|
||||||
// 页面加载完成
|
// 页面加载完成
|
||||||
},
|
},
|
||||||
|
// 页面显示时触发的生命周期函数
|
||||||
onShow() {
|
onShow() {
|
||||||
// 页面显示
|
// 页面显示
|
||||||
},
|
},
|
||||||
|
// 页面隐藏时触发的生命周期函数
|
||||||
onHide() {
|
onHide() {
|
||||||
// 页面隐藏
|
// 页面隐藏
|
||||||
},
|
},
|
||||||
|
// 页面卸载时触发的生命周期函数
|
||||||
onUnload() {
|
onUnload() {
|
||||||
// 页面被关闭
|
// 页面被关闭
|
||||||
},
|
},
|
||||||
|
// 标题被点击时触发的事件处理函数
|
||||||
onTitleClick() {
|
onTitleClick() {
|
||||||
// 标题被点击
|
// 标题被点击
|
||||||
},
|
},
|
||||||
|
// 页面被下拉刷新时触发的事件处理函数
|
||||||
onPullDownRefresh() {
|
onPullDownRefresh() {
|
||||||
// 页面被下拉
|
// 页面被下拉
|
||||||
},
|
},
|
||||||
|
// 页面被拉到底部时触发的事件处理函数
|
||||||
onReachBottom() {
|
onReachBottom() {
|
||||||
// 页面被拉到底部
|
// 页面被拉到底部
|
||||||
},
|
},
|
||||||
|
// 用户点击右上角分享时触发的事件处理函数,返回自定义分享信息
|
||||||
onShareAppMessage() {
|
onShareAppMessage() {
|
||||||
// 返回自定义分享信息
|
// 返回自定义分享信息
|
||||||
return {
|
return {
|
||||||
title: 'My App',
|
title: 'My App', // 分享的标题
|
||||||
desc: 'My App description',
|
desc: 'My App description', // 分享的描述
|
||||||
path: 'pages/index/index',
|
path: 'pages/index/index', // 分享的页面路径
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
// 获取销售订单数据的函数,支持分页获取
|
||||||
fetchData(page) {
|
fetchData(page) {
|
||||||
|
// 从页面数据中解构出登录信息和每页数据数量
|
||||||
const {
|
const {
|
||||||
loginInfo,
|
loginInfo,
|
||||||
pageSize
|
pageSize
|
||||||
} = this.data;
|
} = this.data;
|
||||||
|
// 计算当前页数据的偏移量
|
||||||
const offset = (page - 1) * pageSize;
|
const offset = (page - 1) * pageSize;
|
||||||
// 调用 search_count 方法获取总记录数
|
// 调用 search_count 方法获取销售订单的总记录数
|
||||||
const saleOrderCountData = {
|
const saleOrderCountData = {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0", // JSON-RPC 协议版本
|
||||||
"method": "call",
|
"method": "call", // 调用方法
|
||||||
"id": 2,
|
"id": 2, // 请求的唯一标识
|
||||||
"params": {
|
"params": {
|
||||||
"service": "object",
|
"service": "object", // 服务类型
|
||||||
"method": "execute_kw",
|
"method": "execute_kw", // 执行的方法
|
||||||
"args": [
|
"args": [
|
||||||
loginInfo.databaseName,
|
loginInfo.databaseName, // 数据库名称
|
||||||
loginInfo.uid,
|
loginInfo.uid, // 用户 ID
|
||||||
loginInfo.password,
|
loginInfo.password, // 用户密码
|
||||||
'sale.order',
|
'sale.order', // 操作的模型名称
|
||||||
"search_count",
|
"search_count", // 执行的具体操作,获取记录总数
|
||||||
[
|
[
|
||||||
[]
|
[]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// 调用 jsonrpcFunc 函数发送请求获取总记录数
|
||||||
jsonrpcFunc(loginInfo, saleOrderCountData)
|
jsonrpcFunc(loginInfo, saleOrderCountData)
|
||||||
.then((count) => {
|
.then((count) => {
|
||||||
|
// 将获取到的总记录数设置到页面数据中
|
||||||
this.setData({
|
this.setData({
|
||||||
totalRecords: count
|
totalRecords: count
|
||||||
});
|
});
|
||||||
// console.log('销售订单总记录数:', count);
|
// console.log('销售订单总记录数:', count);
|
||||||
|
|
||||||
|
// 构建获取销售订单数据的请求参数
|
||||||
const saleOrderData = {
|
const saleOrderData = {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0", // JSON-RPC 协议版本
|
||||||
"method": "call",
|
"method": "call", // 调用方法
|
||||||
"id": 2,
|
"id": 2, // 请求的唯一标识
|
||||||
"params": {
|
"params": {
|
||||||
"service": "object",
|
"service": "object", // 服务类型
|
||||||
"method": "execute_kw",
|
"method": "execute_kw", // 执行的方法
|
||||||
"args": [
|
"args": [
|
||||||
loginInfo.databaseName,
|
loginInfo.databaseName, // 数据库名称
|
||||||
loginInfo.uid,
|
loginInfo.uid, // 用户 ID
|
||||||
loginInfo.password,
|
loginInfo.password, // 用户密码
|
||||||
'sale.order',
|
'sale.order', // 操作的模型名称
|
||||||
"search_read",
|
"search_read", // 执行的具体操作,搜索并读取记录
|
||||||
[],
|
[],
|
||||||
{
|
{
|
||||||
fields: [],
|
fields: [], // 需要获取的字段
|
||||||
"limit": pageSize,
|
"limit": pageSize, // 每页显示的记录数
|
||||||
"offset": offset,
|
"offset": offset, // 数据偏移量
|
||||||
"order": "id DESC"
|
"order": "id DESC" // 按 ID 降序排序
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// 调用 jsonrpcFunc 函数发送请求获取销售订单数据
|
||||||
return jsonrpcFunc(loginInfo, saleOrderData);
|
return jsonrpcFunc(loginInfo, saleOrderData);
|
||||||
})
|
})
|
||||||
.then((salesOrderData) => {
|
.then((salesOrderData) => {
|
||||||
|
// 将获取到的销售订单数据进行处理,为每个订单添加一个空的 orderLines 数组
|
||||||
this.setData({
|
this.setData({
|
||||||
combinedOrders: salesOrderData.map(order => ({
|
combinedOrders: salesOrderData.map(order => ({
|
||||||
...order,
|
...order,
|
||||||
@ -121,7 +144,9 @@ Page({
|
|||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
// console.log('销售订单数据:', salesOrderData);
|
// console.log('销售订单数据:', salesOrderData);
|
||||||
|
// 初始化一个空数组,用于存储销售订单行的 ID
|
||||||
const orderlineIDs = [];
|
const orderlineIDs = [];
|
||||||
|
// 遍历销售订单数据,提取订单行的 ID
|
||||||
salesOrderData.forEach(order => {
|
salesOrderData.forEach(order => {
|
||||||
if (order.order_line && Array.isArray(order.order_line)) {
|
if (order.order_line && Array.isArray(order.order_line)) {
|
||||||
order.order_line.forEach(id => {
|
order.order_line.forEach(id => {
|
||||||
@ -131,42 +156,48 @@ Page({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 将提取到的订单行 ID 集合设置到页面数据中
|
||||||
this.setData({
|
this.setData({
|
||||||
orderlineIDs
|
orderlineIDs
|
||||||
});
|
});
|
||||||
// console.log('获取到的销售订单行 ID:', orderlineIDs);
|
// console.log('获取到的销售订单行 ID:', orderlineIDs);
|
||||||
|
// 如果订单行 ID 集合不为空,继续获取订单行详细信息
|
||||||
if (orderlineIDs.length > 0) {
|
if (orderlineIDs.length > 0) {
|
||||||
const domain = orderlineIDs;
|
const domain = orderlineIDs;
|
||||||
|
// 构建获取销售订单行数据的请求参数
|
||||||
const saleOrderLineData = {
|
const saleOrderLineData = {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0", // JSON-RPC 协议版本
|
||||||
"method": "call",
|
"method": "call", // 调用方法
|
||||||
"id": 2,
|
"id": 2, // 请求的唯一标识
|
||||||
"params": {
|
"params": {
|
||||||
"service": "object",
|
"service": "object", // 服务类型
|
||||||
"method": "execute_kw",
|
"method": "execute_kw", // 执行的方法
|
||||||
"args": [
|
"args": [
|
||||||
loginInfo.databaseName,
|
loginInfo.databaseName, // 数据库名称
|
||||||
loginInfo.uid,
|
loginInfo.uid, // 用户 ID
|
||||||
loginInfo.password,
|
loginInfo.password, // 用户密码
|
||||||
'sale.order.line',
|
'sale.order.line', // 操作的模型名称
|
||||||
"read",
|
"read", // 执行的具体操作,读取记录
|
||||||
[domain],
|
[domain], // 要读取的记录 ID 集合
|
||||||
{
|
{
|
||||||
fields: [],
|
fields: [], // 需要获取的字段
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// console.log('saleOrderLineData ', saleOrderLineData);
|
// console.log('saleOrderLineData ', saleOrderLineData);
|
||||||
|
// 调用 jsonrpcFunc 函数发送请求获取销售订单行数据
|
||||||
return jsonrpcFunc(loginInfo, saleOrderLineData);
|
return jsonrpcFunc(loginInfo, saleOrderLineData);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
.then((salesOrderLineData) => {
|
.then((salesOrderLineData) => {
|
||||||
if (salesOrderLineData) {
|
if (salesOrderLineData) {
|
||||||
|
// 从页面数据中获取合并后的订单数据
|
||||||
const {
|
const {
|
||||||
combinedOrders
|
combinedOrders
|
||||||
} = this.data;
|
} = this.data;
|
||||||
|
// 遍历销售订单行数据,将其关联到对应的订单中
|
||||||
salesOrderLineData.forEach(orderLine => {
|
salesOrderLineData.forEach(orderLine => {
|
||||||
const orderId = orderLine.order_id && orderLine.order_id[0];
|
const orderId = orderLine.order_id && orderLine.order_id[0];
|
||||||
const targetOrder = combinedOrders.find(order => order.id === orderId);
|
const targetOrder = combinedOrders.find(order => order.id === orderId);
|
||||||
@ -174,6 +205,7 @@ Page({
|
|||||||
targetOrder.orderLines.push(orderLine);
|
targetOrder.orderLines.push(orderLine);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 将更新后的合并订单数据设置到页面数据中
|
||||||
this.setData({
|
this.setData({
|
||||||
combinedOrders
|
combinedOrders
|
||||||
});
|
});
|
||||||
@ -194,28 +226,30 @@ Page({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 如果 fineCode_3 的 ID 集合不为空,继续获取其详细信息
|
||||||
if (fineCode3Ids.length > 0) {
|
if (fineCode3Ids.length > 0) {
|
||||||
const fineCode3Data = {
|
const fineCode3Data = {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0", // JSON-RPC 协议版本
|
||||||
"method": "call",
|
"method": "call", // 调用方法
|
||||||
"id": 2,
|
"id": 2, // 请求的唯一标识
|
||||||
"params": {
|
"params": {
|
||||||
"service": "object",
|
"service": "object", // 服务类型
|
||||||
"method": "execute_kw",
|
"method": "execute_kw", // 执行的方法
|
||||||
"args": [
|
"args": [
|
||||||
loginInfo.databaseName,
|
loginInfo.databaseName, // 数据库名称
|
||||||
loginInfo.uid,
|
loginInfo.uid, // 用户 ID
|
||||||
loginInfo.password,
|
loginInfo.password, // 用户密码
|
||||||
// 这里需要替换为 fineCode_3 关联的模型名称
|
// 这里需要替换为 fineCode_3 关联的模型名称
|
||||||
'finecode_xima_l',
|
'finecode_xima_l',
|
||||||
"read",
|
"read", // 执行的具体操作,读取记录
|
||||||
[fineCode3Ids],
|
[fineCode3Ids], // 要读取的记录 ID 集合
|
||||||
{
|
{
|
||||||
fields: ['name']
|
fields: ['name'] // 需要获取的字段,只获取名称字段
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// 调用 jsonrpcFunc 函数发送请求获取 fineCode_3 的详细信息
|
||||||
return jsonrpcFunc(loginInfo, fineCode3Data);
|
return jsonrpcFunc(loginInfo, fineCode3Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,13 +257,16 @@ Page({
|
|||||||
})
|
})
|
||||||
.then((fineCode3Data) => {
|
.then((fineCode3Data) => {
|
||||||
if (fineCode3Data) {
|
if (fineCode3Data) {
|
||||||
|
// 从页面数据中获取合并后的订单数据
|
||||||
const {
|
const {
|
||||||
combinedOrders
|
combinedOrders
|
||||||
} = this.data;
|
} = this.data;
|
||||||
|
// 构建一个映射对象,用于存储 fineCode_3 的 ID 和名称的映射关系
|
||||||
const fineCode3NameMap = {};
|
const fineCode3NameMap = {};
|
||||||
fineCode3Data.forEach(item => {
|
fineCode3Data.forEach(item => {
|
||||||
fineCode3NameMap[item.id] = item.name;
|
fineCode3NameMap[item.id] = item.name;
|
||||||
});
|
});
|
||||||
|
// 遍历合并后的订单数据,为每个订单行的 fineCode_3 添加对应的名称
|
||||||
combinedOrders.forEach(order => {
|
combinedOrders.forEach(order => {
|
||||||
order.orderLines.forEach(orderLine => {
|
order.orderLines.forEach(orderLine => {
|
||||||
if (orderLine.fineCode_3 && Array.isArray(orderLine.fineCode_3)) {
|
if (orderLine.fineCode_3 && Array.isArray(orderLine.fineCode_3)) {
|
||||||
@ -237,6 +274,7 @@ Page({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// 将更新后的合并订单数据设置到页面数据中,并将加载进度条设置为 100%
|
||||||
this.setData({
|
this.setData({
|
||||||
combinedOrders,
|
combinedOrders,
|
||||||
isloading: 100
|
isloading: 100
|
||||||
@ -245,58 +283,72 @@ Page({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
// 捕获请求过程中可能出现的错误,并打印错误信息
|
||||||
console.error('请求数据时出错:', error);
|
console.error('请求数据时出错:', error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
//下一页逻辑
|
// 处理下一页的逻辑
|
||||||
handleNextPage() {
|
handleNextPage() {
|
||||||
|
// 从页面数据中解构出当前页码、总记录数和每页数据数量
|
||||||
const {
|
const {
|
||||||
currentPage,
|
currentPage,
|
||||||
totalRecords,
|
totalRecords,
|
||||||
pageSize
|
pageSize
|
||||||
} = this.data;
|
} = this.data;
|
||||||
|
// 计算总页数
|
||||||
const totalPages = Math.ceil(totalRecords / pageSize);
|
const totalPages = Math.ceil(totalRecords / pageSize);
|
||||||
|
// 如果当前页码小于总页数,说明还有下一页
|
||||||
if (currentPage < totalPages) {
|
if (currentPage < totalPages) {
|
||||||
|
// 将当前页码加 1,并更新到页面数据中
|
||||||
this.setData({
|
this.setData({
|
||||||
currentPage: currentPage + 1
|
currentPage: currentPage + 1
|
||||||
});
|
});
|
||||||
|
// 调用 fetchData 函数获取下一页的数据
|
||||||
this.fetchData(currentPage + 1);
|
this.fetchData(currentPage + 1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//
|
// 处理上一页的逻辑
|
||||||
//上一页逻辑
|
|
||||||
handlePreviousPage() {
|
handlePreviousPage() {
|
||||||
|
// 从页面数据中解构出当前页码
|
||||||
const {
|
const {
|
||||||
currentPage
|
currentPage
|
||||||
} = this.data;
|
} = this.data;
|
||||||
|
// 如果当前页码大于 1,说明还有上一页
|
||||||
if (currentPage > 1) {
|
if (currentPage > 1) {
|
||||||
|
// 将当前页码减 1,并更新到页面数据中
|
||||||
this.setData({
|
this.setData({
|
||||||
currentPage: currentPage - 1
|
currentPage: currentPage - 1
|
||||||
});
|
});
|
||||||
|
// 调用 fetchData 函数获取上一页的数据
|
||||||
this.fetchData(currentPage - 1);
|
this.fetchData(currentPage - 1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//
|
// 点击卡片时触发的事件处理函数,用于保存选中的订单数据并跳转到相应页面
|
||||||
//点击卡片触发这条记录保存
|
|
||||||
handleTap(e) {
|
handleTap(e) {
|
||||||
|
// 获取点击卡片的订单 ID
|
||||||
const orderId = e.currentTarget.dataset.info;
|
const orderId = e.currentTarget.dataset.info;
|
||||||
|
// 从页面数据中获取合并后的订单数据
|
||||||
const {
|
const {
|
||||||
combinedOrders
|
combinedOrders
|
||||||
} = this.data;
|
} = this.data;
|
||||||
|
// 查找选中的订单
|
||||||
const selectedOrder = combinedOrders.find(order => order.id === orderId);
|
const selectedOrder = combinedOrders.find(order => order.id === orderId);
|
||||||
if (selectedOrder) {
|
if (selectedOrder) {
|
||||||
|
// 定义存储数据的键名
|
||||||
const objectKey = `saleOrderlines`;
|
const objectKey = `saleOrderlines`;
|
||||||
// const objectKey = `order_${orderId}`;
|
// const objectKey = `order_${orderId}`;
|
||||||
|
// 将选中的订单数据存储到本地存储中
|
||||||
dd.setStorage({
|
dd.setStorage({
|
||||||
key: objectKey,
|
key: objectKey,
|
||||||
data: selectedOrder,
|
data: selectedOrder,
|
||||||
success: function () {
|
success: function () {
|
||||||
|
// 存储成功后,跳转到指定页面
|
||||||
dd.navigateTo({
|
dd.navigateTo({
|
||||||
url: `/pages/deal/saleOrder/kanban/from/saleOrderFrom?objectKey=${objectKey}`
|
url: `/pages/deal/saleOrder/kanban/from/saleOrderFrom?objectKey=${objectKey}`
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fail: function (err) {
|
fail: function (err) {
|
||||||
|
// 存储失败时,打印错误信息
|
||||||
console.error('存储数据到本地存储失败:', err);
|
console.error('存储数据到本地存储失败:', err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user