
<style scoped>
.user-panel {
  margin: 10px auto;
}
</style>
<template>
  <el-dialog
    :visible.sync="showDialog"
    :title="title"
    :modal-append-to-body="true"
    style="text-align: left"
    width="500px"
    @close="closeDialog"
    :close-on-click-modal="false"
    append-to-body
  >
    <div class="user-panel" v-loading="loading">
      <el-form
        ref="form"
        :model="formModel"
        :rules="ruleValidate"
        :label-width="'130px'"
      >

        <el-form-item label="发车时间" prop="startTime">
            <el-time-select 
            placeholder="起始时间" 
            v-model="formModel.startTime"
            :picker-options="{
                start: '00:00',
                step: '00:05',
                end: '23:55'
            }">
            </el-time-select>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="handleSubmit" :loading="submitting"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import routeTimeTableApi from "@/api/bus/routeTimeTable";


export default {
  props: ["businessKey", "title","routeId"],
  data() {
    return {
      formModel: {
        startTime: "",
      },
      ruleValidate: {
        gpsDeviceNo: [
          { required: true, message: "gps设备号不能为空", trigger: "blur" },
        ],
      },
      showDialog: true,
      loading: false,
      submitting: false,
      typeData: [],
      props: {
        // 配置项（必选）
        value: "id",
        label: "name",
        children: "children",
      },
      sceneData: [],
      regionData: [],
      routeList: [],
    };
  },
  created() {

  },
  methods: {
    closeDialog() {
      this.$emit("close", false);
    },
    handleSubmit() {
      var self = this;

      this.$refs["form"].validate((valid) => {
        if (valid) {
          (function () {
            var id = self.formModel.id;

            self.formModel.routeId = self.routeId;

            if (id == null || id.length == 0) {
              return routeTimeTableApi.add(self.formModel);
            } else {
              return routeTimeTableApi.update(self.formModel);
            }
          })().then(function (response) {
            var jsonData = response.data;

            if (jsonData.result) {
              self.$message({
                message: "保存成功!",
                type: "success",
              });

              self.$emit("close", true);
            } else {
              self.$message({
                message: jsonData.message + "",
                type: "warning",
              });

              self.$emit("close", false);
            }
          });
        }
      });
    },
  },

  mounted: function () {
    var self = this;
    (function () {
      if (self.businessKey.length == 0) {
        return routeTimeTableApi.create();
      } else {
        return routeTimeTableApi.edit(self.businessKey);
      }
    })()
      .then((response) => {
        var jsonData = response.data;
        self.loading = false;

        if (jsonData.result) {
          self.formModel = jsonData.data;
        } else {
          self.$message.error(jsonData.message + "");
        }
      })
      .catch((error) => {
        self.$message.error(error + "");
      });
  },
};
</script>
<style>
.user-panel {
  margin: 10px auto;
}

.amap-demo {
  width: 100%;
  height: 400px;
}

.my-font {
  font-size: 20px;
  cursor: pointer;
  margin-right: 10px;
}
</style>