<template>
  <div id="CustomersResponsiblePerson" class="app-container">
    <el-divider content-position="left">负责人信息</el-divider>
    <el-super-form
      v-model="params"
      :dict="dict"
      :rules="rules"
      :size="size"
      :columns="PrincipalCloumns"
      ref="superForm"
      label-width="auto"
      label-position="right"
      style="padding: 20px"
      :disabled="disable"
    >
    </el-super-form>
    <div slot="footer" style="text-align: right">
      <el-button
        type="primary"
        :size="size"
        @click="submitForm('superForm')"
        :disabled="disable"
        >确 定</el-button
      >
      <el-button :size="size" @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { dicts } from "../dicts";
import useColumns from "./columns";
import {
  listCustomersResponsiblePerson,
  getCustomersResponsiblePerson,
  delCustomersResponsiblePerson,
  addCustomersResponsiblePerson,
  updateCustomersResponsiblePerson,
} from "@/api/business/spd/cm/customersResponsiblePerson";
// // 参照弹出框
import ElPopoverSelectV2 from "@/components/popover-select-v2";

export default {
  name: "CustomersResponsiblePerson",
  props: ["pageStu", "row", "disable", "customersId", "customersName"],
  model: {
    prop: "isAdd1",
    event: "jugislist",
  },
  dicts: [...dicts],
  components: {
    ElPopoverSelectV2,
    ElSuperForm: () => import("@/components/super-form/index.vue"),
  },
  data() {
    const { PrincipalCloumns } = useColumns();
    const params = this.$init.params(PrincipalCloumns);
    const rules = this.$init.rules(PrincipalCloumns);
    return {
      rules,
      PrincipalCloumns,
      size: "mini",
      params: {
        ...params,
        id: null,
        person: null,
        customersId: null,
        tenantId: null,
        revision: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
      },
      // 遮罩层
      loading: true,
      // // 选中数组
      // ids: [],
      // // 非单个禁用
      // single: true,
      // // 非多个禁用
      // multiple: true,
      // // 显示搜索条件
      // showSearch: true,
      // // 总条数
      // total: 0,
      // 客户负责人表格数据
      customersResponsiblePersonList: [],
    };
  },
  created() {
    this.initialization();
  },
  methods: {
    // 初始化
    initialization() {
      // 客户主键赋值
      this.params.customersId = this.customersId;
      this.params.customersName = this.customersName;
      if (this.pageStu == "check" || this.pageStu == "update") {
        this.getDetails(this.row);
      }
    },
    // 取消按钮
    cancel() {
      this.$emit("jugislist", false);
    },
    /** 提交按钮 */
    submitForm(prop) {
      this.$refs[prop].validate(async (valid) => {
        if (valid) {
          try {
            let { params } = this;
            let { code, msg } =
              params.id != null
                ? await updateCustomersResponsiblePerson(params)
                : await addCustomersResponsiblePerson(params);
            if (code == 200) {
              this.$notify.success(msg);
              this.cancel();
              this.$parent.handleCheck(params.customersId);
            }
          } catch (error) {}
        }
      });
    },
    /** 获取详情 */
    getDetails(row) {
      getCustomersResponsiblePerson(row.id).then((res) => {
        if (res.code == 200) {
          this.params = res.data;
        }
      });
    },
  },
};
</script>
