index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="mb-[10px]">
  5. <el-card shadow="hover">
  6. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  7. <el-form-item label="用户编码" prop="contactNo">
  8. <el-input v-model="queryParams.contactNo" placeholder="请输入用户编码" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item label="姓名" prop="contactName">
  11. <el-input v-model="queryParams.contactName" placeholder="请输入姓名" clearable @keyup.enter="handleQuery" />
  12. </el-form-item>
  13. <el-form-item label="联系电话" prop="phone">
  14. <el-input v-model="queryParams.phone" placeholder="请输入联系电话" clearable @keyup.enter="handleQuery" />
  15. </el-form-item>
  16. <el-form-item label="所属客户" prop="customerName">
  17. <el-input v-model="queryParams.customerName" placeholder="请输入所属客户" clearable @keyup.enter="handleQuery" />
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  21. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </el-card>
  25. </div>
  26. </transition>
  27. <el-card shadow="never">
  28. <template #header>
  29. <el-row :gutter="10" class="mb8">
  30. <el-col :span="19">
  31. <span>员工信息列表</span>
  32. </el-col>
  33. <el-col :span="1.5">
  34. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()">批量删除</el-button>
  35. </el-col>
  36. <el-col :span="1.5">
  37. <el-button type="primary" plain :disabled="single">修改密码</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button type="warning" plain icon="Download" @click="handleExport">导出数据</el-button>
  41. </el-col>
  42. </el-row>
  43. </template>
  44. <el-table v-loading="loading" border :data="customerContactList" @selection-change="handleSelectionChange">
  45. <el-table-column type="selection" width="55" align="center" />
  46. <el-table-column label="员工编号" align="center" prop="contactNo" />
  47. <el-table-column label="姓名" align="center" prop="contactName" />
  48. <el-table-column label="手机号" align="center" prop="phone" />
  49. <el-table-column label="采购角色" align="center" prop="roleName" />
  50. <el-table-column label="职位" align="center" prop="postName" />
  51. <el-table-column label="所属客户" align="center" prop="customerName" />
  52. <el-table-column label="注册时间" align="center" prop="createTime" width="180">
  53. <template #default="scope">
  54. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="状态" align="center" prop="status">
  58. <template #default="scope">
  59. <!-- <dict-tag :options="sys_normal_disable" :value="scope.row.status" /> -->
  60. {{ scope.row.status === '0' ? '启用' : '停用' }}
  61. </template>
  62. </el-table-column>
  63. <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  64. <template #default="scope">
  65. <el-button link type="primary" @click="handleUpdate(scope.row)">编辑</el-button>
  66. <el-button link type="primary">查看</el-button>
  67. </template>
  68. </el-table-column> -->
  69. </el-table>
  70. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  71. </el-card>
  72. <!-- 添加或修改客户联系人信息对话框 -->
  73. <el-dialog :title="dialog.title" v-model="dialog.visible" width="900px" append-to-body>
  74. <el-form ref="customerContactFormRef" :model="form" :rules="rules" label-width="120px">
  75. <el-row :gutter="20">
  76. <el-col :span="12">
  77. <el-form-item label="联系人姓名" prop="contactName">
  78. <el-input v-model="form.contactName" placeholder="请输入联系人姓名" />
  79. </el-form-item>
  80. </el-col>
  81. <el-col :span="12">
  82. <el-form-item label="手机号码" prop="phone">
  83. <el-input v-model="form.phone" placeholder="请输入手机号码" />
  84. </el-form-item>
  85. </el-col>
  86. </el-row>
  87. <el-row :gutter="20">
  88. <el-col :span="12">
  89. <el-form-item label="办公电话" prop="officePhone">
  90. <el-input v-model="form.officePhone" placeholder="请输入办公电话" />
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="12">
  94. <el-form-item label="自定义登录名" prop="customLoginName">
  95. <el-input v-model="form.customLoginName" placeholder="请输入自定义登录名" />
  96. </el-form-item>
  97. </el-col>
  98. </el-row>
  99. <el-row :gutter="20">
  100. <el-col :span="12">
  101. <el-form-item label="所属部门" prop="deptId">
  102. <el-tree-select
  103. v-model="form.deptId"
  104. :data="customerDeptList"
  105. :props="{ value: 'deptId', label: 'deptName', children: 'children' }"
  106. value-key="deptId"
  107. placeholder="请选择"
  108. check-strictly
  109. :render-after-expand="false"
  110. @change="handleDeptChange"
  111. filterable
  112. style="width: 100%"
  113. />
  114. </el-form-item>
  115. </el-col>
  116. <el-col :span="12">
  117. <el-form-item label="邮箱" prop="email">
  118. <el-input v-model="form.email" placeholder="请输入邮箱" />
  119. </el-form-item>
  120. </el-col>
  121. </el-row>
  122. <el-row :gutter="20">
  123. <el-col :span="12">
  124. <el-form-item label="采购角色" prop="roleId">
  125. <el-select v-model="form.roleId" placeholder="请选择采购角色" clearable filterable style="width: 100%" @change="handleRoleChange">
  126. <el-option v-for="role in roleOptions" :key="role.roleId" :label="role.roleName" :value="role.roleId" />
  127. </el-select>
  128. </el-form-item>
  129. </el-col>
  130. <!-- <el-col :span="12">
  131. <el-form-item label="生日" prop="birthday">
  132. <el-date-picker v-model="form.birthday" type="date" placeholder="请选择" class="w-full" value-format="YYYY-MM-DD" style="width: 100%" />
  133. </el-form-item>
  134. </el-col> -->
  135. </el-row>
  136. <el-row :gutter="20">
  137. <el-col :span="12">
  138. <el-form-item label="性别" prop="gender">
  139. <el-radio-group v-model="form.gender">
  140. <el-radio v-for="dict in sys_user_sex" :key="dict.value" :label="dict.value">{{ dict.label }}</el-radio>
  141. </el-radio-group>
  142. </el-form-item>
  143. </el-col>
  144. <el-col :span="12">
  145. <el-form-item label="启用状态" prop="status">
  146. <el-switch v-model="form.status" active-value="0" inactive-value="1" />
  147. </el-form-item>
  148. </el-col>
  149. </el-row>
  150. <el-row :gutter="20">
  151. <el-col :span="24">
  152. <el-form-item label="详细地址" prop="codeArr">
  153. <el-cascader v-model="codeArr" :options="regionOptions" placeholder="请选择" @change="handleChange" style="width: 100%"></el-cascader>
  154. </el-form-item>
  155. <el-form-item prop="addressDetail">
  156. <el-input v-model="form.addressDetail" type="textarea" :rows="3" placeholder="请输入详细地址" style="width: 100%" />
  157. </el-form-item>
  158. </el-col>
  159. </el-row>
  160. </el-form>
  161. <template #footer>
  162. <div class="dialog-footer">
  163. <el-button type="primary" :loading="buttonLoading" @click="submitForm">确认</el-button>
  164. <el-button @click="cancel">取消</el-button>
  165. </div>
  166. </template>
  167. </el-dialog>
  168. </div>
  169. </template>
  170. <script setup name="CustomerContact" lang="ts">
  171. import {
  172. listCustomerContact,
  173. getCustomerContact,
  174. changeIsPrimary,
  175. delCustomerContact,
  176. addCustomerContact,
  177. updateCustomerContact
  178. } from '@/api/customer/customerFile/customerContact';
  179. import { CustomerContactVO, CustomerContactQuery, CustomerContactForm } from '@/api/customer/customerFile/customerContact/types';
  180. import { listCustomerDept, getCustomerDept } from '@/api/customer/customerFile/customerDept';
  181. import { CustomerDeptVO, CustomerDeptQuery } from '@/api/customer/customerFile/customerDept/types';
  182. import { listRole } from '@/api/system/role';
  183. import type { RoleVO } from '@/api/system/role/types';
  184. import { regionData } from 'element-china-area-data';
  185. const regionOptions = regionData as any;
  186. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  187. const { sys_platform_yes_no, sys_user_sex, sys_normal_disable } = toRefs<any>(
  188. proxy?.useDict('sys_platform_yes_no', 'sys_user_sex', 'sys_normal_disable')
  189. );
  190. const customerContactList = ref<CustomerContactVO[]>([]);
  191. const customerDeptList = ref<CustomerDeptVO[]>([]);
  192. const buttonLoading = ref(false);
  193. const loading = ref(true);
  194. const showSearch = ref(true);
  195. const ids = ref<Array<string | number>>([]);
  196. const single = ref(true);
  197. const multiple = ref(true);
  198. const total = ref(0);
  199. const queryFormRef = ref<ElFormInstance>();
  200. const customerContactFormRef = ref<ElFormInstance>();
  201. const codeArr = ref([]);
  202. const dialog = reactive<DialogOption>({
  203. visible: false,
  204. title: ''
  205. });
  206. const roleOptions = ref<any>([]);
  207. const initFormData: CustomerContactForm = {
  208. id: undefined,
  209. customerId: undefined,
  210. contactName: undefined,
  211. phone: undefined,
  212. customLoginName: undefined,
  213. officePhone: undefined,
  214. officePhoneTwo: undefined,
  215. gender: '2',
  216. roleId: undefined,
  217. deptId: undefined,
  218. email: undefined,
  219. birthday: undefined,
  220. isPrimary: undefined,
  221. addressDetail: undefined,
  222. addressProvince: undefined,
  223. addressCity: undefined,
  224. addressCounty: undefined,
  225. provincialCityCounty: undefined,
  226. status: '0',
  227. remark: undefined
  228. };
  229. const data = reactive<PageData<CustomerContactForm, CustomerContactQuery>>({
  230. form: { ...initFormData },
  231. queryParams: {
  232. pageNum: 1,
  233. pageSize: 10,
  234. customerId: undefined,
  235. contactName: undefined,
  236. phone: undefined,
  237. officePhone: undefined,
  238. officePhoneTwo: undefined,
  239. gender: undefined,
  240. roleId: undefined,
  241. isPrimary: undefined,
  242. addressDetail: undefined,
  243. addressProvince: undefined,
  244. addressCity: undefined,
  245. addressCounty: undefined,
  246. provincialCityCounty: undefined,
  247. status: undefined,
  248. platformCode: undefined,
  249. params: {}
  250. },
  251. rules: {
  252. contactName: [{ required: true, message: '联系人姓名不能为空', trigger: 'blur' }],
  253. phone: [
  254. { required: true, message: '手机号码不能为空', trigger: 'blur' },
  255. { pattern: /^1[3-9]\d{9}$/ as RegExp, message: '请输入正确的手机号格式', trigger: 'blur' }
  256. ]
  257. }
  258. });
  259. const { queryParams, form, rules } = toRefs(data);
  260. /** 查询客户联系人信息列表 */
  261. const getList = async () => {
  262. loading.value = true;
  263. const res = await listCustomerContact(queryParams.value);
  264. customerContactList.value = res.rows;
  265. total.value = res.total;
  266. loading.value = false;
  267. };
  268. /** 加载角色列表 */
  269. const loadRoleOptions = async () => {
  270. try {
  271. // const res: any = await listRole({
  272. // pageNum: 1,
  273. // pageSize: 9999,
  274. // roleName: '',
  275. // roleKey: '',
  276. // status: ''
  277. // } as any);
  278. // roleOptions.value = res?.rows || res?.data?.rows || res?.data || [];
  279. roleOptions.value = [
  280. { roleId: 1, roleName: '管理角色' },
  281. { roleId: 2, roleName: '采购角色' },
  282. { roleId: 3, roleName: '查询角色' },
  283. { roleId: 4, roleName: '审核角色' }
  284. ];
  285. } catch (error) {
  286. console.error('加载角色列表失败:', error);
  287. roleOptions.value = [];
  288. }
  289. };
  290. const handleDeptChange = (deptId: string | number) => {
  291. const dept = customerDeptList.value.find((d) => d.deptId === deptId);
  292. form.value.deptName = dept?.deptName;
  293. };
  294. const handleRoleChange = (roleId: string | number) => {
  295. const role = roleOptions.value.find((r) => r.roleId === roleId);
  296. form.value.roleName = role?.roleName;
  297. };
  298. /** 加载客户部门列表 */
  299. const loadCustomerDeptList = async () => {
  300. try {
  301. const query: CustomerDeptQuery = {};
  302. const res = await listCustomerDept(query);
  303. // 将数据转换为树形结构
  304. customerDeptList.value = proxy?.handleTree<CustomerDeptVO>(res.data, 'id', 'parentId') || [];
  305. } catch (error) {
  306. console.error('加载部门列表失败:', error);
  307. }
  308. };
  309. /** 状态修改 */
  310. const handlePrimaryChange = async (row: any) => {
  311. // const text = row.status === '0' ? '是' : '否';
  312. try {
  313. // await proxy?.$modal.confirm('确认要"' + text + '"吗?');
  314. await changeIsPrimary(row.id, row.isPrimary);
  315. proxy?.$modal.msgSuccess('操作成功');
  316. getList();
  317. } catch (err) {
  318. row.status = row.status === '0' ? '1' : '0';
  319. }
  320. };
  321. /** 取消按钮 */
  322. const cancel = () => {
  323. reset();
  324. dialog.visible = false;
  325. };
  326. /** 表单重置 */
  327. const reset = () => {
  328. form.value = { ...initFormData };
  329. codeArr.value = [];
  330. customerContactFormRef.value?.resetFields();
  331. };
  332. /** 搜索按钮操作 */
  333. const handleQuery = () => {
  334. queryParams.value.pageNum = 1;
  335. getList();
  336. };
  337. /** 处理区域选择变化 */
  338. const handleChange = (val: string[]) => {
  339. // 保存编码
  340. form.value.addressProvince = val[0];
  341. form.value.addressCity = val[1];
  342. form.value.addressCounty = val[2];
  343. // 根据编码获取名称
  344. const names: string[] = [];
  345. if (val[0]) {
  346. const province = regionData.find((item: any) => item.value === val[0]);
  347. if (province) {
  348. names.push(province.label);
  349. if (val[1] && province.children) {
  350. const city = province.children.find((item: any) => item.value === val[1]);
  351. if (city) {
  352. names.push(city.label);
  353. if (val[2] && city.children) {
  354. const county = city.children.find((item: any) => item.value === val[2]);
  355. if (county) {
  356. names.push(county.label);
  357. }
  358. }
  359. }
  360. }
  361. }
  362. }
  363. // 将省市区名称用斜杠连接
  364. form.value.provincialCityCounty = names.join('/');
  365. };
  366. /** 重置按钮操作 */
  367. const resetQuery = () => {
  368. queryFormRef.value?.resetFields();
  369. handleQuery();
  370. };
  371. /** 多选框选中数据 */
  372. const handleSelectionChange = (selection: CustomerContactVO[]) => {
  373. ids.value = selection.map((item) => item.id);
  374. single.value = selection.length != 1;
  375. multiple.value = !selection.length;
  376. };
  377. /** 修改按钮操作 */
  378. const handleUpdate = async (row?: CustomerContactVO) => {
  379. reset();
  380. // 加载部门列表
  381. await loadCustomerDeptList();
  382. const _id = row?.id || ids.value[0];
  383. const res = await getCustomerContact(_id);
  384. // 如果有省市区编码,回显到级联选择器
  385. if (res.data.addressProvince && res.data.addressCity && res.data.addressCounty) {
  386. codeArr.value = [res.data.addressProvince, res.data.addressCity, res.data.addressCounty] as any;
  387. }
  388. Object.assign(form.value, res.data);
  389. dialog.visible = true;
  390. dialog.title = '修改客户联系人信息';
  391. };
  392. /** 提交按钮 */
  393. const submitForm = () => {
  394. customerContactFormRef.value?.validate(async (valid: boolean) => {
  395. if (valid) {
  396. buttonLoading.value = true;
  397. if (form.value.id) {
  398. await updateCustomerContact(form.value).finally(() => (buttonLoading.value = false));
  399. } else {
  400. await addCustomerContact(form.value).finally(() => (buttonLoading.value = false));
  401. }
  402. proxy?.$modal.msgSuccess('操作成功');
  403. dialog.visible = false;
  404. await getList();
  405. }
  406. });
  407. };
  408. /** 删除按钮操作 */
  409. const handleDelete = async (row?: CustomerContactVO) => {
  410. const _ids = row?.id || ids.value;
  411. await proxy?.$modal.confirm('是否确认删除客户联系人信息编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
  412. await delCustomerContact(_ids);
  413. proxy?.$modal.msgSuccess('删除成功');
  414. await getList();
  415. };
  416. /** 导出按钮操作 */
  417. const handleExport = () => {
  418. proxy?.download(
  419. 'customer/customerContact/export',
  420. {
  421. ...queryParams.value
  422. },
  423. `customerContact_${new Date().getTime()}.xlsx`
  424. );
  425. };
  426. onMounted(() => {
  427. loadRoleOptions();
  428. getList();
  429. });
  430. </script>