<template>
  <div>
    <el-form ref="shipForm" :model="shipObj" :rules="rules" label-width="80px">
      <el-form-item label="状态" prop="saExmtStatus">
        <el-radio-group v-model="shipObj.saExmtStatus">
          <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 label="配船时间" v-show="shipObj.saExmtStatus === '2'">
        <el-date-picker type="date" placeholder="请选择日期" v-model="shipObj.configTime" 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 { shipConfigure, serviceMsg } from "@/api/ecw/boxSea";
import { formatNumberString, formatDateStr, constantDict } from "../utils";
/**
 * 配船
 */
export default {
  name: "ship",
  inheritAttrs: false,
  props: {
    shipmentObj: Object,
  },
  data() {
    return {
      // 配船对象
      shipObj: {},
      // 状态
      status: constantDict.saExmtStatus,
      // 校验
      rules: {
        saExmtStatus: [{ required: true, message: "必填", trigger: "change" }],
      },
    };
  },
  created() {
    const voName = this.$attrs.currNode.voName;
    let oldData = { ...this.shipmentObj[voName] };
    oldData = formatNumberString(oldData, ["saExmtStatus"]);
    oldData = formatDateStr(oldData, ["configTime"]);
    this.shipObj = oldData;
  },
  methods: {
    /** 提交 */
    onSubmit(operateType) {
      this.$refs["shipForm"].validate((valid) => {
        if (valid) {
          shipConfigure({
            operateType,
            shipmentId: this.shipmentObj.id,
            ...this.shipObj,
          }).then((res) => {
            serviceMsg(res, this).then(() => {
              this.cancel("submit");
            });
          });
        }
      });
    },
    /** 取消 */
    cancel(type) {
      this.$emit("closeDialog", type);
    },
  },
};
</script>

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