information.vue 13 KB

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