<template>
  <div>
    <el-form ref="agentForm" :model="agentObj" :rules="rules" label-width="120px">
      <el-form-item label="代理商Agent" prop="agentId">
        <supplierSelect v-model="agentObj.agentId" placeholder="请选择代理商" v-bind="$attrs" />
      </el-form-item>
    </el-form>
    <el-row class="operate-button">
      <el-button type="success" @click="onSubmit">提交</el-button>
      <el-button @click="cancel">关闭</el-button>
    </el-row>
  </div>
</template>

<script>
import { agentSet, serviceMsg } from "@/api/ecw/boxSea";
import supplierSelect from "./common/supplierSelect.vue";
/**
 * agent
 */
export default {
  name: "agent",
  components: { supplierSelect },
  data() {
    return {
      // agent对象
      agentObj: {},
      // 校验
      rules: {
        agentId: [{ required: true, message: "必填", trigger: "change" }],
      },
    };
  },
  methods: {
    /** 提交 */
    onSubmit() {
      this.$refs["agentForm"].validate((valid) => {
        if (valid) {
          agentSet({
            shipmentId: this.$attrs.shipmentObj.id,
            ...this.agentObj,
          }).then((res) => {
            serviceMsg(res, this).then(() => {
              this.cancel();
            });
          });
        }
      });
    },
    /** 取消 */
    cancel() {
      this.$emit("closeDialog");
    },
  },
};
</script>

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