<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-collapse class="searchCollapse" disabled>
        <el-collapse-item>
          <template slot="title">
            <el-row class="flex">
              <div class="titleWrapper">
                <el-col :span="6">
                  <el-form-item label="客户名称" prop="customerName">
                    <el-input
                      v-model="queryParams.customerName"
                      placeholder="请输入客户名称"
                      clearable
                      @keyup.enter.native="handleQuery"
                      :style="{ width: '100%' }"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="客户编号" prop="customerCode">
                    <el-input
                      v-model="queryParams.customerCode"
                      placeholder="请输入客户编号"
                      clearable
                      @keyup.enter.native="handleQuery"
                      :style="{ width: '100%' }"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="客户状态" prop="status">
                    <el-select
                      v-model="queryParams.status"
                      placeholder="全部"
                      clearable
                      :style="{ width: '100%' }"
                    >
                      <el-option
                        v-for="dict in dict.type.CUSTOMER_STATUS"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="登记日期" prop="createdDate">
                    <el-date-picker
                      v-model="queryParams.createdDate"
                      type="date"
                      placeholder="请选择登记日期"
                      :style="{ width: '100%' }"
                    >
                      <!-- style="width: 205.4px" -->
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </template>
          <div class="infoWrapper">
            <el-row>
              <el-col :span="6">
                <el-form-item label="登记人" prop="createdBy">
                  <el-input
                    v-model="queryParams.createdBy"
                    placeholder="请输入登记人"
                    clearable
                    @keyup.enter.native="handleQuery"
                    :style="{ width: '100%' }"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="审核状态" prop="state">
                  <el-select
                    v-model="queryParams.state"
                    placeholder="全部"
                    clearable
                    :style="{ width: '100%' }"
                  >
                    <el-option
                      v-for="dict in dict.type.audit_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="是否启用" prop="isOpen">
                  <el-select
                    v-model="queryParams.isOpen"
                    placeholder="全部"
                    clearable
                    :style="{ width: '100%' }"
                  >
                    <el-option
                      v-for="dict in dict.type.start_using_yes_no"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="企业性质" prop="customerNature">
                  <el-select
                    v-model="queryParams.customerNature"
                    placeholder="全部"
                    clearable
                    :style="{ width: '100%' }"
                  >
                    <el-option
                      v-for="dict in dict.type.CUSTOMER_NATURE"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="申请部门" prop="responsibleDept">
                  <treeselect
                    v-model="queryParams.responsibleDept"
                    :options="deptOptions"
                    :show-count="true"
                    placeholder="全部"
                    :style="{ width: '100%' }"
                  />
                  <!-- style="width: 489px" -->
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="行业" prop="trade">
                  <el-select
                    v-model="queryParams.trade"
                    placeholder="全部"
                    clearable
                    :style="{ width: '100%' }"
                  >
                    <el-option
                      v-for="dict in dict.type.CUSTOMER_TRADE"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-collapse-item>
      </el-collapse>
      <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>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleUserPopAdd"
          >新增客户</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleApprovePopAdd"
          >指定审批人员</el-button
        >
      </el-col> -->
    </el-row>
    <el-table
      :header-cell-style="{ background: '#f8f8f9' }"
      v-loading="loading"
      :data="myTaskList"
    >
      <!--  @selection-change="handleSelectionChange" -->
      <el-table-column fixed type="selection" width="55" align="center" />
      <el-table-column
        fixed
        label="申请公司"
        align="center"
        prop="dhrmCompanyName"
      />
      <el-table-column fixed label="申请部门" align="center" prop="deptName" />
      <el-table-column label="客户名称" align="center" prop="customerName" />
      <el-table-column label="客户编码" align="center" prop="customerCode" />
      <el-table-column label="企业性质" align="center" prop="customerNature" />
      <el-table-column label="行业" align="center" prop="trade" />
      <el-table-column label="客户状态" align="center" prop="statusName" />
      <el-table-column label="成立日期" align="center" prop="registDate" />
      <el-table-column label="公司地址" align="center" prop="companyAddress" />
      <el-table-column label="申请人" align="center" prop="userName" />
      <el-table-column label="申请时间" align="center" prop="createdDate" />
      <el-table-column label="联系人" align="center" prop="contactsName" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="登记日期" align="center" prop="createdDate" />
      <el-table-column label="登记人" align="center" prop="userName" />
      <el-table-column label="审核状态" align="center" prop="state" />
      <el-table-column label="是否启用" align="center" prop="isOpen" />
      <el-table-column label="数据来源" align="center" prop="dateFrom" />
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:file:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:file:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加指定审批人员批对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="财务部" prop="financeDept">
          <el-select
            v-model="form.financeDept"
            multiple
            placeholder="请选择"
            :style="{ width: '100%' }"
          >
            <el-option
              v-for="item in financeDeptOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="法务部" prop="lawDept">
          <el-select
            v-model="form.lawDept"
            multiple
            placeholder="请选择"
            :style="{ width: '100%' }"
          >
            <el-option
              v-for="item in lawDeptOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { deptTreeSelect } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "customerInformationIndex",
  dicts: [
    "CUSTOMER_STATUS", //客户状态
    "audit_status", //审核状态
    "start_using_yes_no", //是否启用
    "CUSTOMER_NATURE", //企业性质
    "CUSTOMER_TRADE", //客户行业
  ], 
  components: { Treeselect,SearchFile },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerCode: null,
        customerName: null,
        status: null,
        createdDate: null,
        state: null,
        isOpen: null,
        customerNature: null,
        responsibleDept: null,
        trade: null,
      },
      // 部门树选项
      deptOptions: [],
      loading: false,
      open: false,
      title: "",
      form: {
        financeDept: null,
        lawDept: null,
      },
      rules: {},
      myTaskList: [],
      financeDeptOptions: [],
      lawDeptOptions: [],
    };
  },
  created() {
    // this.getList();
    this.getDeptTree();
  },
  mounted() {},
  methods: {
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    /** 查询客户信息列表 */
    getList() {
      this.loading = true;
      listFile(this.queryParams).then((response) => {
        this.myTaskList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    // 新增客户
    handleUserPopAdd() {
      this.$router.push({ name: "customerInformationAdd" });
    },
    // 指定审批人员
    handleApprovePopAdd() {
      this.reset();
      this.title = "指定审批人员";
      this.open = true;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 指定审批人员
    submitForm() {
      this.open = false;
    },
    // 表单重置
    reset() {
      this.form = {
        financeDept: null,
        lawDept: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      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;
    },
  },
};
</script>
<style lang="scss" scoped>
</style>