index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <div class="h-full flex">
  3. <div class="p-5 w-80 pr-0">
  4. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col">
  5. <div class="flex-1 p-3 overflow-y-auto">
  6. <el-form :model="businessOpportunityForm" label-width="70px" style="max-width: 600px">
  7. <el-form-item label="商机名称">
  8. <el-input v-model="businessOpportunityForm.name" clearable placeholder="请输入"></el-input>
  9. </el-form-item>
  10. <el-form-item label="商机阶段">
  11. <el-select v-model="businessOpportunityForm.stageId" placeholder="请选择">
  12. <el-option v-for="item in fixedData.BusinessStage" :key="item.id" :label="item.name" :value="item.id" />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="客户名称">
  16. <el-input v-model="businessOpportunityForm.customerName" clearable placeholder="请输入"></el-input>
  17. </el-form-item>
  18. <el-form-item label="联系人">
  19. <el-input v-model="businessOpportunityForm.contactPerson" clearable placeholder="请输入"></el-input>
  20. </el-form-item>
  21. <el-form-item label="产品">
  22. <el-select v-model="businessOpportunityForm.product" placeholder="请选择">
  23. <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="负责人">
  27. <el-select v-model="businessOpportunityForm.inchargerId" placeholder="请选择">
  28. <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="创建时间">
  32. <el-date-picker v-model="businessOpportunityForm.startTime" type="date" placeholder="请选择" :clearable="false"
  33. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  34. </el-form-item>
  35. <el-form-item label="">
  36. <el-date-picker v-model="businessOpportunityForm.endTime" type="date" placeholder="请选择" :clearable="false"
  37. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  38. </el-form-item>
  39. </el-form>
  40. </div>
  41. <div class="w-full flex p-3 shadow-[0_-3px_5px_0px_rgba(0,0,0,0.2)]">
  42. <El-button class="w-full" @click="resetForm()">重置</El-Button>
  43. <El-button type="primary" class="w-full" @click="getBusinessTableList()">搜索</El-Button>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="flex-1 p-5 overflow-auto">
  48. <div class="bg-white w-full h-full p-3 shadow-md rounded-md flex flex-col">
  49. <div class="flex justify-end pb-3">
  50. <el-button type="primary" @click="showVisible('newBusinessisible')">新建商机</el-button>
  51. <el-button type="primary" @click="showVisible('batchTransferVisible')"
  52. :disabled="batchTableData.length <= 0">批量转移</el-button>
  53. <el-button type="primary" @click="batchDeteleItem()" :disabled="batchTableData.length <= 0">批量删除</el-button>
  54. <el-button type="primary" @click="showVisible('stageSetVisible')">阶段设置</el-button>
  55. <el-button type="primary" @click="showVisible('deteleBusinessVisible')">回收站</el-button>
  56. <el-button type="primary" @click="showVisible('importVisible')">导入</el-button>
  57. <el-button type="primary" @click="exportBusinessTableList()" :loading="allLoading.exoprtLoading">导出</el-button>
  58. </div>
  59. <div class="flex-1 w-full overflow-hidden">
  60. <el-table ref="businessTableRef" :data="businessTable" border v-loading="allLoading.businessTableLading"
  61. @selection-change="changeBatch" style="width: 100%;height: 100%;">
  62. <el-table-column type="selection" width="55" />
  63. <el-table-column v-for="(item, index) in tableColumn" :prop="item.prop" :label="item.label" :key="index" :width="item.width">
  64. <template #default="scope">
  65. <el-button link type="primary" size="large" @click="dealWithTableColumn(scope.row, item.eventName)" v-if="item.eventName">{{scope.row[item.prop]}}</el-button>
  66. <template v-else>{{scope.row[item.prop]}}</template>
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="操作" fixed="right" width="200">
  70. <template #default="scope">
  71. <el-button link type="primary" size="large"
  72. @click="editShowVisible('newBusinessisible', scope.row)">编辑</el-button>
  73. <el-button link type="primary" size="large" @click="newTask(scope.row)">新建任务</el-button>
  74. <el-button link type="danger" size="large"
  75. @click="businessDeteleItem(scope.row.id, scope.row.name)">删除</el-button>
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. </div>
  80. <div class="flex justify-end pt-3">
  81. <el-pagination layout="total, prev, pager, next, sizes" :total="businessTotalTable"
  82. :hide-on-single-page="true" />
  83. </div>
  84. </div>
  85. </div>
  86. <!-- 弹窗 -->
  87. <el-dialog v-model="allVisible.newBusinessisible" width="1000" :show-close="false" top="10vh"
  88. :before-close="handleClose">
  89. <template #header="{ close, titleId, titleClass }">
  90. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  91. <h4 :id="titleId">{{ allText.newBusinessisibleText }}</h4>
  92. <div>
  93. <el-button type="primary" :loading="allLoading.newBusinessSaveLading"
  94. :disabled="allLoading.businessSaveLading" @click="editBusiness(true)">保存并新建</el-button>
  95. <el-button type="primary" @click="editBusiness(false)" :loading="allLoading.businessSaveLading"
  96. :disabled="allLoading.newBusinessSaveLading">保存</el-button>
  97. <el-button @click="closeVisible('newBusinessisible')">取消</el-button>
  98. </div>
  99. </div>
  100. </template>
  101. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3">
  102. <GenerateForm ref="generateForm" :data="generateFormData" />
  103. <div>相关产品</div>
  104. <RelatedProducts ref="relatedProductsRef" :productTableList="productTableList" />
  105. </div>
  106. </el-dialog>
  107. <!-- 批量转移 -->
  108. <el-dialog v-model="allVisible.batchTransferVisible" width="600" :show-close="false" top="10vh">
  109. <template #header="{ close, titleId, titleClass }">
  110. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  111. <h4 :id="titleId">{{ allText.transferText }}</h4>
  112. <div>
  113. <el-button type="primary" v-loading="allLoading.transferLoading" @click="transferBusiness()">转移</el-button>
  114. <el-button @click="allVisible.batchTransferVisible = false">取消</el-button>
  115. </div>
  116. </div>
  117. </template>
  118. <div class="scroll-bar m-6">
  119. <div class="flex mb-4">
  120. <div class="w-20 flex items-center justify-end pr-4">转移至:</div>
  121. <el-select v-model="transferPersonnel" placeholder="请选择" class="flex1">
  122. <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
  123. </el-select>
  124. </div>
  125. <div class="pl-3 text-[#e94a4a]">转移后,将看不到此商机</div>
  126. </div>
  127. </el-dialog>
  128. <!-- 导入 -->
  129. <el-dialog v-model="allVisible.importVisible" width="680" :show-close="false" top="10vh">
  130. <template #header="{ close, titleId, titleClass }">
  131. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  132. <h4 :id="titleId">导入产品</h4>
  133. <div class="flex">
  134. <el-upload class="upload-demo mr-3" :limit="1" :show-file-list="false" accept=".xlsx" :http-request="importBusiness">
  135. <el-button type="primary" :loading="allLoading.importLoading">导入</el-button>
  136. </el-upload>
  137. <el-button @click="allVisible.importVisible = false">取消</el-button>
  138. </div>
  139. </div>
  140. </template>
  141. <div class="p-8">
  142. <div class="ml-4 mr-4">
  143. <div class="flex items-center">1、点击下载 <el-link type="primary" @click="downloadTemplate(MODURL, '商机导入模板.xlsx')">商机导入模板.xlsx</el-link></div>
  144. <div class="mt-4">2、填写excel文件、商机名称、商机金额、商机阶段必填</div>
  145. </div>
  146. </div>
  147. </el-dialog>
  148. <!-- 新建任务 -->
  149. <TaskModal :visible="allVisible.taskModalVisible" :edit-form="taskModalForm" :save-loading="taskLoading"
  150. @close="closeVisible('taskModalVisible')" @submit="submitForm" :title="'新建任务'"
  151. :disabled-list="['taskType', 'businessOpportunityId']" />
  152. <!-- 回收站 -->
  153. <DeteleBusiness :visibles="allVisible.deteleBusinessVisible" @closeVisible="closeVisible" />
  154. <!-- 阶段设置 -->
  155. <StageSetting :visibles="allVisible.stageSetVisible" @closeVisible="closeVisible" />
  156. </div>
  157. </template>
  158. <script lang="ts" setup>
  159. import { ref, reactive, onMounted, inject } from "vue";
  160. import type { ElTable, FormInstance, FormRules, UploadRequestOptions } from 'element-plus'
  161. import { useRouter, useRoute } from "vue-router";
  162. import { GETSYSFILED, MOD, GETPERSONNEL, GETGENERATEFOEM, GETBUSINESSLIST, UPDATEINSET, BUSINESSDETELE, BATCHTRANSFER, MODURL, tableColumn, BUSIESS_GETSATE } from './api'
  163. import { GETTABLELIST } from '@/pages/product/api'
  164. import { post, get, uploadFile } from "@/utils/request";
  165. import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, createTaskFromType, formatDate, confirmAction, downloadTemplate, downloadFile } from '@/utils/tools'
  166. import { createTask } from '@/components/TaskModal/taskFunction'
  167. import { formatDateTime } from '@/utils/times'
  168. import { GenerateForm } from '@zmjs/form-design';
  169. import RelatedProducts from './component/relatedProducts.vue'
  170. import TaskModal from '@/components/TaskModal/index.vue'
  171. import DeteleBusiness from './component/deteleTables.vue'
  172. import StageSetting from './component/stageSetting.vue'
  173. const route = useRoute()
  174. const router = useRouter()
  175. const globalPopup = inject<GlobalPopup>('globalPopup')
  176. const businessTableRef = ref<InstanceType<typeof ElTable>>() // 商机table dom
  177. const businessTotalTable = ref(0)
  178. const generateForm = ref<typeof GenerateForm>() // 自定义表单dom
  179. const relatedProductsRef = ref<typeof RelatedProducts>()
  180. const generateFormData = ref({
  181. config: {},
  182. list: []
  183. }) // 自定义表单数据
  184. const businessTable = ref([])
  185. const allLoading = reactive({
  186. businessTableLading: false,
  187. businessSaveLading: false,
  188. newBusinessSaveLading: false,
  189. transferLoading: false,
  190. importLoading: false,
  191. exoprtLoading: false,
  192. })
  193. const allVisible = reactive({
  194. newBusinessisible: false,
  195. recycleVisible: false,
  196. taskModalVisible: false,
  197. batchTransferVisible: false,
  198. deteleBusinessVisible: false,
  199. stageSetVisible: false,
  200. importVisible: false
  201. })
  202. const allText = reactive({
  203. newBusinessisibleText: '新建商机',
  204. transferText: '转移商机'
  205. }) // 所有文本
  206. const taskModalForm = ref({}) // 任务弹窗表单
  207. const taskLoading = ref<saveLoadingType>("1");
  208. const batchTableData = ref([]) // 批量数据
  209. const transferPersonnel = ref('') // 转移人
  210. const businessOpportunityForm = reactive<businessOpportunityFormType>({
  211. name: '',
  212. stageId: '',
  213. customerName: '',
  214. contactPerson: '',
  215. product: '',
  216. inchargerId: '',
  217. startTime: getFirstDayOfMonth(new Date()),
  218. endTime: formatDate(new Date()),
  219. pageIndex: 1,
  220. pageFrom: 10
  221. })
  222. const fixedData = reactive({
  223. BusinessStage: [] as fixedDataInterface[],
  224. Personnel: [] as personnelInterface[]
  225. })
  226. const productTableList = ref([])
  227. function editBusiness(visibles: boolean) {
  228. generateForm.value?.getData().then((res: any) => {
  229. let productTableListData = relatedProductsRef?.value?.returnData()
  230. let newForm = {
  231. ...res,
  232. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  233. businessItemProductList: productTableListData ? JSON.stringify(productTableListData) : []
  234. }
  235. allLoading.businessSaveLading = true
  236. post(UPDATEINSET, { ...newForm }).then((_res) => {
  237. allVisible.newBusinessisible = visibles
  238. globalPopup?.showSuccess('保存成功')
  239. getBusinessTableList()
  240. }).finally(() => {
  241. allLoading.businessSaveLading = false
  242. })
  243. }).catch((_err: any) => {
  244. console.log(_err)
  245. globalPopup?.showError('请填写完整')
  246. })
  247. }
  248. function editShowVisible(type: keyof typeof allVisible, item: any) {
  249. console.log(item, '选择数据')
  250. showVisible(type)
  251. }
  252. function newTask(item: any) {
  253. const { id } = item
  254. taskModalForm.value = { ...createTaskFromType(1), businessOpportunityId: id, }
  255. showVisible('taskModalVisible')
  256. }
  257. function submitForm(submitData: any, isClose: boolean) { // 任务提交
  258. taskLoading.value = '2'
  259. createTask(submitData, isClose).then((res) => {
  260. const { saveLoading, isClose } = res
  261. taskLoading.value = saveLoading
  262. allVisible.taskModalVisible = isClose
  263. globalPopup?.showSuccess('新增成功')
  264. }).catch((err) => {
  265. const { saveLoading, isClose, message } = err
  266. taskLoading.value = saveLoading
  267. allVisible.taskModalVisible = isClose
  268. globalPopup?.showError(message)
  269. })
  270. }
  271. function transferBusiness() {
  272. const ids = batchTableData.value.map((item: any) => item.id).join(',')
  273. allLoading.transferLoading = true
  274. post(BATCHTRANSFER, { ids, inchargerId: transferPersonnel.value }).then(() => {
  275. transferPersonnel.value = ''
  276. globalPopup?.showSuccess('转移成功')
  277. closeVisible('batchTransferVisible')
  278. getBusinessTableList()
  279. }).finally(() => {
  280. allLoading.transferLoading = false
  281. })
  282. }
  283. function batchDeteleItem() {
  284. const value = batchTableData.value.map((item: any) => item.id).join(',')
  285. const label = batchTableData.value.map((item: any) => item.name).join(',')
  286. businessDeteleItem(value, label, true)
  287. }
  288. function businessDeteleItem(value: string | number, label: string, batch: boolean = false) {
  289. confirmAction(`确定${batch ? '批量' : ''}删除【${label}】商机吗?`).then(() => {
  290. post(BUSINESSDETELE, { ids: value }).then(res => {
  291. if (res.code != 'ok') {
  292. globalPopup?.showError(res.msg)
  293. return
  294. }
  295. globalPopup?.showSuccess('删除成功')
  296. changeBatch(false)
  297. getBusinessTableList()
  298. }).catch((err) => {
  299. globalPopup?.showError(err.message)
  300. })
  301. })
  302. }
  303. async function importBusiness(param: UploadRequestOptions) {
  304. allLoading.importLoading = true
  305. const formData = new FormData();
  306. formData.append('multipartFile', param.file)
  307. const res = await uploadFile('接口名称', formData).finally(() => {
  308. allLoading.importLoading = false
  309. })
  310. if (res.code == 'ok') {
  311. globalPopup?.showSuccess('导入成功' || '')
  312. getBusinessTableList()
  313. return
  314. }
  315. globalPopup?.showError(res.msg || '')
  316. }
  317. function exportBusinessTableList() {
  318. allLoading.exoprtLoading = true
  319. let valueForm = getFromValue(businessOpportunityForm)
  320. post('接口名称', {...valueForm}).then((res) => {
  321. downloadFile(res.data, '商机表导出.xlsx')
  322. }).finally(() => {
  323. allLoading.exoprtLoading = false
  324. })
  325. }
  326. function changeBatch(flag: boolean = true) {
  327. if (flag) {
  328. batchTableData.value = businessTableRef.value && businessTableRef.value.getSelectionRows()
  329. } else {
  330. batchTableData.value = []
  331. businessTableRef.value && businessTableRef.value.clearSelection()
  332. }
  333. }
  334. function showVisible(type: keyof typeof allVisible) { // 显示弹窗
  335. allVisible[type] = true
  336. }
  337. function closeVisible(type: keyof typeof allVisible) {
  338. allVisible[type] = false
  339. }
  340. function handleClose(done: () => void) {
  341. done()
  342. }
  343. function getBusinessTableList() {
  344. const formValue = getFromValue(businessOpportunityForm)
  345. allLoading.businessTableLading = true
  346. post(GETBUSINESSLIST, { ...formValue }).then((res) => {
  347. const { data, total } = res.data
  348. businessTable.value = data.map((item: any) => {
  349. return {
  350. ...item,
  351. expectedTransactionDate: formatDate(new Date(item.expectedTransactionDate))
  352. }
  353. })
  354. businessTotalTable.value = total
  355. }).finally(() => {
  356. allLoading.businessTableLading = false
  357. })
  358. }
  359. function resetForm() {
  360. let reset = {
  361. startTime: getFirstDayOfMonth(new Date()),
  362. endTime: formatDate(new Date()),
  363. pageIndex: 1,
  364. pageFrom: 10
  365. }
  366. let newBusinessOpportunityForm = resetFromValue(businessOpportunityForm, { ...reset })
  367. Object.assign(businessOpportunityForm, newBusinessOpportunityForm)
  368. getBusinessTableList()
  369. }
  370. async function getSystemField() {
  371. // const systemField = getAllListByCode(['商机阶段'])
  372. // for (let i in systemField) {
  373. // const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  374. // for (let key of Object.keys(fixedData)) {
  375. // if (systemField[i] == key) {
  376. // Object.assign(fixedData, { [key]: data })
  377. // }
  378. // }
  379. // }
  380. const row = await post(BUSIESS_GETSATE, {})
  381. fixedData.BusinessStage = (row.data || []).map((item: any) => {
  382. const { name, id, seq } = item
  383. return { name, id, seq }
  384. }).sort(function (a: any, b: any) {return a.seq - b.seq;});
  385. const { data } = await post(GETPERSONNEL, {})
  386. fixedData.Personnel = data.map((item: any) => {
  387. const { id, name, phone, jobNumber } = item
  388. return {
  389. id, name, phone, jobNumber
  390. }
  391. })
  392. const res = await get(GETGENERATEFOEM)
  393. generateFormData.value = JSON.parse(res.data[0].config)
  394. }
  395. function toBusinessTableDetail(row: any) {
  396. router.push({
  397. path: `${MOD}/detail`,
  398. query: { id: row.id }
  399. })
  400. }
  401. function dealWithTableColumn(row: any, eventName: string) {
  402. if(eventName == 'toClueTableDetail') {
  403. toBusinessTableDetail(row)
  404. }
  405. }
  406. function getProductTableList() {
  407. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  408. if (res.code == 'ok') {
  409. const { record, total } = res.data
  410. productTableList.value = record.map((item: any) => {
  411. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  412. return {
  413. id,
  414. productId: id,
  415. productName,
  416. productCode,
  417. unit,
  418. unitName,
  419. price,
  420. type,
  421. typeName,
  422. inventory,
  423. quantity: '',
  424. discount: '',
  425. totalPrice: ''
  426. }
  427. })
  428. }
  429. })
  430. }
  431. onMounted(() => {
  432. getSystemField()
  433. getProductTableList()
  434. getBusinessTableList()
  435. })
  436. </script>
  437. <style lang="scss" scoped>
  438. .dialog-header {
  439. h4 {
  440. font-size: 18px;
  441. line-height: 24px;
  442. }
  443. }
  444. </style>