<template>
  <div class="people">
      <el-container class="people-container">
          <!--搜索栏-->
          <el-aside class="people-container-left">
               <el-row :gutter="10" class="classHouse-container-left-row">
                        <el-col :span="24" class="mt10 mb20">
                          <el-divider content-position="left" class="classHouse-container-left-row-title">所处区域</el-divider>
                        </el-col>
                        <el-col :span="24">
                          <el-tree
                            class="filter-tree classHouse-container-left-row-tree"
                            :props="peopleTreeObj.defaultProps"
                            :load="loadNode"
                            lazy
                            empty-text="暂无数据"
                            @node-click="handleNodeClick"
                            :highlight-current="true"
                            ref="classHouseTreeRef"
                          ></el-tree>
                        </el-col>
                </el-row>
          </el-aside>
          <!--主体内容区域-->
          <el-main class="classHouse-container-right">
              <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
                <el-form-item prop="phonenumber">
                  <el-input
                    v-model="queryParams.condition"
                    placeholder="贫困集体名称"
                    clearable
                    size="small"
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button type="cyan" 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"
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd"
                  >新增</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
              </el-row>
              <el-table v-loading="loading" :data="list">
                <el-table-column label="序号" type="index" width="50" align="center" />
                <el-table-column label="归属集体编号" align="center" prop="collectiveCode" />
                <el-table-column label="归属集体名称" align="center" prop="collectiveName"/>
                <el-table-column label="关联户数" align="center" prop="collectivePersonNum"/>
                <el-table-column label="集体账户单位" align="center" prop="orgUnit"/>
                <el-table-column label="银行卡号" align="center" prop="bankCardNo"/>
                <el-table-column label="备注说明" align="center" prop="remark"/>
                <el-table-column
                  label="操作"
                  align="center"
                  width="280"
                  class-name="small-padding fixed-width"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="primary"
                      icon="el-icon-view"
                      @click="handleView(scope.row)"
                    >查看</el-button>
                    <el-button
                      size="mini"
                      type="success"
                      icon="el-icon-edit"
                      @click="handleEdit(scope.row)"
                    >编辑</el-button>
                    <el-button
                      size="mini"
                      type="danger"
                      @click="handleDelete(scope.row)"
                      icon="el-icon-delete"
                    >删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNo"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
          </el-main>
      </el-container>
      <!--弹窗口-->
      <add-mobiel
      			v-if="modal.visibleModal"
      			:title="modal.title"
      			:action="modal.action"
      			:visible="modal.visibleModal"
      			:selectRow="modal.selectRow"
      			@closeModal="closeModal">
      		</add-mobiel>
  </div>
</template>

<script>
import { getTree , listOrg , delCollectiveFarmer} from "@/api/belongToSubject/org";
import addMobiel from './modal/addMobiel'
export default {
  name: "org",
  components: {
    addMobiel
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 40,
      // 表格数据
      list: null,
      //树形菜单配置
      peopleTreeObj:{
        defaultProps: {
          label: 'name',
          children: 'children',
          isLeaf: false
        }
      },
      // 表单参数
      form: {},
      //弹出层
      modal:{
        action:'',
        title:'',
        visibleModal:false,
        selectRow:null
      },
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //菜单节点载入
    loadNode(node, resolve) {
      if (node.level === 0) {
        return resolve( [{ name: '重庆市',code:'156050',level:0 }] );
      }else{
         this.getChildrenNode(node,resolve)
      }
    },
    //查询子节点
    getChildrenNode(node,resolve){
      if(node.data.level <= 4){
        let params = {
          code:node.data.code
        }
        getTree(params).then(res => {
            let arr = res.retBody
            const list = arr.map(item => {
              if(item.level > 4){
                item.isLeaf = false
                item.children = null
              }else{
                item.isLeaf = true
              }
              return item
            })
            resolve(list)
          }
        );
      }else{
        resolve([])
      }
    },
    //节点点击
    handleNodeClick(node){
      this.queryParams = {
        pageNo: 1,
        pageSize: 10
      }
      switch(node.level){
        case 0:
           this.queryParams.provinceId = node.code
           break;
        case 2:
           this.queryParams.cityId = node.code
           break;
        case 3:
           this.queryParams.countyId = node.code
           break;
        case 4:
           this.queryParams.townId = node.code
           break;
        case 5:
           this.queryParams.villageId = node.code
           break;
      }
      this.getList()
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listOrg(this.queryParams).then(res => {
          this.loading = false;
          if(res.retHead.errCode == 0){
            this.list = res.retBody;
            this.total = res.retHead.total;
          }
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
        this.modal.visibleModal = true
        this.modal.title = '新增归属集体信息'
        this.modal.action = 'add'
    },
    /** 查看按钮操作 */
    handleView(item){
        this.modal.visibleModal = true
        this.modal.title = '归属集体信息详情'
        this.modal.action = 'view'
        this.modal.selectRow = item
    },
    /** 查看按钮操作 */
    handleEdit(item){
        this.modal.visibleModal = true
        this.modal.title = '编辑归属集体信息'
        this.modal.action = 'edit'
        this.modal.selectRow = item
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除该数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCollectiveFarmer(row);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {
          this.msgError("删除失败")
        });
    },
    //窗口关闭
    closeModal(flag = false){
      this.modal.visibleModal = false
      flag && this.getList()
    }
  }
};
</script>
<style scoped lang="scss">
  .people {
    width: 100%;
    height: 100%;
    margin: 10px 10px 0 0;
    padding: 0 10px 0 0;
    &-container {
      width: 100%;
      height: 100%;
      &-left {
        background: #fff;
        padding: 0 20px;
        width: 320px !important;
        min-height: 850px;
        height: auto;
        &-row {
          margin: 0 !important;
          &-title .el-divider__text {
            font-size: 18px;
            font-weight: 700;
            font-style: normal;
          }
          &-tree {
          }
        }
      }
      &-switch {
        font-size: 28px;
        cursor: pointer;
        color: #1890ff;
        &-leftbtn {
          position: absolute;
          top: 50%;
          left: 325px;
          cursor: pointer;
        }
        &-rightbtn {
          position: absolute;
          top: 50%;
          left: -5px;
          cursor: pointer;
        }
      }
      &-right {
        padding:20px;
        &-main {
          background: #fff;
          height: auto;
          min-height: 850px;
          &-defaultMl {
            margin-left: 10px;
          }
          &-nodefaultMl {
            margin-left: 0;
          }
        }
      }
    }
  }
</style>
