<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true" @submit.native.prevent>
        <el-form-item label="创建日期">
          <el-date-picker
           v-model="search.times"
           type="daterange"
           range-separator="至"
           start-placeholder="开始日期"
           end-placeholder="结束日期"
           size="small"
           style="width:300px"
           format="yyyy-MM-dd"
           value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" size="mini" @click="searchData">查询</el-button>
          <el-button icon="el-icon-refresh" type="info" plain size="mini" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="common-title-div">
      <div class="common-title-name">
        <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
        app配置
      </div>
      <div>
      <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini" @click="addData">新增</el-button>
      <el-button  type="goon" size="mini" icon="el-icon-download" :loading='imgLoading' @click="downloadFile">下载</el-button>
      <!-- <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyData">修改</el-button>
      <el-button icon="el-icon-circle-close" type="danger" size="mini" @click="deleteData">删除</el-button>
      <el-button icon="el-icon-check" type="goon" size="mini" @click="recoverData">启用</el-button> -->
      </div>
    </div>
    <div class="common-table-div">
       <el-table v-loading="dataLoading" ref="dataTable" border :height="height_top" highlight-current-row @selection-change="handleSelectionChange" :data="table.list" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :cell-class-name="tableRowClassName" :summary-method="getSummaries" show-summary>
        <el-table-column type="index" label="NO" fixed="left" align="center">
        </el-table-column>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="appName" label="名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="appDesc" label="描述" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="appVer" label="版本号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="165px" prop="createTime" label="创建时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="createMan" label="创建人" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="165px" prop="updateTime" label="修改时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="updateMan" label="修改人" align="center"></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="[10, 20, 50, 100, 200]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page.totalPage" background>
        </el-pagination>
    </div>
    <el-dialog  :visible.sync="imgVisible">
      <div slot="title" class="titleBox">
        <i class="el-icon-document" style="font-size: 20px"></i>
        <span style="margin-left:10px;font-size:18px">扫码下载</span>
      </div>
      <div style="text-align:center" v-loading='imgLoading'>
        <div style="text-align:center;display:inline-block" ref="qrCode"></div>
      </div>
    </el-dialog>
    <div is="alertComponets" :showFlag="showFlag" :Params="Params" @refresh='refresh'></div>
  </div>
</template>
<script>
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
import alertComponets from './alertComponents';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  components: {alertComponets},
  data () {
    return {
      table: {
        list: []
      },
      imgVisible:false,
      imgLoading:false,
      dataLoading: false,
      icoreFilterFlag: true,
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      showFlag: false,
      Params: {},
      multipleSelection: [],
      search: {
        times:''
      },
      baseUrl: 'https://lims.jnmc.com',
      height_top:0
    }
  },
  created() {
    this.height_top = window.innerHeight - 190; 
  },
 mounted () {
    this.getDataList();
    this.addScreen()
  },
  methods: {
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
        }
        if (index === 1) {
          sums[index] = data.length;
        } 
      });
      return sums;   
    }, 
    refresh () {
      this.getDataList();
    },
    addData () {
      let _this = this;
      _this.showFlag = !_this.showFlag;
      _this.Params = null;
    },
    searchData () {
      this.dataLoading = true;
      this.page.pageNum = 1;
      this.getDataList()
    },
    reset () {
      this.search.times = '';
      this.searchData();
    },
    downloadFile(row){
      this.imgLoading = true
      this.axios.post('pass/baseManagement/v1/limsbaseapps/queryappstatus',{},{individualType: 'json'}).then(res => {
        console.log(res.data)
        if (res.code == 0 || res.code == 200) {
          this.imgVisible = true
          let url = this.baseUrl + '/icore.icp.web/' + res.data.appPath
          this.$nextTick(()=>{
            this.$refs.qrCode.innerHTML = ""; //置空
            new QRCode(this.$refs.qrCode, {
              text: url,
              width: 200,
              height: 200,
              colorDark: "#000000",
              colorLight: "#ffffff",
            })
          })
        }else{
          this.$message.error(res.message)
        }
        this.imgLoading = false
      }).catch(e => {
        this.imgLoading = false
        this.$message.error(res.message)
      });
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList();
    },
    addScreen () {
      this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    getDataList () {
      this.dataLoading = true;
       let startTime = ''
      let endTime = ''
      if (!this.search.times) {
        startTime = ''
        endTime = ''
      }else{
        startTime = this.search.times[0] + ' 00:00:00'
        endTime = this.search.times[1] + ' 23:59:59'
      }
      let obj = {
        object:{},
        startTime:startTime,
        endTime:endTime,
        pageIndex:this.page.pageNum,
        pageSize:this.page.pageSize
      }
      this.axios.post('pass/baseManagement/v1/limsbaseapps/queryPageList',obj,{individualType: 'json'}).then(res => {
        this.dataLoading = false;
        this.table.list = res.data.list;
        this.page.totalPage = res.data.total;
      }).catch(e => {
        this.dataLoading = false;
      });
    },
   tableRowClassName ({
        row, column, rowIndex, columnIndex
      }) {
        if (columnIndex === 10) {
        if (row.validFlag !== '1') {
          return 'error-row';
        }
        return '';
        }
      },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
