index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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="editNewBusiness(false)">新建商机</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="editNewBusiness(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" v-loading="allLoading.generateFormLading">
  102. <GenerateForm ref="businessTemplateRef" :data="businessTemplate" :value="businessTemplateValue" :key="businessTemplateKey" />
  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, URL_IMPOERBUSINESS } 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 '@/components/relatedProducts/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 businessTemplateRef = ref<typeof GenerateForm>() // 自定义表单dom
  179. const relatedProductsRef = ref<typeof RelatedProducts>()
  180. const businessTemplateValue = ref({})
  181. const businessTemplateKey = ref(1)
  182. const businessTemplate = ref({
  183. config: {},
  184. list: []
  185. }) // 自定义表单数据
  186. const businessTable = ref([])
  187. const allLoading = reactive({
  188. businessTableLading: false,
  189. businessSaveLading: false,
  190. newBusinessSaveLading: false,
  191. transferLoading: false,
  192. importLoading: false,
  193. exoprtLoading: false,
  194. generateFormLading: false
  195. })
  196. const allVisible = reactive({
  197. newBusinessisible: false,
  198. recycleVisible: false,
  199. taskModalVisible: false,
  200. batchTransferVisible: false,
  201. deteleBusinessVisible: false,
  202. stageSetVisible: false,
  203. importVisible: false
  204. })
  205. const allText = reactive({
  206. newBusinessisibleText: '新建商机',
  207. transferText: '转移商机'
  208. }) // 所有文本
  209. const taskModalForm = ref({}) // 任务弹窗表单
  210. const taskLoading = ref<saveLoadingType>("1");
  211. const batchTableData = ref([]) // 批量数据
  212. const transferPersonnel = ref('') // 转移人
  213. const businessOpportunityForm = reactive<businessOpportunityFormType>({
  214. name: '',
  215. stageId: '',
  216. customerName: '',
  217. contactPerson: '',
  218. product: '',
  219. inchargerId: '',
  220. startTime: getFirstDayOfMonth(new Date()),
  221. endTime: formatDate(new Date()),
  222. pageIndex: 1,
  223. pageFrom: 10
  224. })
  225. const fixedData = reactive({
  226. BusinessStage: [] as fixedDataInterface[],
  227. Personnel: [] as personnelInterface[]
  228. })
  229. const productTableList = ref([])
  230. function editBusiness(visibles: boolean) {
  231. businessTemplateRef.value?.getData().then((res: any) => {
  232. let productTableListData = relatedProductsRef?.value?.returnData()
  233. let newForm = {
  234. ...res,
  235. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  236. businessItemProductList: productTableListData ? JSON.stringify(productTableListData) : []
  237. }
  238. allLoading.businessSaveLading = true
  239. post(UPDATEINSET, { ...newForm }).then((_res) => {
  240. allVisible.newBusinessisible = visibles
  241. globalPopup?.showSuccess('保存成功')
  242. getBusinessTableList()
  243. }).finally(() => {
  244. allLoading.businessSaveLading = false
  245. })
  246. }).catch((_err: any) => {
  247. console.log(_err)
  248. globalPopup?.showError('请填写完整')
  249. })
  250. }
  251. function editNewBusiness(item: any) {
  252. console.log(item, '选择数据')
  253. showVisible('newBusinessisible')
  254. allLoading.generateFormLading = true
  255. if (item) {
  256. businessTemplateValue.value = item
  257. allText.newBusinessisibleText = '编辑商机'
  258. }
  259. if (!item) {
  260. businessTemplateValue.value = {}
  261. allText.newBusinessisibleText = '新建商机'
  262. }
  263. setTimeout(() => {
  264. businessTemplateRef.value && businessTemplateRef.value.reset()
  265. businessTemplateKey.value++
  266. allLoading.generateFormLading = false
  267. }, 500)
  268. }
  269. function newTask(item: any) {
  270. const { id } = item
  271. taskModalForm.value = { ...createTaskFromType(1), businessOpportunityId: id, }
  272. showVisible('taskModalVisible')
  273. }
  274. function submitForm(submitData: any, isClose: boolean) { // 任务提交
  275. taskLoading.value = '2'
  276. createTask(submitData, isClose).then((res) => {
  277. const { saveLoading, isClose } = res
  278. taskLoading.value = saveLoading
  279. allVisible.taskModalVisible = isClose
  280. globalPopup?.showSuccess('新增成功')
  281. }).catch((err) => {
  282. const { saveLoading, isClose, message } = err
  283. taskLoading.value = saveLoading
  284. allVisible.taskModalVisible = isClose
  285. globalPopup?.showError(message)
  286. })
  287. }
  288. function transferBusiness() {
  289. const ids = batchTableData.value.map((item: any) => item.id).join(',')
  290. allLoading.transferLoading = true
  291. post(BATCHTRANSFER, { ids, inchargerId: transferPersonnel.value }).then(() => {
  292. transferPersonnel.value = ''
  293. globalPopup?.showSuccess('转移成功')
  294. closeVisible('batchTransferVisible')
  295. getBusinessTableList()
  296. }).finally(() => {
  297. allLoading.transferLoading = false
  298. })
  299. }
  300. function batchDeteleItem() {
  301. const value = batchTableData.value.map((item: any) => item.id).join(',')
  302. const label = batchTableData.value.map((item: any) => item.name).join(',')
  303. businessDeteleItem(value, label, true)
  304. }
  305. function businessDeteleItem(value: string | number, label: string, batch: boolean = false) {
  306. confirmAction(`确定${batch ? '批量' : ''}删除【${label}】商机吗?`).then(() => {
  307. post(BUSINESSDETELE, { ids: value }).then(res => {
  308. if (res.code != 'ok') {
  309. globalPopup?.showError(res.msg)
  310. return
  311. }
  312. globalPopup?.showSuccess('删除成功')
  313. changeBatch(false)
  314. getBusinessTableList()
  315. }).catch((err) => {
  316. globalPopup?.showError(err.message)
  317. })
  318. })
  319. }
  320. async function importBusiness(param: UploadRequestOptions) {
  321. allLoading.importLoading = true
  322. const formData = new FormData();
  323. formData.append('multipartFile', param.file)
  324. const res = await uploadFile(URL_IMPOERBUSINESS, formData).finally(() => {
  325. allLoading.importLoading = false
  326. })
  327. if (res.code == 'ok') {
  328. globalPopup?.showSuccess('导入成功' || '')
  329. getBusinessTableList()
  330. return
  331. }
  332. globalPopup?.showError(res.msg || '')
  333. }
  334. function exportBusinessTableList() {
  335. allLoading.exoprtLoading = true
  336. let valueForm = getFromValue(businessOpportunityForm)
  337. post('接口名称', {...valueForm}).then((res) => {
  338. downloadFile(res.data, '商机表导出.xlsx')
  339. }).finally(() => {
  340. allLoading.exoprtLoading = false
  341. })
  342. }
  343. function changeBatch(flag: boolean = true) {
  344. if (flag) {
  345. batchTableData.value = businessTableRef.value && businessTableRef.value.getSelectionRows()
  346. } else {
  347. batchTableData.value = []
  348. businessTableRef.value && businessTableRef.value.clearSelection()
  349. }
  350. }
  351. function showVisible(type: keyof typeof allVisible) { // 显示弹窗
  352. allVisible[type] = true
  353. }
  354. function closeVisible(type: keyof typeof allVisible) {
  355. allVisible[type] = false
  356. }
  357. function handleClose(done: () => void) {
  358. done()
  359. }
  360. function getBusinessTableList() {
  361. const formValue = getFromValue(businessOpportunityForm)
  362. allLoading.businessTableLading = true
  363. post(GETBUSINESSLIST, { ...formValue }).then((res) => {
  364. const { data, total } = res.data
  365. businessTable.value = data.map((item: any) => {
  366. return {
  367. ...item,
  368. expectedTransactionDate: formatDate(new Date(item.expectedTransactionDate))
  369. }
  370. })
  371. businessTotalTable.value = total
  372. }).finally(() => {
  373. allLoading.businessTableLading = false
  374. })
  375. }
  376. function resetForm() {
  377. let reset = {
  378. startTime: getFirstDayOfMonth(new Date()),
  379. endTime: formatDate(new Date()),
  380. pageIndex: 1,
  381. pageFrom: 10
  382. }
  383. let newBusinessOpportunityForm = resetFromValue(businessOpportunityForm, { ...reset })
  384. Object.assign(businessOpportunityForm, newBusinessOpportunityForm)
  385. getBusinessTableList()
  386. }
  387. async function getSystemField() {
  388. // const systemField = getAllListByCode(['商机阶段'])
  389. // for (let i in systemField) {
  390. // const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  391. // for (let key of Object.keys(fixedData)) {
  392. // if (systemField[i] == key) {
  393. // Object.assign(fixedData, { [key]: data })
  394. // }
  395. // }
  396. // }
  397. const row = await post(BUSIESS_GETSATE, {})
  398. fixedData.BusinessStage = (row.data || []).map((item: any) => {
  399. const { name, id, seq } = item
  400. return { name, id, seq }
  401. }).sort(function (a: any, b: any) {return a.seq - b.seq;});
  402. const { data } = await post(GETPERSONNEL, {})
  403. fixedData.Personnel = data.map((item: any) => {
  404. const { id, name, phone, jobNumber } = item
  405. return {
  406. id, name, phone, jobNumber
  407. }
  408. })
  409. const res = await get(GETGENERATEFOEM)
  410. businessTemplate.value = JSON.parse(res.data[0].config)
  411. }
  412. function toBusinessTableDetail(row: any) {
  413. router.push({
  414. path: `${MOD}/detail`,
  415. query: { id: row.id }
  416. })
  417. }
  418. function dealWithTableColumn(row: any, eventName: string) {
  419. if(eventName == 'toClueTableDetail') {
  420. toBusinessTableDetail(row)
  421. }
  422. }
  423. function getProductTableList() {
  424. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  425. if (res.code == 'ok') {
  426. const { record, total } = res.data
  427. productTableList.value = record.map((item: any) => {
  428. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  429. return {
  430. id,
  431. productId: id,
  432. productName,
  433. productCode,
  434. unit,
  435. unitName,
  436. price,
  437. type,
  438. typeName,
  439. inventory,
  440. quantity: '',
  441. discount: '',
  442. totalPrice: ''
  443. }
  444. })
  445. }
  446. })
  447. }
  448. onMounted(() => {
  449. getSystemField()
  450. getProductTableList()
  451. getBusinessTableList()
  452. })
  453. </script>
  454. <style lang="scss" scoped>
  455. .dialog-header {
  456. h4 {
  457. font-size: 18px;
  458. line-height: 24px;
  459. }
  460. }
  461. </style>