information.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div class="information pl-4 pr-4 pt-3 pb-3">
  3. <div class="flex justify-between">
  4. <div class="title">基本信息</div>
  5. <div>
  6. <el-button type="primary" v-if="!info.ownerId">认领</el-button>
  7. <el-button type="primary" v-else @click="operationCli(false)">转移</el-button>
  8. <el-button type="primary" v-permission="['contactsEdit']" @click="editInfo(info)">编辑</el-button>
  9. </div>
  10. </div>
  11. <div class="form flex flex-wrap justify-between">
  12. <div v-for="item in formItems" :key="item.label" class="formItem flex pt-2 pb-1" :style="{ width: item.width }">
  13. <div :class="item.labelClass">{{ item.label }}:</div>
  14. <div class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap ml-1" v-ellipsis-tooltip>{{ item.value }}</div>
  15. </div>
  16. </div>
  17. <el-dialog v-model="allVisible.editContactsVisible" width="1000" :show-close="false" top="10vh">
  18. <template #header="{ close, titleId, titleClass }">
  19. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  20. <h4 :id="titleId">编辑联系人</h4>
  21. <div>
  22. <el-button type="primary" @click="editContactsSave()"
  23. :loading="allLoading.editContactsSaveLoading">保存</el-button>
  24. <el-button @click="closeVisible('editContactsVisible')">取消</el-button>
  25. </div>
  26. </div>
  27. </template>
  28. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3">
  29. <div class="ml-4 mr-4">
  30. <GenerateForm ref="contactsTemplateRef" :data="contactsTemplate" :value="contactsTemplateValue"
  31. :key="contactsTemplateRefKey" v-loading="allLoading.contactsTemplateRefLoading" />
  32. </div>
  33. </div>
  34. </el-dialog>
  35. <el-dialog v-model="allVisible.transferVisible" width="600" :show-close="false" top="10vh">
  36. <template #header="{ close, titleId, titleClass }">
  37. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  38. <h4 :id="titleId">{{ allText.operationText }}</h4>
  39. <div>
  40. <el-button type="primary" :loading="allLoading.transferLoading"
  41. @click="transferBusiness(true)">转移</el-button>
  42. <el-button @click="allVisible.transferVisible = false">取消</el-button>
  43. </div>
  44. </div>
  45. </template>
  46. <div class="scroll-bar m-6">
  47. <div class="flex mb-4">
  48. <div class="w-20 flex items-center justify-end pr-4">转移至:</div>
  49. <el-select v-model="transferValue" placeholder="请选择" class="flex1">
  50. <el-option v-for="item in transferOptions" :key="item.value" :label="item.label"
  51. :value="item.value" />
  52. </el-select>
  53. </div>
  54. <div class="pl-3 text-[#e94a4a]">转移后,将看不到此联系人</div>
  55. </div>
  56. </el-dialog>
  57. </div>
  58. </template>
  59. <script lang="ts" setup>
  60. import { ref, reactive, onMounted, onUnmounted, defineExpose, inject, watchEffect } from 'vue'
  61. import { GenerateForm } from '@zmjs/form-design';
  62. import { getFromValue, getTemplateKey } from '@/utils/tools';
  63. import { GETGENERATEFOEM, GETPERSONNEL, URL_TRANSFERCONTACTS, URL_UPLOAD } from '../api';
  64. import { get, post } from '@/utils/request';
  65. const globalPopup = inject<GlobalPopup>('globalPopup')
  66. const emits = defineEmits(['refreshData']);
  67. const props = defineProps<{
  68. data: any
  69. }>()
  70. const allLoading = reactive({
  71. contactsTemplateRefLoading: false,
  72. editContactsSaveLoading: false,
  73. transferLoading: false
  74. })
  75. const allVisible = reactive({
  76. editContactsVisible: false,
  77. transferVisible: false
  78. })
  79. const allText = reactive({
  80. operationText: '认领联系人'
  81. })
  82. const contactsTemplate = ref({
  83. list: [],
  84. config: {}
  85. })
  86. const contactsTemplateValue = ref({})
  87. const contactsTemplateRef = ref<typeof GenerateForm>()
  88. const contactsTemplateRefKey = ref(1)
  89. const info: any = ref({})
  90. const transferValue = ref('')
  91. const transferOptions = ref<optionType[]>([])
  92. function operationCli(flag: boolean) {
  93. transferValue.value = flag ? '' : info.value.ownerId
  94. allText.operationText = flag ? '认领联系人' : '转移联系人'
  95. showVisible('transferVisible')
  96. }
  97. function transferBusiness(flag: boolean) {
  98. const url = flag ? URL_TRANSFERCONTACTS : ''
  99. const formVal = flag ? { id: info.value.id, ownerId: transferValue.value } : {}
  100. allLoading.transferLoading = true
  101. post(url, { ...formVal }).then((_res) => {
  102. closeVisible('transferVisible')
  103. globalPopup?.showSuccess('转移成功')
  104. emits('refreshData')
  105. }).finally(() => {
  106. allLoading.transferLoading = false
  107. })
  108. }
  109. function editInfo(row: any) {
  110. showVisible('editContactsVisible')
  111. const templateKey = getTemplateKey(contactsTemplate.value.list)
  112. const formVal: templateKey = { id: row.id }
  113. for (let i in templateKey) {
  114. if (row[templateKey[i]] || row[templateKey[i]] == 0) {
  115. formVal[templateKey[i]] = templateKey[i] == 'sex' ? row[templateKey[i]] + '' : row[templateKey[i]]
  116. }
  117. }
  118. setTemplateVal(formVal)
  119. }
  120. function editContactsSave(flag: boolean = false) {
  121. contactsTemplateRef.value?.getData().then((res: any) => {
  122. let formVal = getFromValue({ ...contactsTemplateValue.value, ...res })
  123. allLoading.editContactsSaveLoading = true
  124. post(URL_UPLOAD, { ...formVal }).then((_res) => {
  125. allVisible.editContactsVisible = flag
  126. globalPopup?.showSuccess('保存成功')
  127. emits('refreshData')
  128. }).finally(() => {
  129. allLoading.editContactsSaveLoading = false
  130. })
  131. }).catch((_err: any) => {
  132. console.log(_err)
  133. globalPopup?.showError('请填写完整')
  134. })
  135. }
  136. function setTemplateVal(val: any = {}) {
  137. contactsTemplateValue.value = val
  138. allLoading.contactsTemplateRefLoading = true
  139. setTimeout(() => {
  140. contactsTemplateRefKey.value++
  141. allLoading.contactsTemplateRefLoading = false
  142. }, 1000);
  143. }
  144. function showVisible(type: keyof typeof allVisible) {
  145. allVisible[type] = true
  146. }
  147. function closeVisible(type: keyof typeof allVisible) {
  148. allVisible[type] = false
  149. }
  150. const formItems = reactive([
  151. { label: '联系人', key: 'name', value: '', labelClass: 'w-20 text-right text-gray-500', width: '48%' },
  152. { label: '客户', key: 'customName', value: '', labelClass: 'w-22 text-right text-gray-500', width: '48%' },
  153. { label: '电话', key: 'phone', value: '', labelClass: 'w-22 text-right text-gray-500', width: '48%' },
  154. { label: '邮箱', key: 'email', value: '', labelClass: 'w-22 text-right text-gray-500', width: '48%' },
  155. { label: '职务', key: 'position', value: '', labelClass: 'w-22 text-right text-gray-500', width: '48%' },
  156. { label: '性别', key: 'sexValue', value: '', labelClass: 'w-22 text-right text-gray-500', width: '48%' },
  157. { label: '地址', key: 'address', value: '', labelClass: 'w-22 text-right text-gray-500', width: '48%' },
  158. { label: '负责人', key: 'ownerName', value: '', labelClass: 'w-22 text-right text-gray-500', width: '48%' },
  159. { label: '创建人', key: 'creatorName', value: '', labelClass: 'w-22 text-right text-gray-500', width: '48%' },
  160. { label: '创建时间', key: 'createTime', value: '', labelClass: 'w-22 text-right text-gray-500', width: '48%' },
  161. { label: '备注', key: 'remark', value: '', labelClass: 'w-22 text-right text-gray-500', width: '100%' },
  162. ])
  163. watchEffect(() => {
  164. const { data } = props
  165. info.value = data
  166. formItems.forEach(item => {
  167. item.value = info.value[item.key];
  168. });
  169. });
  170. async function getSystemField() {
  171. const { data } = await post(GETPERSONNEL, {})
  172. transferOptions.value = data.map((item: any) => {
  173. const { id, name, phone, jobNumber } = item
  174. return {
  175. value: id,
  176. label: name
  177. }
  178. })
  179. const datas = await get(GETGENERATEFOEM)
  180. contactsTemplate.value = JSON.parse(datas.data[0].config)
  181. }
  182. // 生命周期钩子
  183. onMounted(async () => {
  184. getSystemField()
  185. });
  186. </script>
  187. <style scoped lang="scss">
  188. .information {
  189. .title {
  190. font-size: 18px;
  191. color: #000
  192. }
  193. .form {
  194. .formItem {
  195. .text {
  196. display: -webkit-box;
  197. /* Safari */
  198. -webkit-line-clamp: 2;
  199. /* number of lines to show */
  200. -webkit-box-orient: vertical;
  201. overflow: hidden;
  202. line-height: 1.5;
  203. }
  204. }
  205. .w-20,
  206. .w-22 {
  207. width: 80px;
  208. }
  209. }
  210. }
  211. </style>