relatedContacts.vue 6.3 KB

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