wujianwei
2026-01-14 d9b20efa8bdb66f5e2cb1793314f57ed66e846b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
  <el-dialog v-model="dialogVisible" title="请选择 关联账单" width="85%" destroy-on-close @close="handleClose"
    append-to-body>
    <div class="search-bar">
      <el-form inline :model="queryParams" class="search-form" size="default">
        <el-form-item label="系统编号:">
          <el-input v-model="queryParams.systemNo" placeholder="请输入系统编号" style="width: 180px" clearable />
        </el-form-item>
 
        <el-form-item label="账单名称:">
          <el-input v-model="queryParams.billName" placeholder="请输入账单名称" style="width: 180px" clearable />
        </el-form-item>
 
        <el-form-item label="客户名称:">
          <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" style="width: 180px" clearable />
        </el-form-item>
 
        <el-form-item label="状态:">
          <el-select v-model="queryParams.status" style="width: 150px;" placeholder="请选择状态" clearable>
            <el-option v-for="dict in sys_bill_status" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
 
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleSearch">搜索</el-button>
          <el-button plain icon="RefreshLeft" @click="handleReset">清空</el-button>
        </el-form-item>
      </el-form>
    </div>
 
    <el-table ref="customerTableRef" :data="customerList" border size="small" style="width: 100%"
      :highlight-current-row="true" row-key="id" @current-change="handleRowSelect" class="customer-table">
      <el-table-column prop="systemNo" label="系统编号" min-width="150" show-overflow-tooltip />
      <el-table-column prop="billName" label="账单名称" min-width="150" show-overflow-tooltip />
      <el-table-column prop="customerName" label="客户名称" min-width="150" show-overflow-tooltip />
      <el-table-column prop="documentCount" label="单据数量" min-width="100" show-overflow-tooltip />
      <el-table-column prop="totalAmount" label="应结算金额" min-width="120" show-overflow-tooltip />
      <el-table-column prop="currency" label="币制" min-width="80" show-overflow-tooltip />
      <el-table-column prop="discountAmount" label="减免金额" min-width="100" show-overflow-tooltip />
      <el-table-column prop="receivedAmount" label="已收金额" min-width="100" show-overflow-tooltip />
      <el-table-column prop="pendingAmount" label="待收金额" min-width="100" show-overflow-tooltip />
 
      <el-table-column prop="status" label="状态" width="100">
        <template #default="scope">
          {{ dictFormat(sys_bill_status, scope.row.status) }}
        </template>
      </el-table-column>
    </el-table>
 
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />
 
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">确定选择</el-button>
      </div>
    </template>
  </el-dialog>
</template>
 
<script setup lang="ts">
import { ref, reactive, watch, nextTick } from 'vue';
import type { Table } from 'element-plus';
import { ElMessage } from 'element-plus';
import useCurrentInstance from "@/utils/useCurrentInstance";
import { listReceivableBillManagement, } from "@/api/cwgl/receivableBillManagement";
 
// 这里的 Customer 接口根据表格字段进行了更新
interface Customer {
  id: string | number;
  systemNo: string;
  billName: string;
  customerName: string;
  status: string | number;
  totalAmount: number;
  // ... 其他列字段
}
 
const props = defineProps({
  visible: { type: Boolean, default: false },
  defaultSelectedId: { type: [String, Number], default: '' }
});
 
const emit = defineEmits(['confirm', 'close', 'update:visible']);
 
const { proxy } = useCurrentInstance();
const { sys_bill_status } = proxy.useDict('sys_bill_status');
 
const dictFormat = (dict: any, value: any) => {
  return proxy.selectDictLabel(dict, value);
};
 
const dialogVisible = ref(false);
const customerList = ref<Customer[]>([]);
const total = ref(0);
const selectedRow = ref<Customer | null>(null);
const customerTableRef = ref<InstanceType<typeof Table>>();
 
// 更新 queryParams 以匹配搜索表单和表格字段
const queryParams = reactive({
  systemNo: '',
  billName: '',
  customerName: '',
  status: '',
  pageNum: 1,
  pageSize: 10
});
 
const getDataList = async () => {
  try {
    const res = await listReceivableBillManagement(queryParams);
    if (res.code === 200) {
      customerList.value = res.rows;
      total.value = res.total;
      return res.rows;
    }
  } catch (err) {
    console.error('加载列表失败:', err);
  }
  return [];
};
 
const autoSelectRow = (list: Customer[]) => {
  if (!props.defaultSelectedId || list.length === 0) return;
  nextTick(() => {
    const target = list.find(item => String(item.id) === String(props.defaultSelectedId));
    if (target && customerTableRef.value) {
      customerTableRef.value.setCurrentRow(target);
      selectedRow.value = target;
    }
  });
};
 
const handleSearch = () => {
  queryParams.pageNum = 1;
  getList();
};
 
const handleReset = () => {
  // 重置字段必须与 queryParams 定义的一致
  queryParams.systemNo = '';
  queryParams.billName = '';
  queryParams.customerName = '';
  queryParams.status = '';
  handleSearch();
};
 
const getList = () => {
  getDataList().then((list) => {
    autoSelectRow(list);
  });
};
 
const handleRowSelect = (val: Customer | null) => {
  selectedRow.value = val;
};
 
const handleConfirm = () => {
  if (!selectedRow.value) {
    ElMessage.warning('请先点击表格选择一行数据');
    return;
  }
  emit('confirm', selectedRow.value);
  handleClose();
};
 
const handleClose = () => {
  emit('update:visible', false);
  emit('close');
};
 
watch(() => props.visible, (newVal) => {
  dialogVisible.value = newVal;
  if (newVal) {
    getList();
  }
});
</script>