<!-- 基础数据-分析项目对照 -->
<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true" @submit.native.prevent>
        <el-form-item label='对照名称'>
          <el-input v-model="search.mtName" @keyup.enter.native="searchData()" style="width:200px" size="small"></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-circle-close" type="danger" size="mini" @click="deleteData">删除</el-button>
      <el-button icon="el-icon-check" type="goon" size="mini" @click="recoverData">启用</el-button>
      <!-- <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> -->
      </div>
    </div>
    <div class="common-table-div" style="margin-bottom:0">
       <el-table v-loading="dataLoading" ref="table1" @row-click='searchDatail' border :height="theight1" highlight-current-row @selection-change="handleSelectionChange" :data="table.list" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :row-class-name="tableRowClassName" show-summary :summary-method="getSummaries">
        <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="mtNo" label="对照编号"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="mtName" label="对照名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="mtType1" label="对照类型" align="center">
          <!-- <template slot-scope="scope">
              <span v-if="scope.row.mtType == 1">仪器</span>
              <span v-else-if="scope.row.mtType == 0">接口</span>
          </template> -->
        </el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="dataSourceName" label="对照来源" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" 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="80px" prop="memo" 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>
        <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="addDataShow">新增</el-button>
      <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyTable">修改</el-button>
      <el-button icon="el-icon-circle-close" type="danger" size="mini" @click="deleteTable">删除</el-button>
      <!-- <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> -->
      </div>
    </div>
    <div class="common-table-div">
       <el-table v-loading="dataLoading2" ref="dataTable" border :height="theight2" highlight-current-row @selection-change="handleSelectionChange2" :data="table.list2" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :row-class-name="tableRowClassName2" show-summary :summary-method="getSummaries">
        <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="itemTypeName" label="项目类型" align="center"></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="100px" prop="anlyItemName" label="分析项目名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="mtAItemNo" label="对照项目编号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="mtAItemName" label="对照项目名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" 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="165px" prop="memo" 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 @size-change="pageSizeChange2" @current-change="pageCurrentChange2"
          :current-page="pageIndex2" :page-sizes="[10, 20, 50, 100, 200]" :page-size="pagesize2" layout="total, sizes, prev, pager, next, jumper"
          :total="pageTotal" background>
        </el-pagination>
    </div> -->
    <div is="alertComponets" :showFlag="showFlag" :Params="Params" @refresh='refresh'></div>
    <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible1">
        <div slot="title" class="titleBox">
        <i :class="dtableType === 0? 'el-icon-document':'el-icon-edit-outline'" style="font-size: 20px"></i>
        <!-- <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/more.png' /> -->
        <span style="margin-left:10px;font-size:18px">{{dtableTypeDsc}}</span>
        </div>
       <el-form ref="baseData" label-width="100px" :model="baseData" :rules="ruleValidate">
         <el-row>
           <el-col :span='12'>
              <el-form-item prop="itemTypeCode" label="项目类型">
               <el-select v-model="baseData.itemTypeCode" @change="selectval" filterable collapse-tags size="small" style="width: 100%;">
                  <el-option v-for="item in itemTypeNameType" :key="item.baseCode" :label="item.baseName"
                    :value="item.baseCode">
                  </el-option>
                </el-select>
               </el-form-item>
            </el-col>
          <el-col :span="12">
             <el-form-item prop="anlyItemNo" label="分析项目">
              <el-select v-model="baseData.anlyItemNo" style="width: 100%;" filterable collapse-tags size="small">
                <el-option v-for="item in anlyItemNameType" :key="item.anlyItemNo" :label="'('+item.anlyItemNo +') '+item.anlyItemName" :value="item.anlyItemNo">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
         </el-row>
         <el-row>
            <el-col :span="12">
              <el-form-item prop="mtAItemNo" label="对照项目编号">
                <el-input v-model="baseData.mtAItemNo" style="width: 100%;" size="small"></el-input>
              </el-form-item>
            </el-col>
           <el-col :span="12">
            <el-form-item prop="mtAItemName" label="对照项目名称">
              <el-input v-model="baseData.mtAItemName" style="width: 100%;" size="small"></el-input>
            </el-form-item>
          </el-col>
         </el-row>
         <el-row>
           <el-col :span="24">
            <el-form-item label="备注">
              <el-input v-model="baseData.memo" style="width: 100%;" size="small"></el-input>
            </el-form-item>
          </el-col>
         </el-row>
       </el-form>
       <span slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" icon="el-icon-check" @click="dtableType === 0 ? addData1():modifyData1()">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancel2">取消</el-button>
      </span>
    </el-dialog>
  </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: [],
        list2: []
      },
      dataLoading: false,
      dataLoading2: false,
      icoreFilterFlag: true,
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      mtNo: '',
      pageIndex2: 1,
      pagesize2: 999,
      pageTotal: 0,
      multipleSelection2: [],
      baseData: {},
      dtableType: 0,
      dtableTypeDsc: '新增项目对照明细',
      dialogTableVisible1: false,
      anlyItemNameType: [],
      itemTypeNameType: [],
      showFlag: false,
      Params: {},
      ruleValidate: {
        itemTypeCode: [{ required: true, message: '该项不能为空', trigger: 'change' }],
        anlyItemNo: [{ required: true, message: '该项不能为空', trigger: 'change' }],
        mtAItemNo: [{ required: true, message: '该项不能为空', trigger: 'blur' }],
        mtAItemName: [{ required: true, message: '该项不能为空', trigger: 'blur' }]
        // merchAtrrName: [{ required: true, message: '该项不能为空', trigger: 'change' }]
       },
      multipleSelection: [],
      search: {
        mtName: ''
      },
      theight1: 0,
      theight2: 0
    }
  },
  created () {
    this.theight1 = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 130;
    this.theight2 = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 130;
  },
 mounted () {
   this.axios.post('pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode', {validFlag: 1, baseCode: 4804}, {individualType: 'json'}).then(res => {
    this.itemTypeNameType = res.data
   })
    this.getDataList();
  },
  methods: {
    refresh () {
      this.getDataList();
    },
    selectval (code) {
      if (!code) {
        this.anlyItemNameType = []
        return
      }
      this.anlyItemNameType = []
      this.axios.post('pass/baseManagement/v1/limsstdanlyitems/queryLimsStdAnlyItemList', {itemTypeCode: code, validFlag: 1}, {individualType: 'json'}).then(res => {
      this.anlyItemNameType = res.data;
    })
    },
     closeDialog () {
       this.dtableType = 0,
       this.baseData = {}
      this.dtableTypeDsc = '新增项目对照明细'
     },
     cancel2 () {
       this.dtableType = 0,
       this.baseData = {}
      this.dtableTypeDsc = '新增项目对照明细'
      this.dialogTableVisible1 = false
     },
    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;
    },
    getCode (code, arr, codeKey, nameKey) {
        if (!code) {
          return '';
        }
        let targetRow = arr.find(item => {
          return item[codeKey] === code;
        });
        // console.log(targetRow, 'targetRow');
        return targetRow ? targetRow[nameKey] : '';
      },
     clearFilter (arg) {
      this.$refs.dataTable.clearIcoreTableFilter()
    },
    addData () {
      let _this = this;
      _this.showFlag = !_this.showFlag;
      _this.Params = null;
    },
    addDataShow () {
      if (this.multipleSelection.length != 1) {
        this.$message.warning('请勾选一条项目对照信息数据！')
        return
      }
      this.dialogTableVisible1 = true
    },
    addData1 () {
      this.$refs['baseData'].validate((valid) => {
          if (valid) {
            this.baseData.mtNo = this.multipleSelection[0].mtNo
            this.baseData.itemTypeName = this.getCode(this.baseData.itemTypeCode, this.itemTypeNameType, 'baseCode', 'baseName')
            this.baseData.anlyItemName = this.getCode(this.baseData.anlyItemNo, this.anlyItemNameType, 'anlyItemNo', 'anlyItemName')
             this.axios.post('pass/baseManagement/v1/limsbaseitemmatchds/addLimsBaseItemMatchD/', this.baseData, {individualType: 'json'}).then(res => {
                if (res.succeed) {
                  this.dialogTableVisible1 = false;
                 this.$message.success('添加成功')
                  this.details(this.mtNo)
                } else {
                 this.$message.error(res.message)
                }
                }).catch(e => {
                 this.$message.error(e.message)
               })
         }
       })
    },
    modifyData1 () {
      this.$refs['baseData'].validate((valid) => {
        if (valid) {
        this.baseData.itemTypeName = this.getCode(this.baseData.itemTypeCode, this.itemTypeNameType, 'baseCode', 'baseName')
        this.baseData.anlyItemName = this.getCode(this.baseData.anlyItemNo, this.anlyItemNameType, 'anlyItemNo', 'anlyItemName')
        this.axios.post('pass/baseManagement/v1/limsbaseitemmatchds/updateLimsBaseItemMatchD', this.baseData, {individualType: 'json'}).then(res => {
           if (res.succeed) {
             this.dialogTableVisible1 = false;
            this.$message.success('修改成功')
            this.details(this.mtNo)
           } else {
            this.$message.error(res.message)
           }
           }).catch(e => {
            this.$message.error(e.message)
          })
        }
        })
    },
    modifyTable () {
      // if(this.multipleSelection.length != 1){
      //   this.$message.warning('请勾选一条项目对照信息数据！')
      //   return
      // }
      if (this.multipleSelection2.length != 1) {
        this.$message.warning('请勾选一条项目对照明细信息数据！')
        return
      }
      this.dtableType = 1,
      this.dtableTypeDsc = '修改项目对照明细'
      this.baseData = Object.assign({}, this.multipleSelection2[0])
      this.selectval(this.baseData.itemTypeCode)
      this.dialogTableVisible1 = true
    },
    deleteTable () {
      if (this.multipleSelection2.length != 1) {
        this.$message.warning('请勾选一条项目对照明细信息数据！')
        return
      }
      this.axios.post('pass/baseManagement/v1/limsbaseitemmatchds/deleteLimsBaseItemMatchD?id=' + this.multipleSelection2[0].id, {individualType: 'json'}).then(res => {
           if (res.succeed) {
            this.$message.success('删除成功')
            this.details(this.mtNo)
           } else {
            this.$message.error(res.message)
           }
           }).catch(e => {
            this.$message.error(e.message)
          })
    },
    modifyData () {
      let _this = this;
      if (_this.multipleSelection.length !== 1) {
        this.$message.warning('请勾选您要修改的一条数据！')
      } else {
        _this.showFlag = !_this.showFlag;
        _this.Params = _this.multipleSelection
      }
    },
    recoverData () {
       let _this = this;
        if (_this.multipleSelection.length < 1) {
        this.$message.warning('请勾选您要启用的数据！')
      } else {
        _this.dialogTableVisible = false;
        for (var i = 0; i < _this.multipleSelection.length; i++) {
        _this.multipleSelection[i].updateMan = userName;
        _this.multipleSelection[i].updateNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsbaseitemmatchs/recover', _this.multipleSelection, {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)
       })
      }
    },
    deleteData () {
       let _this = this;
        if (_this.multipleSelection.length < 1) {
        this.$message.warning('请勾选您要删除的数据！')
      } else {
        _this.dialogTableVisible = false;
        for (var i = 0; i < _this.multipleSelection.length; i++) {
        _this.multipleSelection[i].updateMan = userName;
        _this.multipleSelection[i].updateNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsbaseitemmatchs/abolish', _this.multipleSelection, {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)
       })
      }
    },
    searchData () {
        this.dataLoading = true;
        this.page.pageNum = 1;
        this.getDataList()
      },
    searchDatail (row) {
      this.pageIndex2 = 1
        this.mtNo = row.mtNo
        this.details(this.mtNo)
      },
    details (mtNo) {
      let obj = {
        'object': {
          'mtNo': mtNo
        },
        pageIndex: this.pageIndex2,
        pagesize: this.pagesize2
      }
      this.dataLoading2 = true
       this.axios.post('pass/baseManagement/v1/limsbaseitemmatchds/queryLimsBaseItemMatchD', obj, {individualType: 'json'}).then(res => {
        if (res.succeed) {
          this.dataLoading2 = false
         this.table.list2 = res.data.list
         this.table.list2.forEach(item => {
                item.validFlag1 = item.validFlag === '0' ? '无效' : item.validFlag === '1' ? '有效' : ''
              })
         this.pageTotal = res.data.total
        } else {
          this.dataLoading2 = false
        }
       }).catch(err => {
         this.dataLoading2 = false
       })
    },
    reset () {
      let _this = this;
      _this.search.mtName = '';
      _this.searchData();
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    handleSelectionChange2 (val) {
      this.multipleSelection2 = val;
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList();
    },
    pageSizeChange2 (size) {
      this.pagesize2 = size;
      this.details(this.mtNo)
    },
    pageCurrentChange2 (index) {
      this.pageIndex2 = index;
      this.details(this.mtNo)
    },
    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 () {
      let obj = {
        object: {
          'mtName': this.search.mtName,
          'validFlag': ''
        },
        pageIndex: this.page.pageNum,
        pageSize: this.page.pageSize

      }
        this.dataLoading = true;
        this.axios.post('pass/baseManagement/v1/limsbaseitemmatchs/queryLimsBaseItemMatchPage', 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' ? '有效' : ''
                item.mtType1 = item.mtType === '0' ? '系统接口' : item.mtType === '1' ? '设备接口' : ''
              })
              if (this.table.list.length > 0) {
          this.$refs.table1.setCurrentRow(this.table.list[0])
          this.searchDatail(this.table.list[0])
        }
              this.page.totalPage = res.data.total;
            }).catch(e => {
              this.dataLoading = false;
            });
    },
    tableRowClassName ({row, column, rowIndex, columnIndex}) {
      if (row.validFlag !== '1') {
        return 'error-row';
      }
      return '';
    },
    tableRowClassName2 ({row, column, rowIndex, columnIndex}) {
      if (row.validFlag !== '1') {
        return 'error-row';
      }
      return '';
    },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
  // watch: {
  //   icoreFilterFlag:function (val) {
  //     if (val === true) {
  //       this.addScreen ()
  //     }
  //   }
  // }
}
</script>
<style  scoped>
</style>
