experience.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div id="experience">
  3. <el-row>
  4. <el-col :span="24" class="style">
  5. <el-col :span="24" class="top">
  6. <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
  7. </el-col>
  8. <el-col :span="24" class="main">
  9. <van-form>
  10. <van-field v-model="form.title" name="标题" label="标题" placeholder="标题" :rules="[{ required: true, message: '请填写标题' }]" />
  11. <van-field
  12. v-model="form.content"
  13. name="内容"
  14. label="内容"
  15. placeholder="内容"
  16. type="textarea"
  17. rows="3"
  18. autosize
  19. :rules="[{ required: true, message: '请填写内容' }]"
  20. />
  21. <div style="margin: 16px;">
  22. <van-button round block type="info" @click="onSubmit">
  23. 提交
  24. </van-button>
  25. </div>
  26. </van-form>
  27. </el-col>
  28. </el-col>
  29. </el-row>
  30. </div>
  31. </template>
  32. <script>
  33. import NavBar from '@/layout/common/topInfo.vue';
  34. import { mapState, createNamespacedHelpers } from 'vuex';
  35. const { mapActions: experience } = createNamespacedHelpers('experience');
  36. const { mapActions: util } = createNamespacedHelpers('util');
  37. export default {
  38. name: 'experience',
  39. props: {},
  40. components: {
  41. NavBar,
  42. },
  43. data: function() {
  44. return {
  45. title: '',
  46. isleftarrow: '',
  47. navShow: true,
  48. form: {},
  49. };
  50. },
  51. created() {
  52. this.search();
  53. },
  54. methods: {
  55. ...util({ modelFetch: 'fetch' }),
  56. ...experience(['update', 'create']),
  57. async search() {
  58. const { classid, userid } = this.user;
  59. const res = await this.modelFetch({ model: 'experience', classid, studentid: userid });
  60. if (this.$checkRes(res)) this.$set(this, `form`, res.data || {});
  61. },
  62. async onSubmit() {
  63. let msg = this.$toast({
  64. duration: 0,
  65. message: '加载中...',
  66. forbidClick: true,
  67. });
  68. let duplicate = _.cloneDeep(this.form);
  69. let res;
  70. if (_.get(duplicate, '_id')) {
  71. res = await this.update(duplicate);
  72. } else {
  73. const { termid, batchid, classid, userid } = this.user;
  74. if (!termid) {
  75. this.$notify({ type: 'danger', message: '学生缺少期信息' });
  76. return;
  77. }
  78. if (!batchid) {
  79. this.$notify({ type: 'danger', message: '学生缺少批次信息' });
  80. return;
  81. }
  82. if (!classid) {
  83. this.$notify({ type: 'danger', message: '学生缺少班级信息' });
  84. return;
  85. }
  86. if (!userid) {
  87. this.$notify({ type: 'danger', message: '缺少学生信息' });
  88. return;
  89. }
  90. duplicate = { ...duplicate, termid, batchid, classid, studentid: userid };
  91. res = await this.create(duplicate);
  92. }
  93. msg.clear();
  94. this.$checkRes(res, '培训心得保存成功', res.errmsg || '培训心得保存失败');
  95. },
  96. },
  97. computed: {
  98. ...mapState(['user']),
  99. },
  100. mounted() {
  101. this.title = this.$route.meta.title;
  102. this.isleftarrow = this.$route.meta.isleftarrow;
  103. },
  104. watch: {
  105. $route(to, from) {
  106. this.title = to.meta.title;
  107. this.isleftarrow = to.meta.isleftarrow;
  108. },
  109. },
  110. };
  111. </script>
  112. <style lang="less" scoped>
  113. .style {
  114. width: 100%;
  115. min-height: 667px;
  116. position: relative;
  117. background-color: #f9fafc;
  118. }
  119. .top {
  120. height: 46px;
  121. overflow: hidden;
  122. }
  123. .main {
  124. min-height: 570px;
  125. }
  126. </style>