information.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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">{{ businessLabel }}名称:</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">{{ businessLabel }}金额:</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">转移{{ businessLabel }}</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]">转移后,将看不到此{{ businessLabel }}</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, 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 isExistBusiness = sessionStorage.getItem("isExistBusiness");
  142. const businessLabel = isExistBusiness === "1" ? "商机" : "项目";
  143. const information = ref<any>({})
  144. const transferValue = ref('')
  145. const transferOptions = ref<personnelInterface[]>([])
  146. const generateFormValue = ref({})
  147. const generateForm = ref<typeof GenerateForm>() // 自定义表单dom
  148. const productTableListValue = ref<any[]>([])
  149. const contactsId = ref('')
  150. const contactsList = ref<optionType[]>([])
  151. const allVisible = reactive({
  152. editBusinessVisible: false,
  153. transferBusinessVisible: false,
  154. saveContactVisible: false
  155. })
  156. const allLoading = reactive({
  157. editBusinessLoading: false,
  158. businessSaveLading: false,
  159. transferBusinessLoading: false,
  160. saveContactLoading: false
  161. })
  162. const generateFormData = ref({
  163. config: {},
  164. list: []
  165. }) // 自定义表单数据
  166. function associateContact() {
  167. contactsId.value = ''
  168. getContactList()
  169. showVisible('saveContactVisible')
  170. }
  171. function getContactList() {
  172. post(URL_GETALL, { customerId: information.value.customerId }).then(({ data }) => {
  173. contactsList.value = data.map((item: any) => {
  174. return { value: item.id, label: item.name }
  175. })
  176. })
  177. }
  178. function saveAssociateContact() {
  179. allLoading.saveContactLoading = false
  180. post(URL_SAVECONTACT, { id: information.value.id, contactsId: contactsId.value }).then(() => {
  181. globalPopup?.showSuccess('关联成功')
  182. closeVisible('saveContactVisible')
  183. emits('refreshData')
  184. }).finally(() => {
  185. allLoading.saveContactLoading = false
  186. })
  187. }
  188. function transferBusiness() {
  189. const ids = information.value?.id
  190. const inchargerId = information.value?.inchargerName ? transferValue.value : userInfo.id
  191. if (!inchargerId) {
  192. globalPopup?.showWarning('请选择转移的人员')
  193. return
  194. }
  195. allLoading.transferBusinessLoading = true
  196. post(BATCHTRANSFER, { ids, inchargerId }).then((res) => {
  197. if (res.code == 'ok') {
  198. globalPopup?.showSuccess('操作成功')
  199. allVisible.transferBusinessVisible = false
  200. emits('refreshData')
  201. }
  202. }).finally(() => {
  203. allLoading.transferBusinessLoading = false
  204. })
  205. }
  206. function claimBusiness() {
  207. confirmAction(`确定认领【${information.value.name}】${businessLabel}吗?`).then(() => {
  208. transferBusiness()
  209. })
  210. }
  211. function editBusiness() {
  212. generateForm.value?.getData().then((res: any) => {
  213. let formVal = {
  214. id: information.value.id,
  215. ...res,
  216. expectedTransactionDate: res.expectedTransactionDate ? formatDate(new Date(res.expectedTransactionDate)) : '',
  217. businessItemProductList: JSON.stringify(productTableListValue.value)
  218. }
  219. allLoading.businessSaveLading = true
  220. post(UPDATEINSET, { ...formVal }).then((_res) => {
  221. allVisible.editBusinessVisible = false
  222. globalPopup?.showSuccess('保存成功')
  223. emits('refreshData')
  224. }).finally(() => {
  225. allLoading.businessSaveLading = false
  226. })
  227. }).catch((_err: any) => {
  228. console.log(_err)
  229. globalPopup?.showError('请填写完整')
  230. })
  231. }
  232. function editProductShow() {
  233. const productList = information.value.businessItemProducts || []
  234. const list = productList.map((item: any) => {
  235. const { id, productName, productId, productCode, unit, unitName, typeName, type, price, inventory, orderProductDetail, num, discount, sealPrice, totalPrice, quantity } = item
  236. return {
  237. id, productId: productId, productName, productCode, unit, unitName, typeName, type, price, inventory,
  238. num, discount, sealPrice, totalPrice, quantity
  239. }
  240. })
  241. productTableListValue.value = list
  242. }
  243. function showVisible(type: keyof typeof allVisible) {
  244. if (type == 'editBusinessVisible') {
  245. const { name, customerId, contactsId, amountOfMoney, expectedTransactionDate, stageId, inchargerId, remark } = information.value
  246. generateFormValue.value = { name, customerId, contactsId, amountOfMoney, expectedTransactionDate, stageId, inchargerId, remark }
  247. editProductShow()
  248. }
  249. allVisible[type] = true
  250. }
  251. function closeVisible(type: keyof typeof allVisible) {
  252. allVisible[type] = false
  253. }
  254. async function getSystemField() {
  255. const { data } = await post(GETPERSONNEL, {})
  256. transferOptions.value = data.map((item: any) => {
  257. const { id, name, phone, jobNumber } = item
  258. return {
  259. id, name, phone, jobNumber
  260. }
  261. })
  262. const res = await get(GETGENERATEFOEM)
  263. generateFormData.value = JSON.parse(res.data[0].config)
  264. }
  265. watchEffect(() => {
  266. information.value = props.information
  267. });
  268. // 生命周期钩子
  269. onMounted(() => {
  270. getSystemField()
  271. });
  272. </script>
  273. <style scoped lang="scss">
  274. .information {
  275. .title {
  276. font-size: 18px;
  277. color: #606266
  278. }
  279. .form {
  280. .formItem {
  281. width: 48%;
  282. }
  283. .text {
  284. display: -webkit-box;
  285. /* Safari */
  286. -webkit-line-clamp: 2;
  287. /* number of lines to show */
  288. -webkit-box-orient: vertical;
  289. overflow: hidden;
  290. line-height: 1.5;
  291. }
  292. }
  293. }</style>