index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div>
  3. <a @click="updateInfo()">修改</a>
  4. <!--新建文档作业模态框-->
  5. <b-modal :active.sync="isUpdateModalActive" :width="640" scroll="keep">
  6. <div class="card">
  7. <div class="title">修改{{ updateTitle }}作业</div>
  8. <div class="content">
  9. <b-field
  10. label="作业名称"
  11. :type="$v.params.name.$error ? 'is-danger' : ''"
  12. :message="$v.params.name.$error ? '请填写作业名称' : ''"
  13. >
  14. <b-input
  15. placeholder="请填写作业名称"
  16. v-model="$v.params.name.$model"
  17. ></b-input>
  18. </b-field>
  19. <b-field
  20. label="作业描述"
  21. :type="$v.params.description.$error ? 'is-danger' : ''"
  22. :message="$v.params.description.$error ? '请填写作业描述' : ''"
  23. >
  24. <b-input
  25. type="textarea"
  26. placeholder="请填写作业描述"
  27. v-model="$v.params.description.$model"
  28. ></b-input>
  29. </b-field>
  30. <b-field label="开始时间">
  31. <b-input
  32. disabled
  33. :value="displayUnixTime(params.startAt)"
  34. ></b-input>
  35. </b-field>
  36. <b-field
  37. label="结束时间"
  38. :type="$v.params.endAt.$error ? 'is-danger' : ''"
  39. :message="$v.params.endAt.$error ? '请填写作业结束时间' : ''"
  40. >
  41. <flat-pickr
  42. placeholder="Click to select..."
  43. class="input"
  44. v-model="$v.params.endAt.$model"
  45. :config="endAtConfig"
  46. ></flat-pickr>
  47. </b-field>
  48. <a
  49. class="button is-link"
  50. :class="{ 'is-loading': loadingUpdateAssignment }"
  51. @click="updateAssignment()"
  52. >
  53. 确认修改
  54. </a>
  55. </div>
  56. </div>
  57. </b-modal>
  58. </div>
  59. </template>
  60. <script>
  61. import timeMixins from "@/mixins/time";
  62. import { putDocAssignment } from "@/api/assignment";
  63. import { putCodeAssignment } from "@/api/assignment";
  64. import { required } from "vuelidate/lib/validators";
  65. import BInput from "buefy/src/components/input/Input";
  66. export default {
  67. components: { BInput },
  68. props: {
  69. updateItem: {
  70. type: Object
  71. },
  72. assignType: {
  73. type: Number
  74. }
  75. },
  76. mixins: [timeMixins],
  77. mounted() {
  78. if (this.assignType === 1) {
  79. this.updateTitle = "文档";
  80. } else {
  81. this.updateTitle = "代码";
  82. }
  83. },
  84. data() {
  85. return {
  86. isUpdateModalActive: false,
  87. params: {
  88. name: null,
  89. description: null,
  90. startAt: null,
  91. endAt: null
  92. },
  93. updateTitle: "",
  94. myPromise: null,
  95. startAtConfig: {
  96. ...this.getDefaultConfig(),
  97. minDate: "today",
  98. maxDate: null
  99. },
  100. endAtConfig: {
  101. ...this.getDefaultConfig(),
  102. minDate: "today",
  103. maxDate: null
  104. },
  105. submitting: false,
  106. loadingUpdateAssignment: false
  107. };
  108. },
  109. methods: {
  110. /**
  111. * 准备修改
  112. */
  113. updateInfo() {
  114. this.isUpdateModalActive = true;
  115. this.params.name = this.updateItem.name;
  116. this.params.description = this.updateItem.description;
  117. this.params.startAt = this.updateItem.startAt;
  118. this.params.endAt = this.updateItem.endAt;
  119. },
  120. /**
  121. * 确认修改
  122. */
  123. updateAssignment() {
  124. if (this.submitting) return;
  125. this.$v.params.$touch();
  126. if (!this.$v.params.$invalid) {
  127. this.loadingUpdateAssignment = true;
  128. this.submitting = true;
  129. this.isUpdateModalActive = false;
  130. // this.parseParams();
  131. const param = {
  132. ...this.params,
  133. startAt: parseInt(this.params.startAt),
  134. endAt: parseInt(this.params.endAt)
  135. };
  136. if (this.assignType === 1) {
  137. this.myPromise = putDocAssignment(param, this.updateItem.id);
  138. } else {
  139. this.myPromise = putCodeAssignment(param, this.updateItem.id);
  140. }
  141. this.myPromise.then(res => {
  142. if (res.code === 0) {
  143. this.$emit("updateDocData", res.data);
  144. this.loadingUpdateAssignment = false;
  145. } else {
  146. this.loadingUpdateAssignment = false;
  147. this.$dialog.alert({
  148. title: "修改失败",
  149. message: res.message,
  150. type: "is-danger",
  151. hasIcon: true
  152. });
  153. }
  154. });
  155. this.submitting = true;
  156. }
  157. }
  158. },
  159. validations: {
  160. params: {
  161. name: {
  162. required
  163. },
  164. description: {
  165. required
  166. },
  167. startAt: {
  168. required
  169. },
  170. endAt: {
  171. required
  172. }
  173. }
  174. },
  175. watch: {
  176. isUpdateModalActive(newValue) {
  177. if (newValue === false) {
  178. this.$v.params.$reset();
  179. }
  180. }
  181. }
  182. };
  183. </script>
  184. <style lang="scss" scoped>
  185. .card {
  186. text-align: left;
  187. padding: 30px;
  188. .title {
  189. font-size: 1.25rem;
  190. small {
  191. color: gray;
  192. font-size: 1rem;
  193. }
  194. }
  195. .content {
  196. a {
  197. margin-top: 30px;
  198. width: 100%;
  199. }
  200. }
  201. }
  202. </style>