index.vue
4.5 KB
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
<script setup lang="ts">
import { reactive, onMounted, getCurrentInstance,ref } from "vue";
import { getTableList, deleteAccendant } from "@/api/notify/serviceman.ts";
import Detail from "./detail.vue";
import { parseTime } from "@/utils/tool.ts";
import Pagination from "@/components/Pagination/index.vue";
import type { ElForm } from 'element-plus'
let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例
const detailRef = ref<InstanceType<typeof ElForm>>();
// 数据筛选
const searchData = reactive({
name: null,
accendantType:1,
page: 1,
pageSize: 10,
});
// 展示
const data = reactive({
total: 0,
tableList: [],
dialogVisible: false,
loading: false,
title: "新增维修人员",
formObj: {},
});
/**
* 列表查询
*/
const search = (): void => {
data.loading = true;
getTableList(searchData)
.then((res) => {
data.tableList = res.data.data.list;
data.total = res.data.data.total;
data.loading = false;
})
.catch((err) => {
console.log(err);
data.loading = false;
});
};
/**
* 编辑
* @param { Object } 列表对象
*/
const edit = (row: Object) => {
data.title = "编辑维修人员";
data.formObj = JSON.parse(JSON.stringify(row));
data.dialogVisible = true;
};
/**
* 删除
* @param { number } accendantId 唯一ID
*/
const remove = (accendantId: number) => {
instance?.proxy?.$messageBox
.confirm("确认要进行此操作?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
})
.then(() => {
deleteAccendant({ accendantId: accendantId }).then((res) => {
instance?.proxy?.$message.success("操作成功"); //调用
search();
});
})
.catch((err) => {});
};
/**
* 组件操作成功回调
*/
const changeData: void = () => {
data.dialogVisible = false;
search();
};
/**
* 弹框关闭
*/
const dialogClose: void = () => {
data.title = "新增维修人员";
data.formObj = {};
detailRef.value.resetForm();
};
onMounted(() => {
search();
});
</script>
<template>
<div class="app-container">
<!-- 搜索 -->
<el-form :inline="true" :model="searchData" @submit.native.prevent>
<el-form-item>
<el-input
placeholder="请输入姓名/电话"
v-model="searchData.name"
clearable
></el-input>
</el-form-item>
<el-form-item
><el-button type="primary" @click="search"
>查询</el-button
></el-form-item
>
<el-row>
<el-form-item>
<el-button type="primary" @click="data.dialogVisible = true"
>新增</el-button
>
</el-form-item>
</el-row>
</el-form>
<!-- 表格 -->
<el-table border :data="data.tableList" v-loading="data.loading">
<el-table-column label="姓名" prop="name"></el-table-column>
<el-table-column label="性别" prop="sex"></el-table-column>
<el-table-column label="年龄" prop="age"></el-table-column>
<el-table-column label="服务小区" prop="truckSpaceCount">
<template #default="scope">
<span v-for="item in scope.row.neighborhoods">{{ `${item.name} ` }}</span>
</template>
</el-table-column>
<el-table-column label="联系电话" prop="mobile"></el-table-column>
<el-table-column label="身份证号" prop="idCard"></el-table-column>
<el-table-column label="创建时间" prop="createTime">
<template #default="scope">
<span>{{ parseTime(new Date(scope.row.createTime).getTime()) }}</span>
</template>
</el-table-column>
<el-table-column label="操作">
<template #default="scope">
<el-button type="text" size="mini" @click="edit(scope.row)"
>编辑</el-button
>
<el-button type="text" size="mini" @click="remove(scope.row.id)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
v-if="data.total > 0"
:total="data.total"
v-model:currentPage="searchData.page"
v-model:pageSize="searchData.pageSize"
@pageChange="search"
></Pagination>
<!-- 详情弹框 -->
<el-dialog
v-model="data.dialogVisible"
:title="data.title"
width="30%"
@close="dialogClose"
>
<Detail
ref="detailRef"
@cancel="data.dialogVisible = false"
@success="changeData"
:formObj="data.formObj"
></Detail>
</el-dialog>
</div>
</template>
<style></style>