<template>
  <div class="main-contain">

    <div class="app-container">
      <div class="cell clearfix">
        <el-input
            style="width: 400px;"
            v-model.trim="searchKey"
            class="filter-item"
            placeholder="病人姓名/透析号"
            size="small"
            @keyup.enter.native='search'
        />
        <el-button
            class="filter-item"
            type="primary"
            icon="el-icon-search"
            @click="search"
            size="small"
        >搜索
        </el-button
        >
      </div>



      <el-table
          ref="multipleTable"
          :row-style="{ color: '#303133' }"
          :header-cell-style="{
          backgroundColor: 'rgb(245, 247, 250)',
          color: '#606266'
        }"
          :data="tableData"
          border
          fit
          highlight-current-row
          style="width: 100%;margin-top: 10px;"
      >

        <el-table-column
            type="index"
            label="序号"
            width="40px"
            align="center"
        ></el-table-column>


        <el-table-column
            property="name"
            label="姓名"
            min-width="70"
            align="center"
        >
          <template slot-scope="scope">
            <router-link
                :to="'/patients/patient/' + scope.row.id"
                style="color:#409eff;width:100%;display:block;"
            >{{ scope.row.name }}
            </router-link
            >
          </template>
        </el-table-column>
        <el-table-column label="性别" min-width="60" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.gender == 1">男</span>
            <span v-else-if="scope.row.gender == 2">女</span>
            <span v-else>未知</span>
          </template>
        </el-table-column>

        <el-table-column label="转归" align="center">
          <template slot-scope="scope">
            <span>{{ LapsetoInfo(scope.row) }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center" min-width="140">
          <template slot-scope="scope">
            <el-tooltip
                class="item"
                effect="dark"
                content="人员信息查询"
                placement="top"
            >
              <el-button
                  type="primary"
                  icon="el-icon-edit"
                  size="small"
                  @click="OpenQuery(scope.row, scope.$index)"
              ></el-button>
            </el-tooltip>

          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.page"
          :page-sizes="[10, 20, 50, 100,200,500,1000,2000]"
          :page-size="listQuery.limit"
          background
          style="margin-top:20px;"
          align="right"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
      >
      </el-pagination>

    </div>


  </div>
</template>

<script>
import { code, EditLapseto, fetchList, getMaxDialysisNo, OpenView, postExportPatients,GetRemind } from '@/api/patient'
import { generateLog } from '@/api/config'
import QRCode from 'qrcodejs2'
import Vue from 'vue'
import { Base64 } from 'js-base64'
import { jsGetAge,uParseTime } from '@/utils/tools'
import { log } from 'util'
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import UploadExcel from '@/xt_pages/components/UploadExcel'
import axios from 'axios'

export default {
  name: 'Patient',
  components: {
    UploadExcel,
    BreadCrumb
  },
  data() {
    return {

      currentIndex: -1,
      LapsetoDialogVisible: false,
      centerDialogVisible: false,
      checkAll: false,
      isIndeterminate: true,
      dialogVisible: false,
      exportLogVisible: false,
      exportVisible:false,
      phoneVisible:false,
      idCardNoVisible:false,
      wechatbindimg: '',
      isShow:true,
      active: true,
      schedulType: 0,
      lapsetoForm: {
        lapseto_type: 0,
        lapseto_time: '',
        patient_id: 0,
        out_reason:''
      },
      sourceType: 0,
      sourceID: 0,
      lapsetoType: 1,
      sourceArr: [
        { value: 0, label: '全部', source: 0, lapseto: 0 },
        { value: 3, label: '门诊', source: 1, lapseto: 1 },
        { value: 4, label: '住院', source: 2, lapseto: 1 }
      ],
      lapsetoArr: [
        { value: 0, label: '全部', source: 0, lapseto: 0 },
        { value: 1, label: '转出', source: 0, lapseto: 2 },
        { value: 2, label: '留治', source: 0, lapseto: 1 },
        { value: 3, label: '死亡', source:0,  lapseto: 3 },
      ],
      scheduling: [
        {
          value: 1,
          label: '已排班'
        },
        {
          value: 2,
          label: '未排班'
        }
      ],
      prescription: [
        {
          value: 1,
          label: '有处方'
        },
        {
          value: 2,
          label: '无处方'
        }
      ],
      tableData: null,
      searchKey: '',
      // value2: '',
      total: 0,
      pageTotal: 0,
      dialysisVisible:false,
      pageSelect: 0,
      max_dialysis_no: '',
      listQuery: {
        page: 1,
        limit: 10,
        schedul_type: 0,
        binding_state: 0,
        lapseto: 1,
        source: 0,
        start_time: '',
        end_time: '',
        keywords: '',
        contagion: '',
        reimbursement_way: '',
        isscheduling: '',
        isprescription: ''
      },
      multipleSelection: [],
      bindWechatDialog: false,
      contagionList: [],
      reimbursement_ways: [],
      patient: null,
      id: '',
      name: '',
      dialysis_no: '',
      patientPrint: {},
      patient_id: '',
      gender: '',
      idcardno: '',
      phone: '',
      healthcareno: '',
      startTime: '',
      export_date: [],
      lapeseto:"",
      value:13,
      dialogTableVisible:false,
      gridData:[],
      totalOne: 0,
      page: 1,
      limit: 5
    }
  },
  created() {
    if(sessionStorage.getItem('patientPageSize')){
      this.listQuery.limit = parseInt(sessionStorage.getItem('patientPageSize'))
    }
    this.getList()
    this.contagionList = this.$store.getters.contagions
    this.reimbursement_ways = this.$store.getters.reimbursement_ways

    const keyword = this.$route.query && this.$route.query.keyword
    if (typeof keyword === 'string' && keyword.length > 0) {
      this.listQuery.keywords = keyword
      this.searchKey = keyword
    }
    //获取
    this.GetRemindPatientList()
  },

  methods: {
    OpenQuery(row, index){
      let params ={
        id_card_no:row.id_card_no,
        admin_user_id:  this.$store.getters.xt_user.user.id,
      };
      var that = this;
      axios.get('http://127.0.0.1:9532/api/patient/info', {
        params: params
      })
          .then(function(response) {
            if (response.data.state == 0) {
              that.$message.error(response.data.msg);
              return false
            } else {

              if(response.data.data.failed_code == -10){
                // that.$message.error(response.data.data.msg)
                that.$confirm(response.data.data.msg, '医保错误信息', {
                  confirmButtonText: '确 定',
                  type: 'warning'
                }).then(() => {

                }).catch(() => {
                })
              }else{
                that.dialogFormVisible = true;
                that.insutypes = [];
                that.psn_no =  response.data.data.info.output.baseinfo.psn_no;

              }
            }
          })
          .catch(function(error) {

          })

    },
    handleSizeChange(val) {
      sessionStorage.setItem('patientPageSize',val)
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    search() {

      this.listQuery.keywords = this.searchKey
      this.getList()
    },
    changeOtherSearch() {
      this.getList()
    },
    getList() {
      console.log("parasm2222",this.listQuery)
      fetchList(this.listQuery).then(response => {
        if (response.data.state === 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          this.tableData = response.data.data.patients
          console.log('病人是', this.tableData)
          this.pageTotal = this.tableData.length
          this.total = response.data.data.total

        }
      })
    },

  }
}
Vue.prototype.$QRCode = function() {
  var name = this.name
  var dialysis_no = this.dialysis_no
  var id = this.id
  var gender = this.gender
  if (gender === 1) {
    gender = '男'
  }
  if (gender === 2) {
    gender = '女'
  }
  var idcardno = this.idcardno
  var phone = this.phone
  var healthcareno = this.healthcareno

  // BASE64加密
  // var eid = this.Base64.encode(id)
  // var ename = this.Base64.encode(name)
  // var egender = this.Base64.encode(gender)
  // var eidcardno = this.Base64.encode(idcardno)
  // var ephone = this.Base64.encode(phone)
  // var ehealthcareno = this.Base64.encode(healthcareno)
  // var edialysisno = this.Base64.encode(dialysis_no)
  var eid = id
  var ename = name
  var egender = gender
  var eidcardno = idcardno
  var ephone = phone
  var ehealthcareno = healthcareno
  var edialysisno = dialysis_no
  console.log(
      'user_id' + eid,
      'name:' + ename,
      'gender:' + egender,
      'idcard_no:' + eidcardno,
      'phone:' + ephone,
      'healthcare_no:' + ehealthcareno,
      'edialysis_no:' + edialysisno
  )
  const salting = 'admin-authority'
  new QRCode('qrcode', {
    width: 150, // 设置宽度
    height: 150, // 设置高度
    text:
        'user_id:' +
        eid +
        ',' +
        'name:' +
        ename +
        ',' +
        'dialysis_no:' +
        edialysisno +
        ',' +
        'gender:' +
        egender +
        ',' +
        'idcard_no:' +
        eidcardno +
        ',' +
        'phone:' +
        ephone +
        ',' +
        'healthcare_no:' +
        ehealthcareno
  })
}
</script>

<style rel="stylesheet/scss" lang="scss">
.app-container {
  /*margin: 20 px;*/
  font-size: 15px;

.filter-container {
  padding-bottom: 5px;
}

.search-component {
  width: 500px;

.searchBox {
  width: 300px;
  height: 36px;
  line-height: 36px;
  padding-left: 15px;
  border: 1px #dcdfe6 solid;
  border-right: none;
  outline: none;
  float: left;
  border-radius: 6px 0 0 6px;
  font-size: 14px;
  color: #333;
  background: #fff;
  box-shadow: 3px 3px 4px rgba(135, 135, 135, 0.05);
}

.searchBtn {
  background-color: #409eff;
  color: #fff;
  font-size: 15px;
  text-align: center;
  height: 36px;
  line-height: 36px;
  float: left;
  outline: none;
  width: 70px;
  border: none;
  border-radius: 0 6px 6px 0;
  font-family: "Microsoft Yahei";
  cursor: pointer;
}

}
.amount {
  font-weight: normal;
  padding: 10px 0 0 0;
  color: #606266;
  font-size: 14px;

span {
  color: #ef2525;
  font-family: "Arial";
  padding: 0 2px;
}

}

.print_main_content {
  background-color: white;
  width: 960px;
  margin: 0 auto;
  padding: 0 0 20px 0;
}

.print_main_content .order_title {
  text-align: center;
  font-size: 23px;
  line-height: 50px;
  font-weight: 500px;
}

.print_main_content table {
  width: 100%;
  border: 1px solid;
  border-collapse: collapse;
  padding: 2px;
}

.print_main_content table tbody tr td {
  border: 1px solid;
  text-align: center;
  /* font-size: 17px; */
  padding: 10px 8px;
}

.td_proj_title {
  font-size: 18px;
  line-height: 25px;
  font-weight: 500;
}

.td_proj_content {
  font-size: 18px;
  line-height: 25px;
}

.td_align_left {
  text-align: left;
}

.print_footnote_panel {
  font-size: 17px;
  line-height: 40px;
}

.print_footnote_panel .proj {
  display: inline-block;
  width: 49%;
}

.print_footnote_panel .proj .proj_title {
  font-weight: 500;
}

}
.el-table td,
.el-table th.is-leaf,
.el-table--border,
.el-table--group {
  border-color: #d0d3da;
}

.el-table--border::after,
.el-table--group::after,
.el-table::before {
  background-color: #d0d3da;
}

.el-select--small {
  width: 196px;
}

.el-checkbox__inner::after {
  height: 10px;
  left: 7px;
}

.el-checkbox__inner {
  width: 20px;
  height: 20px;
}
</style>
