index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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="supplierNo">
  8. <el-input v-model="queryParams.supplierNo" placeholder="请输入供应商编号" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item label="供应商名称" prop="supplierName">
  11. <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称" clearable @keyup.enter="handleQuery" />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  15. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. </el-card>
  19. </div>
  20. </transition>
  21. <el-card shadow="never">
  22. <template #header>
  23. <el-row :gutter="10" class="mb8">
  24. <el-col :span="1.5">
  25. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['supplier:contract:add']">新增</el-button>
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['supplier:contract:edit']">修改</el-button>
  29. </el-col>
  30. <el-col :span="1.5">
  31. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['supplier:contract:remove']">删除</el-button>
  32. </el-col>
  33. <el-col :span="1.5">
  34. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['supplier:contract:export']">导出</el-button>
  35. </el-col>
  36. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  37. </el-row>
  38. </template>
  39. <el-table v-loading="loading" border :data="contractList" @selection-change="handleSelectionChange">
  40. <el-table-column type="selection" width="55" align="center" />
  41. <el-table-column label="主键ID" align="center" prop="id" v-if="false" />
  42. <el-table-column label="供应商编号" align="center" prop="supplierNo" />
  43. <el-table-column label="供应商名称" align="center" prop="supplierName" />
  44. <el-table-column label="合同数" align="center" prop="contractNum" />
  45. <el-table-column label="有效期内合同" align="center" prop="validContract" />
  46. <el-table-column label="失效合同" align="center" prop="invalidContract" />
  47. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  48. <template #default="scope">
  49. <el-button link type="primary" @click="handleManage(scope.row)">管理</el-button>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  54. </el-card>
  55. <!-- 添加或修改合同管理对话框 -->
  56. <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
  57. <el-form ref="contractFormRef" :model="form" :rules="rules" label-width="80px">
  58. </el-form>
  59. <template #footer>
  60. <div class="dialog-footer">
  61. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  62. <el-button @click="cancel">取 消</el-button>
  63. </div>
  64. </template>
  65. </el-dialog>
  66. </div>
  67. </template>
  68. <script setup name="Contract" lang="ts">
  69. import { listContract, getContract, delContract, addContract, updateContract } from '@/api/supplier/contract';
  70. import { ContractVO, ContractQuery, ContractForm } from '@/api/supplier/contract/types';
  71. import { useRouter } from 'vue-router';
  72. const router = useRouter();
  73. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  74. const contractList = ref<ContractVO[]>([]);
  75. const buttonLoading = ref(false);
  76. const loading = ref(true);
  77. const showSearch = ref(true);
  78. const ids = ref<Array<string | number>>([]);
  79. const single = ref(true);
  80. const multiple = ref(true);
  81. const total = ref(0);
  82. const queryFormRef = ref<ElFormInstance>();
  83. const contractFormRef = ref<ElFormInstance>();
  84. const dialog = reactive<DialogOption>({
  85. visible: false,
  86. title: ''
  87. });
  88. const initFormData: ContractForm = {
  89. }
  90. const data = reactive<PageData<ContractForm, ContractQuery>>({
  91. form: {...initFormData},
  92. queryParams: {
  93. pageNum: 1,
  94. pageSize: 10,
  95. supplierNo: undefined,
  96. supplierName: undefined,
  97. params: {
  98. }
  99. },
  100. rules: {
  101. }
  102. });
  103. const { queryParams, form, rules } = toRefs(data);
  104. /** 查询合同管理列表 */
  105. const getList = async () => {
  106. loading.value = true;
  107. const res = await listContract(queryParams.value);
  108. contractList.value = res.rows;
  109. total.value = res.total;
  110. loading.value = false;
  111. }
  112. /** 取消按钮 */
  113. const cancel = () => {
  114. reset();
  115. dialog.visible = false;
  116. }
  117. /** 表单重置 */
  118. const reset = () => {
  119. form.value = {...initFormData};
  120. contractFormRef.value?.resetFields();
  121. }
  122. /** 搜索按钮操作 */
  123. const handleQuery = () => {
  124. queryParams.value.pageNum = 1;
  125. getList();
  126. }
  127. /** 重置按钮操作 */
  128. const resetQuery = () => {
  129. queryFormRef.value?.resetFields();
  130. handleQuery();
  131. }
  132. /** 多选框选中数据 */
  133. const handleSelectionChange = (selection: ContractVO[]) => {
  134. ids.value = selection.map(item => item.id);
  135. single.value = selection.length != 1;
  136. multiple.value = !selection.length;
  137. }
  138. /** 新增按钮操作 */
  139. const handleAdd = () => {
  140. reset();
  141. dialog.visible = true;
  142. dialog.title = "添加合同管理";
  143. }
  144. /** 修改按钮操作 */
  145. const handleUpdate = async (row?: ContractVO) => {
  146. reset();
  147. const _id = row?.id || ids.value[0]
  148. const res = await getContract(_id);
  149. Object.assign(form.value, res.data);
  150. dialog.visible = true;
  151. dialog.title = "修改合同管理";
  152. }
  153. /** 管理按钮操作 - 路由到合同详情页 */
  154. const handleManage = (row: ContractVO) => {
  155. router.push({
  156. // name: 'SupplierContractDetail',
  157. path: `/supplier/contract/detail`,
  158. query: {
  159. supplierId: row.supplierId
  160. }
  161. });
  162. }
  163. /** 提交按钮 */
  164. const submitForm = () => {
  165. contractFormRef.value?.validate(async (valid: boolean) => {
  166. if (valid) {
  167. buttonLoading.value = true;
  168. if (form.value.id) {
  169. await updateContract(form.value).finally(() => buttonLoading.value = false);
  170. } else {
  171. await addContract(form.value).finally(() => buttonLoading.value = false);
  172. }
  173. proxy?.$modal.msgSuccess("操作成功");
  174. dialog.visible = false;
  175. await getList();
  176. }
  177. });
  178. }
  179. /** 删除按钮操作 */
  180. const handleDelete = async (row?: ContractVO) => {
  181. const _ids = row?.id || ids.value;
  182. await proxy?.$modal.confirm('是否确认删除合同管理编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
  183. await delContract(_ids);
  184. proxy?.$modal.msgSuccess("删除成功");
  185. await getList();
  186. }
  187. /** 导出按钮操作 */
  188. const handleExport = () => {
  189. proxy?.download('supplier/contract/export', {
  190. ...queryParams.value
  191. }, `contract_${new Date().getTime()}.xlsx`)
  192. }
  193. onMounted(() => {
  194. getList();
  195. });
  196. </script>