Browse Source

feat: 添加规格排序功能,按照净重/毛重分类并按数值范围排序

pull/19/head
徐飞洋 1 month ago
parent
commit
7ffd5c26ba
  1. 22
      pages/evaluate1/index.js

22
pages/evaluate1/index.js

@ -239,6 +239,28 @@ Page({
console.log('提取的规格和价格:', specifications); console.log('提取的规格和价格:', specifications);
// 对规格进行排序
specifications.sort((a, b) => {
// 解析两个规格
const specA = this.parseSpecification(a.name);
const specB = this.parseSpecification(b.name);
// 如果有一个规格解析失败,保持原顺序
if (!specA || !specB) {
return 0;
}
// 1. 按类型排序:净重在前,毛重在后
if (specA.type !== specB.type) {
return specA.type === '净重' ? -1 : 1;
}
// 2. 按规格最小值排序:从小到大
return specA.min - specB.min;
});
console.log('排序后的规格:', specifications);
this.setData({ this.setData({
specifications: specifications, specifications: specifications,
error: '', // 清除之前的错误 error: '', // 清除之前的错误

Loading…
Cancel
Save