user_edit.vue.jinja2 2.2 KB
Newer Older
W
wjmcat 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
<template>
  <div class="container">
    <el-card class="box-card margin-space" style="margin:20px;">
      <el-form :model="form" label-width="120px" :rules="rules" ref="form">
      {%- for column in columns -%}
          {% if column.type == "str" %}
        <el-form-item label="{{ column.description }}" prop="{{ column.field }}">
          <el-input v-model="form.{{ column.field }}" placeholder="请输入{{ column.description }}" />
        </el-form-item>
          {%- elif column.type == "int" %}
        <el-input-number style="width:100%;" v-model="form.{{ column.field }}"
            :min="0" :max="100" label="请输入{{ column.description }}">
        </el-input-number>
          {% else %}
          {% endif %}
      {%- endfor -%}
        <el-form-item>
          <el-button type="primary" @click="submit">提 交</el-button>
          <el-button @click="reset_form">重 置</el-button>
          <el-button @click="show=false">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { add_news } from "./api_result";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";

import { quillEditor } from "vue-quill-editor";
export default {
  name: "edit",
  components: { quillEditor },
  data() {
    return {
      loading: false,
      show: false,
      form: {},
      rules: {
      {% for column in columns %}
        {{ column.field }}: [{ required: true, message: "请输入{{ column.description }}", trigger: ["blur"] }],
      {% endfor %}
      }
    };
  },
  methods: {
    show_dialog() {
      this.show = true;
      this.loading = false;
      this.form = {
      };
    },
    reset_form() {
      this.form = {};
    },
    submit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loading = true;
          let $this = this;
          add_news(this.form).then(function(res) {
            $this.loading = false;
            if (res.code === 200) {
              $this.show = false;
              $this.$emit("fresh");
            } else {
              alert(res.message);
            }
          });
        } else {
          return false;
        }
      });
    }
  }
 };
</script>