zhitong.yu
8 天以前 378d781e6f35f89652aa36e079a8b7fc44cea77e
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
<template>
  <div class="main-box">
    <TreeFilter
      label="name"
      :title="t('Person.companyList')"
      :request-api="getUserDepartment"
      @change="changeTreeFilter"
      :labeltext="t('treeFilter.searchPlaceholder')"
      :zhankai="t('treeFilter.expandAll')"
      :zhedie="t('treeFilter.collapseAll')"
    />
    <div class="table-box">
      <ProTable
        v-loading="loading"
        ref="proTable"
        :columns="columns"
        :request-api="getPersonList"
        :init-param="initParam"
        :search-col="{ xs: 1, sm: 1, md: 2, lg: 3, xl: 3 }"
      >
        <!-- 表格 header 按钮 -->
        <template #tableHeader>
          <!-- <el-button type="primary" v-if="BUTTONS.add" plain :icon="CirclePlus" @click="openDrawer('新增')">
            {{ $t("Person.addPerson") }}
          </el-button> -->
        </template>
        <template #UpdateList>
          <!-- <el-tooltip class="box-item" effect="dark" content="批量修改" placement="top">
            <el-button :icon="Edit" circle @click="openListDrawer('编辑')" />
          </el-tooltip> -->
        </template>
        <!-- 电量 -->
        <template #ppower="scope">
          <VueUiGizmo :config="config" :dataset="scope.row.ppower" />
        </template>
        <!-- 表格操作 -->
        <template #operation="scope">
          <el-button type="primary" link :icon="View" @click="viewDrawer($t('Config.view'), scope.row)">{{
            $t("Config.view")
          }}</el-button>
          <el-button type="primary" v-if="BUTTONS.edit" link :icon="EditPen" @click="openDrawer($t('Config.update'), scope.row)">
            {{ $t("Config.update") }}
          </el-button>
          <el-button type="primary" v-if="BUTTONS.delete" link :icon="Delete" @click="deleteAccount(scope.row)">{{
            $t("Config.delete")
          }}</el-button>
        </template>
      </ProTable>
 
      <PersonDrawer ref="drawerRef" />
      <PersonListDrawer ref="drawerListRef" />
      <PersonInfoCard ref="viewRef" />
      <ImportExcel ref="dialogRef" />
    </div>
  </div>
</template>
<script setup lang="tsx" name="useTreeFilter">
import { ref, reactive, onMounted } from "vue";
import { User } from "@/api/interface";
import { useHandleData } from "@/hooks/useHandleData";
import ProTable from "@/components/ProTable/index.vue";
import TreeFilter from "@/components/TreeFilter/index.vue";
import { useAuthButtons } from "@/hooks/useAuthButtons";
import ImportExcel from "@/components/ImportExcel/index.vue";
import { ElMessage } from "element-plus";
import PersonInfoCard from "@/views/proTable/components/hxzk/person/PersonInfoCard.vue";
import PersonDrawer from "@/views/proTable/components/hxzk/person/PersonDrawer.vue";
import PersonListDrawer from "@/views/proTable/components/hxzk/person/PersonListDrawer.vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import { Delete, EditPen, View } from "@element-plus/icons-vue";
import { getPersonList, addPerson, editPerson, deletePerson } from "@/api/modules/hxzk/person/person";
import { DepartmentAutocomplete } from "@/api/modules/hxzk/department/department";
import { getUserDepartment } from "@/api/modules/hxzk/user/user";
import { useI18n } from "vue-i18n";
 
import { useDict } from "@/utils/dict";
 
import { VueUiGizmo } from "vue-data-ui";
import "vue-data-ui/style.css";
import notData from "@/assets/images/notData.png";
// 使用 useI18n 获取 i18n 实例
const { t } = useI18n({
  useScope: "global"
});
const { BUTTONS } = useAuthButtons();
const { PersonStatus } = useDict();
// ProTable 实例
const proTable = ref<ProTableInstance>();
 
// 如果表格需要初始化请求参数,直接定义传给 ProTable(之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
const initParam = reactive({ departmentId: "" });
const loading = ref(true);
// 树形筛选切换
const changeTreeFilter = (val: string) => {
  proTable.value!.pageable.pageNum = 1;
  initParam.departmentId = val;
  companyid.value = val;
  const params = {
    companyid: companyid.value
  };
  DepartmentAutocomplete(params).then(result => {
    PersonDepartMent.value = result;
  });
  ElMessage({
    message: t("Config.Checked"),
    grouping: true,
    type: "success"
  });
};
 
// 电量配置项
const config = ref({
  type: "battery",
  size: 70,
  stroke: "#8a8a8aff",
  color: "#33ff57ff",
  useGradient: false,
  gradientColor: "rgba(255, 0, 0, 1)",
  showPercentage: true,
  textColor: "rgba(26, 26, 26, 1)",
  fontFamily: "inherit",
  formatter: null
});
 
