<template>
  <div id="CustomersDepartment" class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="auto">
      <el-divider content-position="left">科室信息</el-divider>
      <el-row type="flex" class="row-bg" justify="space-around">
        <el-col :span="6">
          <el-form-item label="科室名称" prop="name">
            <el-input v-model="form.name" placeholder="请输入科室名称" :disabled="disable" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="客户名称" prop="customersName">
            <el-input v-model="form.customersName" placeholder="请输入客户名称" :disabled="disable" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="负责人姓名" prop="responsiblePersonName">
            <el-popover-select-v2 v-model="form.responsiblePersonName" title="负责人" valueKey="name"
              referName="CONTACTS_PARAM" :dataMapping="{responsiblePerson: 'id', responsiblePersonName: 'name'}"
              :source.sync="form" placeholder="请选择负责人" :disabled="disable" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" class="row-bg" justify="space-around">
        <el-col :span="6">
          <el-form-item label="联系人手机" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入联系人手机" :disabled="disable" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="科室位置" prop="address">
            <el-input v-model="form.address" placeholder="请输入科室位置" :disabled="disable" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="常规治疗" prop="conventionalTherapy">
            <el-input v-model="form.conventionalTherapy" placeholder="请输入常规治疗" :disabled="disable" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" class="row-bg" justify="space-around">
        <el-col :span="6">
          <el-form-item label="科室特色" prop="characteristic">
            <el-input v-model="form.characteristic" placeholder="请输入科室特色" :disabled="disable" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="业务员名称" prop="salesmanName">
            <el-input v-model="form.salesmanName" placeholder="请输入业务员名称" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="备注" prop="memo">
            <el-input v-model="form.memo" placeholder="请输入备注" :disabled="disable" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" class="row-bg" justify="space-around">
        <el-col :span="6">
          <el-form-item label="单据状态" prop="state">
          </el-form-item>
        </el-col>
      </el-row>
      <el-button type="primary" @click="submitForm" :disabled="disable">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </el-form>
  </div>
</template>

<script>
  import {
    listCustomersDepartment,
    getCustomersDepartment,
    delCustomersDepartment,
    addCustomersDepartment,
    updateCustomersDepartment
  } from "@/api/business/spd/cm/customersDepartment";
  // 参照弹出框
  import ElPopoverSelectV2 from "@/components/popover-select-v2";

  export default {
    name: "CustomersDepartment",
    props: ['pageStu', 'row', 'disable', 'customersId'],
    model: {
      prop: 'isAdd2',
      event: 'jugislist'
    },
    components: {
      ElPopoverSelectV2,
    },
    data() {
      return {
        // 不能直接改变props传来的值
        sonPageStu: this.pageStu,
        sonDisable: this.disable,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 客户科室表格数据
        customersDepartmentList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          customersName: null,
          responsiblePerson: null,
          responsiblePersonName: null,
          phone: null,
          address: null,
          conventionalTherapy: null,
          characteristic: null,
          salesman: null,
          salesmanName: null,
          marketingArea: null,
          marketingAreaName: null,
          memo: null,
          state: null,
          customersId: null,
          tenantId: null,
          revision: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          name: [{
            required: true,
            message: '科室名称不能为空',
            trigger: 'blur'
          }],
        }
      };
    },
    created() {
      this.reset();
      // 客户主键赋值
      this.form.customersId = this.customersId;
      if (this.pageStu == 'check' || this.pageStu == 'update') {
        this.getDetails(this.row);
      }
    },
    methods: {
      // 取消按钮
      cancel() {
        this.$emit('jugislist', false);
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          name: null,
          customersName: null,
          responsiblePerson: null,
          responsiblePersonName: null,
          phone: null,
          address: null,
          conventionalTherapy: null,
          characteristic: null,
          salesman: null,
          salesmanName: null,
          marketingArea: null,
          marketingAreaName: null,
          memo: null,
          state: null,
          customersId: null,
          tenantId: null,
          revision: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          delFlag: null
        };
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateCustomersDepartment(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.cancel();
              });
            } else {
              addCustomersDepartment(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.cancel();
              });
            }
          }
        });
      },
      /** 获取详情 */
      getDetails(row) {
        getCustomersDepartment(row.id).then(res => {
          if (res.code == 200) {
            this.form = res.data;
          }
        })
      },
    }
  };

</script>
