<template>
  <div class="app-container">
    <div v-show="viewState ==1">
      <button-bar view-title="项目列表" ref="btnbar" :btndisabled="btndisabled" @btnhandle="btnHandle" />
      <div class="main-content">
        <div class="searchcon">
          <el-button size="small" class="searchbtn" @click="clicksearchShow">{{ searchxianshitit }}</el-button>
          <div v-show="isSearchShow" class="search">
            <el-form ref="listQueryform" :inline="true" :model="listQuery" label-width="80px" class="tab-header">
              <el-form-item label="项目名称">
                <el-input v-model="listQuery.params.entryName" maxlength="20" placeholder="请输入项目名称" class="addinputw"
                  clearable />
              </el-form-item>
              <el-form-item label="项目类型">
                  <el-select v-model="listQuery.params.projectType" placeholder="请选择"  >
                  <el-option
                     v-for="(item,i) in ProjectTypeList"
                     :key="i"
                     :label="item.projectType"
                     :value="item.projectType">
                   </el-option>
                 </el-select>
              </el-form-item>
              <el-form-item label="贷款行">
                  <el-select v-model="listQuery.params.bankName" placeholder="请选择"  >
                  <el-option
                     v-for="(item,i) in storehouseList"
                     :key="i"
                     :label="item.bankName"
                     :value="item.bankName">
                   </el-option>
                 </el-select>
              </el-form-item>
            </el-form>
            <div class="btn" style="text-align: center;">
              <el-button type="primary" icon="el-icon-search" size="small" @click="handleReset">查询</el-button>
              <el-button type="primary" icon="el-icon-refresh" size="small" @click="handleFilter">重置</el-button>
            </div>
          </div>
        </div>
        <div class="listtop">
          <div class="tit">项目列表</div>
          <!-- 翻页分页 -->
          <!-- <pageye v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/> -->
        </div>
        <div class="">
          <el-table v-loading="listLoading" :data="list" border style="width: 100%;">
            <!-- <el-table-column type="selection" align="center" width="50"/> -->
            <el-table-column label="序号" type="index" width="80" :index="indexMethod" align="center" />
            <el-table-column label="操作" wid align="center" width="180">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" @click="toDetail(scope.row)">查看</el-button>
                <el-button type="primary" size="mini" @click="toEdit(scope.row)">编辑</el-button>
                <!-- <el-button type="primary" size="mini" @click="doDel(scope.row)">删除</el-button> -->
              </template>
            </el-table-column>
            <el-table-column label="项目名称"  prop="entryName"  width="250" align="center" />
              <el-table-column label="所属行业" prop="industryName" width="120" align="center" />
            <el-table-column label="项目类型" prop="typeName" width="120" align="center" />
            <el-table-column label="授信额度" prop="creditLimit" width="120" align="center" />
              <el-table-column label="签约日期" prop="signingDate" width="120" align="center" />
              <el-table-column label="到期日期" prop="endDate" width="120" align="center" />
              <el-table-column label="用信总额" prop="useLimit" width="120" align="center" />
            <el-table-column label="贷款行" prop="bankName" width="180" align="center" />
            <el-table-column label="客户经理" prop="bmanagerName" width="120" align="center" />
            <!-- <el-table-column label="企业名称"  prop="enterpriseName"  width="250"  align="center" /> -->
            <!-- <el-table-column label="联系人" prop="econtacts" width="100" align="center" /> -->
            <el-table-column label="监管负责人" prop="regulatoryLeader" width="120" align="center" />
          </el-table>
        </div>
        <div class="pages">
          <pagination v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current"
            :limit.sync="listQuery.size" class="pagination" @pagination="getList" />
        </div>
      </div>
    </div>
    <projectAdd v-show="viewState ==2 || viewState ==3" ref="divAdd" @doback="resetState"  @reloadlist="getList" />
    <projectInfo v-show="viewState ==4" ref="divInfo" @doback="resetState"   @reloadlist="getList"/>
  </div>
</template>

