<template>
    <div class="examination">
     <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible" customClass="customWidth_test4">
        <div slot="title" class="titleBox">
         <i class="el-icon-document" style="font-size: 20px"></i>
        <span style="margin-left:10px;font-size:18px;margin-right:20px">新增分析项目</span>
        <span style="font-size:16px;color:#fff;">分析项目名称</span>
        <el-input v-model="anlyItemName" size="small" @keyup.enter.native="searchData" style="width: 150px;"></el-input>
        <el-button icon="el-icon-search" type="goon" size="mini" @click="searchData">查询</el-button>
        </div>
        <el-row>
          <el-col :span='12'>
            <div class="common-table-div">
               <el-table v-loading="dataLoading" ref="dataTable" border :height="350" 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="80px" prop="" label="操作" align="center">
                <template slot-scope="{row}">
                  <el-button type="text" size='mini' @click="checkRow(row)">添加</el-button>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="anlyItemNo" label="分析项目编号" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemName" label="分析项目名称" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" 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="90px" prop="itemTypeName" label="项目类型" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="dspOrder" label="显示顺序" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="dataTypeName" label="数据类型" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemAlias" label="分析项目别名" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemDesc" label="分析项目描述" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemEng" label="分析项目英文" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="unitName" label="度量单位" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="formulaName" label="计算公式" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="reviseRuleName" label="修约规则" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="outputTypeName" label="输出类型" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="defaultValue" label="默认值" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="maxSign" label="上限符" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="maxValue" label="上限值" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="minSign" label="下限符" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="minValue" label="下限值" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="anlyCnt" label="分析次数" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否计算" align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.isCompute == 1">是</span>
                    <span v-else-if="scope.row.isCompute == 0">否</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" label="是否中间项" align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.isMid == 1">是</span>
                    <span v-else-if="scope.row.isMid == 0">否</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否报出" align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.isReport == 1">是</span>
                    <span v-else-if="scope.row.isReport == 0">否</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否必检" align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.isLogin == 1">是</span>
                    <span v-else-if="scope.row.isLogin == 0">否</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否报警" align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.isAlarm == 1">是</span>
                    <span v-else-if="scope.row.isAlarm == 0">否</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否贵重" align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.isRare == 1">是</span>
                    <span v-else-if="scope.row.isRare == 0">否</span>
                </template>
              </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="80px" prop="createMan" 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-column  sortable :show-overflow-tooltip="true" min-width="80px" 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"
                :total="page.totalPage" background>
              </el-pagination>
            </div>
          </el-col>
          <el-col :span='12'>
            <div class="common-table-div">
               <el-table  border :height="350"  :data="table.list2" :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 sortable :show-overflow-tooltip="true" min-width="80px" prop="" label="操作" align="center">
                <template slot-scope="{index}">
                  <el-button type="text" size='mini' @click="removeItem(index)">删除</el-button>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="anlyItemNo" label="分析项目编号" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemName" label="分析项目名称" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="数据状态" align="center">
                <template slot-scope="scope">
                  <span>{{scope.row.validFlag == 1 ? '是' : scope.row.validFlag == 0 ? '否' : ''}}</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="itemTypeName" label="项目类型" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="dspOrder" label="显示顺序" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="dataTypeName" label="数据类型" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemAlias" label="分析项目别名" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemDesc" label="分析项目描述" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemEng" label="分析项目英文" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="unitName" label="度量单位" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="formulaName" label="计算公式" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="reviseRuleName" label="修约规则" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="outputTypeName" label="输出类型" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="defaultValue" label="默认值" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="maxSign" label="上限符" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="maxValue" label="上限值" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="minSign" label="下限符" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="minValue" label="下限值" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="anlyCnt" label="分析次数" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否计算" align="center">
                <template slot-scope="scope">
                  <span>{{scope.row.isCompute == 1 ? '是' : scope.row.isCompute == 0 ? '否' : ''}}</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" label="是否中间项" align="center">
                <template slot-scope="scope">
                  <span>{{scope.row.isMid == 1 ? '是' : scope.row.isMid == 0 ? '否' : ''}}</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否报出" align="center">
                <template slot-scope="scope">
                  <span>{{scope.row.isReport == 1 ? '是' : scope.row.isReport == 0 ? '否' : ''}}</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否必检" align="center">
                <template slot-scope="scope">
                  <span>{{scope.row.isLogin == 1 ? '是' : scope.row.isLogin == 0 ? '否' : ''}}</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否报警" align="center">
                <template slot-scope="scope">
                  <span>{{scope.row.isAlarm == 1 ? '是' : scope.row.isAlarm == 0 ? '否' : ''}}</span>
                </template>
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" label="是否贵重" align="center">
                <template slot-scope="scope">
                  <span>{{scope.row.isRare == 1 ? '是' : scope.row.isRare == 0 ? '否' : ''}}</span>
                </template>
              </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="80px" prop="createMan" 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-column  sortable :show-overflow-tooltip="true" min-width="80px" prop="updateMan" label="修改人" align="center"></el-table-column>
               </el-table>
               </div>
          </el-col>
        </el-row>
       <div style="margin-top: 50px; margin-left: 700px">
       <span slot="footer" class="dialog-footer">
        <el-button type="goon" icon="el-icon-check" size="mini" @click="addData()">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancel">取消</el-button>
      </span>
       </div>
    </el-dialog>
    </div>
