<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="创建日期" prop="createDate">
        <el-date-picker clearable
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="部门名称" prop="departmentName">
        <el-input
          v-model="queryParams.departmentName"
          placeholder="请输入部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门编码" prop="departmentCode">
        <el-input
          v-model="queryParams.departmentCode"
          placeholder="请输入部门编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售区域" prop="area">
        <el-input
          v-model="queryParams.area"
          placeholder="请输入销售区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售组织" prop="organization">
        <el-input
          v-model="queryParams.organization"
          placeholder="请输入销售组织"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最佳拜访地点" prop="visitPlace">
        <el-input
          v-model="queryParams.visitPlace"
          placeholder="请输入最佳拜访地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最佳拜访时间" prop="visitTime">
        <el-date-picker clearable
          v-model="queryParams.visitTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择最佳拜访时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="家庭地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入家庭地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮件" prop="mail">
        <el-input
          v-model="queryParams.mail"
          placeholder="请输入邮件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关键决策人" prop="decisionMaker">
        <el-input
          v-model="queryParams.decisionMaker"
          placeholder="请输入关键决策人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="擅长领域" prop="fieldExpertise">
        <el-input
          v-model="queryParams.fieldExpertise"
          placeholder="请输入擅长领域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支持度" prop="support">
        <el-input
          v-model="queryParams.support"
          placeholder="请输入支持度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="决策力" prop="power">
        <el-input
          v-model="queryParams.power"
          placeholder="请输入决策力"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职称" prop="jobTitle">
        <el-input
          v-model="queryParams.jobTitle"
          placeholder="请输入职称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职务" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入职务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任职科室" prop="section">
        <el-input
          v-model="queryParams.section"
          placeholder="请输入任职科室"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上级联系人" prop="superiorContact">
        <el-input
          v-model="queryParams.superiorContact"
          placeholder="请输入上级联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务爱好" prop="hobby">
        <el-input
          v-model="queryParams.hobby"
          placeholder="请输入业务爱好"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="籍贯" prop="birthplace">
        <el-input
          v-model="queryParams.birthplace"
          placeholder="请输入籍贯"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生日" prop="birthday">
        <el-date-picker clearable
          v-model="queryParams.birthday"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择生日">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="联系人分类" prop="contactClassification">
        <el-input
          v-model="queryParams.contactClassification"
          placeholder="请输入联系人分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属客户编码" prop="customerCode">
        <el-input
          v-model="queryParams.customerCode"
          placeholder="请输入所属客户编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gander">
        <el-input
          v-model="queryParams.gander"
          placeholder="请输入性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属客户" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入所属客户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <ContactList :key="timer" :source = "'Contact'" :bo="this.queryParams" :boAuthority="boAuthority" />
  </div>
</template>

<script>
import { listContact, getContact, delContact, addContact, updateContact } from "@/api/business/spd/bo/contact";
import ContactList from '../contact/contactList.vue'

export default {
  name: "Contact",
  components: {ContactList},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 联系人管理表格数据
      contactList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        boId: null,
        createDate: null,
        departmentName: null,
        departmentCode: null,
        area: null,
        organization: null,
        visitPlace: null,
        visitTime: null,
        address: null,
        mail: null,
        telephone: null,
        decisionMaker: null,
        fieldExpertise: null,
        support: null,
        power: null,
        jobTitle: null,
        position: null,
        section: null,
        superiorContact: null,
        state: null,
        hobby: null,
        birthplace: null,
        birthday: null,
        contactClassification: null,
        customerName: null,
        customerCode: null,
        gander: null,
        name: null,
        code: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        area: [
          { required: true, message: "销售区域不能为空", trigger: "blur" }
        ],
        organization: [
          { required: true, message: "销售组织不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "家庭地址不能为空", trigger: "blur" }
        ],
        telephone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        decisionMaker: [
          { required: true, message: "关键决策人不能为空", trigger: "blur" }
        ],
        power: [
          { required: true, message: "决策力不能为空", trigger: "blur" }
        ],
        jobTitle: [
          { required: true, message: "职称不能为空", trigger: "blur" }
        ],
        position: [
          { required: true, message: "职务不能为空", trigger: "blur" }
        ],
        section: [
          { required: true, message: "任职科室不能为空", trigger: "blur" }
        ],
        customerName: [
          { required: true, message: "所属客户名称不能为空", trigger: "blur" }
        ],
        gander: [
          { required: true, message: "性别不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        code: [
          { required: true, message: "编号不能为空", trigger: "blur" }
        ],
      },
      //重新加载子组件参数
      timer: '',
      //列表权限写死
      boAuthority:{
        boAuthority:{
          contactAdd:true,
          contactEdit:true,
          contactView:true,
          contactDel:true,
        }
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询联系人管理列表 */
    getList() {
      this.loading = true;
      listContact(this.queryParams).then(response => {
        this.contactList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        boId: null,
        delFlag: null,
        updateTime: null,
        updateBy: null,
        createDate: null,
        createBy: null,
        departmentName: null,
        departmentCode: null,
        area: null,
        organization: null,
        visitPlace: null,
        visitTime: null,
        address: null,
        mail: null,
        telephone: null,
        decisionMaker: null,
        fieldExpertise: null,
        support: null,
        power: null,
        jobTitle: null,
        position: null,
        section: null,
        superiorContact: null,
        state: null,
        hobby: null,
        birthplace: null,
        birthday: null,
        contactClassification: null,
        customerName: null,
        customerCode: null,
        gander: null,
        name: null,
        code: null,
        id: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log('this.queryParams',this.queryParams);
      this.queryParams.pageNum = 1;
      this.timer = new Date().getTime();
      // this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加联系人管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContact(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改联系人管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContact(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContact(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除联系人管理编号为"' + ids + '"的数据项？').then(function() {
        return delContact(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/contact/export', {
        ...this.queryParams
      }, `contact_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
