contactInfo.vue 14 KB

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