<template>
  <div ref="list">
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="95px" >
      <el-form-item label="经纪人" prop="userName">
        <el-input
          v-model="queryParams.userName"
          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>
    <el-table v-loading="loading" :data="userList" @sort-change="handleSortChange" :height="340"  ref="table"
              @selection-change="handleSelectionChange" row-key="id" :highlight-current-row="true" @row-click="handleRowClick" >
      <el-table-column label="经纪人"  prop="userName" sortable='custom' min-width="200px"/>
      <el-table-column label="真实姓名"  prop="realName" sortable='custom' min-width="200px"/>
    </el-table>
    <pagination
      size="small"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      layout=" prev, pager,next"
      @pagination="getList"
    />
  </div>
</template>
<script>
import {
  listUser
} from "@/api/system/user";
import AutoTableHeight from '@/views/broker/AutoTableHeight';
import {changeUserStatus} from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "DfBroker",
  mixins: [AutoTableHeight],
  dicts: ["df_broker_staus","sys_yes_no"],
  components: {Treeselect},
  data() {
    return {
      readonly:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中名字
      names: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 代理商经纪表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined,
        userType: "jj",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        brokerName: [
          {required: true, message: "代理商名称不能为空", trigger: "blur"}
        ],
        isInstitution: [
          {required: true, message: "是否机构不能为空", trigger: "blur"}
        ],
        staus: [
          {required: true, message: "状态不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    clearSelection() {
      this.resetQuery();
    },
    tenantIdnormalizer(node, instanceId) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.id,
        label: node.brokerName,
        children: node.children
      }
    },
    // 点击行
    handleRowClick(row) {
      this.$emit('row-click', row);
    },
    /** 查询代理商经纪列表 */
    getList() {
      this.loading = true;
      this.queryParams.isBroker = "Y";
      listUser(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      }).catch(e => {
        this.loading = false;
      });
      // listBrokerByTree().then(response => {
      //   this.brokerOptions = response.data;
      // });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        parentId: null,
        brokerName: null,
        brokerAddress: null,
        brokerDesc: null,
        orderNum: null,
        chargePerson: null,
        contactPhone: null,
        email: null,
        isInstitution: null,
        staus: null,
        remark: null,
      };
      this.resetForm("form");
    },
    //排序
    handleSortChange(col) {
      this.$sortBy(col, this.queryParams);
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.names = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

  }
};
</script>
