refactor(ContractSelect): 优化选中合同的加载逻辑

将原有的列表搜索获取选中合同的方式,改为直接调用getOrder接口单个查询,简化代码逻辑并提升查询效率
This commit is contained in:
2026-06-19 13:14:02 +08:00
parent 66838b6c69
commit 491eed3dad

View File

@@ -116,7 +116,7 @@
</template>
<script>
import { listOrder, listTodayOrder } from '@/api/crm/order';
import { listOrder, listTodayOrder, getOrder } from '@/api/crm/order';
export default {
name: "ContractSelect",
@@ -314,14 +314,13 @@ export default {
this.contractList = res.rows || [];
// 初始加载时,确保已选中的合同在列表中
if (!query && this.value && !this.contractList.some(item => String(item.orderId) === String(this.value))) {
const res2 = await listOrder({
pageNum: 1,
pageSize: 100,
keyword: this.value,
});
const found = (res2.rows || []).find(item => String(item.orderId) === String(this.value));
if (found) {
this.contractList.unshift(found);
try {
const contract = await getOrder(this.value);
if (contract.data) {
this.contractList.unshift(contract.data);
}
} catch (e) {
console.error('Failed to fetch selected contract:', e);
}
}
} catch (error) {