index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div id="index">
  3. <list-frame :title="pageTitle" @query="search" :total="total" :needFilter="false" :needAdd="false">
  4. <data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" @arrange="toArrange"></data-table>
  5. </list-frame>
  6. <el-dialog title="上报可行日期" width="30%" :visible.sync="dialog" center :destroy-on-close="true" @close="handleClose">
  7. <data-form :data="info" :fields="Ffields" :rules="rules" @save="handleSave" :isNew="!info.id" :styles="{ padding: 0 }" labelWidth="80px" :reset="false">
  8. <template #custom="{item,form}">
  9. <template v-if="item.model == 'daterange'">
  10. <el-checkbox-group v-model="form[item.model]">
  11. <el-checkbox v-for="i in 12" :key="i" :label="`${i}`" :disabled="inRange(i)">{{ i }}月</el-checkbox>
  12. </el-checkbox-group>
  13. </template>
  14. </template>
  15. </data-form>
  16. </el-dialog>
  17. </div>
  18. </template>
  19. <script>
  20. var moment = require('moment');
  21. // moment.locale('zh-cn');
  22. import _ from 'lodash';
  23. import Vue from 'vue';
  24. import listFrame from '@frame/layout/admin/list-frame';
  25. import dataTable from '@frame/components/data-table';
  26. import dataForm from '@frame/components/form';
  27. import { mapState, createNamespacedHelpers } from 'vuex';
  28. const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
  29. const { mapActions: schPlan } = createNamespacedHelpers('schPlan');
  30. export default {
  31. name: 'index',
  32. props: {},
  33. components: { listFrame, dataTable, dataForm },
  34. data: () => {
  35. return {
  36. dialog: false,
  37. opera: [
  38. {
  39. label: '上报可行日期',
  40. icon: 'el-icon-date',
  41. method: 'edit',
  42. },
  43. {
  44. label: '查看计划安排',
  45. icon: 'el-icon-document',
  46. method: 'arrange',
  47. },
  48. ],
  49. fields: [
  50. { label: '年度', prop: 'year' },
  51. { label: '标题', prop: 'title' },
  52. ],
  53. info: { daterange: [] },
  54. form: {},
  55. Ffields: [
  56. { label: '年度', model: 'year', type: 'text' },
  57. { label: '标题', model: 'title', type: 'text' },
  58. { label: '时间范围', model: 'planrange', type: 'text' },
  59. { label: '请假日期', model: 'daterange', custom: true },
  60. ],
  61. rules: {},
  62. list: [],
  63. total: 0,
  64. startmonth: 1,
  65. endmonth: 12,
  66. };
  67. },
  68. created() {
  69. this.search();
  70. },
  71. methods: {
  72. ...trainplan(['query', 'create', 'delete', 'update']),
  73. ...schPlan({ schPlanQuery: 'query', createSchPlan: 'create', updateSchPlan: 'update' }),
  74. async search({ skip = 0, limit = 10, ...info } = {}) {
  75. info = { planyearid: this.defaultOption.planyearid };
  76. const res = await this.query({ skip, limit, ...info });
  77. if (this.$checkRes(res)) {
  78. this.$set(this, `list`, res.data);
  79. this.$set(this, `total`, res.total);
  80. }
  81. },
  82. async toEdit({ data }) {
  83. let res = await this.schPlanQuery({ planid: data.id, schid: _.get(this.user, 'code') });
  84. let { year, id, title, termnum } = data;
  85. let plan = { schid: this.user.code, year, planid: id, title, daterange: [] };
  86. this.$set(this, `info`, plan);
  87. if (this.$checkRes(res)) {
  88. if (res.data.length > 0) this.$set(this, `info`, { ...res.data[0], title });
  89. }
  90. if (termnum) {
  91. let mid = termnum.map(i => i.batchnum).flat();
  92. let start = _.get(_.head(_.orderBy(mid, 'startdate', 'asc')), 'startdate');
  93. let end = _.get(_.head(_.orderBy(mid, 'enddate', 'desc')), 'enddate');
  94. let planrange = `${start} 至 ${end}`;
  95. this.$set(this, `info`, { ...this.info, planrange });
  96. let sm = moment(start).month() + 1;
  97. let em = moment(end).month() + 1;
  98. this.$set(this, `startmonth`, sm);
  99. this.$set(this, `endmonth`, em);
  100. }
  101. this.dialog = true;
  102. },
  103. async handleSave({ data, isNew }) {
  104. let res;
  105. let msg;
  106. let duplicate = JSON.parse(JSON.stringify(data));
  107. if (isNew) {
  108. //create
  109. res = await this.createSchPlan(duplicate);
  110. msg = '添加成功';
  111. } else {
  112. //update
  113. res = await this.updateSchPlan(duplicate);
  114. msg = '修改成功';
  115. }
  116. if (this.$checkRes(res, msg, res.errmsg || '操作失败')) {
  117. this.handleClose();
  118. }
  119. },
  120. handleClose() {
  121. this.dialog = false;
  122. this.info = { daterange: [] };
  123. this.$set(this, `startmonth`, 1);
  124. this.$set(this, `endmonth`, 12);
  125. },
  126. toSort() {
  127. this.info.daterange.sort((a, b) => a - b);
  128. },
  129. toArrange({ data }) {
  130. this.$router.push({ path: './detail', query: { id: data.id } });
  131. },
  132. inRange(val) {
  133. return !_.inRange(val, this.startmonth, this.endmonth + 1);
  134. },
  135. },
  136. computed: {
  137. ...mapState(['user', 'defaultOption']),
  138. pageTitle() {
  139. return `${this.$route.meta.title}`;
  140. },
  141. },
  142. metaInfo() {
  143. return { title: this.$route.meta.title };
  144. },
  145. };
  146. </script>
  147. <style lang="less" scoped></style>