contractManagement.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="mb-[10px]">
  5. <el-card shadow="hover">
  6. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  7. <el-form-item label="合同编号" prop="contractNo">
  8. <el-input v-model="queryParams.contractNo" placeholder="请输入合同编号" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item label="合同名称" prop="contractName">
  11. <el-input v-model="queryParams.contractName" placeholder="请输入合同名称" clearable @keyup.enter="handleQuery" />
  12. </el-form-item>
  13. <el-form-item label="合同类型" prop="contractType">
  14. <el-select v-model="queryParams.contractType" placeholder="请选择合同类型" clearable>
  15. <el-option v-for="dict in contract_type" :key="dict.value" :label="dict.label" :value="dict.value" />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item label="合同状态" prop="approvalStatus">
  19. <el-select v-model="queryParams.approvalStatus" placeholder="请选择合同状态" clearable>
  20. <el-option v-for="dict in contract_status" :key="dict.value" :label="dict.label" :value="dict.value" />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  25. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. </el-card>
  29. </div>
  30. </transition>
  31. <el-card shadow="never">
  32. <template #header>
  33. <el-row :gutter="10" class="mb8" type="flex" justify="space-between" align="middle">
  34. <span style="font-size: 16px; font-weight: 500">合同管理信息列表</span>
  35. <div style="display: flex; flex-wrap: nowrap; gap: 10px">
  36. <el-button v-if="!isViewMode" type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['customer:contract:add']"
  37. >新增合同</el-button
  38. >
  39. </div>
  40. </el-row>
  41. </template>
  42. <el-table v-loading="loading" border :data="contractList" @selection-change="handleSelectionChange">
  43. <el-table-column label="合同编号" align="center" prop="contractNo" />
  44. <el-table-column label="合同名称" align="center" prop="contractName" />
  45. <el-table-column label="合同类型" align="center" prop="contractType">
  46. <template #default="scope">
  47. <dict-tag :options="contract_type" :value="scope.row.contractType" />
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="起始时间" align="center" prop="startTime" width="180">
  51. <template #default="scope">
  52. <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="截至时间" align="center" prop="endTime" width="180">
  56. <template #default="scope">
  57. <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="上传时间" align="center" prop="uploadTime" width="180">
  61. <template #default="scope">
  62. <span>{{ parseTime(scope.row.uploadTime, '{y}-{m}-{d}') }}</span>
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="状态" align="center" prop="approvalStatus">
  66. <template #default="scope">
  67. <dict-tag :options="contract_status" :value="scope.row.approvalStatus" />
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="附件管理" align="center" prop="annex" />
  71. <el-table-column v-if="!isViewMode" label="操作" align="center" class-name="small-padding fixed-width">
  72. <template #default="scope">
  73. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['customer:contract:edit']">编辑</el-button>
  74. <el-button link type="primary" icon="Edit" @click="handleReview(scope.row)" v-hasPermi="['customer:contract:edit']">查看</el-button>
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  79. </el-card>
  80. <!-- 添加或修改客户合同对话框 -->
  81. <el-drawer :title="dialog.title" v-model="dialog.visible" size="70%" direction="rtl" :close-on-click-modal="true" append-to-body>
  82. <el-form ref="contractFormRef" :model="form" :rules="rules" label-width="120px">
  83. <el-row :gutter="20">
  84. <el-col :span="8">
  85. <el-form-item label="合同编号" prop="contractNo">
  86. <el-input v-model="form.contractNo" disabled />
  87. </el-form-item>
  88. </el-col>
  89. <el-col :span="8">
  90. <el-form-item label="合同名称" prop="contractName">
  91. <el-input v-model="form.contractName" placeholder="请输入合同名称" :disabled="isViewMode" />
  92. </el-form-item>
  93. </el-col>
  94. <el-col :span="8">
  95. <el-form-item label="合同类型" prop="contractType">
  96. <el-select v-model="form.contractType" placeholder="请选择合同类型" class="w-full" :disabled="isViewMode">
  97. <el-option v-for="dict in contract_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
  98. </el-select>
  99. </el-form-item>
  100. </el-col>
  101. </el-row>
  102. <el-row :gutter="20">
  103. <el-col :span="8">
  104. <el-form-item label="合同金额" prop="contractAmount">
  105. <el-input v-model="form.contractAmount" placeholder="请输入合同金额" :disabled="isViewMode" />
  106. </el-form-item>
  107. </el-col>
  108. <el-col :span="8">
  109. <el-form-item label="客户编号" prop="customerNo">
  110. <el-input v-model="form.customerNo" placeholder="请输入客户编号" disabled />
  111. </el-form-item>
  112. </el-col>
  113. <el-col :span="8">
  114. <el-form-item label="客户名称" prop="customerName">
  115. <el-input v-model="form.customerName" placeholder="请输入客户名称" :disabled="isViewMode" />
  116. </el-form-item>
  117. </el-col>
  118. </el-row>
  119. <el-row :gutter="20">
  120. <el-col :span="8">
  121. <el-form-item label="客户负责人" prop="customerLeader">
  122. <el-input v-model="form.customerLeader" placeholder="请输入客户负责人" :disabled="isViewMode" />
  123. </el-form-item>
  124. </el-col>
  125. <el-col :span="8">
  126. <el-form-item label="我方负责人" prop="projectLeader">
  127. <el-input v-model="form.projectLeader" placeholder="请输入我方负责人" :disabled="isViewMode" />
  128. </el-form-item>
  129. </el-col>
  130. <el-col :span="8">
  131. <el-form-item label="起始时间" prop="startTime">
  132. <el-date-picker
  133. v-model="form.startTime"
  134. type="date"
  135. value-format="YYYY-MM-DD"
  136. placeholder="请选择起始时间"
  137. class="w-full"
  138. style="width: 100%"
  139. :disabled="isViewMode"
  140. />
  141. </el-form-item>
  142. </el-col>
  143. </el-row>
  144. <el-row :gutter="20">
  145. <el-col :span="8">
  146. <el-form-item label="截止时间" prop="endTime">
  147. <el-date-picker
  148. v-model="form.endTime"
  149. type="date"
  150. value-format="YYYY-MM-DD"
  151. placeholder="请选择截止时间"
  152. class="w-full"
  153. style="width: 100%"
  154. :disabled="isViewMode"
  155. :disabled-date="disabledEndDate"
  156. />
  157. </el-form-item>
  158. </el-col>
  159. </el-row>
  160. <el-row :gutter="20">
  161. <el-col :span="16">
  162. <el-form-item label="附件管理" prop="annex">
  163. <el-upload action="#" :auto-upload="false" :disabled="isViewMode">
  164. <el-button type="primary" :disabled="isViewMode">选择文件</el-button>
  165. </el-upload>
  166. </el-form-item>
  167. </el-col>
  168. </el-row>
  169. </el-form>
  170. <template #footer>
  171. <div class="dialog-footer">
  172. <el-button v-if="!isViewMode" :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  173. <el-button @click="cancel">{{ isViewMode ? '关 闭' : '取 消' }}</el-button>
  174. </div>
  175. </template>
  176. </el-drawer>
  177. </div>
  178. </template>
  179. <script setup name="Contract" lang="ts">
  180. import { listContract, getContract, delContract, addContract, updateContract } from '@/api/customer/customerFile/contract';
  181. import { ContractVO, ContractQuery, ContractForm } from '@/api/customer/customerFile/contract/types';
  182. // 接收父组件传递的props
  183. const props = defineProps<{
  184. customerId?: string;
  185. customerNo?: string;
  186. customerName?: string;
  187. }>();
  188. const route = useRoute();
  189. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  190. const { contract_type, contract_status } = toRefs<any>(proxy?.useDict('contract_type', 'contract_status'));
  191. // 查看模式
  192. const isViewMode = computed(() => route.query.status === 'view');
  193. const contractList = ref<ContractVO[]>([]);
  194. const buttonLoading = ref(false);
  195. const loading = ref(true);
  196. const showSearch = ref(true);
  197. const ids = ref<Array<string | number>>([]);
  198. const single = ref(true);
  199. const multiple = ref(true);
  200. const total = ref(0);
  201. const queryFormRef = ref<ElFormInstance>();
  202. const contractFormRef = ref<ElFormInstance>();
  203. const dialog = reactive<DialogOption>({
  204. visible: false,
  205. title: ''
  206. });
  207. const initFormData: ContractForm = {
  208. id: undefined,
  209. customerNo: undefined,
  210. customerId: undefined,
  211. customerName: undefined,
  212. contractNo: undefined,
  213. contractName: undefined,
  214. contractAmount: undefined,
  215. customerLeader: undefined,
  216. projectLeader: undefined,
  217. contractType: undefined,
  218. startTime: undefined,
  219. endTime: undefined,
  220. uploadTime: undefined,
  221. settlementType: undefined,
  222. contractStatus: undefined,
  223. approvalStatus: undefined,
  224. annex: undefined,
  225. remark: undefined
  226. };
  227. const data = reactive<PageData<ContractForm, ContractQuery>>({
  228. form: { ...initFormData },
  229. queryParams: {
  230. pageNum: 1,
  231. pageSize: 10,
  232. customerNo: undefined,
  233. customerId: undefined,
  234. contractNo: undefined,
  235. contractName: undefined,
  236. contractAmount: undefined,
  237. customerLeader: undefined,
  238. projectLeader: undefined,
  239. contractType: undefined,
  240. startTime: undefined,
  241. endTime: undefined,
  242. uploadTime: undefined,
  243. settlementType: undefined,
  244. contractStatus: undefined,
  245. approvalStatus: undefined,
  246. annex: undefined,
  247. platformCode: undefined,
  248. params: {}
  249. },
  250. rules: {
  251. customerNo: [{ required: true, message: '客户编号不能为空', trigger: 'blur' }],
  252. contractAmount: [{ required: true, message: '合同金额不能为空', trigger: 'blur' }],
  253. contractType: [{ required: true, message: '合同类型不能为空', trigger: 'change' }],
  254. startTime: [{ required: true, message: '合同开始时间不能为空', trigger: 'blur' }],
  255. endTime: [{ required: true, message: '合同结束时间不能为空', trigger: 'blur' }]
  256. }
  257. });
  258. const { queryParams, form, rules } = toRefs(data);
  259. /** 禁用截止日期:只能选择起始日期之后的日期 */
  260. const disabledEndDate = (time: Date) => {
  261. if (!form.value.startTime) {
  262. return false; // 如果没有选择起始时间,不限制
  263. }
  264. // 将起始时间字符串转换为Date对象
  265. const startDate = new Date(form.value.startTime);
  266. // 截止日期必须大于起始日期
  267. return time.getTime() < startDate.getTime();
  268. };
  269. /** 查询客户合同列表 */
  270. const getList = async () => {
  271. loading.value = true;
  272. // 使用props传递的customerId进行查询
  273. if (props.customerId) {
  274. queryParams.value.customerId = props.customerId;
  275. }
  276. const res = await listContract(queryParams.value);
  277. contractList.value = res.rows;
  278. total.value = res.total;
  279. loading.value = false;
  280. };
  281. /** 取消按钮 */
  282. const cancel = () => {
  283. reset();
  284. dialog.visible = false;
  285. };
  286. /** 表单重置 */
  287. const reset = () => {
  288. form.value = { ...initFormData };
  289. contractFormRef.value?.resetFields();
  290. };
  291. /** 搜索按钮操作 */
  292. const handleQuery = () => {
  293. queryParams.value.pageNum = 1;
  294. getList();
  295. };
  296. /** 重置按钮操作 */
  297. const resetQuery = () => {
  298. queryFormRef.value?.resetFields();
  299. handleQuery();
  300. };
  301. /** 多选框选中数据 */
  302. const handleSelectionChange = (selection: ContractVO[]) => {
  303. ids.value = selection.map((item) => item.id);
  304. single.value = selection.length != 1;
  305. multiple.value = !selection.length;
  306. };
  307. /** 新增按钮操作 */
  308. const handleAdd = () => {
  309. reset();
  310. // 将props中的客户信息赋值给form
  311. if (props.customerId) {
  312. form.value.customerId = props.customerId;
  313. }
  314. if (props.customerNo) {
  315. form.value.customerNo = props.customerNo;
  316. }
  317. if (props.customerName) {
  318. form.value.customerName = props.customerName;
  319. }
  320. dialog.visible = true;
  321. dialog.title = '添加客户合同';
  322. };
  323. /** 修改按钮操作 */
  324. const handleUpdate = async (row?: ContractVO) => {
  325. reset();
  326. const _id = row?.id || ids.value[0];
  327. const res = await getContract(_id);
  328. Object.assign(form.value, res.data);
  329. dialog.visible = true;
  330. dialog.title = '修改客户合同';
  331. };
  332. /** 查看按钮操作 */
  333. const handleReview = async (row?: ContractVO) => {
  334. reset();
  335. const _id = row?.id || ids.value[0];
  336. const res = await getContract(_id);
  337. Object.assign(form.value, res.data);
  338. dialog.visible = true;
  339. dialog.title = '查看合同详情';
  340. };
  341. /** 提交按钮 */
  342. const submitForm = () => {
  343. contractFormRef.value?.validate(async (valid: boolean) => {
  344. if (valid) {
  345. buttonLoading.value = true;
  346. if (form.value.id) {
  347. await updateContract(form.value).finally(() => (buttonLoading.value = false));
  348. } else {
  349. await addContract(form.value).finally(() => (buttonLoading.value = false));
  350. }
  351. proxy?.$modal.msgSuccess('操作成功');
  352. dialog.visible = false;
  353. await getList();
  354. }
  355. });
  356. };
  357. /** 删除按钮操作 */
  358. const handleDelete = async (row?: ContractVO) => {
  359. const _ids = row?.id || ids.value;
  360. await proxy?.$modal.confirm('是否确认删除客户合同编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
  361. await delContract(_ids);
  362. proxy?.$modal.msgSuccess('删除成功');
  363. await getList();
  364. };
  365. /** 导出按钮操作 */
  366. const handleExport = () => {
  367. proxy?.download(
  368. 'customer/contract/export',
  369. {
  370. ...queryParams.value
  371. },
  372. `contract_${new Date().getTime()}.xlsx`
  373. );
  374. };
  375. onMounted(() => {
  376. // 初始化时将customerId赋值给queryParams
  377. if (props.customerId) {
  378. queryParams.value.customerId = props.customerId;
  379. }
  380. getList();
  381. });
  382. // 监听props变化
  383. watch(
  384. () => props.customerId,
  385. (newId) => {
  386. if (newId) {
  387. queryParams.value.customerId = newId;
  388. getList();
  389. }
  390. }
  391. );
  392. </script>