|
| 1 | +<template> |
| 2 | + <el-dialog |
| 3 | + title="Create New Problem" |
| 4 | + :visible.sync="$store.state.createProblem.displayCreateProblem" |
| 5 | + width="500px" |
| 6 | + class="max-screen" |
| 7 | + > |
| 8 | + <el-form> |
| 9 | + <div class="icon-lable"> |
| 10 | + <i class="el-icon-s-operation" /> |
| 11 | + PID |
| 12 | + </div> |
| 13 | + <el-form-item prop="username"> |
| 14 | + <el-input v-model="pid" placeholder="PID"> |
| 15 | + <template slot="prepend">#.</template> |
| 16 | + <i v-if="errorPID" slot="suffix" class="icon-error el-input__icon el-icon-circle-close"></i> |
| 17 | + <i v-else slot="suffix" class="icon-success el-input__icon el-icon-circle-check"></i> |
| 18 | + </el-input> |
| 19 | + </el-form-item> |
| 20 | + <div class="icon-lable"> |
| 21 | + <i class="el-icon-edit-outline" /> |
| 22 | + Title |
| 23 | + </div> |
| 24 | + <el-form-item> |
| 25 | + <el-input v-model="title" placeholder="Title"></el-input> |
| 26 | + </el-form-item> |
| 27 | + <el-form-item> |
| 28 | + <el-button |
| 29 | + type="primary" |
| 30 | + v-on:click="Submit();" |
| 31 | + > |
| 32 | + Edit Detail |
| 33 | + </el-button> |
| 34 | + <el-button v-on:click="$store.state.createProblem.displayCreateProblem = false">Cancel</el-button> |
| 35 | + </el-form-item> |
| 36 | + </el-form> |
| 37 | + </el-dialog> |
| 38 | +</template> |
| 39 | + |
| 40 | +<script> |
| 41 | +import apiurl from './../../apiurl'; |
| 42 | +
|
| 43 | +export default { |
| 44 | + name: 'CreateProblem', |
| 45 | + data() { |
| 46 | + return { |
| 47 | + pid: null, |
| 48 | + title: null, |
| 49 | + errorPID: true |
| 50 | + }; |
| 51 | + }, |
| 52 | + watch: { |
| 53 | + pid(val) { |
| 54 | + this.$axios |
| 55 | + .get(apiurl('/problem/' + String(val))) |
| 56 | + .then(() => { |
| 57 | + this.errorPID = true; |
| 58 | + }) |
| 59 | + .catch(() => { |
| 60 | + this.errorPID = false; |
| 61 | + }); |
| 62 | + } |
| 63 | + }, |
| 64 | + methods: { |
| 65 | + Submit() { |
| 66 | + this.$axios |
| 67 | + .post(apiurl('/problem'), { |
| 68 | + pid: this.pid, |
| 69 | + title: this.title, |
| 70 | + description: 'Input description' |
| 71 | + }) |
| 72 | + .then(() => { |
| 73 | + this.$store.state.createProblem.displayCreateProblem = false; |
| 74 | + this.$router.push('/problem/' + this.pid + '/edit'); |
| 75 | + }) |
| 76 | + .catch(err => { |
| 77 | + if (err.request.status === 400) { |
| 78 | + this.$SegmentMessage.error(this, 'PID or title is empty'); |
| 79 | + } else if(err.request.status === 403) { |
| 80 | + this.$SegmentMessage.error(this, 'Permission denied'); |
| 81 | + } else { |
| 82 | + this.$SegmentMessage.error(this, 'Unkown error'); |
| 83 | + } |
| 84 | + }); |
| 85 | + } |
| 86 | + } |
| 87 | +}; |
| 88 | +</script> |
0 commit comments