relatedContacts.vue 5.8 KB

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