<template>
  <div class="examination">
     <!-- 新增分析项目指标 -->
     <el-dialog @close="fxcloseDialog" :close-on-click-modal='false' :visible.sync="fxdialogTableVisible" width='80%'>
        <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="searchData2" style="width: 150px;"></el-input>
        <el-button icon="el-icon-search" type="goon" size="mini" @click="searchData2">查询</el-button>
        </div>
        <el-row>
          <el-col :span='12'>
            <div class="common-table-div">
               <el-table v-loading="fxdataLoading" ref="dataTable" border :height="350" highlight-current-row :data="fxlist" :icore-filter-flag="icoreFilterFlag"
               :header-cell-style="tableHeaderCellStyle" :cell-class-name="fxtableRowClassName" :summary-method="getSummaries" show-summary>
              <el-table-column type="index" label="NO" 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" prop="validFlag1" label="数据状态" align="center">
              </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" prop="isCompute1" label="是否计算" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" prop="isMid1" min-width="90px" label="是否中间项" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" prop="isReport1" min-width="80px" label="是否报出" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isLogin1" label="是否登录" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isAlarm1" label="是否报警" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isRare1" 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="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 @size-change="fxpageSizeChange" @current-change="fxpageCurrentChange"
                :current-page="fxpage.pageNum" :page-sizes="[100, 200,500]" :page-size="fxpage.pageSize" layout="total, sizes, prev, pager, next"
                :total="fxpage.totalPage" background>
              </el-pagination>
            </div>
          </el-col>
          <el-col :span='12'>
            <div class="common-table-div">
               <el-table  border :height="350"  :data="checkList" :icore-filter-flag="icoreFilterFlag"
               :header-cell-style="tableHeaderCellStyle" :cell-class-name="fxtableRowClassName" :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="scope">
                  <el-button type="text" size='mini' @click="removeItem(scope.$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" prop="validFlag1" label="数据状态" align="center">
              </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" prop="isCompute1" label="是否计算" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="isMid1" label="是否中间项" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isReport1" label="是否报出" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isLogin1" label="是否登录" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isAlarm1" label="是否报警" align="center">
              </el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isRare1" 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="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: 20px; margin-right: 50px" class="clearfix">
       <span slot="footer" class="dialog-footer" style="float:right">
        <el-button type="goon"  icon="el-icon-check" size="mini" @click="fxaddData()">确定</el-button>
        <el-button size="mini"  type="goon" icon="el-icon-remove-outline" @click="fxcancel">取消</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: ["showFlag2", "Params", "Params2"],
  data() {
    return {
      fxdialogTableVisible: false,
      fxdataLoading:false,
      fxlist: [],
      checkList: [],
      fxpage: {
        pageSize: 500,
        pageNum: 1,
        totalPage: 0
      },
      tableType: 0,
      anlyItemName:'',
      fxData: {},
      icoreFilterFlag: true,
    };
  },
  mounted() {
    this.getList ()
  },
  methods: {
    fxcancel() {
      this.checkList = []
      this.fxData = {};
      this.fxdialogTableVisible = false;
    },
    fxaddData () {
      let _this = this;
      if(_this.checkList.length <= 0){
        this.$message.warning('请先添加数据到右边的表格中')
        return
      }
      this.checkList.forEach(item =>{
        item.planId = this.fxData.planId
        item.matNo = this.fxData.matNo
        item.matName = this.fxData.matName
      })
      this.axios.post('pass/testManagement/v1/limstestplands/batchsaveLimsPlanD', this.checkList, {individualType: 'json'}).then(res => {
         if (res.succeed) {
          this.fxdialogTableVisible = false;
          this.$message.success('添加成功')
          this.$emit("refresh");
         } else {
          this.$message.error(res.message)
         }
         }).catch(e => {
          this.$message.error(e.message)
        })
    },
    checkRow(row){
      this.checkList.push(row)
    },
    removeItem(index){
      this.checkList.splice(index,1)
    },
    searchData2(){
      this.fxpage.pageNum = 1
      this.getList()
    },
    getList () {
        this.fxdataLoading = true;
        let obj = {
          object:{
            anlyItemName:this.anlyItemName,
            validFlag:1
          },
          pageIndex:this.fxpage.pageNum,
          pageSize:this.fxpage.pageSize
        }
        this.axios.post('pass/baseManagement/v1/limsstdanlyitems/queryLimsStdAnlyItemPage/',obj,{individualType: 'json'}).then(res => {
          this.fxdataLoading = false;
          this.fxlist = res.data.list;
          this.fxlist.forEach(item =>{
            item.validFlag1 = item.validFlag == 1 ? '有效' : item.validFlag == 0 ? '无效' : ''
            item.isCompute1 = item.isCompute == 1 ? '是' : item.isCompute == 0 ? '否' : ''
            item.isMid1 = item.isMid == 1 ? '是' : item.isMid == 0 ? '否' : ''
            item.isReport1 =  item.isReport == 1 ? '是' : item.isReport == 0 ? '否' : ''
            item.isLogin1 = item.isLogin == 1 ? '是' : item.isLogin == 0 ? '否' : ''
            item.isAlarm1 = item.isAlarm == 1 ? '是' : item.isAlarm == 0 ? '否' : ''
            item.isRare1 = item.isRare == 1 ? '是' : item.isRare == 0 ? '否' : ''
          })
          this.fxpage.totalPage = res.data.total;
        }).catch(e => {
          this.fxdataLoading = false;
        });
    },
     fxpageSizeChange (size) {
        this.fxpage.pageSize = size;
        this.getList();
      },
    fxpageCurrentChange (index) {
      this.fxpage.pageNum = index;
      this.getList();
    },
    fxcloseDialog () {
      this.checkList = []
      this.fxData = {};
    },
     fxtableRowClassName ({
        row, column, rowIndex, columnIndex
      }) {
        if (columnIndex === 4) {
        if (row.validFlag !== '1') {
          return 'error-row';
        }
        return '';
        }
    },
     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;
    },
     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: {
    showFlag2(arg) {
        this.fxData = Object.assign({planId: this.Params.planId,matNo: this.Params.matNo,matName: this.Params.matName,});
        this.tableType = 0;
        this.fxdialogTableVisible = true;
    },
  },
};
</script>
<style lang="less">
.customWidth_certifi4 {
  width: 600px !important;
}
</style>
