information.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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.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 productTableListValue = ref<any[]>([])
  131. const contactsId = ref('')
  132. const contactsList = ref<optionType[]>([])
  133. const allVisible = reactive({
  134. editBusinessVisible: false,
  135. transferBusinessVisible: false,
  136. saveContactVisible: false
  137. })
  138. const allLoading = reactive({
  139. editBusinessLoading: false,
  140. businessSaveLading: false,
  141. transferBusinessLoading: false,
  142. saveContactLoading: false
  143. })
  144. const generateFormData = ref({
  145. config: {},
  146. list: []
  147. }) // 自定义表单数据
  148. function associateContact() {
  149. contactsId.value = ''
  150. getContactList()
  151. showVisible('saveContactVisible')
  152. }
  153. function getContactList() {
  154. post(URL_GETALL, { customerId: information.value.customerId }).then(({ data }) => {
  155. contactsList.value = data.map((item: any) => {
  156. return { value: item.id, label: item.name }
  157. })
  158. })
  159. }
  160. function saveAssociateContact() {
  161. allLoading.saveContactLoading = false
  162. post(URL_SAVECONTACT, { id: information.value.id, contactsId: contactsId.value }).then(() => {
  163. globalPopup?.showSuccess('关联成功')
  164. closeVisible('saveContactVisible')
  165. emits('refreshData')
  166. }).finally(() => {
  167. allLoading.saveContactLoading = false
  168. })
  169. }
  170. function transferBusiness() {
  171. const ids = information.value?.id
  172. const inchargerId = information.value?.inchargerName ? transferValue.value : userInfo.id
  173. if (!inchargerId) {
  174. globalPopup?.showWarning('请选择转移的人员')
  175. return
  176. }
  177. allLoading.transferBusinessLoading = true
  178. post(BATCHTRANSFER, { ids, inchargerId }).then((res) => {
  179. if (res.code == 'ok') {
  180. globalPopup?.showSuccess('操作成功')
  181. allVisible.transferBusinessVisible = false
  182. emits('refreshData')
  183. }
  184. }).finally(() => {
  185. allLoading.transferBusinessLoading = false
  186. })
  187. }
  188. function claimBusiness() {
  189. confirmAction(`确定认领【${information.value.name}】商机吗?`).then(() => {
  190. transferBusiness()
  191. })
  192. }
  193. function editBusiness() {
  194. generateForm.value?.getData().then((res: any) => {
  195. let formVal = {
  196. ...res,
  197. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  198. businessItemProductList: JSON.stringify(productTableListValue.value)
  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 editProductShow() {
  214. const productList = information.value.businessItemProducts || []
  215. const list = productList.map((item: any) => {
  216. const { id, productName, productId, productCode, unit, unitName, typeName, type, price, inventory, orderProductDetail, num, discount, sealPrice, totalPrice, quantity } = item
  217. return {
  218. id, productId: productId, productName, productCode, unit, unitName, typeName, type, price, inventory,
  219. num, discount, sealPrice, totalPrice, quantity
  220. }
  221. })
  222. productTableListValue.value = list
  223. }
  224. function showVisible(type: keyof typeof allVisible) {
  225. if (type == 'editBusinessVisible') {
  226. const { name, customerId, contactsId, amountOfMoney, expectedTransactionDate, stageId, inchargerId, remark } = information.value
  227. generateFormValue.value = { name, customerId, contactsId, amountOfMoney, expectedTransactionDate, stageId, inchargerId, remark }
  228. editProductShow()
  229. }
  230. allVisible[type] = true
  231. }
  232. function closeVisible(type: keyof typeof allVisible) {
  233. allVisible[type] = false
  234. }
  235. async function getSystemField() {
  236. const { data } = await post(GETPERSONNEL, {})
  237. transferOptions.value = data.map((item: any) => {
  238. const { id, name, phone, jobNumber } = item
  239. return {
  240. id, name, phone, jobNumber
  241. }
  242. })
  243. const res = await get(GETGENERATEFOEM)
  244. generateFormData.value = JSON.parse(res.data[0].config)
  245. }
  246. watchEffect(() => {
  247. information.value = props.information
  248. });
  249. // 生命周期钩子
  250. onMounted(() => {
  251. getSystemField()
  252. });
  253. </script>
  254. <style scoped lang="scss">
  255. .information {
  256. .title {
  257. font-size: 18px;
  258. color: #000
  259. }
  260. .form {
  261. .formItem {
  262. width: 48%;
  263. }
  264. .text {
  265. display: -webkit-box;
  266. /* Safari */
  267. -webkit-line-clamp: 2;
  268. /* number of lines to show */
  269. -webkit-box-orient: vertical;
  270. overflow: hidden;
  271. line-height: 1.5;
  272. }
  273. }
  274. }</style>