<template>
  <div>
    <el-form ref="settlementForm" :model="settlementObj" label-width="80px">
      <el-form-item label="可结算">
        <el-date-picker type="date" placeholder="请选择日期" v-model="settlementObj.slSettlementTime" value-format="yyyy-MM-dd"></el-date-picker>
      </el-form-item>
      <el-form-item label="已结算">
        <el-date-picker type="date" placeholder="请选择日期" v-model="settlementObj.slSettledTime" value-format="yyyy-MM-dd"></el-date-picker>
      </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 { settlementCreate } from "@/api/ecw/boxSea";
import { formatDateStr, serviceMsg } from "../utils";
/**
 * 结算
 */
export default {
  name: "settlement",
  inheritAttrs: false,
  data() {
    return {
      // 结算对象
      settlementObj: {},
    };
  },
  created() {
    const voName = this.$attrs.currNode.voName;
    let oldData = { ...this.$attrs.shipmentObj[voName] };
    oldData = formatDateStr(oldData, ["slSettlementTime", "slSettledTime"]);
    this.settlementObj = oldData;
  },
  methods: {
    /** 提交 */
    onSubmit(operateType) {
      this.$refs["settlementForm"].validate((valid) => {
        if (valid) {
          settlementCreate({
            ...this.settlementObj,
            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>
