experience.vue 3.4 KB

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