<template>
  <div>
    <el-form ref="cDocForm" :model="cDocObj" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="出单方式">
            <el-select v-model="cDocObj.cdOutBillType" placeholder="请选择出单方式">
              <el-option v-for="item in method" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="电放时间">
            <el-date-picker type="date" placeholder="请选择日期" v-model="cDocObj.cdElectricTime" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="寄送时间">
            <el-date-picker type="date" placeholder="请选择日期" v-model="cDocObj.cdSendTime" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="快递单号">
            <el-input v-model="cDocObj.cdBillNo" placeholder="请输入快递单号"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="电放凭证附件">
        <FileUpload :limit="1" :isShowTip=false v-model="cDocObj.cdElectricVoucher" :fileType="fileType" />
      </el-form-item>

      <el-form-item label="agent list">
        <el-radio-group v-model="cDocObj.cdAgentlistType">
          <el-radio v-for="item in status" :key="item.value" :label="item.value">{{item.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-date-picker type="date" placeholder="请选择日期" v-model="cDocObj.cdAgentlistTime" value-format="yyyy-MM-dd"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <FileUpload :limit="1" :isShowTip=false v-model="cDocObj.cdAgentlistFile" :fileType="fileType" />
      </el-form-item>

      <el-form-item label="soncap">
        <el-radio-group v-model="cDocObj.cdSoncapType">
          <el-radio v-for="item in status" :key="item.value" :label="item.value">{{item.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-date-picker type="date" placeholder="请选择日期" v-model="cDocObj.cdSoncapTime" value-format="yyyy-MM-dd"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <FileUpload :limit="1" :isShowTip=false v-model="cDocObj.cdSoncapFile" :fileType="fileType" />
      </el-form-item>

    </el-form>
    <el-row class="operate-button">
      <el-button type="primary" @click="onSubmit(1)">保存</el-button>
      <el-button type="success" @click="onSubmit(2)">提交</el-button>
      <el-button @click="cancel">关闭</el-button>
    </el-row>
  </div>
</template>

<script>
import { clearanceDocCreate, serviceMsg } from "@/api/ecw/boxSea";
import {
  constantDict,
  formatDateStr,
  formatNumberString,
  fileTypes,
} from "../utils";
import FileUpload from "@/components/FileUpload";

/**
 * 清关文件
 */
export default {
  name: "clrDocument",
  inheritAttrs: false,
  components: { FileUpload },
  data() {
    return {
      // 清关文件对象
      cDocObj: {},
      // 出单方式
      method: constantDict.billingMethod,
      // 选项
      status: constantDict.isFile,
      // 文件类型
      fileType: fileTypes,
    };
  },
  created() {
    const voName = this.$attrs.currNode.voName;
    let oldData = { ...this.$attrs.shipmentObj[voName] };
    oldData = formatDateStr(oldData, [
      "cdElectricTime",
      "cdSendTime",
      "cdAgentlistTime",
      "cdSoncapTime",
    ]);
    oldData = formatNumberString(oldData, [
      "cdOutBillType",
      "cdAgentlistType",
      "cdSoncapType",
    ]);
    this.cDocObj = oldData;
  },
  methods: {
    /** 提交 */
    onSubmit(operateType) {
      this.$refs["cDocForm"].validate((valid) => {
        if (valid) {
          clearanceDocCreate({
            ...this.cDocObj,
            shipmentId: this.$attrs.shipmentObj.id,
            operateType,
          }).then((res) => {
            serviceMsg(res, this).then(() => {
              this.cancel("submit");
            });
          });
        }
      });
    },
    /** 取消 */
    cancel(type) {
      this.$emit("closeDialog", type);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
