| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <template>
- <div>
- <a @click="updateInfo()">修改</a>
- <!--新建文档作业模态框-->
- <b-modal :active.sync="isUpdateModalActive" :width="640" scroll="keep">
- <div class="card">
- <div class="title">修改{{ updateTitle }}作业</div>
- <div class="content">
- <b-field
- label="作业名称"
- :type="$v.params.name.$error ? 'is-danger' : ''"
- :message="$v.params.name.$error ? '请填写作业名称' : ''"
- >
- <b-input
- placeholder="请填写作业名称"
- v-model="$v.params.name.$model"
- ></b-input>
- </b-field>
- <b-field
- label="作业描述"
- :type="$v.params.description.$error ? 'is-danger' : ''"
- :message="$v.params.description.$error ? '请填写作业描述' : ''"
- >
- <b-input
- type="textarea"
- placeholder="请填写作业描述"
- v-model="$v.params.description.$model"
- ></b-input>
- </b-field>
- <b-field label="开始时间">
- <b-input
- disabled
- :value="displayUnixTime(params.startAt)"
- ></b-input>
- </b-field>
- <b-field
- label="结束时间"
- :type="$v.params.endAt.$error ? 'is-danger' : ''"
- :message="$v.params.endAt.$error ? '请填写作业结束时间' : ''"
- >
- <flat-pickr
- placeholder="Click to select..."
- class="input"
- v-model="$v.params.endAt.$model"
- :config="endAtConfig"
- ></flat-pickr>
- </b-field>
- <a
- class="button is-link"
- :class="{ 'is-loading': loadingUpdateAssignment }"
- @click="updateAssignment()"
- >
- 确认修改
- </a>
- </div>
- </div>
- </b-modal>
- </div>
- </template>
- <script>
- import timeMixins from "@/mixins/time";
- import { putDocAssignment } from "@/api/assignment";
- import { putCodeAssignment } from "@/api/assignment";
- import { required } from "vuelidate/lib/validators";
- import BInput from "buefy/src/components/input/Input";
- export default {
- components: { BInput },
- props: {
- updateItem: {
- type: Object
- },
- assignType: {
- type: Number
- }
- },
- mixins: [timeMixins],
- mounted() {
- if (this.assignType === 1) {
- this.updateTitle = "文档";
- } else {
- this.updateTitle = "代码";
- }
- },
- data() {
- return {
- isUpdateModalActive: false,
- params: {
- name: null,
- description: null,
- startAt: null,
- endAt: null
- },
- updateTitle: "",
- myPromise: null,
- startAtConfig: {
- ...this.getDefaultConfig(),
- minDate: "today",
- maxDate: null
- },
- endAtConfig: {
- ...this.getDefaultConfig(),
- minDate: "today",
- maxDate: null
- },
- submitting: false,
- loadingUpdateAssignment: false
- };
- },
- methods: {
- /**
- * 准备修改
- */
- updateInfo() {
- this.isUpdateModalActive = true;
- this.params.name = this.updateItem.name;
- this.params.description = this.updateItem.description;
- this.params.startAt = this.updateItem.startAt;
- this.params.endAt = this.updateItem.endAt;
- },
- /**
- * 确认修改
- */
- updateAssignment() {
- if (this.submitting) return;
- this.$v.params.$touch();
- if (!this.$v.params.$invalid) {
- this.loadingUpdateAssignment = true;
- this.submitting = true;
- this.isUpdateModalActive = false;
- // this.parseParams();
- const param = {
- ...this.params,
- startAt: parseInt(this.params.startAt),
- endAt: parseInt(this.params.endAt)
- };
- if (this.assignType === 1) {
- this.myPromise = putDocAssignment(param, this.updateItem.id);
- } else {
- this.myPromise = putCodeAssignment(param, this.updateItem.id);
- }
- this.myPromise.then(res => {
- if (res.code === 0) {
- this.$emit("updateDocData", res.data);
- this.loadingUpdateAssignment = false;
- } else {
- this.loadingUpdateAssignment = false;
- this.$dialog.alert({
- title: "修改失败",
- message: res.message,
- type: "is-danger",
- hasIcon: true
- });
- }
- });
- this.submitting = true;
- }
- }
- },
- validations: {
- params: {
- name: {
- required
- },
- description: {
- required
- },
- startAt: {
- required
- },
- endAt: {
- required
- }
- }
- },
- watch: {
- isUpdateModalActive(newValue) {
- if (newValue === false) {
- this.$v.params.$reset();
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .card {
- text-align: left;
- padding: 30px;
- .title {
- font-size: 1.25rem;
- small {
- color: gray;
- font-size: 1rem;
- }
- }
- .content {
- a {
- margin-top: 30px;
- width: 100%;
- }
- }
- }
- </style>
|