railWay.vue 3.07 KB
Newer Older
neogcg's avatar
neogcg committed
1
<template>
neogcg's avatar
neogcg committed
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
  <div>
    <el-form
      ref="form"
      :model="formData"
      :rules="rules"
      label-width="200px"
      class="form"
    >
      <el-form-item label="铁路名:" prop="name">
        <el-input v-model="formData.name" placeholder="请输入铁路名" />
      </el-form-item>
      <el-form-item label="铁路线起点站名:" prop="startPointName">
        <el-input
          v-model="formData.startPointName"
          placeholder="请输入铁路线起点站名"
        />
      </el-form-item>
      <el-form-item label="铁路线终点站名:" prop="endPointName">
        <el-input
          v-model="formData.endPointName"
          placeholder="请输入铁路线终点站名"
        />
      </el-form-item>
      <el-form-item label="铁路全长(公里):" prop="totalLong">
        <el-input
          v-model="formData.totalLong"
          placeholder="请输入铁路全长公里数"
        />
      </el-form-item>
    </el-form>
    <div class="btn">
neogcg's avatar
neogcg committed
33 34 35
      <el-button type="primary" @click="reset">重置</el-button>
      <el-button type="primary" @click="submit">确认提交</el-button>
    </div>
neogcg's avatar
neogcg committed
36
  </div>
neogcg's avatar
neogcg committed
37 38
</template>
<script>
neogcg's avatar
neogcg committed
39
import { railWaysave } from "../../api";
neogcg's avatar
neogcg committed
40
import { successAlert, warningAlert } from "@/utils/alert";
neogcg's avatar
neogcg committed
41
import { mapGetters, mapActions } from "vuex";
neogcg's avatar
neogcg committed
42
export default {
neogcg's avatar
neogcg committed
43 44 45 46 47 48 49 50 51
  props: [],
  components: {},
  data() {
    return {
      formData: {
        endPointName: "",
        name: "",
        startPointName: "",
        totalLong: "",
neogcg's avatar
neogcg committed
52
      },
neogcg's avatar
neogcg committed
53

neogcg's avatar
neogcg committed
54
      rules: {
neogcg's avatar
neogcg committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        name: [
          { required: true, message: "请输入铁路名", trigger: "blur" },
          // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        startPointName: [
          { required: true, message: "请输入铁路线起点站名", trigger: "blur" },
        ],
        endPointName: [
          { required: true, message: "请输入铁路线终点站名", trigger: "blur" },
        ],
        totalLong: [
          { required: true, message: "请输入铁路全长公里数", trigger: "blur" },
        ],
        siteLongitude: [
          { required: true, message: "请输入铁路全长公里数", trigger: "blur" },
        ],
      },
neogcg's avatar
neogcg committed
72 73 74 75
    };
  },
  computed: {},
  methods: {
neogcg's avatar
neogcg committed
76
    ...mapActions({
neogcg's avatar
neogcg committed
77 78
      asyncrailWayList: "railWay/asyncList",
    }),
neogcg's avatar
neogcg committed
79
    reset() {
neogcg's avatar
neogcg committed
80 81 82
      this.$refs.form.resetFields();
    },
    submit() {
neogcg's avatar
neogcg committed
83
      this.$refs.form.validate((valid) => {
neogcg's avatar
neogcg committed
84
        if (valid) {
neogcg's avatar
neogcg committed
85
          railWaysave(this.formData).then((res) => {
neogcg's avatar
neogcg committed
86 87 88 89 90
            if (res.code == 200) {
              successAlert("添加成功");
              this.asyncrailWayList();
            } else {
              warning("添加失败");
neogcg's avatar
neogcg committed
91 92
            }
          });
neogcg's avatar
neogcg committed
93
        }
neogcg's avatar
neogcg committed
94 95 96 97 98 99
        this.formData = {
          endPointName: "",
          name: "",
          startPointName: "",
          totalLong: "",
        };
neogcg's avatar
neogcg committed
100 101
      });
    },
neogcg's avatar
neogcg committed
102 103
  },
  mounted() {},
neogcg's avatar
neogcg committed
104 105 106 107
};
</script>
<style lang="scss" scoped>
.form {
neogcg's avatar
neogcg committed
108 109 110 111 112 113 114 115 116
  padding: 20px 0;
  width: 600px;
  margin: 0 auto;
}
.btn {
  padding-top: 50px;
  text-align: center;
  button {
    width: 120px;
neogcg's avatar
neogcg committed
117
  }
neogcg's avatar
neogcg committed
118
}
neogcg's avatar
neogcg committed
119
</style>