maven
8 天以前 4cc27f93a1901e12eb12a198029911c483dd991f
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="search-form">
      <el-form-item v-if="shouldShowSearch" label="搜索">
        <el-input
            v-model="queryParams.searchAll"
            :placeholder="searchPlaceholder"
            clearable
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">查询</el-button>
        <!--        <el-button @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>
    <el-card>
 
 
      <!-- 操作按钮区 -->
      <!--      <el-row :gutter="24" class="table-toolbar">-->
      <!--        <el-button-->
      <!--            :icon="Plus"-->
      <!--            type="primary"-->
      <!--            v-show="activeTab === 'payable'"-->
      <!--            @click="handleAdd"-->
      <!--        >新增应付款项</el-button>-->
 
      <!--      </el-row>-->
      <!-- 表格组件 -->
      <div class="table-container">
        <!-- 加载状态 -->
        <el-skeleton v-if="loading" animated>
          <template #template>
            <el-skeleton-item variant="h1" style="width: 40%"/>
            <div style="padding: 14px;">
              <el-skeleton-item variant="text"/>
              <el-skeleton-item variant="text"/>
              <el-skeleton-item variant="text"/>
            </div>
          </template>
        </el-skeleton>
 
        <!-- 数据表格 -->
        <data-table
            v-else
            :showOverflowTooltip="false"
            :border="true"
            @edit="handleEdit"
            :columns="columns"
            :loading="loading"
            style="width: 100%; height: calc(100vh - 29em)"
            :show-selection="activeTab === 'payable'"
            :table-data="tableData"
        >
          <!-- 空状态插槽 -->
          <template #empty>
            <el-empty
                :description="`暂无${currentTabConfig?.label || ''}数据`"
                :image-size="120"
            >
              <template #description>
                <p>暂无{{ currentTabConfig?.label || '' }}数据</p>
              </template>
            </el-empty>
          </template>
        </data-table>
      </div>
 
 
      <pagination
          v-if="total > 0"
          :layout="'total, prev, pager, next, jumper'"
          :limit="state.pageSize"
          :current-page="state.current"
          :total="total"
          @pagination="handlePageChange"
      />
 
      <!-- 查看详情弹窗 -->
      <DilogTable
          v-model="dialogTableVisible"
          :title="dialogTableTitle"
          :table-data="dialogTableData"
          :columns="dialogTableColumns"
          @submit="handleSubmit"
          @success="payableHandleSuccess"
          width="70%"
          height="500px"
      />
    </el-card>
    <PayableDialog
        v-model:dialogPayableFormVisible="dialogPayableFormVisible"
        v-model:form="copyForm"
        :title="title"
        @submit="handleSubmit"
        @success="payableHandleSuccess"
        ref="productionDialogs">
    </PayableDialog>>
  </div>
</template>
 
<script setup>
import {computed, onMounted, reactive, ref, nextTick, toRefs} from "vue";
import {ElMessage} from "element-plus";
import {Delete, Plus} from "@element-plus/icons-vue";
 
// 组件导入
import DataTable from "@/components/Table/ETable.vue";
import Pagination from "@/components/PIMTable/Pagination.vue";
import DilogTable from "@/components/dialog/DilogTable.vue";
 
// API 服务导入
import {findPayablePage} from "@/api/payable/index"
 
const userStore = useUserStore();
const dictStore = useDictStore()
import useUserStore from "@/store/modules/user";
import useDictStore from "@/store/modules/dict"
import PayableDialog from "@/views/payable/components/PayableDialog.vue";
 
let userList = ref([]);
userStore.getUserList().then((res) => {
  userList.value = res;
});
 
 
// 响应式状态管理 - 使用解构和默认值
const productionDialogs = ref(null); // 添加ref声明
const initFormState = () => ({consumables: false});
const dialogPayableFormVisible = ref(false);
const addOrEdit = ref("edit");
const state = reactive({
  form: initFormState(),
  title: "",
  copyForm: {},
  loading: false,
  activeTab: "payable",
  selectedRows: [],
  tableData: [],
  // 分页状态
  pageNum: 1,
  pageSize: 10,
  current: 1,
  total: 0,
  // 查询参数
  queryParams: {
    searchAll: "",
  },
});
const userInfo = ref({});
 
onMounted(() => {
  let res = userStore.getInfo();
  userInfo.value = res.user;
  getList()
})
const handleEdit = (row) => {
  form.value = JSON.parse(JSON.stringify(row));
  addOrEdit.value = "edit";
  handleAddEdit()
}
const handleAddEdit = () => {
  addOrEdit.value == "add" ? (title.value = "新增") : addOrEdit.value == "viewRow" ? (title.value = "查看") : (title.value = "编辑");
  title.value = title.value + "应付管理";
  openDialog();
};
 
