index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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="clueSourceId" label="客户名称" width="180"></el-table-column>
  70. <el-table-column prop="phone" label="联系人" width="180">
  71. <template #default="scope">
  72. <el-button link type="primary" size="large">{{
  73. scope.row.phone
  74. }}</el-button>
  75. </template>
  76. </el-table-column>
  77. <el-table-column prop="email" label="商机金额" width="180"></el-table-column>
  78. <el-table-column prop="customerIndustryId" label="商机阶段" width="180"></el-table-column>
  79. <el-table-column prop="customerLevelId" label="预计成交" width="180"></el-table-column>
  80. <el-table-column prop="inchargerId" label="负责人" width="180"></el-table-column>
  81. <el-table-column prop="createName" 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">编辑</el-button>
  86. <el-button link type="primary" size="large">新建任务</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. </div>
  120. </template>
  121. <script lang="ts" setup>
  122. import { ref, reactive, onMounted, inject } from "vue";
  123. import type { FormInstance, FormRules } from 'element-plus'
  124. import { useRouter, useRoute } from "vue-router";
  125. import { GETSYSFILED, MOD, GETPERSONNEL, GETGENERATEFOEM, GETBUSINESSLIST, UPDATEINSET } from './api'
  126. import { GETTABLELIST } from '@/pages/product/api'
  127. import { post, get } from "@/utils/request";
  128. import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, getLastDayOfMonth, formatDate } from '@/utils/tools'
  129. import { GenerateForm } from '@zmjs/form-design';
  130. import RelatedProducts from './component/relatedProducts.vue'
  131. const route = useRoute()
  132. const router = useRouter()
  133. const globalPopup = inject<GlobalPopup>('globalPopup')
  134. const businessTotalTable = ref(0)
  135. const generateForm = ref<typeof GenerateForm>() // 自定义表单dom
  136. const relatedProductsRef = ref<typeof RelatedProducts>()
  137. const generateFormData = ref({
  138. config: {},
  139. list: []
  140. }) // 自定义表单数据
  141. const businessTable = ref([])
  142. const allLoading = reactive({
  143. businessTableLading: false,
  144. businessSaveLading: false,
  145. newBusinessSaveLading: false,
  146. })
  147. const allVisible = reactive({
  148. newBusinessisible: false,
  149. recycleVisible: false,
  150. })
  151. const allText = reactive({
  152. newBusinessisibleText: '新建商机'
  153. }) // 所有文本
  154. const businessOpportunityForm = reactive<businessOpportunityFormType>({
  155. name: '',
  156. stageId: '',
  157. customerName: '',
  158. contactPerson: '',
  159. product: '',
  160. inchargerId: '',
  161. startTime: getFirstDayOfMonth(new Date()),
  162. endTime: formatDate(new Date()),
  163. pageIndex: 1,
  164. pageFrom: 10
  165. })
  166. const fixedData = reactive({
  167. BusinessStage: [] as fixedDataInterface[],
  168. Personnel: [] as personnelInterface[]
  169. })
  170. const productTableList = ref([])
  171. function editBusiness(visibles: boolean) {
  172. generateForm.value?.getData().then((res: any) => {
  173. let productTableListData = relatedProductsRef?.value?.returnData()
  174. let newForm = {
  175. ...res,
  176. expectedTransactionDate: res.expectedTransactionDate ? formatDate(new Date(res.expectedTransactionDate)) : '',
  177. businessItemProductList: productTableListData ? JSON.stringify(productTableListData) : []
  178. }
  179. allLoading.businessSaveLading = true
  180. post(UPDATEINSET, { ...newForm }).then((_res) => {
  181. allVisible.newBusinessisible = visibles
  182. globalPopup?.showSuccess('保存成功')
  183. getBusinessTableList()
  184. }).finally(() => {
  185. allLoading.businessSaveLading = false
  186. })
  187. }).catch((_err: any) => {
  188. console.log(_err)
  189. globalPopup?.showError('请填写完整')
  190. })
  191. }
  192. function showVisible(type: keyof typeof allVisible) { // 显示弹窗
  193. allVisible[type] = true
  194. }
  195. function closeVisible(type: keyof typeof allVisible) {
  196. allVisible[type] = false
  197. }
  198. function handleClose(done: () => void) {
  199. done()
  200. }
  201. function getBusinessTableList() {
  202. const formValue = getFromValue(businessOpportunityForm)
  203. post(GETBUSINESSLIST, { ...formValue }).then((res) => {
  204. const { data, total } = res.data
  205. businessTable.value = data
  206. businessTotalTable.value = total
  207. })
  208. }
  209. function resetForm() {
  210. let reset = {
  211. startTime: getFirstDayOfMonth(new Date()),
  212. endTime: formatDate(new Date()),
  213. pageIndex: 1,
  214. pageFrom: 10
  215. }
  216. let newBusinessOpportunityForm = resetFromValue(businessOpportunityForm, { ...reset })
  217. Object.assign(businessOpportunityForm, newBusinessOpportunityForm)
  218. getBusinessTableList()
  219. }
  220. async function getSystemField() {
  221. const systemField = getAllListByCode(['商机阶段'])
  222. for (let i in systemField) {
  223. const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  224. for (let key of Object.keys(fixedData)) {
  225. if (systemField[i] == key) {
  226. Object.assign(fixedData, { [key]: data })
  227. }
  228. }
  229. }
  230. const { data } = await post(GETPERSONNEL, {})
  231. fixedData.Personnel = data.map((item: any) => {
  232. const { id, name, phone, jobNumber } = item
  233. return {
  234. id, name, phone, jobNumber
  235. }
  236. })
  237. const res = await get(GETGENERATEFOEM)
  238. generateFormData.value = JSON.parse(res.data[0].config)
  239. }
  240. function toBusinessTableDetail(row: any) {
  241. console.log('点击跳转详情')
  242. router.push({
  243. path: `${MOD}/detail`,
  244. query: { id: row.id }
  245. })
  246. }
  247. function getProductTableList() {
  248. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  249. if (res.code == 'ok') {
  250. const { record, total } = res.data
  251. productTableList.value = record.map((item: any) => {
  252. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  253. return {
  254. id,
  255. productId: id,
  256. productName,
  257. productCode,
  258. unit,
  259. unitName,
  260. price,
  261. type,
  262. typeName,
  263. inventory,
  264. quantity: '',
  265. discount: '',
  266. totalPrice: ''
  267. }
  268. })
  269. }
  270. })
  271. }
  272. onMounted(() => {
  273. getSystemField()
  274. getProductTableList()
  275. getBusinessTableList()
  276. })
  277. </script>
  278. <style lang="scss" scoped>
  279. .dialog-header {
  280. h4 {
  281. font-size: 18px;
  282. line-height: 24px;
  283. }
  284. }
  285. </style>