|
@@ -20,6 +20,7 @@ Page({
|
|
|
type: 4,
|
|
|
}
|
|
|
],
|
|
|
+ searchText: '', // 搜索关键词
|
|
|
orders: [],
|
|
|
souimg: '',
|
|
|
pageNumber: 1,
|
|
@@ -66,87 +67,132 @@ Page({
|
|
|
this.getdatalist(true);
|
|
|
},
|
|
|
|
|
|
+ // 模糊搜索
|
|
|
+ onSearchInput(e) {
|
|
|
+ const value = e.detail.value.trim();
|
|
|
+ this.setData({
|
|
|
+ searchText: value,
|
|
|
+ pageNumber: 1,
|
|
|
+ hasMore: true,
|
|
|
+ orders: []
|
|
|
+ }, () => {
|
|
|
+ this.getdatalist();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
async getdatalist(isLoadMore = false) {
|
|
|
if (this.data.isLoading || !this.data.hasMore) return;
|
|
|
|
|
|
this.setData({ isLoading: true });
|
|
|
- const { pageNumber, pageSize } = this.data;
|
|
|
- try {
|
|
|
- // 根据 categoriesindex 的值动态设置 filter
|
|
|
- const filter = {};
|
|
|
- if (this.data.categoriesindex !== 1) {
|
|
|
- filter.where = {
|
|
|
- status: this.data.categoriesindex - 2, // 减去 2
|
|
|
- };
|
|
|
- }
|
|
|
+
|
|
|
+ const { pageNumber, pageSize, categoriesindex, searchText, orders } = this.data;
|
|
|
+
|
|
|
+ let dbRegExp = null;
|
|
|
+ let jsRegExp = null;
|
|
|
+
|
|
|
+ if (searchText) {
|
|
|
+ dbRegExp = db.RegExp({
|
|
|
+ regexp: searchText,
|
|
|
+ options: 'i'
|
|
|
+ });
|
|
|
+ jsRegExp = new RegExp(searchText, 'i');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构造订单表的筛选条件
|
|
|
+ // 获取本地存储的用户信息
|
|
|
+ const userInfo = wx.getStorageSync('userInfo');
|
|
|
+ const userId = userInfo && userInfo._id ? userInfo._id : ''; // 根据你的userInfo结构取ID
|
|
|
+ const schoolId = userInfo && userInfo.school_id ? userInfo.school_id : ''; // 根据你的userInfo结构取ID
|
|
|
|
|
|
+ let orderWhere = {
|
|
|
+ user_id: userId, // 每次必传
|
|
|
+ school_id: schoolId
|
|
|
+ };
|
|
|
+ if (categoriesindex !== 1) {
|
|
|
+ orderWhere.status = categoriesindex - 2;
|
|
|
+ }
|
|
|
+ if (dbRegExp) {
|
|
|
+ orderWhere = _.and([
|
|
|
+ orderWhere,
|
|
|
+ { order_id: dbRegExp }
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 第一步:查订单表
|
|
|
const { data } = await models.orders.list({
|
|
|
- filter, // 动态传递 filter
|
|
|
+ filter: { where: orderWhere },
|
|
|
pageSize,
|
|
|
pageNumber,
|
|
|
- getCount: true, // 开启用来获取总数
|
|
|
- envType: 'prod', // 正式环境
|
|
|
+ getCount: true,
|
|
|
+ envType: 'prod'
|
|
|
});
|
|
|
-
|
|
|
- // 返回查询到的数据列表 records 和 总数 total
|
|
|
- const collectList = data.records || [];
|
|
|
- if (collectList.length === 0) {
|
|
|
+
|
|
|
+ const orderList = data.records || [];
|
|
|
+ if (orderList.length === 0) {
|
|
|
this.setData({ hasMore: false, isLoading: false });
|
|
|
return;
|
|
|
}
|
|
|
- console.log(collectList, 'collectList');
|
|
|
-
|
|
|
- const fileManagerIds = collectList.map(item => item.merchandise_id);
|
|
|
-
|
|
|
- console.log(fileManagerIds, 'fileManagerIds');
|
|
|
- // 第二步:循环获取每个文件数据(单条查询)
|
|
|
+
|
|
|
+ // 第二步:查商品表
|
|
|
+ const fileManagerIds = orderList.map(item => item.merchandise_id);
|
|
|
+
|
|
|
const fileDetailPromises = fileManagerIds.map(id => {
|
|
|
return models.wx_merchandise.list({
|
|
|
- filter: {
|
|
|
- where: {
|
|
|
- _id: id
|
|
|
- }
|
|
|
- },
|
|
|
- envType: "prod"
|
|
|
- }).then(res => {
|
|
|
- const record = res.data?.records?.[0];
|
|
|
- if (!record) {
|
|
|
- console.warn(`未找到 _id 为 ${id} 的文件`);
|
|
|
- }
|
|
|
- return record || null;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.error(`获取文件 ${id} 失败`, err);
|
|
|
- return null;
|
|
|
- });
|
|
|
+ filter: { where: { _id: id } },
|
|
|
+ envType: 'prod'
|
|
|
+ }).then(res => res.data?.records?.[0] || null)
|
|
|
+ .catch(err => {
|
|
|
+ console.error(`商品获取失败: ${id}`, err);
|
|
|
+ return null;
|
|
|
+ });
|
|
|
});
|
|
|
-
|
|
|
- // 第三步:等待所有请求完成
|
|
|
+
|
|
|
const fileDetails = await Promise.all(fileDetailPromises);
|
|
|
- console.log(fileDetails, 'fileDetails');
|
|
|
-
|
|
|
- // 第四步:过滤无效项,并添加 checked 字段
|
|
|
- const newFiles = fileDetails
|
|
|
- .filter(Boolean) // 去掉 null 或 undefined
|
|
|
- .map((file, index) => {
|
|
|
- const historyRecord = collectList[index]; // 获取原 download_history 的记录
|
|
|
- if (!file) return null;
|
|
|
- return {
|
|
|
- ...file,
|
|
|
- ...historyRecord
|
|
|
+
|
|
|
+ // 第三步:合并数据,并进行模糊搜索筛选(匹配一个就保留)
|
|
|
+ const mergedOrders = [];
|
|
|
+
|
|
|
+ for (let i = 0; i < orderList.length; i++) {
|
|
|
+ const order = orderList[i];
|
|
|
+ const merch = fileDetails[i];
|
|
|
+
|
|
|
+ if (!merch) continue;
|
|
|
+
|
|
|
+ if (jsRegExp) {
|
|
|
+ const matchOrderId = jsRegExp.test(order._id || '');
|
|
|
+ const matchName = jsRegExp.test(merch.name || '');
|
|
|
+
|
|
|
+ if (!matchOrderId && !matchName) {
|
|
|
+ continue; // 都没匹配上,跳过
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先把 _id 改名为 order_id
|
|
|
+ const { _id, school_id, ...restOrder } = order;
|
|
|
+ const orderRenamed = {
|
|
|
+ ...restOrder,
|
|
|
+ orders_id: _id,
|
|
|
+ schools_id: school_id
|
|
|
};
|
|
|
- });
|
|
|
|
|
|
+ mergedOrders.push({
|
|
|
+ ...orderRenamed,
|
|
|
+ ...merch
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第四步:更新数据
|
|
|
this.setData({
|
|
|
- orders: isLoadMore ? this.data.orders.concat(newFiles) : newFiles,
|
|
|
+ orders: isLoadMore ? orders.concat(mergedOrders) : mergedOrders,
|
|
|
pageNumber: pageNumber + 1,
|
|
|
- hasMore: collectList.length === pageSize, // 如果返回的数量小于 pageSize,说明已经到底
|
|
|
+ hasMore: orderList.length === pageSize,
|
|
|
isLoading: false
|
|
|
});
|
|
|
- } catch (err) {
|
|
|
- console.error('获取失败:', err);
|
|
|
- this.setData({ isLoading: false });
|
|
|
- }
|
|
|
+ } catch (err) {
|
|
|
+ console.error('获取数据失败:', err);
|
|
|
+ this.setData({ isLoading: false });
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
tabcategories(e) {
|
|
@@ -154,6 +200,7 @@ Page({
|
|
|
console.log('type:', type);
|
|
|
this.setData({
|
|
|
categoriesindex: type,
|
|
|
+ searchText: '', // ✅ 清空搜索关键词
|
|
|
pageNumber: 1, // 重置页码
|
|
|
hasMore: true, // 重置是否有更多数据
|
|
|
orders: [], // 清空旧数据
|
|
@@ -162,15 +209,7 @@ Page({
|
|
|
this.getdatalist(false);
|
|
|
});
|
|
|
},
|
|
|
-
|
|
|
- handleAction1(e) {
|
|
|
- console.log('查看详情', e);
|
|
|
- },
|
|
|
-
|
|
|
- handleAction2(e) {
|
|
|
- console.log('处理其他操作', e);
|
|
|
- },
|
|
|
-
|
|
|
+
|
|
|
// 处理第一个按钮的点击事件
|
|
|
handleAction1: function (event) {
|
|
|
const index = event.currentTarget.dataset.index; // 获取点击的订单索引
|
|
@@ -179,15 +218,24 @@ Page({
|
|
|
switch (status) {
|
|
|
case 1:
|
|
|
console.log("查看详情", index);
|
|
|
+ const item = this.data.orders[index];
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/subpackages/orderdetails/orderdetails?data=' + encodeURIComponent(JSON.stringify(item))
|
|
|
+ });
|
|
|
// 执行查看详情的逻辑
|
|
|
break;
|
|
|
- case 2:
|
|
|
+ case 0:
|
|
|
console.log("取消订单", index);
|
|
|
// 执行取消订单的逻辑
|
|
|
break;
|
|
|
- case 3:
|
|
|
+ case 2:
|
|
|
console.log("申请售后", index);
|
|
|
// 执行申请售后的逻辑
|
|
|
+ const items = this.data.orders[index];
|
|
|
+ console.log(items, 'itemsitemsitemsitems');
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/subpackages/afterservice/afterservice?data=' + encodeURIComponent(JSON.stringify(items))
|
|
|
+ });
|
|
|
break;
|
|
|
default:
|
|
|
console.log("未知状态");
|
|
@@ -202,13 +250,14 @@ Page({
|
|
|
switch (status) {
|
|
|
case 1:
|
|
|
console.log("确认收货", index);
|
|
|
+ this.getyesordels(this.data.orders[index])
|
|
|
// 执行确认收货的逻辑
|
|
|
break;
|
|
|
- case 2:
|
|
|
+ case 0:
|
|
|
console.log("立即支付", index);
|
|
|
// 执行立即支付的逻辑
|
|
|
break;
|
|
|
- case 3:
|
|
|
+ case 2:
|
|
|
console.log("再来一单", index);
|
|
|
// 执行再来一单的逻辑
|
|
|
break;
|
|
@@ -217,6 +266,64 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ // 确认收货
|
|
|
+ async getyesordels (list) {
|
|
|
+ console.log(list, 'list');
|
|
|
+ const userInfo = wx.getStorageSync('userInfo');
|
|
|
+ const userId = userInfo && userInfo._id ? userInfo._id : ''; // 根据你的userInfo结构取ID
|
|
|
+ const schoolId = userInfo && userInfo.school_id ? userInfo.school_id : ''; // 根据你的userInfo结构取ID
|
|
|
+
|
|
|
+ const { data } = await models.orders.update({
|
|
|
+ data: {
|
|
|
+ status: 2, // 状态
|
|
|
+ },
|
|
|
+ filter: {
|
|
|
+ where: {
|
|
|
+ $and: [
|
|
|
+ {
|
|
|
+ merchandise_id: {
|
|
|
+ $eq: list._id, // 推荐传入_id数据标识进行操作
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ user_id: {
|
|
|
+ $eq: userId, // 推荐传入_id数据标识进行操作
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ school_id: {
|
|
|
+ $eq: schoolId, // 推荐传入_id数据标识进行操作
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ envType: "prod",
|
|
|
+ });
|
|
|
+ console.log(data.count, 'data.count');
|
|
|
+ if (Number(data.count) > 0) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '确认收货成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ });
|
|
|
+ // ✅ 重新获取数据
|
|
|
+ this.setData({
|
|
|
+ pageNumber: 1,
|
|
|
+ hasMore: true,
|
|
|
+ orders: []
|
|
|
+ }, () => {
|
|
|
+ this.getdatalist(false);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '确认收货失败',
|
|
|
+ icon: 'error',
|
|
|
+ duration: 1500
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
goToGoodsList (e) {
|
|
|
const index = e.currentTarget.dataset.type;
|
|
|
const item = this.data.orders[index];
|
|
@@ -224,5 +331,32 @@ Page({
|
|
|
wx.navigateTo({
|
|
|
url: '/subpackages/orderdetails/orderdetails?data=' + encodeURIComponent(JSON.stringify(item))
|
|
|
});
|
|
|
- }
|
|
|
+ },
|
|
|
+
|
|
|
+ // async adds () {
|
|
|
+ // const { data } = await models.orders.create({
|
|
|
+ // data: {
|
|
|
+ // adresses_id: "BWSLJAGVZA", // 地址id
|
|
|
+ // sys_updateby_id: "", // 更新人
|
|
|
+ // merchandise_id: "BULGAD2DA8", // 商品id
|
|
|
+ // real_money: 223.12, // 实际付款金额
|
|
|
+ // updat_adress: "", // 修改后地址
|
|
|
+ // update_phone: "", // 修改后电话
|
|
|
+ // delete: 0, // 逻辑删除
|
|
|
+ // way: 1, // 收货方式
|
|
|
+ // update_name: "", // 修改后收货人
|
|
|
+ // school_id: "BU5N9CFX2Q", // 学校_id
|
|
|
+ // user_id: "BWYRRKQVNY", // 用户_id
|
|
|
+ // num_index: 1, // 商品数据
|
|
|
+ // tracking_number: "物流单号888", // 物流单号
|
|
|
+ // order_id: "订单号888", // 订单号
|
|
|
+ // status: 2, // 状态
|
|
|
+ // },
|
|
|
+ // // envType: pre 体验环境, prod 正式环境
|
|
|
+ // envType: "prod",
|
|
|
+ // });
|
|
|
+
|
|
|
+ // // 返回创建的数据 id
|
|
|
+ // console.log(data);
|
|
|
+ // }
|
|
|
});
|