<template>
    <div>
        <crumbs title="病例入录" style="min-width: 980px">
            <el-form :inline="true" class="demo-form-inline">
                <el-form-item label="医院：">
                   <el-input size="mini" v-model="filter.hospitalName" placeholder="医院" clearable></el-input>
               </el-form-item>
                <el-form-item label="病人案例号：">
                   <el-input size="mini" v-model="filter.brzyid" placeholder="病人案例号" clearable></el-input>
               </el-form-item>
               <el-form-item>
                   <el-button size="mini" @click="filterDatas">查找</el-button>
                   <!-- <el-button size="mini" type="warning" @click="addRecord">添加测试病例</el-button> -->
               </el-form-item>
            </el-form>
        </crumbs>
        <div class="contents">
            <el-table
                    :data="list"
                    border
                    style="width: 100%">
                <el-table-column
                  :resizable = "false"
                  prop="id"
                  label="ID"
                >
                </el-table-column>
                <el-table-column
                        :resizable = "false"
                        prop="caseNumber"
                        label="病案号"
                      >
                </el-table-column>
                <el-table-column
                        :resizable = "false"
                        prop="hospitalName"
                        label="医院"
                >
                </el-table-column>
                <el-table-column
                        :resizable = "false"
                        prop="creator"
                        label="是否标注"
                        width="">
                    <template slot-scope="scope">
                        <span style="margin:0 3px;" :class="scope.row.isTag?'colorBlue':''">{{scope.row.isTag ? "是":"否"}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        :resizable = "false"
                        prop="operate"
                        label="操作"
                        width="180">
                    <template slot-scope="scope">
                        <el-button  @click="editRecord(scope.row)" type="text" size="small">标注</el-button>
                        <span style="margin:0 3px;">|</span>
                        <el-button @click="showDelDialog(scope.row)" class="delete" type="text" size="small">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--<div class="pagination">
                <el-pagination :current-page.sync="currentPage"
                               @current-change="currentChange"
                               background
                               :page-size="pageSize"
                               :page-sizes="pageSizeArr"
                               @size-change="handleSizeChange"
                               :layout="pageLayout"
                               :total="total">
                </el-pagination>
            </div>-->
        </div>
    </div>
</template>

<script>
  import api from '@api/records.js';
  /*import config from '@api/config.js';
  import utils from '@api/utils.js';*/

  export default {
    name: 'RecordInput',   //慢病指标值关联维护
    data: function() {
      return {
        list: [],
        searched: false,
        filter:{
          brzyid:'',
          hospitalName:''
        },
        /*currentPage: 1,
        pageSize: config.pageSize,
        pageSizeArr:config.pageSizeArr,
        pageLayout:config.pageLayout,
        total: 0,*/
      }
    },
    created() {
      const that = this;
      //返回时避免参数未赋值就获取列表
      setTimeout(function(){
        that.getDataList();
      });
    },
    watch: {
      'filter': {
        handler: function () {
          this.searched = false;
        },
        deep: true
      }
    },
    beforeRouteEnter(to, from, next) {
      next(vm => {
        //const pm = to.param;
        Object.assign(vm, to.params);
        //vm.inCurrentPage=to.params.currentPage;
      })
    },
    methods: {
      /*handleSizeChange(val){
        this.pageSize = val;
        this.currentPage = utils.getCurrentPage(this.currentPage, this.total, this.pageSize);
        this.getDataList();
      },*/
      indexMethod(index) {
            return   index + 1;
        },
      addRecord(){
        this.$router.push({
          name:'AddRecordInput',
        })
      },
      getDataList(isTurnPage) {
        const param = this.getFilterItems(isTurnPage);
        this.searched = true;
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        api.getRecordInpList(param).then((res) => {
          loading.close();
          if(res.data.code == '0') {
            this.list = res.data.data;
            this.total = res.data.data.length;
            /*if(this.inCurrentPage!==undefined){
              this.currentPage=this.inCurrentPage;
              this.inCurrentPage = undefined;
            }*/
          }else{
            this.$message({
              message:result.msg,
              type:'warning',
              showClose: true
            });
          }
        })
      },
      filterDatas() {
        //this.currentPage = 1;
        this.getDataList();
      },
      editRecord(row,isShow) {
        const param = {
          caseNumber:  row.caseNumber
        }
       
         const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
         api.getInputcasesDetial(param).then((res) => {
          loading.close();
          if(res.data.code == '0') {
            const data = res.data.data
           this.$router.push({
              name: 'AddRecordInput',
              params: {isEdit: true, data: data[0]}
            });
            /*if(this.inCurrentPage!==undefined){
              this.currentPage=this.inCurrentPage;
              this.inCurrentPage = undefined;
            }*/
          }
        })
        

            
        // const pam = this.searched ? {
        //   /*currentPage: this.currentPage,
        //   pageSize:this.pageSize,*/
        //   filter: this.filter,
          
        // } : {
        //   /*currentPage: this.currentPage,
        //   pageSize:this.pageSize*/};
        // this.$router.push({
        //   name:isShow?'ShowRecord':'AddRecordInput',
        //   params: pam
        // })
      },
      /*currentChange(next) {
        this.currentPage = next;
        this.getDataList(true);
      },*/
      getFilterItems(isTurnPage) {
        //翻页时筛选条件没点确定则清空
        if(isTurnPage&&!this.searched){
        };
        const param = {
          /*current: this.inCurrentPage||this.currentPage,
          size: this.pageSize,*/
          // textId:
          caseNumber:this.filter.brzyid.trim(),
          hospitalName: this.filter.hospitalName.trim()
        };
        return param;
      },
     warning(msg,type){
        this.$message({
          showClose: true,
          message:msg,
          type:type||'warning'
        })
      },
      showConfirmDialog(msg,resolve){
        this.$alert(msg, '提示', {
          confirmButtonText: '确定',
          type: 'warning'
        }).then(() => {
          resolve();
        }).catch(() => {});
      },
      showDelDialog(row){
        const param = {
         textId: row.id 
        };
        const txt ='是否删除该病例？';
        this.showConfirmDialog(txt,()=>{
          api.removeRecordInpById(param).then((res)=>{
            if(res.data.code=='0'){
              this.getDataList();
              this.warning(res.data.msg || '操作成功','success');
            }else{
              this.warning(res.data.msg);
            }
          }).catch((error)=>{
            this.warning(error);
          })
        });
      }
    }
  }
</script>


<style lang="less">
    @import "../../less/admin.less";
    .delete{
        color: red;
    }
    .delete:hover {
        color: red;
    }
    .colorBlue{
      color:blue;
    }
    .review{
        color: #22ccc8;
    }
    .pagination {
        min-width: 1010px;
    }
</style>