</template>
<script>
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  props: ['showFlag', 'Params'],
    data () {
        return {
          table: {
            list: [],
            list2: []
          },
          dataLoading: false,
          icoreFilterFlag: true,
          page: {
            pageSize: 200,
            pageNum: 1,
            totalPage: 0
          },
          anlyItemName:'',
          multipleSelection: [],
          dialogTableVisible: false,
          monitorForm: {
          tableData: [{}]
          }
        }
    },
    mounted () {
      this.getList ()
    },
    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;
    },
      cancel () {
        let _this = this;
        this.anlyItemName = ''
        _this.monitorForm.tableData = [{}]
        _this.dialogTableVisible = false
        _this.$emit('refresh')
      },
      getList () {
        this.dataLoading = true;
        let obj = {
          object:{
            anlyItemName:this.anlyItemName
          },
          pageIndex:this.page.pageNum,
          pageSize:this.page.pageSize
        }
        this.axios.post('pass/baseManagement/v1/limsstdanlyitems/queryLimsStdAnlyItemPage/',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;
        });
      },
      searchData(){
        this.page.pageNum = 1
        this.getList()
      },
      addData () {
        let _this = this;
        if(_this.table.list2.length <= 0){
          this.$message.warning('请先添加数据到右边的表格中')
          return
        }
        for (var i = 0; i < _this.table.list2.length; i++) {
          this.table.list2.createMan = userName;
          this.table.list2.createNo = userId;
          this.table.list2.testItemNo = _this.Params[0].testItemNo;
          this.table.list2.testItemName = _this.Params[0].testItemName;
        }
        _this.axios.post('pass/baseManagement/v1/limsstdtestitemds/addLimsStdTestItemDList', this.table.list2, {individualType: 'json'}).then(res => {
           if (res.succeed) {
            _this.dialogTableVisible = false;
            this.$message.success('添加成功')
            _this.$emit('refresh')
           } else {
            this.$message.error(res.message)
           }
           }).catch(e => {
            this.$message.error(e.message)
          })
      },
      checkRow(row){
        this.table.list2.push(row)
        console.log(row);
      },
      removeItem(index){
        this.table.list2.splice(index,1)
      },
      handleSelectionChange (val) {
        this.monitorForm.tableData = val;
      },
      pageSizeChange (size) {
        this.page.pageSize = size;
        this.getList();
      },
      pageCurrentChange (index) {
        this.page.pageNum = index;
        this.getList();
      },
      closeDialog () {
       let _this = this;
       this.anlyItemName = ''
       _this.monitorForm.tableData = [{}];
       _this.$emit('refresh')
      },
     tableRowClassName ({
        row, column, rowIndex, columnIndex
      }) {
        if (columnIndex === 4) {
        if (row.validFlag !== '1') {
          return 'error-row';
        }
        return '';
        }
      },
      tableHeaderCellStyle () {
      return 'background-color: rgb(249,249,249) !important;color: rgb(73, 72, 72);border-bottom: 1px solid #DCDFE7;border-top:3px solid #3ac1ea;'
      }
    },
    watch: {
      showFlag (arg) {
        this.getList()
        this.dialogTableVisible = true
        }
      }
}
</script>
<style lang="less">
.customWidth_test4{
  width: 1000px !important
}
</style>
