<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true">
        <el-form-item label='标准内容号'>
          <el-input v-model="search.contentNo" @keyup.enter.native="searchData" size="small" placeholder="请输入查询内容" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label='标准名称'>
          <el-input v-model="search.stdName" @keyup.enter.native="searchData" size="small" placeholder="请输入查询内容" style="width: 200px;"></el-input>
        </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' />
        标准内容配置
      </div>
      <div>
      <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini" @click="addData">新增</el-button>
      <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyData">修改</el-button>
      <el-button icon="el-icon-remove-outline" 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" :row-class-name="tableRowClassName" :summary-method="getSummaries" show-summary :row-key="getRowKeys"
        @expand-change="expandChange">
        <el-table-column type="expand" fixed="left">
          <template slot-scope="{row}">
            <el-table  ref="dataTable3" border  highlight-current-row :data="row.data"
             :header-cell-style="tableHeaderCellStyle2" :cell-class-name="tableRowClassName2">
             <el-table-column type="index" label="NO" fixed="left" align="center">
             </el-table-column>
             <el-table-column width="50px" fixed="left" align="center">
                <template slot-scope="scope">
                  <div style="cursor: pointer;line-height:20px" @click.prevent="deleteData2(scope.row)">
                   <i class="el-icon-delete" style="font-size:18px; color:rgb(18, 52, 243)"></i>
                  </div>
                </template>
             </el-table-column>
             <el-table-column  width="50px" fixed="left" :render-header="renderHeader"  align="center">
                <template slot-scope="scope">
                  <div style="cursor: pointer;line-height:20px" @click.prevent="modifyData2(scope.$index,scope.row)">
                    <i class="el-icon-edit" style="font-size:18px; color:rgb(18, 52, 243)"></i>
                  </div>
                </template>
             </el-table-column>
             <el-table-column :show-overflow-tooltip="true" min-width="140px" prop="contentName" label="标准名称" align="center"></el-table-column>
             <el-table-column :show-overflow-tooltip="true" min-width="150px" prop="stdItemName" label="标准项目名称" align="center"></el-table-column>
             <el-table-column :show-overflow-tooltip="true" min-width="115px" prop="dspOrder" label="显示顺序" align="center"></el-table-column>
             <el-table-column :show-overflow-tooltip="true" min-width="140px" prop="dataTypeName" label="结果类型" align="center"></el-table-column>
             <el-table-column :show-overflow-tooltip="true" min-width="195px" prop="resultValue" label="结果值" align="center"></el-table-column>
             <el-table-column :show-overflow-tooltip="true" min-width="140px" prop="validFlag1" label="数据状态" align="center"></el-table-column>
             <el-table-column :show-overflow-tooltip="true" min-width="140px" prop="memo" 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="160px" prop="createTime" 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-column sortable :show-overflow-tooltip="true" min-width="160px" prop="updateTime" label="修改时间" align="center"></el-table-column>
             </el-table>
          </template>
        </el-table-column>
        <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="contentNo" label="标准内容号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="stdNo" label="标准号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="stdName" label="标准名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="gradeName" label="牌号/等级" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="validFlag1" label="数据状态"  align="center">
           <!-- <template slot-scope="scope">
              <span v-if="scope.row.validFlag == 1">有效</span>
              <span v-else-if="scope.row.validFlag == 0">无效</span>
          </template> -->
        </el-table-column>
        <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="lenMaxSign" label="长度上限符号"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="prdLenMax" label="长度上限"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="lenMinSign" label="长度下限符号"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="prdLenMin" label="长度下限"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="wthMaxSign" label="宽度上限符号"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="prdWthMax" label="宽度上限"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="wthMinSign" label="宽度下限符号"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="prdWthMin" label="宽度下限"  align="center"></el-table-column> -->
        <!-- <el-table-column sortable width="200px" prop="memo" label="宽度下限符号2"  align="center"></el-table-column><el-table-column sortable width="200px" prop="memo" label="数据状态"  align="center"></el-table-column>
        <el-table-column sortable width="200px" prop="memo" label="宽度下限2"  align="center"></el-table-column> -->
        <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="thkMaxSign" label="厚度上限符号"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="prdThkMax" label="厚度上限"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="thkMinSign" label="厚度下限符号"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="prdThkMin" label="厚度下限"  align="center"></el-table-column> -->
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="condition1" label="条件1" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="condition2" label="条件2" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="condition3" label="条件3" 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" min-width="95px" prop="createMan" label="创建人" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="createTime" 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-column sortable :show-overflow-tooltip="true" min-width="160px" prop="updateTime" 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>
    <div is="alertComponets" :showFlag="showFlag" :Params="Params"  @refresh='refresh'></div>
    <div is="alertComponets2" :showFlag2="showFlag2" :Params2="Params2" @refresh='refresh2'></div>
    <div is="alertComponets3" :showFlag="showFlag3" :Params="Params3"  @refresh='refresh2'></div>
  </div>
