UpdateOrg.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <el-dialog :visible="visible" width="700px" title="修改机构" :before-close="close" :close-on-click-modal="false">
  3. <main class="update-org">
  4. <div class="update-org-info">
  5. <el-form ref="form" :model="orgInfo" :rules="rules" :hide-required-asterisk="true" label-width="80px">
  6. <el-form-item label="名称" prop="name">
  7. <el-input v-model="orgInfo.name" autocomplete="off" />
  8. </el-form-item>
  9. <el-form-item label="学员限额">
  10. <el-input
  11. v-model="orgInfo.max_count_student"
  12. @input="orgInfo.max_count_student = orgInfo.max_count_student.replace(/[^\d]/g, '')"
  13. />
  14. </el-form-item>
  15. <el-form-item label="教师限额">
  16. <el-input
  17. v-model="orgInfo.max_count_teacher"
  18. @input="orgInfo.max_count_teacher = orgInfo.max_count_teacher.replace(/[^\d]/g, '')"
  19. />
  20. </el-form-item>
  21. <el-form-item label="到期日期">
  22. <el-date-picker
  23. v-model="orgInfo.due_date"
  24. type="date"
  25. value-format="yyyy-MM-dd"
  26. placeholder="选择日期"
  27. ></el-date-picker>
  28. </el-form-item>
  29. <el-form-item label="介绍">
  30. <el-input v-model="orgInfo.intro" type="textarea" :rows="3" resize="none" autocomplete="off" />
  31. </el-form-item>
  32. </el-form>
  33. </div>
  34. <div class="update-org-image">
  35. <el-upload
  36. action="no"
  37. class="avatar-uploader"
  38. :http-request="upload"
  39. :before-upload="beforeUpload"
  40. :show-file-list="false"
  41. accept="image/*"
  42. >
  43. <img v-if="orgInfo.picture_url" :src="orgInfo.picture_url" class="avatar" />
  44. <i v-else class="el-icon-plus avatar-uploader-icon" />
  45. </el-upload>
  46. </div>
  47. </main>
  48. <footer slot="footer">
  49. <el-button type="primary" @click="updateOrg">确定</el-button>
  50. <el-button @click="close">关闭</el-button>
  51. </footer>
  52. </el-dialog>
  53. </template>
  54. <script>
  55. import { GetOrgInfo, UpdateOrg } from '@/api/org';
  56. import { fileUpload } from '@/api/app';
  57. export default {
  58. props: {
  59. orgId: {
  60. default: '',
  61. type: String
  62. }
  63. },
  64. data() {
  65. return {
  66. visible: false,
  67. orgInfo: {
  68. name: '',
  69. intro: '',
  70. picture_url: '',
  71. picture_id: '',
  72. max_count_student: 0,
  73. max_count_teacher: 0,
  74. due_date: ''
  75. },
  76. rules: {
  77. name: [{ required: true, message: '名称不能为空' }]
  78. }
  79. };
  80. },
  81. watch: {
  82. visible(newValue) {
  83. if (newValue) {
  84. GetOrgInfo({ id: this.orgId }).then(res => {
  85. this.orgInfo = res;
  86. });
  87. } else {
  88. this.orgInfo = {};
  89. }
  90. }
  91. },
  92. methods: {
  93. updateOrg() {
  94. this.$refs.form.validate(valid => {
  95. if (!valid) return false;
  96. const { name, intro, picture_id, max_count_student, max_count_teacher, due_date } = this.orgInfo;
  97. UpdateOrg({ id: this.orgId, name, intro, picture_id, max_count_student, max_count_teacher, due_date }).then(
  98. () => {
  99. this.$message.success('修改机构成功');
  100. this.visible = false;
  101. this.$emit('refresh');
  102. }
  103. );
  104. });
  105. },
  106. beforeUpload(file) {
  107. let isImage = /^image/.test(file.type);
  108. if (!isImage) {
  109. this.$message.error('上传的文件不是图片,请重新上传!');
  110. }
  111. return isImage;
  112. },
  113. upload(file) {
  114. fileUpload('Open', file).then(({ file_info_list }) => {
  115. if (file_info_list.length > 0) {
  116. const { file_url, file_id } = file_info_list[0];
  117. this.orgInfo.picture_url = file_url;
  118. this.orgInfo.picture_id = file_id;
  119. }
  120. });
  121. },
  122. show() {
  123. this.visible = true;
  124. },
  125. close() {
  126. this.visible = false;
  127. }
  128. }
  129. };
  130. </script>
  131. <style lang="scss">
  132. $avatar-w: 198px;
  133. .update-org {
  134. display: flex;
  135. &-info {
  136. flex: 7;
  137. margin-right: 12px;
  138. }
  139. &-image {
  140. flex: 3;
  141. .avatar-uploader {
  142. display: inline-block;
  143. .el-upload {
  144. position: relative;
  145. overflow: hidden;
  146. cursor: pointer;
  147. border: 1px dashed #d9d9d9;
  148. border-radius: 6px;
  149. &:hover {
  150. border-color: #409eff;
  151. }
  152. }
  153. &-icon {
  154. width: $avatar-w;
  155. height: $avatar-w;
  156. font-size: 28px;
  157. line-height: $avatar-w;
  158. color: #8c939d;
  159. text-align: center;
  160. }
  161. .avatar {
  162. display: block;
  163. width: $avatar-w;
  164. height: $avatar-w;
  165. }
  166. }
  167. }
  168. }
  169. </style>