<script>
  import req from '@/api/project/project'
  import Pagination from '@/components/pagination'
  import pageye from '@/components/pagination/pageye'
  import ButtonBar from '@/components/ButtonBar'
  import projectAdd from './projectAdd2.vue'
  import projectInfo from './projectInfo2.vue'
  export default {
    name: 'CustomerManagement',
    components: {
      Pagination,
      pageye,
      ButtonBar,
      projectAdd,
      projectInfo,

    },
    data() {
      return {
          listLoading: false,
        btndisabled: false,
        btnList: [{
            type: 'primary',
            size: 'small',
            icon: 'plus',
            btnKey: 'toAdd',
            btnLabel: '新增'
          },

          {
            type: 'info',
            size: 'small',
            icon: 'cross',
            btnKey: 'doClose',
            btnLabel: '关闭'
          }
        ],
        isSearchShow: false,
        searchxianshitit: '显示查询条件',
        list: [],
        listQuery: {
          current: 1,
          size: 10,
          params: {
            entryName: '',
            projectType: '',
            bankName: '',
          },
          total: 0
        },
        viewState: 1,
        storehouseList:[],
        ProjectTypeList:[],
      }
    },
    mounted() {
      this.$refs['btnbar'].setButtonList(this.btnList)
    },
    created() {
      this.init()
      // 加载列表
    },
    methods: {
      btnHandle(btnKey) {
        switch (btnKey) {
          case 'toAdd':
            this.toAdd()
            break

          case 'doClose':
            this.doClose()
            break
          default:
            break
        }
      },
      // 搜索条件效果
      clicksearchShow() {
        this.isSearchShow = !this.isSearchShow
        if (this.isSearchShow) {
          this.searchxianshitit = '隐藏查询条件'
        } else {
          this.searchxianshitit = '显示查询条件'
        }
      },
      // 初始化
      init() {
        this.getList()
        this.getBankName()
      },
      // 序号
      indexMethod(index) {
        var pagestart = (this.listQuery.current - 1) * this.listQuery.size
        var pageindex = index + 1 + pagestart
        return pageindex
      },
      getBankName(){
        req.getBankName().then((res)=>{
          this.storehouseList=res.data
        })
        req.getProjectType().then((res)=>{
          this.ProjectTypeList=res.data
        })
      },
      // 查询列表信息
      getList() {
        this.listLoading = true
        req.listPage(this.listQuery).then((response) => {
          this.listLoading = false
          if (response.success) {
            this.list = response.data.records
            this.listQuery.total = response.data.total
          } else {
            this.list = []
            this.listQuery.total = 0
          }
        })
      },
      // 查询按钮
      handleReset() {
        this.listQuery.current = 1
        this.getList()
      },
      // 重置
      handleFilter() {
        this.listQuery = {
          current: 1,
          size: 10,
          total: 0,
          params: {
            entryName: '',
            projectType: '',
            bankName: '',
          }
        }
        this.getList()
      },
      // 打开添加
      toAdd() {
        this.viewState = 2
        this.$refs['divAdd'].showAdd()
      },
      // 打开修改
      toEdit(row) {
        this.viewState = 3
        this.$refs['divAdd'].showEdit(row)
      },
      // 根据本行ID删除数据
      doDel(row) {
        const tip = '请确认是否删除所选记录?'
        this.$confirm(tip, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          req.delBySids(row.sid).then((response) => {
            if (response.success) {
              this.$message({
                showClose: true,
                type: 'success',
                message: '删除成功'
              })
              this.getList()
            } else {
              this.$message({
                showClose: true,
                type: 'error',
                message: '删除失败'
              })
            }
          })
        })
      },
      toDetail(row) {
        this.viewState = 4
        this.$refs['divInfo'].showAdd(row.sid)
      },
      resetState() {
        this.viewState = 1
      },
      jump(sid) {
        console.log("jump",sid)
        this.viewState = 2
         this.$refs['divAdd'].showAdd(sid)
      },
      close(sid){
        this.viewState = 4
        this.$refs['divInfo'].showAdd(sid)
      },
      doClose() {
        this.$store.dispatch('tagsView/delView', this.$route)
        this.$router.go(-1)
      }
    }
  }
</script>
<style scoped>
</style>
