index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="auxiliary-advice-container layout-padding">
  3. <div class="layout-padding-auto layout-padding-view pd20">
  4. <ProTable
  5. ref="proTableRef"
  6. :columns="columns"
  7. :data="state.tableData"
  8. @updateTable="queryList"
  9. :loading="state.loading"
  10. :total="state.total"
  11. v-model:page-index="state.queryParams.PageIndex"
  12. v-model:page-size="state.queryParams.PageSize"
  13. >
  14. <template #table-search>
  15. <el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
  16. <el-form-item label="意见类型" prop="CommonType">
  17. <el-select v-model="state.queryParams.CommonType" placeholder="请选择意见类型" @change="handleQuery">
  18. <el-option v-for="item in commonType" :value="item.key" :key="item.key" :label="item.value" />
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="常用语分类" prop="isOpen">
  22. <el-select v-model="state.queryParams.isOpen" placeholder="请选择意见类型" @change="handleQuery">
  23. <el-option v-for="item in openState" :value="item.key" :key="item.key" :label="item.value" />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
  28. <el-button @click="resetQuery(ruleFormRef)" v-waves class="default-button"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
  29. </el-form-item>
  30. </el-form>
  31. </template>
  32. <!-- 表格 header 按钮 -->
  33. <template #tableHeader="scope">
  34. <el-button type="primary" @click="onAdviceAdd"> <SvgIcon name="ele-Plus" class="mr5" />新增 </el-button>
  35. <el-button type="danger" @click="onAdviceDelete" :disabled="!scope.isSelected"> <SvgIcon name="ele-Delete" class="mr5" />删除<span v-if="proTableRef?.selectedList?.length">({{proTableRef?.selectedList?.length}})</span> </el-button>
  36. </template>
  37. <template #isOpen="{ row }">
  38. {{ row.isOpen ? '公开常用意见' : '个人常用意见' }}
  39. </template>
  40. <!-- 表格操作 -->
  41. <template #operation="{ row }">
  42. <el-button link type="primary" @click="updateAdvice(row)" v-auth="'auxiliary:advice:edit'" title="修改参数"> 修改 </el-button>
  43. </template>
  44. </ProTable>
  45. </div>
  46. <!-- 常用意见新增 -->
  47. <advice-add ref="adviceAddRef" @updateList="queryList" :commonType="commonType" />
  48. <!-- 常用意见编辑 -->
  49. <advice-edit ref="adviceEditRef" @updateList="queryList" :commonType="commonType" />
  50. </div>
  51. </template>
  52. <script lang="tsx" setup name="auxiliaryAdvice">
  53. import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
  54. import { ElMessage, ElMessageBox, FormInstance } from 'element-plus';
  55. import { formatDate } from '@/utils/formatTime';
  56. import { commonBaseData, deleteCommon, publicCommonList } from '@/api/auxiliary/advice';
  57. // 引入组件
  58. const AdviceAdd = defineAsyncComponent(() => import('@/views/auxiliary/advice/components/Advice-add.vue')); // 常用意见新增
  59. const AdviceEdit = defineAsyncComponent(() => import('@/views/auxiliary/advice/components/Advice-edit.vue')); // 常用意见编辑
  60. const proTableRef = ref<RefType>(); // 表格ref
  61. // 表格配置项
  62. const columns = ref<any[]>([
  63. { type: 'selection', width: 40 },
  64. {
  65. label: '意见内容',
  66. prop: 'content',
  67. minWidth: 300,
  68. },
  69. {
  70. label: '意见类型',
  71. prop: 'commonTypeText',
  72. minWidth: 150,
  73. },
  74. {
  75. label: '常用意见分类',
  76. prop: 'isOpen',
  77. minWidth: 150,
  78. },
  79. {
  80. label: '创建人',
  81. prop: 'creatorName',
  82. minWidth:120
  83. },
  84. {
  85. label: '创建部门',
  86. prop: 'creatorOrgName',
  87. minWidth:140
  88. },
  89. {
  90. label: '创建时间',
  91. prop: 'creationTime',
  92. width: 160,
  93. render: ({ row }) => {
  94. return <span>{formatDate(row.creationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
  95. },
  96. },
  97. { prop: 'operation', label: '操作', fixed: 'right', width: 80, align: 'center' },
  98. ]);
  99. // 定义变量内容
  100. const state = reactive({
  101. loading: false, // 加载状态
  102. queryParams: {
  103. // 查询参数
  104. PageIndex: 1,
  105. PageSize: 20,
  106. CommonType: null, // 常用意见类型
  107. isOpen: null, // 是否公开
  108. },
  109. total: 0, // 总条数
  110. tableData: [], // 表格数据
  111. });
  112. const ruleFormRef = ref<RefType>(null); // 表单ref
  113. const commonType = ref<EmptyArrayType>([]); // 常用意见类型
  114. const openState = ref<EmptyArrayType>([
  115. {
  116. key: true,
  117. value: '公开常用意见',
  118. },
  119. {
  120. key: false,
  121. value: '个人常用意见',
  122. },
  123. ]); // 是否公开
  124. const getBaseData = async () => {
  125. try {
  126. const res = await commonBaseData();
  127. commonType.value = res.result?.commonType ?? [];
  128. } catch (error) {
  129. console.log(error);
  130. }
  131. };
  132. /** 搜索按钮操作 */
  133. const handleQuery = () => {
  134. state.queryParams.PageIndex = 1;
  135. queryList();
  136. };
  137. // 获取列表
  138. const queryList = () => {
  139. state.loading = true;
  140. publicCommonList(state.queryParams)
  141. .then((res) => {
  142. state.loading = false;
  143. state.tableData = res.result.items ?? [];
  144. state.total = res.result.total ?? 0;
  145. })
  146. .finally(() => {
  147. state.loading = false;
  148. });
  149. };
  150. // 重置表单
  151. const resetQuery = (formEl: FormInstance | undefined) => {
  152. if (!formEl) return;
  153. formEl.resetFields();
  154. queryList();
  155. };
  156. // 新增意见
  157. const adviceAddRef = ref<RefType>(); // 意见新增
  158. const onAdviceAdd = () => {
  159. adviceAddRef.value.openDialog();
  160. };
  161. // 修改意见
  162. const adviceEditRef = ref<RefType>(); // 修改意见
  163. const updateAdvice = (row: any) => {
  164. adviceEditRef.value.openDialog(row);
  165. };
  166. // 删除参数
  167. const onAdviceDelete = () => {
  168. const ids = proTableRef.value.selectedList.map((item: any) => item.id);
  169. ElMessageBox.confirm(`您确定要删除选择的【${proTableRef.value.selectedList.length}】个常用意见,是否继续?`, '提示', {
  170. confirmButtonText: '确认',
  171. cancelButtonText: '取消',
  172. type: 'warning',
  173. draggable: true,
  174. cancelButtonClass: 'default-button',
  175. autofocus: false,
  176. })
  177. .then(() => {
  178. deleteCommon({ ids }).then(() => {
  179. ElMessage.success('操作成功');
  180. queryList();
  181. });
  182. })
  183. .catch(() => {});
  184. };
  185. // 页面加载时
  186. onMounted(() => {
  187. getBaseData();
  188. queryList();
  189. });
  190. </script>