index.vue 7.5 KB

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