index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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">批量转移</el-button>
  52. <el-button type="primary">批量删除</el-button>
  53. <el-button type="primary">阶段设置</el-button>
  54. <el-button type="primary">回收站</el-button>
  55. <el-button type="primary">导入</el-button>
  56. <el-button type="primary">导出</el-button>
  57. </div>
  58. <div class="flex-1 w-full overflow-hidden">
  59. <el-table ref="clueTableRef" :data="businessTable" border v-loading="allLoading.businessTableLading"
  60. style="width: 100%;height: 100%;">
  61. <el-table-column type="selection" width="55" />
  62. <el-table-column prop="name" label="商机名称" width="180">
  63. <template #default="scope">
  64. <el-button link type="primary" size="large" @click="toBusinessTableDetail(scope.row)">{{
  65. scope.row.name
  66. }}</el-button>
  67. </template>
  68. </el-table-column>
  69. <el-table-column prop="customerName" label="客户名称" width="180"></el-table-column>
  70. <el-table-column prop="contactsName" label="联系人" width="180">
  71. <template #default="scope">
  72. <el-button link type="primary" size="large">{{
  73. scope.row.contactsName
  74. }}</el-button>
  75. </template>
  76. </el-table-column>
  77. <el-table-column prop="amountOfMoney" label="商机金额" width="180"></el-table-column>
  78. <el-table-column prop="stageValue" label="商机阶段" width="180"></el-table-column>
  79. <el-table-column prop="expectedTransactionDate" label="预计成交" width="180"></el-table-column>
  80. <el-table-column prop="inchargerName" label="负责人" width="180"></el-table-column>
  81. <el-table-column prop="creatorName" label="创建人" width="180"></el-table-column>
  82. <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
  83. <el-table-column label="操作" fixed="right" width="200">
  84. <template #default="scope">
  85. <el-button link type="primary" size="large" @click="editShowVisible('newBusinessisible', scope.row)">编辑</el-button>
  86. <el-button link type="primary" size="large" @click="newTask(scope.row)">新建任务</el-button>
  87. <el-button link type="danger" size="large">删除</el-button>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. </div>
  92. <div class="flex justify-end pt-3">
  93. <el-pagination layout="total, prev, pager, next, sizes" :total="businessTotalTable"
  94. :hide-on-single-page="true" />
  95. </div>
  96. </div>
  97. </div>
  98. <!-- 弹窗 -->
  99. <el-dialog v-model="allVisible.newBusinessisible" width="1000" :show-close="false" top="10vh"
  100. :before-close="handleClose">
  101. <template #header="{ close, titleId, titleClass }">
  102. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  103. <h4 :id="titleId">{{ allText.newBusinessisibleText }}</h4>
  104. <div>
  105. <el-button type="primary" :loading="allLoading.newBusinessSaveLading"
  106. :disabled="allLoading.businessSaveLading" @click="editBusiness(true)">保存并新建</el-button>
  107. <el-button type="primary" @click="editBusiness(false)" :loading="allLoading.businessSaveLading"
  108. :disabled="allLoading.newBusinessSaveLading">保存</el-button>
  109. <el-button @click="closeVisible('newBusinessisible')">取消</el-button>
  110. </div>
  111. </div>
  112. </template>
  113. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3">
  114. <GenerateForm ref="generateForm" :data="generateFormData" />
  115. <div>相关产品</div>
  116. <RelatedProducts ref="relatedProductsRef" :productTableList="productTableList" />
  117. </div>
  118. </el-dialog>
  119. <!-- 新建任务 -->
  120. <TaskModal :visible="allVisible.taskModalVisible" :edit-form="taskModalForm" :save-loading="taskLoading"
  121. @close="closeVisible('taskModalVisible')" @submit="submitForm" :title="'新建任务'" :disabled-list="['taskType', 'businessOpportunityId']" />
  122. </div>
  123. </template>
  124. <script lang="ts" setup>
  125. import { ref, reactive, onMounted, inject } from "vue";
  126. import type { FormInstance, FormRules } from 'element-plus'
  127. import { useRouter, useRoute } from "vue-router";
  128. import { GETSYSFILED, MOD, GETPERSONNEL, GETGENERATEFOEM, GETBUSINESSLIST, UPDATEINSET } from './api'
  129. import { GETTABLELIST } from '@/pages/product/api'
  130. import { post, get } from "@/utils/request";
  131. import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, createTaskFromType, formatDate } from '@/utils/tools'
  132. import { createTask } from '@/components/TaskModal/taskFunction'
  133. import { formatDateTime } from '@/utils/times'
  134. import { GenerateForm } from '@zmjs/form-design';
  135. import RelatedProducts from './component/relatedProducts.vue'
  136. import TaskModal from '@/components/TaskModal/index.vue'
  137. const route = useRoute()
  138. const router = useRouter()
  139. const globalPopup = inject<GlobalPopup>('globalPopup')
  140. const businessTotalTable = ref(0)
  141. const generateForm = ref<typeof GenerateForm>() // 自定义表单dom
  142. const relatedProductsRef = ref<typeof RelatedProducts>()
  143. const generateFormData = ref({
  144. config: {},
  145. list: []
  146. }) // 自定义表单数据
  147. const businessTable = ref([])
  148. const allLoading = reactive({
  149. businessTableLading: false,
  150. businessSaveLading: false,
  151. newBusinessSaveLading: false,
  152. })
  153. const allVisible = reactive({
  154. newBusinessisible: false,
  155. recycleVisible: false,
  156. taskModalVisible: false
  157. })
  158. const allText = reactive({
  159. newBusinessisibleText: '新建商机'
  160. }) // 所有文本
  161. const taskModalForm = ref({}) // 任务弹窗表单
  162. const taskLoading = ref<saveLoadingType>("1");
  163. const businessOpportunityForm = reactive<businessOpportunityFormType>({
  164. name: '',
  165. stageId: '',
  166. customerName: '',
  167. contactPerson: '',
  168. product: '',
  169. inchargerId: '',
  170. startTime: getFirstDayOfMonth(new Date()),
  171. endTime: formatDate(new Date()),
  172. pageIndex: 1,
  173. pageFrom: 10
  174. })
  175. const fixedData = reactive({
  176. BusinessStage: [] as fixedDataInterface[],
  177. Personnel: [] as personnelInterface[]
  178. })
  179. const productTableList = ref([])
  180. function editBusiness(visibles: boolean) {
  181. generateForm.value?.getData().then((res: any) => {
  182. let productTableListData = relatedProductsRef?.value?.returnData()
  183. let newForm = {
  184. ...res,
  185. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  186. businessItemProductList: productTableListData ? JSON.stringify(productTableListData) : []
  187. }
  188. allLoading.businessSaveLading = true
  189. post(UPDATEINSET, { ...newForm }).then((_res) => {
  190. allVisible.newBusinessisible = visibles
  191. globalPopup?.showSuccess('保存成功')
  192. getBusinessTableList()
  193. }).finally(() => {
  194. allLoading.businessSaveLading = false
  195. })
  196. }).catch((_err: any) => {
  197. console.log(_err)
  198. globalPopup?.showError('请填写完整')
  199. })
  200. }
  201. function editShowVisible(type: keyof typeof allVisible, item: any) {
  202. console.log(item, '选择数据')
  203. showVisible(type)
  204. }
  205. function newTask(item: any) {
  206. const { id } = item
  207. taskModalForm.value = { ...createTaskFromType(1), businessOpportunityId: id, }
  208. showVisible('taskModalVisible')
  209. }
  210. function submitForm(submitData: any, isClose: boolean) { // 任务提交
  211. taskLoading.value = '2'
  212. createTask(submitData, isClose).then((res) => {
  213. const { saveLoading, isClose } = res
  214. taskLoading.value = saveLoading
  215. allVisible.taskModalVisible = isClose
  216. globalPopup?.showSuccess('新增成功')
  217. }).catch((err) => {
  218. const { saveLoading, isClose, message } = err
  219. taskLoading.value = saveLoading
  220. allVisible.taskModalVisible = isClose
  221. globalPopup?.showSuccess(message)
  222. })
  223. }
  224. function showVisible(type: keyof typeof allVisible) { // 显示弹窗
  225. allVisible[type] = true
  226. }
  227. function closeVisible(type: keyof typeof allVisible) {
  228. allVisible[type] = false
  229. }
  230. function handleClose(done: () => void) {
  231. done()
  232. }
  233. function getBusinessTableList() {
  234. const formValue = getFromValue(businessOpportunityForm)
  235. post(GETBUSINESSLIST, { ...formValue }).then((res) => {
  236. const { data, total } = res.data
  237. businessTable.value = data.map((item: any) => {
  238. return {
  239. ...item,
  240. expectedTransactionDate: formatDate(new Date(item.expectedTransactionDate))
  241. }
  242. })
  243. businessTotalTable.value = total
  244. })
  245. }
  246. function resetForm() {
  247. let reset = {
  248. startTime: getFirstDayOfMonth(new Date()),
  249. endTime: formatDate(new Date()),
  250. pageIndex: 1,
  251. pageFrom: 10
  252. }
  253. let newBusinessOpportunityForm = resetFromValue(businessOpportunityForm, { ...reset })
  254. Object.assign(businessOpportunityForm, newBusinessOpportunityForm)
  255. getBusinessTableList()
  256. }
  257. async function getSystemField() {
  258. const systemField = getAllListByCode(['商机阶段'])
  259. for (let i in systemField) {
  260. const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  261. for (let key of Object.keys(fixedData)) {
  262. if (systemField[i] == key) {
  263. Object.assign(fixedData, { [key]: data })
  264. }
  265. }
  266. }
  267. const { data } = await post(GETPERSONNEL, {})
  268. fixedData.Personnel = data.map((item: any) => {
  269. const { id, name, phone, jobNumber } = item
  270. return {
  271. id, name, phone, jobNumber
  272. }
  273. })
  274. const res = await get(GETGENERATEFOEM)
  275. generateFormData.value = JSON.parse(res.data[0].config)
  276. }
  277. function toBusinessTableDetail(row: any) {
  278. console.log('点击跳转详情')
  279. router.push({
  280. path: `${MOD}/detail`,
  281. query: { id: row.id }
  282. })
  283. }
  284. function getProductTableList() {
  285. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  286. if (res.code == 'ok') {
  287. const { record, total } = res.data
  288. productTableList.value = record.map((item: any) => {
  289. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  290. return {
  291. id,
  292. productId: id,
  293. productName,
  294. productCode,
  295. unit,
  296. unitName,
  297. price,
  298. type,
  299. typeName,
  300. inventory,
  301. quantity: '',
  302. discount: '',
  303. totalPrice: ''
  304. }
  305. })
  306. }
  307. })
  308. }
  309. onMounted(() => {
  310. getSystemField()
  311. getProductTableList()
  312. getBusinessTableList()
  313. })
  314. </script>
  315. <style lang="scss" scoped>
  316. .dialog-header {
  317. h4 {
  318. font-size: 18px;
  319. line-height: 24px;
  320. }
  321. }
  322. </style>