</template>
<script>
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
import alertComponets from './alertComponents';
import alertComponets2 from './alertComponents2';
import alertComponets3 from './alertComponents3';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  components: {alertComponets,alertComponets2,alertComponets3},
  data () {
    return {
      table: {
        list: [],
        list2: [],
        list3: [],
        list4: []
      },
      dataLoading: false,
      dataLoading2: false,
      icoreFilterFlag: true,
      expands: [],
      getRowKeys (row) {
        return row.contentNo
      },
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      showFlag: false,
      showFlag2: false,
      showFlag3: false,
      contentNo: '',
      contentNo1: '',
      Params: {},
      showFlag2: false,
      Params2: {},
      Params3: {},
      multipleSelection3: [],
      multipleSelection4: [],
      search: {
        stdName: '',
        contentNo: '',
      },
      height_top:0
    }
  },
  created() {
    this.height_top = window.innerHeight - 190 < 300 ? 300 : 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 () {
      let _this = this;
      _this.getDataList();
    },
    refresh2 () {
      let _this = this;
      _this.getDataList();
    },
    addData () {
      let _this = this;
      _this.showFlag = !_this.showFlag;
      _this.Params = null;
    },
    modifyData () {
      let _this = this;
      if (_this.multipleSelection3.length !== 1) {
        this.$message.warning('请勾选您要修改的一条数据！')
      } else {
        _this.showFlag = !_this.showFlag;
        _this.Params = _this.multipleSelection3
      }
    },
    deleteData () {
       let _this = this;
        if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要停用的数据！')
       } else {
        for (var j= 0; j < _this.multipleSelection3.length; j++) {
          if (_this.multipleSelection3[j].validFlag === '0') {
          this.$message.warning('请勾选状态为有效的数据！')  
          return 
          }
        }
        _this.dialogTableVisible = false;
        // _this.multipleSelection = []
        // _this.multipleSelection.push(_this.multipleSelection3)
        for (var i = 0; i < _this.multipleSelection3.length; i++) {
        _this.multipleSelection3[i].updateMan = userName;
        _this.multipleSelection3[i].updateNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsstdcontents/abolish', _this.multipleSelection3, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('停用操作成功');
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    recoverData () {
       let _this = this;
        if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要恢复的数据！')
        } else {
          for (var j= 0; j < _this.multipleSelection3.length; j++) {
          if (_this.multipleSelection3[j].validFlag === '1') {
          this.$message.warning('请勾选状态为无效的数据！')  
          return 
          }
        }
        _this.dialogTableVisible = false;
        for (var i = 0; i < _this.multipleSelection3.length; i++) {
        _this.multipleSelection3[i].updateMan = userName;
        _this.multipleSelection3[i].updateNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsstdcontents/recover', _this.multipleSelection3, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('恢复成功');
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    addData2 () {
      let _this = this;
      _this.showFlag2 = !_this.showFlag2;
    },
    modifyData2 (index,row) {
      this.Params3 = row
      this.showFlag3 = !this.showFlag3;
    },
    deleteData2 (row) {
      this.axios.post('pass/baseManagement/v1/limsstdcontentds/deleteLimsStdContentD?id=' +row.contentNoD).then(res => {
        if (res.succeed) {
         this.$message.success('删除成功');
         this.getDataList();
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
    },
    searchData () {
      this.page.pageNum = 1;
      this.getDataList()
    },
    reset () {
      let _this = this;
      _this.search.stdName = '';
      _this.search.contentNo = '';
      _this.searchData();
    },
    handleSelectionChange (val) {
      this.multipleSelection3 = val;
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList();
    },
    handleSelectionChange2 (val) {
      this.multipleSelection4 = val;
    },
    addScreen () {
      this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          let aaa = this.$refs.dataTable.$el.getElementsByClassName('el-table__fixed')[1].getElementsByTagName('td')[1];
          if (aaa !== undefined) {
              aaa.appendChild(ss)
          }
       });
    },
    getDataList () {
      this.dataLoading = true;
      let obj = {
        object:{
          contentNo:this.search.contentNo,
          stdName:this.search.stdName
        },
        pageIndex:this.page.pageNum,
        pageSize:this.page.pageSize
      }
      this.table.list = []
      this.axios.post('pass/baseManagement/v1/limsstdcontents/queryLimsStdContentPage',obj,{individualType: "json"}).then(res => {
        this.dataLoading = false;
        this.table.list = res.data.list;
        this.table.list.forEach(item =>{
          item.validFlag1 = item.validFlag === '0' ? '无效' : item.validFlag === '1' ? '有效' : ''
        })
        this.page.totalPage = res.data.total;
      }).catch(e => {
        this.dataLoading = false;
      });
    },
    tableRowClassName ({row, column, rowIndex, columnIndex}) {
      if (row.validFlag === '0') {
        return 'error-row';
      } 
      return '';
    },
    tableRowClassName2 ({
        row, column, rowIndex, columnIndex
      }) {
        if (columnIndex === 8) {
        if (row.validFlag === '0') {
          return 'error-row';
        } 
        return '';
        }
      },
    getDataList2 () {
      this.dataLoading2 = true
      this.table.list3 = []
      this.table.list4 = []
      this.$set(this.table.list4,{})
      this.axios.post('pass/baseManagement/v1/limsstdcontentds/queryLimsStdContentDPage',{object:{contentNo:this.contentNo}},{individualType: "json",}).then(res => {
        this.dataLoading2 = false
        this.table.list3 = res.data.list;
        this.table.list3.forEach((item,index) =>{
          item.validFlag1 = item.validFlag === '0' ? '无效' : item.validFlag === '1' ? '有效' : ''
          this.$set(this.table.list4,index,item)
        })
      }).catch(e => {
        this.dataLoading2 = false
      });
    },
    expandChange(row, expandedRows) { 
      this.dataLoading2 = true
      this.Params2 = row
      this.axios.post('pass/baseManagement/v1/limsstdcontentds/queryLimsStdContentDPage',{object:{contentNo:row.contentNo}},{individualType: "json"}).then(res => {
        this.dataLoading2 = false
        let data = res.data.list;
        data.forEach((item,index) =>{
          item.validFlag1 = item.validFlag === '0' ? '无效' : item.validFlag === '1' ? '有效' : ''
        })
        this.$set(row, 'data', data)
      }).catch(e => {
        this.dataLoading2 = false
      });
      // if (expandedRows.length) {
      //   this.expands = []
      //   if (row) {
      //     this.expands.push (row.contentNo)
      //     this.contentNo = row.contentNo
      //     this.Params2 = row
      //     this.getDataList2 ()
      //   }
      // } else {
      //   this.expands = []
      // }
    },
    renderHeader (h) {
         return (
             <div style="cursor: pointer ;line-height:20px" onClick={() => this.addData2()}>
             <i class="el-icon-plus" style="font-size:20px; color:rgb(18, 52, 243)"></i>
             </div>
         )
      },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    },
    tableHeaderCellStyle2 () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
