relatedContacts.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div class="relatedTasks pl-4 pr-4 pt-3 pb-3 h-full flex flex-col">
  3. <div class="flex justify-between">
  4. <div class="title">相关联系人</div>
  5. <div v-permission="['contactsAdd']">
  6. <el-button type="primary" @click="editContacts(information)">新建联系人</el-button>
  7. </div>
  8. </div>
  9. <div class="flex-1 overflow-auto pt-3">
  10. <el-table :data="relatedCustomertable" border style="width: 100%;height: 300px;">
  11. <el-table-column label="序号" width="80">
  12. <template #default="scope">
  13. {{ scope.$index + 1 }}
  14. </template>
  15. </el-table-column>
  16. <el-table-column prop="name" label="联系人姓名">
  17. <template #default="scope">
  18. <el-button link type="primary" size="large">{{
  19. scope.row.name
  20. }}</el-button>
  21. </template>
  22. </el-table-column>
  23. <el-table-column prop="phone" label="电话号码" width="130" />
  24. <el-table-column prop="email" label="邮箱" width="130" />
  25. <el-table-column prop="position" label="职务" width="130" />
  26. <el-table-column prop="sexValue" label="性别" width="130" />
  27. <el-table-column prop="ownerName" label="负责人" width="130" />
  28. <el-table-column prop="creatorName" label="创建人" width="130" />
  29. <el-table-column prop="createTime" label="创建时间" width="130" />
  30. </el-table>
  31. </div>
  32. <!-- 弹窗 -->
  33. <el-dialog v-model="allVisible.editContactsVisible" width="1000" :show-close="false" top="10vh">
  34. <template #header="{ close, titleId, titleClass }">
  35. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  36. <h4 :id="titleId">{{ '新建联系人' }}</h4>
  37. <div>
  38. <el-button type="primary" :loading="allLoading.editContactsSaveLoading"
  39. @click="editContactsSave(false)">新建</el-button>
  40. <el-button @click="closeVisible('editContactsVisible')">取消</el-button>
  41. </div>
  42. </div>
  43. </template>
  44. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3">
  45. <div class="ml-4 mr-4">
  46. <GenerateForm ref="contactsTemplateRef" :data="contactsTemplate" :value="contactsTemplateValue"
  47. :key="contactsTemplateRefKey" v-loading="allLoading.contactsTemplateRefLoading" />
  48. </div>
  49. </div>
  50. </el-dialog>
  51. </div>
  52. </template>
  53. <script lang="ts" setup>
  54. import { GETGENERATEFOEM, URL_ADD } from '@/pages/contacts/api';
  55. import { get, post } from '@/utils/request';
  56. import { setTemplateDataDisable } from '@/utils/tools';
  57. import { GenerateForm } from '@zmjs/form-design';
  58. import { ref, reactive, onMounted, onUnmounted, defineExpose, inject, watchEffect } from 'vue'
  59. const emits = defineEmits(['refreshData']);
  60. const globalPopup = inject<GlobalPopup>('globalPopup')
  61. const props = defineProps<{
  62. data: any
  63. }>()
  64. const information = ref({})
  65. const relatedCustomertable = ref([])
  66. const contactsTemplateValue = ref({})
  67. const contactsTemplateRefKey = ref(1)
  68. const contactsTemplateRef = ref<typeof GenerateForm>()
  69. const contactsTemplate = ref({
  70. list: [],
  71. config: {}
  72. })
  73. function editContactsSave(flag: boolean) {
  74. contactsTemplateRef.value?.getData().then((res: any) => {
  75. allLoading.editContactsSaveLoading = true
  76. post(URL_ADD, { ...contactsTemplateValue.value, ...res }).then((_res) => {
  77. allVisible.editContactsVisible = flag
  78. globalPopup?.showSuccess('操作成功')
  79. if (flag) {
  80. contactsTemplateRef.value?.reset()
  81. }
  82. emits('refreshData')
  83. }).finally(() => {
  84. allLoading.editContactsSaveLoading = false
  85. })
  86. }).catch((_err: any) => {
  87. console.log(_err)
  88. globalPopup?.showError('请填写完整')
  89. })
  90. }
  91. function editContacts(data: any) {
  92. showVisible('editContactsVisible')
  93. const { id, telPhone } = data
  94. contactsTemplateValue.value = { customId: id, phone: telPhone }
  95. allLoading.contactsTemplateRefLoading = true
  96. setTimeout(() => {
  97. contactsTemplateRefKey.value++
  98. allLoading.contactsTemplateRefLoading = false
  99. }, 1000);
  100. }
  101. const allLoading = reactive({
  102. contactsTemplateRefLoading: false,
  103. editContactsSaveLoading: false
  104. })
  105. const allVisible = reactive({
  106. editContactsVisible: false,
  107. })
  108. watchEffect(() => {
  109. const { data } = props
  110. information.value = data
  111. relatedCustomertable.value = (data.contacts || [])
  112. })
  113. async function getSystemField() {
  114. const datas = await get(GETGENERATEFOEM)
  115. let newConfig = JSON.parse(datas.data[0].config)
  116. newConfig.list = setTemplateDataDisable(newConfig.list, ['customId'])
  117. contactsTemplate.value = newConfig
  118. }
  119. function showVisible(type: keyof typeof allVisible) {
  120. allVisible[type] = true
  121. }
  122. function closeVisible(type: keyof typeof allVisible) {
  123. allVisible[type] = false
  124. }
  125. // 生命周期钩子
  126. onMounted(() => {
  127. getSystemField()
  128. });
  129. </script>
  130. <style scoped lang="scss">
  131. .relatedTasks {
  132. .title {
  133. font-size: 18px;
  134. color: #000
  135. }
  136. }
  137. </style>