const openDialog = () => {
  if (addOrEdit.value === "edit" || addOrEdit.value === "viewRow") {
    // 确保复制一份数据,避免直接引用
    copyForm.value = JSON.parse(JSON.stringify(form.value));
    // console.log(copyForm.value)
    copyForm.value.fileList = copyForm.value.attachFileList.map((item) => {
      return {
        id: item.id,
        url: item.downloadUrl,
        uid: item.id,
        status: "success",
        name: item.originalFilename
      }
    })
    dialogPayableFormVisible.value = true;
    // 触发ref里面的方法
    return;
  }
};
 
 
const handleQuery = () => {
  state.loading = true;
  state.current = 1;
  getList()
}
 
const handlePageChange = (it) => {
  state.current = it.page
  getList();
}
 
 
 
 
const getList = async () => {
  loading.value = true;
  try {
    let resp = await findPayablePage(
        {
          current: state.current,
          pageSize: state.current
          , ...state.queryParams
        })
    tableData.value = resp.data.records
    total.value = resp.data.total || 0;
  } finally {
    loading.value = false;
  }
}
 
// 使用解构简化访问
const {
  form,
  title,
  copyForm,
  loading,
  activeTab,
  selectedRows,
  current,
  tableData,
  pageNum,
  pageSize,
  total,
  queryParams,
} = toRefs(state);
 
// 添加缺失的响应式变量
const dialogTableVisible = ref(false);
const dialogTableTitle = ref('');
const dialogTableData = ref([]);
const dialogTableColumns = ref([]);
 
 
const payableHandleSuccess = (val) => {
  ElMessage.success("操作成功");
  dialogPayableFormVisible.value = false;
  getList()
}
const handleSubmit = (val) => {
  if (val.result.code !== 200) {
    ElMessage.error("操作失败:" + val.result.msg);
    return;
  }
  ElMessage.success(val.title + val.result.msg);
  dialogPayableFormVisible.value = false;
  getList();
};
 
// 标签页配置 - 便于后续扩展
const tabsConfig = {
  payable: {
    searchPlaceholder: "",
    showSearch: true,
    // deleteApi: ,
    columns: [
      /* 暂时不知道是否需要      {prop: "equipmentNo", label: "供应商名称", minWidth: 100},*/
      {prop: "ticketNo", label: "发票号", minWidth: 100},
      {prop: "paymentAmount", label: "付款金额(元)", minWidth: 100},
      // {prop: "specification", label: "附件", minWidth: 100},
      {
        prop: "payableType", label: "付款类型", minWidth: 100,
        formatter: (row) => {
          if (row.payableType == null) {
            return ""
          }
          const dictItem = dictStore.getDictDataByTypeAndValue("payable_type", row.payableType);
          return dictItem ? dictItem.label : "";
        }
      },
      {
        prop: "registrantId", label: "录入人", minWidth: 100,
        formatter: (row) => {
          // 匹配用户信息
          const user = userList.value.find((user) => user.userId === row.registrantId);
          return user ? user.nickName : "未知用户";
        },
      },
      {prop: "registrationDate", label: "录入日期", minWidth: 100},
    ],
  }
};
 
 
// 当前标签页配置
const currentTabConfig = computed(() => tabsConfig[activeTab.value]);
 
// 计算属性
const searchPlaceholder = computed(
    () => currentTabConfig.value?.searchPlaceholder || "请输入搜索信息"
);
const shouldShowSearch = computed(
    () => currentTabConfig.value?.showSearch || false
);
const columns = computed(() => currentTabConfig.value?.columns || []);
const selectedCount = computed(() => selectedRows.value.length);
 
 
// 动态获取操作列宽度
const getOperationsWidth = () => {
  if (activeTab.value === 'equipmentRequisition') {
    return 250; // 为归还按钮预留更多空间
  }
  return 200; // 默认宽度
};
 
 
</script>
 
<style scoped>
/* 响应式布局 */
@media screen and (min-width: 768px) {
  .search-form :deep(.el-form-item) {
    width: 50%;
  }
}
 
@media screen and (min-width: 1200px) {
  .search-form :deep(.el-form-item) {
    width: 16%;
  }
}
 
.table-toolbar {
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
 
.app-container {
  padding: 18px !important;
}
 
/* 响应式表格 */
@media screen and (max-width: 768px) {
  .table-toolbar {
    flex-direction: column;
  }
 
  .table-toolbar .el-button {
    width: 100%;
  }
}
 
/* 表格工具栏 */
.table-toolbar,
.table-toolbar > * {
  margin: 0 0 0 0 !important;
}
 
.table-toolbar {
  margin-bottom: 20px !important;
}
 
.el-form--inline .el-form-item {
  margin-right: 25px;
}
 
.main-container {
  background: red !important;
}
 
/* 设备状态样式 */
.status-using {
  color: #409eff;
  font-weight: 500;
}
 
.status-partial-return {
  color: #e6a23c;
  font-weight: 500;
}
 
.status-returned {
  color: #67c23a;
  font-weight: 500;
}
 
.status-unknown {
  color: #909399;
  font-weight: 500;
}
 
/* 状态标签样式 */
:deep(.el-table .cell .status-tag) {
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
</style>