refactor(ContractSelect): 优化选中合同的加载逻辑
将原有的列表搜索获取选中合同的方式,改为直接调用getOrder接口单个查询,简化代码逻辑并提升查询效率
This commit is contained in:
@@ -116,7 +116,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listOrder, listTodayOrder } from '@/api/crm/order';
|
import { listOrder, listTodayOrder, getOrder } from '@/api/crm/order';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ContractSelect",
|
name: "ContractSelect",
|
||||||
@@ -314,14 +314,13 @@ export default {
|
|||||||
this.contractList = res.rows || [];
|
this.contractList = res.rows || [];
|
||||||
// 初始加载时,确保已选中的合同在列表中
|
// 初始加载时,确保已选中的合同在列表中
|
||||||
if (!query && this.value && !this.contractList.some(item => String(item.orderId) === String(this.value))) {
|
if (!query && this.value && !this.contractList.some(item => String(item.orderId) === String(this.value))) {
|
||||||
const res2 = await listOrder({
|
try {
|
||||||
pageNum: 1,
|
const contract = await getOrder(this.value);
|
||||||
pageSize: 100,
|
if (contract.data) {
|
||||||
keyword: this.value,
|
this.contractList.unshift(contract.data);
|
||||||
});
|
}
|
||||||
const found = (res2.rows || []).find(item => String(item.orderId) === String(this.value));
|
} catch (e) {
|
||||||
if (found) {
|
console.error('Failed to fetch selected contract:', e);
|
||||||
this.contractList.unshift(found);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user