<template>
  <div class="app-container">
    <!-- Start 列表页面 -->
    <div>
      <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" class="tab-header" label-width="150px">
              <el-form-item label="数据字典类别编码:">
                <el-input v-model="listQuery.params.dictTypeCode" clearable placeholder=""/>
              </el-form-item>
              <el-form-item label="数据字典类别名称:">
                <el-input v-model="listQuery.params.dictTypeName" clearable placeholder=""/>
              </el-form-item>
              <el-form-item label="数据key:">
                <el-input v-model="listQuery.params.dictKey" clearable placeholder=""/>
              </el-form-item>
              <el-form-item label="数据value:">
                <el-input v-model="listQuery.params.dictValue" clearable placeholder=""/>
              </el-form-item>
              <el-form-item label="映射来源:">
                <el-select v-model="listQuery.params.map_sourceKey" filterable placeholder="">
                  <el-option v-for="item in mappingsource_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="映射实体名称:">
                <el-input v-model="listQuery.params.map_object" clearable placeholder=""/>
              </el-form-item>
              <el-form-item label="映射项目类别:">
                <el-input v-model="listQuery.params.map_item" clearable placeholder=""/>
              </el-form-item>
              <el-form-item label="映射项目编码:">
                <el-input v-model="listQuery.params.map_itemKey" clearable placeholder=""/>
              </el-form-item>
              <el-form-item label="映射项目值:">
                <el-input v-model="listQuery.params.map_itemValue" clearable placeholder=""/>
              </el-form-item>
            </el-form>
            <div class="btn" style="text-align: center;">
              <el-button type="primary" icon="el-icon-search" @click="handleFilter" size="small">查询</el-button>
              <el-button type="primary" icon="el-icon-refresh" @click="handleReset" size="small">重置</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 :key="tableKey" v-loading="listLoading" :data="list" border style="width: 100%;">
            <el-table-column fixed width="60px" label="序号" type="index" :index="indexMethod" align="center"/>
            <el-table-column label="数据字典类别编码" width="200" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.dictTypeCode }}</span>
              </template>
            </el-table-column>
            <el-table-column label="数据字典类别名称" align="center" width="200">
              <template slot-scope="scope">
                <span>{{ scope.row.dictTypeName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="数据key" align="center" width="150">
              <template slot-scope="scope">
                <span>{{ scope.row.dictKey }}</span>
              </template>
            </el-table-column>
            <el-table-column label="数据value" align="center" width="150">
              <template slot-scope="scope">
                <span>{{ scope.row.dictValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="映射来源" align="center" width="100">
              <template slot-scope="scope">
                <span>{{ scope.row.map_sourceValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="映射实体名称" align="center" width="200">
              <template slot-scope="scope">
                <span>{{ scope.row.map_object }}</span>
              </template>
            </el-table-column>
            <el-table-column label="映射项目类别" align="center" width="200">
              <template slot-scope="scope">
                <span>{{ scope.row.map_item }}</span>
              </template>
            </el-table-column>
            <el-table-column label="映射项目编码" align="center" width="200">
              <template slot-scope="scope">
                <span>{{ scope.row.map_itemKey }}</span>
              </template>
            </el-table-column>
            <el-table-column label="映射项目值" align="center" width="200">
              <template slot-scope="scope">
                <span>{{ scope.row.map_itemValue }}</span>
              </template>
            </el-table-column>
          </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>
  </div>
</template>

<script>
import Pagination from '@/components/pagination'
import pageye from '@/components/pagination/pageye'
import ButtonBar from '@/components/ButtonBar'
import { listPage } from '@/api/system/datamapping/datamapping'
import { typeValues } from '@/api/system/roleAdminister'

export default {
  name: 'shujuyingshe',
  components: {
    Pagination,
    pageye,
    ButtonBar,
  },
  data() {
    return {
      btndisabled: false,
      btnList: [
        {
          type: 'info',
          size: 'small',
          icon: 'cross',
          btnKey: 'doClose',
          btnLabel: '关闭'
        }
      ],
      isSearchShow: false,
      searchxianshitit: '显示查询条件',
      // 查询条件 -----------
      tableKey: 0,
      list: [],
      mappingsource_list: [],
      FormLoading: false,
      listLoading: false,
      listQuery: {
        params: {
          map_sourceKey: '',
          map_sourceValue: '',
          map_object: '',
          map_item: '',
          map_itemKey: '',
          map_itemValue: '',
          dictTypeCode: '',
          dictTypeName: '',
          dictKey: '',
          dictValue: ''
        },
        current: 1,
        size: 5,
        total: 0
      },
      rules: {}
    }
  },
  created() {
    // 加载列表
    this.getList()
    this.init()
  },
  mounted() {
    this.$refs['btnbar'].setButtonList(this.btnList)
  },
  methods: {
    init() {
      typeValues({ type: 'sys_mappingsource' }).then((resp) => {
        if (resp.success) {
          this.mappingsource_list = resp.data
        }
      })
    },
    // 搜索条件效果
    clicksearchShow() {
      this.isSearchShow = !this.isSearchShow
      if (this.isSearchShow) {
        this.searchxianshitit = '隐藏查询条件'
      } else {
        this.searchxianshitit = '显示查询条件'
      }
    },
    btnHandle(btnKey) {
      console.log('XXXXXXXXXXXXXXX    ' + btnKey)
      switch (btnKey) {
        case 'doClose':
          this.doClose()
          break
        default:
          break
      }
    },
    // 序号
    indexMethod(index) {
      var pagestart = (this.listQuery.current - 1) * this.listQuery.size
      var pageindex = index + 1 + pagestart
      return pageindex
    },
    // 查询列表信息
    getList() {
      this.listLoading = true
      listPage(this.listQuery).then((response) => {
        console.log('列表查询结果：', response)
        this.listLoading = false
        if (response.success && response.data && response.data.total > 0) {
          this.list = response.data.records
          this.listQuery.total = response.data.total
        } else {
          this.list = []
          this.listQuery.total = 0
        }
      })
    },
    // 查询按钮
    handleFilter() {
      this.listQuery.current = 1
      this.getList()
    },
    handleReset() {
      this.listQuery = {
        params: {
          map_sourceKey: '',
          map_sourceValue: '',
          map_object: '',
          map_item: '',
          map_itemKey: '',
          map_itemValue: '',
          dictTypeCode: '',
          dictTypeName: '',
          dictKey: '',
          dictValue: ''
        },
        current: 1,
        size: 5,
        total: 0
      }
      this.getList()
    },
    doClose() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.go(-1)
    }
  }
}
</script>
<style scoped>
/*表格列设置fixed后固定列出现下边框的设置*/
/deep/ .el-table__fixed {
  height: 100% !important;
}
/*表格列设置fixed后固定列出现下边框的设置*/
/deep/ .el-table__fixed-right {
  height: 100% !important;
}
</style>
