<!--数据迁移配置-->
<template>
  <div class="systemBase common-container-deriction">
    <div class="common-title-div">数据迁移配置
      <div class="common-operation-button-div">
        <el-button icon="el-icon-circle-plus-outline" type="primary" size="mini" v-loading.fullscreen.lock="operateLoading"
           @click="addData"  v-privilege="activeMenu + 'ADD'">新增</el-button>
          <el-button icon="el-icon-edit" type="primary" size="mini" v-loading.fullscreen.lock="operateLoading"
          @click="modifyData"  v-privilege="activeMenu + 'UPDATE'">修改</el-button>
          <el-button size="mini" type="danger" plain icon="el-icon-remove-outline" v-loading.fullscreen.lock="operateLoading"
          @click="abolishData"  v-privilege="activeMenu + 'ABOLISH'">废除</el-button>
        <el-button size="mini" type="primary" icon="el-icon-check" v-loading.fullscreen.lock="operateLoading"
          @click="recoveryData"  v-privilege="activeMenu + 'RECOVERY'">启用</el-button>
      </div>
    </div>
    <div class="common-table-div">
     <el-table v-loading="dataLoading" @row-click="rowChange" ref="dataTable" :row-class-name="tableRowClassName" highlight-current-row
        border :height="tableHeight" @selection-change="handleSelectionChange" :data="table.list" :exchangeFilterMap="{'valueFlag':{'1':'无效','0':'有效'}}"
        :icore-filter-flag="icoreFilterFlag">
        <el-table-column type="index" label="序号" fixed="left" align="center"></el-table-column>
        <el-table-column type="selection" width="55" fixed="left" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="dataMigrationNo" label="配置编号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="220px" prop="countTypeNo" label="迁出表名" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="countPk" label="迁出表主键" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="rateValue" label="迁出条件表达式" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="220px" prop="contrastTypeNo" label="迁入表名" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="migrationNum" label="迁移数量" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="200px" prop="memo" label="备注" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" prop="valueFlag" width="70px" label="状态" align="center">
          <template slot-scope="scope">
              <span v-if="scope.row.valueFlag == 1">无效</span>
              <span v-else-if="scope.row.valueFlag == 0">有效</span>
          </template>
        </el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="70px" prop="createManName" label="创建人" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="150px" prop="createTime" label="创建时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="70px" prop="updateManName" label="修改人" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="150px" prop="updateTime" label="修改时间" align="center"></el-table-column>
        <!-- <el-table-column sortable :show-overflow-tooltip="true" fixed="right" min-width="80px" prop="updateTime" label="操作" align="center">
         <template slot-scope="scope">
              <el-button
               type="goon" size="mini" @click="migrateData(scope.row)">数据迁移
              </el-button>
         </template>
        </el-table-column> -->
      </el-table>
    </div>
    <div class="common-foot-style">
      <el-pagination v-loading="dataLoading" @size-change="pageSizeChange" @current-change="pageCurrentChange"
          :current-page="page.pageNum" :page-sizes="[100, 500, 1000]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page.totalPage">
        </el-pagination>
    </div>
    <!-- <div ref="editTitle" class="common-title-div" style="border-top: 1px solid #d5d5d5;">编辑区
    </div> -->
    <div ref="editDiv" class="commom-edit-div" style="border-top: 1px solid #d5d5d5; margin-top: 10px">
      <el-form ref="baseData" label-width="80px" :rules="ruleValidate" :inline="true" :model="baseData">
            <el-form-item prop="countTypeNo" label="迁出表名">
              <el-input v-model="baseData.countTypeNo" size="small" clearable placeholder="请输入" style="width:150px"></el-input>
            </el-form-item>
            <el-form-item prop="countPk" label="迁出表主键">
              <el-input v-model="baseData.countPk" size="small" clearable placeholder="请输入" style="width:150px"></el-input>
            </el-form-item>
            <el-form-item prop="rateValue" label="迁出条件">
              <el-input v-model="baseData.rateValue" size="small" clearable placeholder="请输入" style="width:150px"></el-input>
            </el-form-item>
            <el-form-item prop="contrastTypeNo" label="迁入表名">
              <el-input v-model="baseData.contrastTypeNo" size="small" clearable placeholder="请输入" style="width:150px"></el-input>
            </el-form-item>
             <el-form-item prop="migrationNum" label="迁移数量">
              <el-input v-model="baseData.migrationNum" size="small" clearable placeholder="请输入" style="width:150px"></el-input>
            </el-form-item>
            <el-form-item prop="memo" label="备      注">
              <el-input v-model="baseData.memo" size="small" clearable placeholder="请输入" style="width:150px"></el-input>
            </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
 import {
    meterbasedatamigrations
  } from '../../../utils/api.js';
  import {
    Delete,
    Recovery,
    add,
    modify,
    discard
  } from '../../../utils/httpRequest.js';
  import pinyinUtils from '../../../utils/pinyin/pinyinUtils.js'
  export default {
    data () {
      return {
        dataLoading: false,
        operateLoading: false,
        icoreFilterFlag: true,
        baseData: {
          countTypeNo: '',
          rateValue: '',
          contrastTypeNo: '',
          memo: '',
          migrationNum: '',
          countPk: ''
        },
        page: {
          pageSize: 500,
          pageNum: 1,
          totalPage: 0
        },
        table: {
          list: []
        },
        multipleSelection: [],
        tableHeight: 0,
        ruleValidate: {
          countTypeNo: [{
            required: true,
            message: '迁出表名不能为空',
            trigger: 'change'
          }],
          rateValue: [{
            required: true,
            message: '迁出条件不能为空',
            trigger: 'change'
          }],
          contrastTypeNo: [{
            required: true,
            message: '迁入表名不能为空',
            trigger: 'change'
          }],
          migrationNum: [{
            required: true,
            message: '迁移数量不能为空',
            trigger: 'change'
          }],
          countPk: [{
            required: true,
            message: '迁出表主键不能为空',
            trigger: 'change'
          }]
        },
        activeMenu: ''
      }
    },
    created () {
       this.tableHeight = (window.innerHeight - 220) > 400 ? window.innerHeight - 220 : 400
       this.activeMenu = window.top.localStorage.getItem('activeMenu')
    },
    mounted () {
      // this.tableHeight = this.getTableHeight(this.$refs['dataTable'].$el) - 80;
      this.getDataList();
    },
    methods: {
      rowChange (row, column, event) {
        let row1 = Object.assign ({}, row)
        this.baseData = row1;
      },
      addData () {
        let _this = this;
        _this.$refs['baseData'].validate((valid) => {
          if (valid) {
            _this.operateLoading = true;
            let baseDataAdd = {};
            baseDataAdd.countTypeNo = _this.baseData.countTypeNo
            baseDataAdd.rateValue = _this.baseData.rateValue
            baseDataAdd.contrastTypeNo = _this.baseData.contrastTypeNo
            baseDataAdd.memo = _this.baseData.memo
            baseDataAdd.migrationNum = _this.baseData.migrationNum
            baseDataAdd.countPk = _this.baseData.countPk
            add(meterbasedatamigrations, baseDataAdd, (e) => {
              _this.operateLoading = false;
              _this.getDataList();
              if (!e) {
                _this.$refs['baseData'].resetFields && _this.$refs['baseData'].resetFields();
              }
            })
          }
        });
      },
      modifyData () {
        let _this = this;
        _this.$refs['baseData'].validate((valid) => {
          if (valid) {
            _this.operateLoading = true;
            modify(meterbasedatamigrations + _this.baseData.dataMigrationNo + '/', _this.baseData, (e) => {
              _this.operateLoading = false;
              _this.getDataList();
              if (!e) {
                _this.$refs['baseData'].resetFields && _this.$refs['baseData'].resetFields();
              }
            })
          }
        });
      },
      recoveryData () {
        let _this = this;
        _this.operateLoading = true;
        Recovery(meterbasedatamigrations + 'Recovery', _this.multipleSelection, (e) => {
          _this.operateLoading = false;
          if (!e) {
            _this.getDataList();
          }
        });
      },
       abolishData () {
        let _this = this;
        _this.operateLoading = true;
        discard(meterbasedatamigrations + 'abolish', _this.multipleSelection, (e) => {
          _this.operateLoading = false;
          if (!e) {
            _this.getDataList();
          }
        });
      },
      handleSelectionChange (val) {
        this.multipleSelection = val;
      },
      getTableHeight (dom) {
        return (window.innerHeight - dom.offsetTop);
      },
      pageSizeChange (size) {
        this.page.pageSize = size;
        this.getDataList();
      },
      migrateData(row) {

      },
      pageCurrentChange (index) {
        this.page.pageNum = index;
        this.getDataList();
      },
      getDataList () {
        this.dataLoading = true;
        this.axios.get(meterbasedatamigrations + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize)
          .then(res => {
            this.dataLoading = false;
            this.table.list = res.data.list;
            this.page.totalPage = res.data.total;
          }).catch(e => {
            this.dataLoading = false;
          });
      },
      tableRowClassName ({
        row,
        rowIndex
      }) {
        if (row.valueFlag !== '0') {
          return 'error-row2';
        }
        return '';
      },
      myBlur () {
        if (this.baseData.customerSupplierName) {
          this.baseData.mnemonicCode = pinyinUtils.initial(this.baseData.customerSupplierName);
        }
      }
    }
  }
</script>

<style scoped>
  .el-select {
    width: 100%;
  }
</style>
