information.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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" @click="associateContact()" v-if="!information.cuntactsId">关联联系人</el-button>
  7. <el-button type="primary" @click="claimBusiness()" v-if="!information.customerId">认领</el-button>
  8. <el-button type="primary" @click="showVisible('transferBusinessVisible')"
  9. v-if="information.customerId">转移</el-button>
  10. <el-button type="primary" @click="showVisible('editBusinessVisible')">编辑</el-button>
  11. </div>
  12. </div>
  13. <div class="form flex flex-wrap justify-between">
  14. <div class="formItem flex pt-5 pb-1">
  15. <div class="w-20 text-right text-gray-500">商机名称:</div>
  16. <div class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap ml-1">{{ information.name }}</div>
  17. </div>
  18. <div class="formItem flex pt-5 pb-1">
  19. <div class="w-22 text-right text-gray-500">客户名称:</div>
  20. <div class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap ml-1">{{ information.customerName }}
  21. </div>
  22. </div>
  23. <div class="formItem flex pt-5 pb-1">
  24. <div class="w-22 text-right text-gray-500">联系人:</div>
  25. <div class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap ml-1">{{ information.contactsName }}
  26. </div>
  27. </div>
  28. <div class="formItem flex pt-5 pb-1">
  29. <div class="w-22 text-right text-gray-500">商机金额:</div>
  30. <div class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap ml-1">{{ information.amountOfMoney || 0
  31. }} 元</div>
  32. </div>
  33. <div class="formItem flex pt-5 pb-1">
  34. <div class="w-22 text-right text-gray-500">负责人:</div>
  35. <div class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap ml-1">{{ information.creatorName }}</div>
  36. </div>
  37. <div class="formItem flex pt-5 pb-1">
  38. <div class="w-22 text-right text-gray-500">预计成交日期:</div>
  39. <div class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap ml-1">{{
  40. information.expectedTransactionDate }}</div>
  41. </div>
  42. <div class="formItem flex pt-5 pb-1" style="width: 100%;">
  43. <div class="w-22 text-right text-gray-500">备注:</div>
  44. <div class="flex-1 ml-1 text ">
  45. {{ information.remark }}
  46. </div>
  47. </div>
  48. </div>
  49. <!-- 编辑弹窗 -->
  50. <el-dialog v-model="allVisible.editBusinessVisible" width="1000" :show-close="false" top="10vh">
  51. <template #header="{ close, titleId, titleClass }">
  52. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  53. <h4 :id="titleId">{{ '编辑产品' }}</h4>
  54. <div>
  55. <el-button type="primary" @click="editBusiness()"
  56. :loading="allLoading.businessSaveLading">保存</el-button>
  57. <el-button @click="closeVisible('editBusinessVisible')">取消</el-button>
  58. </div>
  59. </div>
  60. </template>
  61. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3">
  62. <GenerateForm ref="generateForm" :data="generateFormData" :value="generateFormValue" />
  63. </div>
  64. </el-dialog>
  65. <!-- 转移 -->
  66. <el-dialog v-model="allVisible.transferBusinessVisible" width="600" :show-close="false" top="10vh">
  67. <template #header="{ close, titleId, titleClass }">
  68. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  69. <h4 :id="titleId">{{ '转移商机' }}</h4>
  70. <div>
  71. <el-button type="primary" :loading="allLoading.transferBusinessLoading"
  72. @click="transferBusiness()">转移</el-button>
  73. <el-button @click="allVisible.transferBusinessVisible = false">取消</el-button>
  74. </div>
  75. </div>
  76. </template>
  77. <div class="scroll-bar m-6">
  78. <div class="flex mb-4">
  79. <div class="w-20 flex items-center justify-end pr-4">转移至:</div>
  80. <el-select v-model="transferValue" placeholder="请选择" class="flex1">
  81. <el-option v-for="item in transferOptions" :key="item.id" :label="item.name" :value="item.id" />
  82. </el-select>
  83. </div>
  84. <div class="pl-3 text-[#e94a4a]">转移后,将看不到此商机</div>
  85. </div>
  86. </el-dialog>
  87. <!-- 关联 -->
  88. <el-dialog v-model="allVisible.saveContactVisible" width="600" :show-close="false" top="10vh">
  89. <template #header="{ close, titleId, titleClass }">
  90. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  91. <h4 :id="titleId">{{ '关联联系人' }}</h4>
  92. <div>
  93. <el-button type="primary" :loading="allLoading.saveContactLoading"
  94. @click="saveAssociateContact()">关联</el-button>
  95. <el-button @click="allVisible.saveContactVisible = false">取消</el-button>
  96. </div>
  97. </div>
  98. </template>
  99. <div class="scroll-bar m-6">
  100. <div class="flex mb-4">
  101. <div class="w-20 flex items-center justify-end pr-4">联系人:</div>
  102. <el-select v-model="contactsId" placeholder="请选择" class="flex1">
  103. <el-option v-for="item in contactsList" :key="item.value" :label="item.label" :value="item.value" />
  104. </el-select>
  105. </div>
  106. </div>
  107. </el-dialog>
  108. </div>
  109. </template>
  110. <script lang="ts" setup>
  111. import { ref, reactive, onMounted, onUnmounted, defineExpose, inject, watchEffect } from 'vue'
  112. import { GenerateForm } from '@zmjs/form-design';
  113. import { get, post } from '@/utils/request';
  114. import { BATCHTRANSFER, GETGENERATEFOEM, GETPERSONNEL, UPDATEINSET, URL_SAVECONTACT } from '../api';
  115. import { formatDateTime } from '@/utils/times';
  116. import { confirmAction } from '@/utils/tools';
  117. import { useStore } from '@/store/index'
  118. import { URL_GETALL } from '@/pages/contacts/api';
  119. const { userInfo } = useStore()
  120. const globalPopup = inject<GlobalPopup>('globalPopup')
  121. const emits = defineEmits(['refreshData']);
  122. const props = defineProps<{
  123. information: any
  124. }>()
  125. const information = ref<any>({})
  126. const transferValue = ref('')
  127. const transferOptions = ref<personnelInterface[]>([])
  128. const generateFormValue = ref({})
  129. const generateForm = ref<typeof GenerateForm>() // 自定义表单dom
  130. const contactsId = ref('')
  131. const contactsList = ref<optionType[]>([])
  132. const allVisible = reactive({
  133. editBusinessVisible: false,
  134. transferBusinessVisible: false,
  135. saveContactVisible: false
  136. })
  137. const allLoading = reactive({
  138. editBusinessLoading: false,
  139. businessSaveLading: false,
  140. transferBusinessLoading: false,
  141. saveContactLoading: false
  142. })
  143. const generateFormData = ref({
  144. config: {},
  145. list: []
  146. }) // 自定义表单数据
  147. function associateContact() {
  148. contactsId.value = ''
  149. getContactList()
  150. showVisible('saveContactVisible')
  151. }
  152. function getContactList() {
  153. post(URL_GETALL, { customerId: information.value.customerId }).then(({ data }) => {
  154. contactsList.value = data.map((item: any) => {
  155. return { value: item.id, label: item.name }
  156. })
  157. })
  158. }
  159. function saveAssociateContact() {
  160. allLoading.saveContactLoading = false
  161. post(URL_SAVECONTACT, { id: information.value.id, contactsId: contactsId.value }).then(() => {
  162. globalPopup?.showSuccess('关联成功')
  163. closeVisible('saveContactVisible')
  164. emits('refreshData')
  165. }).finally(() => {
  166. allLoading.saveContactLoading = false
  167. })
  168. }
  169. function transferBusiness() {
  170. const ids = information.value?.id
  171. const inchargerId = information.value?.inchargerName ? transferValue.value : userInfo.id
  172. if (!inchargerId) {
  173. globalPopup?.showWarning('请选择转移的人员')
  174. return
  175. }
  176. allLoading.transferBusinessLoading = true
  177. post(BATCHTRANSFER, { ids, inchargerId }).then((res) => {
  178. if (res.code == 'ok') {
  179. globalPopup?.showSuccess('操作成功')
  180. allVisible.transferBusinessVisible = false
  181. emits('refreshData')
  182. }
  183. }).finally(() => {
  184. allLoading.transferBusinessLoading = false
  185. })
  186. }
  187. function claimBusiness() {
  188. confirmAction(`确定认领【${information.value.name}】商机吗?`).then(() => {
  189. console.log('执行认领')
  190. })
  191. }
  192. function editBusiness() {
  193. console.log('点击了保存')
  194. return
  195. generateForm.value?.getData().then((res: any) => {
  196. let formVal = {
  197. ...res,
  198. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  199. }
  200. allLoading.businessSaveLading = true
  201. post(UPDATEINSET, { ...formVal }).then((_res) => {
  202. allVisible.editBusinessVisible = false
  203. globalPopup?.showSuccess('保存成功')
  204. emits('refreshData')
  205. }).finally(() => {
  206. allLoading.businessSaveLading = false
  207. })
  208. }).catch((_err: any) => {
  209. console.log(_err)
  210. globalPopup?.showError('请填写完整')
  211. })
  212. }
  213. function showVisible(type: keyof typeof allVisible) {
  214. if (type == 'editBusinessVisible') {
  215. const { name, customerId, contactsId, amountOfMoney, expectedTransactionDate, stageId, inchargerId, remark } = information.value
  216. generateFormValue.value = { name, customerId, contactsId, amountOfMoney, expectedTransactionDate, stageId, inchargerId, remark }
  217. }
  218. allVisible[type] = true
  219. }
  220. function closeVisible(type: keyof typeof allVisible) {
  221. allVisible[type] = false
  222. }
  223. async function getSystemField() {
  224. const { data } = await post(GETPERSONNEL, {})
  225. transferOptions.value = data.map((item: any) => {
  226. const { id, name, phone, jobNumber } = item
  227. return {
  228. id, name, phone, jobNumber
  229. }
  230. })
  231. const res = await get(GETGENERATEFOEM)
  232. generateFormData.value = JSON.parse(res.data[0].config)
  233. }
  234. watchEffect(() => {
  235. information.value = props.information
  236. });
  237. // 生命周期钩子
  238. onMounted(() => {
  239. getSystemField()
  240. });
  241. </script>
  242. <style scoped lang="scss">
  243. .information {
  244. .title {
  245. font-size: 18px;
  246. color: #000
  247. }
  248. .form {
  249. .formItem {
  250. width: 48%;
  251. }
  252. .text {
  253. display: -webkit-box;
  254. /* Safari */
  255. -webkit-line-clamp: 2;
  256. /* number of lines to show */
  257. -webkit-box-orient: vertical;
  258. overflow: hidden;
  259. line-height: 1.5;
  260. }
  261. }
  262. }</style>