index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="年份" prop="holidayYear">
  5. <el-date-picker clearable
  6. v-model="queryParams.holidayYear"
  7. type="year"
  8. value-format="YYYY"
  9. placeholder="请选择年份"
  10. @change="handleYearChange">
  11. </el-date-picker>
  12. </el-form-item>
  13. </el-form>
  14. <el-row :gutter="10" class="mb8">
  15. <el-col :span="1.5">
  16. <el-button
  17. type="primary"
  18. plain
  19. icon="Plus"
  20. @click="handleAdd"
  21. v-hasPermi="['biz:config:add']"
  22. >新增
  23. </el-button>
  24. </el-col>
  25. <el-col :span="1.5">
  26. <el-button
  27. type="success"
  28. plain
  29. icon="Edit"
  30. :disabled="single"
  31. @click="handleUpdate"
  32. v-hasPermi="['biz:config:edit']"
  33. >修改
  34. </el-button>
  35. </el-col>
  36. <el-col :span="1.5">
  37. <el-button
  38. type="danger"
  39. plain
  40. icon="Delete"
  41. :disabled="multiple"
  42. @click="handleDelete"
  43. v-hasPermi="['biz:config:remove']"
  44. >删除
  45. </el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button
  49. type="warning"
  50. plain
  51. icon="Download"
  52. @click="handleExport"
  53. v-hasPermi="['biz:config:export']"
  54. >导出
  55. </el-button>
  56. </el-col>
  57. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  58. </el-row>
  59. <el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
  60. <el-table-column type="selection" width="55" align="center"/>
  61. <el-table-column label="年份" align="center" prop="holidayYear"/>
  62. <el-table-column label="节假日名称" align="center" prop="holidayName"/>
  63. <el-table-column label="开始日期" align="center" prop="startDate" width="180">
  64. <template #default="scope">
  65. <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="结束日期" align="center" prop="endDate" width="180">
  69. <template #default="scope">
  70. <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="备注" align="center" prop="remark"/>
  74. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  75. <template #default="scope">
  76. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['biz:config:edit']">
  77. 修改
  78. </el-button>
  79. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
  80. v-hasPermi="['biz:config:remove']">删除
  81. </el-button>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. <pagination
  86. v-show="total>0"
  87. :total="total"
  88. v-model:page="queryParams.pageNum"
  89. v-model:limit="queryParams.pageSize"
  90. @pagination="getList"
  91. />
  92. <!-- 添加或修改节假日配置对话框 -->
  93. <el-dialog :title="title" v-model="open" width="500px" append-to-body>
  94. <el-form ref="configRef" :model="form" :rules="rules" label-width="120px">
  95. <el-form-item label="年份" prop="holidayYear">
  96. <el-date-picker clearable
  97. v-model="form.holidayYear"
  98. type="year"
  99. value-format="YYYY"
  100. placeholder="请选择年份">
  101. </el-date-picker>
  102. </el-form-item>
  103. <el-form-item label="节假日名称" prop="holidayName">
  104. <el-input v-model="form.holidayName" placeholder="请输入节假日名称"/>
  105. </el-form-item>
  106. <el-form-item label="开始日期" prop="startDate">
  107. <el-date-picker clearable
  108. v-model="form.startDate"
  109. type="date"
  110. value-format="YYYY-MM-DD"
  111. placeholder="请选择开始日期">
  112. </el-date-picker>
  113. </el-form-item>
  114. <el-form-item label="结束日期" prop="endDate">
  115. <el-date-picker clearable
  116. v-model="form.endDate"
  117. type="date"
  118. value-format="YYYY-MM-DD"
  119. placeholder="请选择结束日期">
  120. </el-date-picker>
  121. </el-form-item>
  122. <el-form-item label="备注" prop="remark">
  123. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
  124. </el-form-item>
  125. </el-form>
  126. <template #footer>
  127. <div class="dialog-footer">
  128. <el-button type="primary" @click="submitForm">确 定</el-button>
  129. <el-button @click="cancel">取 消</el-button>
  130. </div>
  131. </template>
  132. </el-dialog>
  133. </div>
  134. </template>
  135. <script setup name="Config">
  136. import {addConfig, delConfig, getConfig, listConfig, updateConfig} from "@/api/biz/config";
  137. const {proxy} = getCurrentInstance();
  138. const configList = ref([]);
  139. const open = ref(false);
  140. const loading = ref(true);
  141. const showSearch = ref(true);
  142. const ids = ref([]);
  143. const single = ref(true);
  144. const multiple = ref(true);
  145. const total = ref(0);
  146. const title = ref("");
  147. const data = reactive({
  148. form: {},
  149. queryParams: {
  150. pageNum: 1,
  151. pageSize: 10,
  152. holidayYear: new Date().getFullYear().toString(),
  153. holidayName: null,
  154. startDate: null,
  155. endDate: null,
  156. createBy: null,
  157. createTime: null,
  158. updateBy: null,
  159. updateTime: null,
  160. remark: null
  161. },
  162. rules: {}
  163. });
  164. const {queryParams, form, rules} = toRefs(data);
  165. /** 查询节假日配置列表 */
  166. function getList() {
  167. loading.value = true;
  168. listConfig(queryParams.value).then(response => {
  169. configList.value = response.rows;
  170. total.value = response.total;
  171. loading.value = false;
  172. });
  173. }
  174. // 取消按钮
  175. function cancel() {
  176. open.value = false;
  177. reset();
  178. }
  179. // 表单重置
  180. function reset() {
  181. form.value = {
  182. autoId: null,
  183. holidayYear: null,
  184. holidayName: null,
  185. startDate: null,
  186. endDate: null,
  187. createBy: null,
  188. createTime: null,
  189. updateBy: null,
  190. updateTime: null,
  191. remark: null
  192. };
  193. proxy.resetForm("configRef");
  194. }
  195. /** 搜索按钮操作 */
  196. function handleQuery() {
  197. queryParams.value.pageNum = 1;
  198. getList();
  199. }
  200. /** 重置按钮操作 */
  201. function resetQuery() {
  202. proxy.resetForm("queryRef");
  203. handleQuery();
  204. }
  205. // 多选框选中数据
  206. function handleSelectionChange(selection) {
  207. ids.value = selection.map(item => item.autoId);
  208. single.value = selection.length != 1;
  209. multiple.value = !selection.length;
  210. }
  211. /** 新增按钮操作 */
  212. function handleAdd() {
  213. reset();
  214. open.value = true;
  215. title.value = "添加节假日配置";
  216. }
  217. /** 修改按钮操作 */
  218. function handleUpdate(row) {
  219. reset();
  220. const _autoId = row.autoId || ids.value
  221. getConfig(_autoId).then(response => {
  222. form.value = response.data;
  223. // 确保年份字段正确显示
  224. if (response.data.holidayYear) {
  225. form.value.holidayYear = response.data.holidayYear.toString();
  226. }
  227. open.value = true;
  228. title.value = "修改节假日配置";
  229. });
  230. }
  231. /** 提交按钮 */
  232. function submitForm() {
  233. proxy.$refs["configRef"].validate(valid => {
  234. if (valid) {
  235. if (form.value.autoId != null) {
  236. updateConfig(form.value).then(response => {
  237. proxy.$modal.msgSuccess("修改成功");
  238. open.value = false;
  239. getList();
  240. });
  241. } else {
  242. addConfig(form.value).then(response => {
  243. proxy.$modal.msgSuccess("新增成功");
  244. open.value = false;
  245. getList();
  246. });
  247. }
  248. }
  249. });
  250. }
  251. /** 删除按钮操作 */
  252. function handleDelete(row) {
  253. const _autoIds = row.autoId || ids.value;
  254. proxy.$modal.confirm('是否确认删除节假日配置编号为"' + _autoIds + '"的数据项?').then(function () {
  255. return delConfig(_autoIds);
  256. }).then(() => {
  257. getList();
  258. proxy.$modal.msgSuccess("删除成功");
  259. }).catch(() => {
  260. });
  261. }
  262. /** 导出按钮操作 */
  263. function handleExport() {
  264. proxy.download('biz/config/export', {
  265. ...queryParams.value
  266. }, `config_${new Date().getTime()}.xlsx`)
  267. }
  268. // 年份选择变化事件
  269. function handleYearChange(value) {
  270. console.log('选择的年份:', value);
  271. // 年份变化时重新查询数据
  272. handleQuery();
  273. }
  274. getList();
  275. </script>