const PersonDepartMent = ref([{}]);
 
// 表格配置项
const columns = reactive<ColumnProps<User.ResUserList>[]>([
  { type: "selection", fixed: "left", width: 70 },
 
  {
    prop: "ptagid",
    label: t("Person.tagid"),
    search: {
      el: "input",
      span: 3,
      label: `${t("Person.tagid")}/${t("Person.name")}`
    },
    render: scope => {
      return (
        <el-tag size="large" effect="light">
          {scope.row.ptagid}
        </el-tag>
      );
    }
  },
  {
    prop: "pname",
    label: t("Person.name")
  },
 
  {
    prop: "psex",
    label: t("Person.gender")
  },
 
  {
    prop: "pdepartment",
    label: t("Person.department"),
    enum: PersonDepartMent,
    search: { el: "select", props: { filterable: true }, span: 2 }
  },
 
  {
    prop: "ponline",
    label: t("Person.online"),
    enum: PersonStatus,
    search: { el: "select", props: { filterable: true }, span: 2 },
    render: scope => {
      const statusText = scope.row.ponline === "1" ? t("Person.status.online") : t("Person.status.offline");
      const tagType = scope.row.ponline === "1" ? "primary" : "danger";
      return (
        <el-tag size="large" effect="plain" type={tagType}>
          {statusText}
        </el-tag>
      );
    }
  },
  { prop: "ppower", label: t("Person.power"), width: 100 },
  {
    prop: "pzu",
    label: t("Person.position")
  },
  {
    prop: "company",
    label: t("Person.company"),
    width: 100,
    render: scope => {
      return <el-tag size="large">{scope.row.company}</el-tag>;
    }
  },
  {
    prop: "baoliu38",
    label: t("Person.photo"),
    render: scope => {
      const handleError = e => {
        e.target.src = notData;
        e.target.onerror = null;
      };
      return <img style={{ width: "30px", height: "30px" }} src={scope.row.baoliu38} onError={handleError} />;
    }
  },
  {
    prop: "pphone",
    label: t("Person.phone")
  },
  {
    prop: "baoliu1",
    label: t("Person.cardNumber"),
    width: 190,
    render: scope => {
      return <el-tag size="large">{scope.row.baoliu1}</el-tag>;
    }
  },
 
  { prop: "paddtiem", label: t("Config.time"), width: 160 },
  { prop: "operation", label: t("Config.operation"), width: 260, fixed: "right" }
]);
 
// 删除终端信息
const deleteAccount = async (params: User.ResUserList) => {
  await useHandleData(
    deletePerson,
    { ptagid: params.ptagid, pname: params.pname },
    t("Person.deleteConfirm", { name: params.pname }),
    t
  );
  proTable.value?.getTableList();
};
 
// 打开 drawer(新增、编辑)
const drawerListRef = ref<InstanceType<typeof UserDrawer> | null>(null);
// 批量修改
// const openListDrawer = (title: string) => {
//   if (!proTable.value?.selectedList.length > 0) {
//     ElMessage.warning("请至少选中1条记录");
//     return;
//   }
//   const params = {
//     title,
//     initParam,
//     isView: title === "查看",
//     row: { ...proTable.value?.selectedList },
//     api: title === "新增" ? addPerson : title === "编辑" ? editPerson : undefined,
//     getTableList: proTable.value?.getTableList
//   };
//   drawerListRef.value?.acceptParams(params);
// };
 
// 打开 drawer(新增、编辑)
const drawerRef = ref<InstanceType<typeof UserDrawer> | null>(null);
// 打开 viewRef(查看)
const viewRef = ref<InstanceType<typeof UserDrawer> | null>(null);
const openDrawer = (title: string, row: Partial<User.ResUserList> = {}) => {
  const params = {
    title,
    initParam,
    isView: title === "查看",
    row: { ...row },
    api: title === "新增" ? addPerson : title === "编辑" ? editPerson : undefined,
    getTableList: proTable.value?.getTableList
  };
  drawerRef.value?.acceptParams(params);
};
const viewDrawer = (title: string, row: Partial<User.ResUserList> = {}) => {
  const params = {
    title,
    initParam,
    isView: title === "查看",
    row: { ...row },
    api: title === "新增" ? addPerson : title === "编辑" ? editPerson : undefined,
    getTableList: proTable.value?.getTableList
  };
  viewRef.value?.acceptParams(params);
};
const companyid = ref("");
onMounted(() => {
  // 编号自动补全
  const params = {
    companyid: companyid.value
  };
  DepartmentAutocomplete(params).then(result => {
    PersonDepartMent.value = result;
  });
});
</script>
<style scoped>
.example-showcase .el-loading-mask {
  z-index: 9;
}
</style>