index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <doc-alert title="【合同】合同管理、合同提醒" url="https://doc.iocoder.cn/crm/contract/" />
  3. <doc-alert title="【通用】数据权限" url="https://doc.iocoder.cn/crm/permission/" />
  4. <ContentWrap>
  5. <!-- 搜索工作栏 -->
  6. <el-form
  7. ref="queryFormRef"
  8. :inline="true"
  9. :model="queryParams"
  10. class="-mb-15px"
  11. label-width="68px"
  12. >
  13. <el-form-item label="合同编号" prop="no">
  14. <el-input
  15. v-model="queryParams.no"
  16. class="!w-240px"
  17. clearable
  18. placeholder="请输入合同编号"
  19. @keyup.enter="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="合同名称" prop="name">
  23. <el-input
  24. v-model="queryParams.name"
  25. class="!w-240px"
  26. clearable
  27. placeholder="请输入合同名称"
  28. @keyup.enter="handleQuery"
  29. />
  30. <el-form-item label="客户" prop="customerId">
  31. <el-select
  32. v-model="queryParams.customerId"
  33. class="!w-240px"
  34. clearable
  35. lable-key="name"
  36. placeholder="请选择客户"
  37. value-key="id"
  38. @keyup.enter="handleQuery"
  39. >
  40. <el-option
  41. v-for="item in customerList"
  42. :key="item.id"
  43. :label="item.name"
  44. :value="item.id!"
  45. />
  46. </el-select>
  47. </el-form-item>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-button @click="handleQuery">
  51. <Icon class="mr-5px" icon="ep:search" />
  52. 搜索
  53. </el-button>
  54. <el-button @click="resetQuery">
  55. <Icon class="mr-5px" icon="ep:refresh" />
  56. 重置
  57. </el-button>
  58. <el-button v-hasPermi="['crm:contract:create']" type="primary" @click="openForm('create')">
  59. <Icon class="mr-5px" icon="ep:plus" />
  60. 新增
  61. </el-button>
  62. <el-button
  63. v-hasPermi="['crm:contract:export']"
  64. :loading="exportLoading"
  65. plain
  66. type="success"
  67. @click="handleExport"
  68. >
  69. <Icon class="mr-5px" icon="ep:download" />
  70. 导出
  71. </el-button>
  72. </el-form-item>
  73. </el-form>
  74. </ContentWrap>
  75. <!-- 列表 -->
  76. <ContentWrap>
  77. <el-tabs v-model="activeName" @tab-click="handleTabClick">
  78. <el-tab-pane label="我负责的" name="1" />
  79. <el-tab-pane label="我参与的" name="2" />
  80. <el-tab-pane label="下属负责的" name="3" />
  81. </el-tabs>
  82. <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
  83. <el-table-column align="center" fixed="left" label="合同编号" prop="no" width="180" />
  84. <el-table-column align="center" fixed="left" label="合同名称" prop="name" width="160">
  85. <template #default="scope">
  86. <el-link :underline="false" type="primary" @click="openDetail(scope.row.id)">
  87. {{ scope.row.name }}
  88. </el-link>
  89. </template>
  90. </el-table-column>
  91. <el-table-column align="center" label="客户名称" prop="customerName" width="120">
  92. <template #default="scope">
  93. <el-link
  94. :underline="false"
  95. type="primary"
  96. @click="openCustomerDetail(scope.row.customerId)"
  97. >
  98. {{ scope.row.customerName }}
  99. </el-link>
  100. </template>
  101. </el-table-column>
  102. <el-table-column align="center" label="商机名称" prop="businessName" width="130">
  103. <template #default="scope">
  104. <el-link
  105. :underline="false"
  106. type="primary"
  107. @click="openBusinessDetail(scope.row.businessId)"
  108. >
  109. {{ scope.row.businessName }}
  110. </el-link>
  111. </template>
  112. </el-table-column>
  113. <el-table-column
  114. align="center"
  115. label="合同金额(元)"
  116. prop="totalPrice"
  117. width="140"
  118. :formatter="erpPriceTableColumnFormatter"
  119. />
  120. <el-table-column
  121. align="center"
  122. label="下单时间"
  123. prop="orderDate"
  124. width="120"
  125. :formatter="dateFormatter2"
  126. />
  127. <el-table-column
  128. align="center"
  129. label="合同开始时间"
  130. prop="startTime"
  131. width="120"
  132. :formatter="dateFormatter2"
  133. />
  134. <el-table-column
  135. align="center"
  136. label="合同结束时间"
  137. prop="endTime"
  138. width="120"
  139. :formatter="dateFormatter2"
  140. />
  141. <el-table-column align="center" label="客户签约人" prop="contactName" width="130">
  142. <template #default="scope">
  143. <el-link
  144. :underline="false"
  145. type="primary"
  146. @click="openContactDetail(scope.row.signContactId)"
  147. >
  148. {{ scope.row.signContactName }}
  149. </el-link>
  150. </template>
  151. </el-table-column>
  152. <el-table-column align="center" label="公司签约人" prop="signUserName" width="130" />
  153. <el-table-column align="center" label="备注" prop="remark" width="200" />
  154. <el-table-column
  155. align="center"
  156. label="已回款金额(元)"
  157. prop="totalReceivablePrice"
  158. width="140"
  159. :formatter="erpPriceTableColumnFormatter"
  160. />
  161. <el-table-column
  162. align="center"
  163. label="未回款金额(元)"
  164. prop="totalReceivablePrice"
  165. width="140"
  166. :formatter="erpPriceTableColumnFormatter"
  167. >
  168. <template #default="scope">
  169. {{ erpPriceInputFormatter(scope.row.totalPrice - scope.row.totalReceivablePrice) }}
  170. </template>
  171. </el-table-column>
  172. <el-table-column
  173. :formatter="dateFormatter"
  174. align="center"
  175. label="最后跟进时间"
  176. prop="contactLastTime"
  177. width="180px"
  178. />
  179. <el-table-column align="center" label="负责人" prop="ownerUserName" width="120" />
  180. <el-table-column align="center" label="所属部门" prop="ownerUserDeptName" width="100px" />
  181. <el-table-column
  182. :formatter="dateFormatter"
  183. align="center"
  184. label="更新时间"
  185. prop="updateTime"
  186. width="180px"
  187. />
  188. <el-table-column
  189. :formatter="dateFormatter"
  190. align="center"
  191. label="创建时间"
  192. prop="createTime"
  193. width="180px"
  194. />
  195. <el-table-column align="center" label="创建人" prop="creatorName" width="120" />
  196. <el-table-column align="center" fixed="right" label="合同状态" prop="auditStatus" width="120">
  197. <template #default="scope">
  198. <dict-tag :type="DICT_TYPE.CRM_AUDIT_STATUS" :value="scope.row.auditStatus" />
  199. </template>
  200. </el-table-column>
  201. <el-table-column fixed="right" label="操作" width="250">
  202. <template #default="scope">
  203. <el-button
  204. v-if="scope.row.auditStatus === 0"
  205. v-hasPermi="['crm:contract:update']"
  206. link
  207. type="primary"
  208. @click="openForm('update', scope.row.id)"
  209. >
  210. 编辑
  211. </el-button>
  212. <el-button
  213. v-if="scope.row.auditStatus === 0"
  214. v-hasPermi="['crm:contract:update']"
  215. link
  216. type="primary"
  217. @click="handleSubmit(scope.row)"
  218. >
  219. 提交审核
  220. </el-button>
  221. <el-button
  222. v-else
  223. link
  224. v-hasPermi="['crm:contract:update']"
  225. type="primary"
  226. @click="handleProcessDetail(scope.row)"
  227. >
  228. 查看审批
  229. </el-button>
  230. <el-button
  231. v-hasPermi="['crm:contract:query']"
  232. link
  233. type="primary"
  234. @click="openDetail(scope.row.id)"
  235. >
  236. 详情
  237. </el-button>
  238. <el-button
  239. v-hasPermi="['crm:contract:delete']"
  240. link
  241. type="danger"
  242. @click="handleDelete(scope.row.id)"
  243. >
  244. 删除
  245. </el-button>
  246. </template>
  247. </el-table-column>
  248. </el-table>
  249. <!-- 分页 -->
  250. <Pagination
  251. v-model:limit="queryParams.pageSize"
  252. v-model:page="queryParams.pageNo"
  253. :total="total"
  254. @pagination="getList"
  255. />
  256. </ContentWrap>
  257. <!-- 表单弹窗:添加/修改 -->
  258. <ContractForm ref="formRef" @success="getList" />
  259. </template>
  260. <script lang="ts" setup>
  261. import { dateFormatter, dateFormatter2 } from '@/utils/formatTime'
  262. import download from '@/utils/download'
  263. import * as ContractApi from '@/api/crm/contract'
  264. import ContractForm from './ContractForm.vue'
  265. import { DICT_TYPE } from '@/utils/dict'
  266. import { erpPriceInputFormatter, erpPriceTableColumnFormatter } from '@/utils'
  267. import * as CustomerApi from '@/api/crm/customer'
  268. import { TabsPaneContext } from 'element-plus'
  269. defineOptions({ name: 'CrmContract' })
  270. const message = useMessage() // 消息弹窗
  271. const { t } = useI18n() // 国际化
  272. const loading = ref(true) // 列表的加载中
  273. const total = ref(0) // 列表的总页数
  274. const list = ref([]) // 列表的数据
  275. const queryParams = reactive({
  276. pageNo: 1,
  277. pageSize: 10,
  278. sceneType: '1', // 默认和 activeName 相等
  279. name: null,
  280. customerId: null,
  281. orderDate: [],
  282. no: null
  283. })
  284. const queryFormRef = ref() // 搜索的表单
  285. const exportLoading = ref(false) // 导出的加载中
  286. const activeName = ref('1') // 列表 tab
  287. const customerList = ref<CustomerApi.CustomerVO[]>([]) // 客户列表
  288. /** tab 切换 */
  289. const handleTabClick = (tab: TabsPaneContext) => {
  290. queryParams.sceneType = tab.paneName
  291. handleQuery()
  292. }
  293. /** 查询列表 */
  294. const getList = async () => {
  295. loading.value = true
  296. try {
  297. const data = await ContractApi.getContractPage(queryParams)
  298. list.value = data.list
  299. total.value = data.total
  300. } finally {
  301. loading.value = false
  302. }
  303. }
  304. /** 搜索按钮操作 */
  305. const handleQuery = () => {
  306. queryParams.pageNo = 1
  307. getList()
  308. }
  309. /** 重置按钮操作 */
  310. const resetQuery = () => {
  311. queryFormRef.value.resetFields()
  312. handleQuery()
  313. }
  314. /** 添加/修改操作 */
  315. const formRef = ref()
  316. const openForm = (type: string, id?: number) => {
  317. formRef.value.open(type, id)
  318. }
  319. /** 删除按钮操作 */
  320. const handleDelete = async (id: number) => {
  321. try {
  322. // 删除的二次确认
  323. await message.delConfirm()
  324. // 发起删除
  325. await ContractApi.deleteContract(id)
  326. message.success(t('common.delSuccess'))
  327. // 刷新列表
  328. await getList()
  329. } catch {}
  330. }
  331. /** 导出按钮操作 */
  332. const handleExport = async () => {
  333. try {
  334. // 导出的二次确认
  335. await message.exportConfirm()
  336. // 发起导出
  337. exportLoading.value = true
  338. const data = await ContractApi.exportContract(queryParams)
  339. download.excel(data, '合同.xls')
  340. } catch {
  341. } finally {
  342. exportLoading.value = false
  343. }
  344. }
  345. /** 提交审核 **/
  346. const handleSubmit = async (row: ContractApi.ContractVO) => {
  347. await message.confirm(`您确定提交【${row.name}】审核吗?`)
  348. await ContractApi.submitContract(row.id)
  349. message.success('提交审核成功!')
  350. await getList()
  351. }
  352. /** 查看审批 */
  353. const handleProcessDetail = (row: ContractApi.ContractVO) => {
  354. push({ name: 'BpmProcessInstanceDetail', query: { id: row.processInstanceId } })
  355. }
  356. /** 打开合同详情 */
  357. const { push } = useRouter()
  358. const openDetail = (id: number) => {
  359. push({ name: 'CrmContractDetail', params: { id } })
  360. }
  361. /** 打开客户详情 */
  362. const openCustomerDetail = (id: number) => {
  363. push({ name: 'CrmCustomerDetail', params: { id } })
  364. }
  365. /** 打开联系人详情 */
  366. const openContactDetail = (id: number) => {
  367. push({ name: 'CrmContactDetail', params: { id } })
  368. }
  369. /** 打开商机详情 */
  370. const openBusinessDetail = (id: number) => {
  371. push({ name: 'CrmBusinessDetail', params: { id } })
  372. }
  373. /** 初始化 **/
  374. onMounted(async () => {
  375. await getList()
  376. customerList.value = await CustomerApi.getCustomerSimpleList()
  377. })
  378. </script>