<template>
  <div class="app-container">
    <el-form
      label-position="left"
      ref="editForm"
      v-loading="loading"
      label-width="160px"
      :model="dto"
      :rules="rules"
    >
      <div class="itemGroup">
        <el-divider content-position="left">交航信息</el-divider>
        <el-form-item label="提单名称" prop="LadingBillNumber">
          <el-input v-model="dto.LadingBillNumber" />
        </el-form-item>
         <el-form-item label="提单重量(KG)" prop="TotalWeight">
          <el-input v-model="dto.TotalWeight" />
        </el-form-item>
        <el-form-item label="交航航班号" prop="FlightNo">
          <el-input v-model="dto.FlightNo" />
        </el-form-item>
        <el-form-item label="预计到达时间" prop="Eta">
          <el-date-picker
            v-model="dto.Eta"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="预计到达时间"
          />
        </el-form-item>
        <el-form-item label="航班起飞" prop="Etd">
          <el-date-picker
            v-model="dto.Etd"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="航班起飞"
          />
        </el-form-item>
        <el-form-item label="pdf扫描件" prop="PdfUrl">
          <el-upload
            class="upload-demo"
            action="http://wms.xingyunyi.cn/api/Finance/updateLoadFile"
            :on-success="changeFileUrl"
          >
            <el-button
              slot="trigger"
              size="small"
              type="info"
              icon="el-icon-upload"
              >选择文件</el-button
            >
          </el-upload>
          <span v-if="dto.PdfUrl"
            ><a :href="dto.PdfUrl" target="_blank">pdf扫描件查看</a></span
          >
        </el-form-item>
        <el-form-item label="起始港" prop="FromPortCode">
          <el-input v-model="dto.FromPortCode" />
        </el-form-item>
        <el-form-item label="中转港" prop="TransitPortCode">
          <el-input
            v-model="dto.TransitPortCode"
            placeholder="多个中转港用英文逗号隔开"
          />
        </el-form-item>
        <el-form-item label="目的港" prop="ToPortCode">
          <el-input v-model="dto.ToPortCode" />
        </el-form-item>
        <el-form-item label="交货类型" prop="CargoType">
          <el-select
            v-model="dto.CargoType"
            placeholder="交货类型"
            clearable
            filterable
          >
            <el-option
              v-for="item in CargoTypes"
              :key="item.Name"
              :label="item.Name"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="版号" prop="UldNo">
          <el-input v-model="dto.UldNo" />
        </el-form-item>
        <el-form-item label="版型" prop="UldType">
          <el-input v-model="dto.UldType" />
        </el-form-item>
      </div>
      <div class="itemGroup">
        <el-divider content-position="left">到达信息</el-divider>
        <el-form-item label="航班实际到达时间" prop="Ata">
          <el-date-picker
            v-model="dto.Ata"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="航班实际到达时间"
          />
        </el-form-item>
        <el-form-item label="航班实际起飞时间" prop="Atd">
          <el-date-picker
            v-model="dto.Atd"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="航班实际起飞时间"
          />
        </el-form-item>
        <el-form-item label="时区" prop="TimeZone">
          <el-input v-model="dto.TimeZone" />
        </el-form-item>
      </div>
      <div class="itemGroup" style="text-align: center">
        <el-form-item>
          <el-button type="primary" :loading="loading" @click="save()"
            >保存</el-button
          >
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>
<script>
import { Get9518Des } from "@/api/enum/enums";
import {
  GetTrunkLineInfo,
  EditTrunkLinePager,
} from "@/api/channel/CNTrunkLine";
export default {
  name: "ChannelCNTrunkLineEdit",
  data() {
    return {
      loading: false,
      uploading: false,
      CargoTypes: [],
      dto: {
        Id: 0,
        LadingBillNumber: "",
        TotalWeight:null,
        FlightNo: "",
        Eta: null,
        Etd: null,
        FromPortCode: "",
        TransitPortCode: "",
        ToPortCode: "",
        CargoType: null,
        UldNo: "",
        UldType: "",
        DeliveryPushStatus: 10,
        ArrivePushStatus: 10,
        ErrorMessage: "",
        ArriveFlightNo: "",
        Ata: null,
        Atd: null,
        TimeZone: 8,
        PdfUrl: "",
        DeliveryPushStatusStr: "",
        ArrivePushStatusStr: "",
      },
      rules: {
        LadingBillNumber: [
          { required: true, message: "请输入提单号", trigger: "blur" },
        ],
        FromPortCode: [
          { required: true, message: "请输入起始港", trigger: "blur" },
        ],
        ToPortCode: [
          { required: true, message: "请输入目的港", trigger: "blur" },
        ],
        Etd: [
          { required: true, message: "请输入航班起飞时间", trigger: "blur" },
        ],
        Eta: [
          { required: true, message: "请输入预计到达时间", trigger: "blur" },
        ],
         FlightNo: [
          { required: true, message: "请填写交航航班号", trigger: "blur" },
        ],
         CargoType: [
          { required: true, message: "请选择交货类型，并在交货类型为整版时填写版型版号", trigger: "blur" },
        ],
         TotalWeight: [
          { required: true, message: "请填写提单重量", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    var Id = this.$route.params.Id;
    if (Id > 0) {
      GetTrunkLineInfo(Id).then((res) => {
        this.dto = res;
      });
    }
    Get9518Des("CargoTypeEnum").then((res) => {
      this.CargoTypes = res;
      console.log(res);
    });
  },
  methods: {
    changeFileUrl(r) {
      this.dto.PdfUrl = r.Data.url;
    },
    save() {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          EditTrunkLinePager(this.dto)
            .then((res) => {
              this.$message({
                type: "success",
                message: "保存成功",
              });
              this.$router.push({
                name: "ChannelCNTrunkLine",
              });
            })
            .finally(() => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>
