<template>
    <div>
        <crumbs title="测试病例记录维护" style="min-width: 980px">
            <el-form :inline="true" class="demo-form-inline">
                <!--<el-form-item label="病人住院ID：">
                   <el-input size="mini" v-model="filter.brzyid" placeholder="病人住院ID" clearable></el-input>
               </el-form-item>
               <!-form-item>
                   <el-button size="mini" @click="filterDatas">查找</el-button>
                   <el-button size="mini" type="warning" @click="addRelation">添加测试病例</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="basyid"
                        label="病案首页ID"
                        width="180">
                </el-table-column>
                <el-table-column
                        :resizable = "false"
                        prop="brzyid"
                        label="病人住院ID"
                        width="180">
                </el-table-column>
                <el-table-column
                        :resizable = "false"
                        prop="brbaxm"
                        label="姓名">
                </el-table-column>
                <!--<el-table-column
                        :resizable = "false"
                        prop="operName"
                        label="性别">
                </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="editRecord(scope.row,true)" 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: 'RecordManager',   //慢病指标值关联维护
    data: function() {
      return {
        list: [],
        searched: false,
        filter:{
          brzyid:'',
        },
        /*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();
      },*/
      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.getRecordList(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;
            }*/
          }
        })
      },
      filterDatas() {
        //this.currentPage = 1;
        this.getDataList();
      },
      editRecord(row,isShow) {
        const pam = this.searched ? {
          /*currentPage: this.currentPage,
          pageSize:this.pageSize,*/
          filter: this.filter,
          basyid:row.basyid,
          brzyid:row.brzyid
        } : {
          basyid:row.basyid,
          brzyid:row.brzyid
          /*currentPage: this.currentPage,
          pageSize:this.pageSize*/};
        this.$router.push({
          name:isShow?'ShowRecord':'AddRecord',
          params: pam
        })
      },
      /*currentChange(next) {
        this.currentPage = next;
        this.getDataList(true);
      },*/
      getFilterItems(isTurnPage) {
        //翻页时筛选条件没点确定则清空
        if(isTurnPage&&!this.searched){
          this.filter.brzyid='';
        };
        const param = {
          /*current: this.inCurrentPage||this.currentPage,
          size: this.pageSize,*/
          name:this.filter.brzyid.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 = {
          "conceptId": row.conceptId,
          "isDeleted": row.isDeleted=== 'N'?'Y':'N',
          "relationId": 18
        };
        const txt = row.isDeleted=== 'N'?'是否删除该关联？':'是否重新启用该关联？';
        this.showConfirmDialog(txt,()=>{
          api.delAssaySon(param).then((res)=>{
            if(res.data.code=='0'){
              if(!this.searched){
                //未点确认时清空搜索条件
                this.filter={
                  brzyid:'',
                };
              }
              if(row.isDeleted !== 'N'){       //恢复成功后跳转到筛选条件的首页
                this.currentPage = 1;
              }
              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;
    }
    .review{
        color: #22ccc8;
    }
    .pagination {
        min-width: 1010px;
    }
</style>