<template>
  <div class="patient-container">
    <patient-sidebar :id="patientID" defaultActive="1-6" v-on:tran-patient="onTranPatient"></patient-sidebar>
    <div class="patient-app-container advice-container app-container">
      <div class="cell clearfix">
      当前时间: <el-input  style="width:130px;" v-model="nowtime" :disabled="true"></el-input>
        干体重:<el-input style="width:100px" v-model="dryweight" :disabled="true"></el-input>&nbsp;
         <el-button size="medium" type="primary" @click="dialogVisible =true" v-show="addShow">新增</el-button>
         <el-button size="medium" type="primary" @click="dialogVisible =true" v-show="adjustShow">调整</el-button>
      </div>
      <el-table  :data="tableData" border style="width:100%">
      <el-table-column     prop="date"    label="时间"      align="center">
          <template  slot-scope="scope">
              {{CreateTime(scope.row.ctime)}}
          </template>
     </el-table-column>
      <el-table-column     prop="date"    label="调整值"   align="center">
        <template slot-scope="scope">
              {{scope.row.adjusted_value}}
        </template>
     </el-table-column>
      <el-table-column     prop="date"    label="干体重"    align="center">
         <template slot-scope="scope">
              {{scope.row.dry_weight}}
         </template>
      </el-table-column>
      <el-table-column     prop="date"    label="医生"      align="center">
          <template slot-scope="scope">
                {{scope.row.user_name}}
          </template>
      </el-table-column>
      <el-table-column     prop="date"    label="备注"      align="center">
          <template slot-scope="scope">
              {{scope.row.remakes}}
          </template>
      </el-table-column>
  </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10,20,50,100]"
        :page-size="10"
        background
        style="margin-top:20px;"
        align="right"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"></el-pagination>

     <el-dialog
         title="调整干体重"
         :visible.sync="dialogVisible"
         width="30%"
         center>
      <el-form label-width="120px" :model="dryWeightForm" ref="dryWeightForm" :rules="rules">
          <el-form-item label="干体重:" required prop="dry_weight">
              <el-input style="width:200px" v-model="dryWeightForm.dry_weight"></el-input>
          </el-form-item>
          <el-form-item label="医生:" required prop="doctors">
              <el-select v-model="dryWeightForm.doctors" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.admin_user_id"
                  :label="item.user_name"
                  :value="item.admin_user_id">
              </el-option>
           </el-select>
          </el-form-item>
           <el-form-item label="备注:" style="width:290px">
            <el-input
             type="textarea"
             :autosize="{ minRows: 2, maxRows: 4}"
             placeholder="请输入内容"
             v-model="dryWeightForm.remarks">
           </el-input>
        </el-form-item>
      </el-form>

     <span slot="footer" class="dialog-footer">
     <el-button @click="dialogVisible = false">取 消</el-button>
     <el-button type="primary" @click="UpdateDryWeightData('dryWeightForm')">确 定</el-button>
     </span>
     </el-dialog>

    </div>
  </div>
</template>
<script>
  const moment = require('moment')
  import PatientSidebar from './components/PatientSidebar'
  import EditGroupAdvice from './components/EditGroupAdvice'
  import { fetchAllAdminUsers, fetchAllDoctorAndNurse } from '@/api/doctor'
  import { fetchPatient, PostRemind, getDryWeightData, getAllDoctor, UpdateDryWeightData, getAllData } from '@/api/patient'

  import { jsGetAge, uParseTime } from '@/utils/tools'
  import { getDataConfig } from '@/utils/data'
  export default {
    name: 'doctorAdvice',
    components: {
      PatientSidebar,
      EditGroupAdvice
    },
    data() {
      return {
        tableData: [],
        nowtime: moment(new Date()).format('YYYY-MM-DD'),
        patientID: '',
        dryweight: '',
        dialogVisible: false,
        options: [],
        textarea2: '',
        dryWeightForm: {
          dry_weight: '',
          doctors: '',
          remarks: ''
        },
        addShow: true,
        adjustShow: false,
        page: 1,
        limit: 10,
        total: 0,
        rules: {
          dry_weight: [{ required: true, message: '请输入干体重!' }],
          doctors: [{ required: true, message: '请选择医生!' }]
        }
      }
    },
    methods: {
      clickuseradvicecell(row, column, cell, event) {
      },
      onTranPatient: function(tranPatient) {
        this.currentPatient = tranPatient
      },
      CreateTime(time) {
        return uParseTime(time, '{y}-{m}-{d} {h}:{i}:{s}')
      },
      getDryWeightData(id) {
        getDryWeightData(id).then(response => {
          if (response.data.state === 1) {
            var pre = response.data.data.pre
            console.log('pre是什么', pre)
            for (let index = 0; index < pre.length; index++) {
              this.dryweight = pre[0].dry_weight
            }
          }
        })
      },
      getAllDoctor() {
        getAllDoctor().then(response => {
          if (response.data.state == 1) {
            var appRole = response.data.data.appRole
            console.log('approle', appRole)
            this.options = appRole
          }
        })
      },
      UpdateDryWeightData(formName) {
        const params = {
          dry_weight: this.dryWeightForm.dry_weight,
          doctors: this.dryWeightForm.doctors,
          remarks: this.dryWeightForm.remarks,
          patient_id: this.patientID,
          dryweight: this.dryweight,
          mode : "1"
        }

        this.$refs[formName].validate((valid) => {
          if (valid) {
            UpdateDryWeightData(params).then(response => {
              if (response.data.state === 1) {
                var patientDryweight = response.data.data.patientDryweight
                console.log('patientdryweight', patientDryweight)
                this.dialogVisible = false
                const id = this.$route.params && this.$route.params.id
                this.getAllData(id)
                this.getDryWeightData(id)
              }else{
                this.$message.error(response.data.msg)
                return false
              }
            })
          }
        })
      },
      getAllData(id, page, limit) {
        getAllData(id, this.page, this.limit).then(response => {
          if (response.data.state === 1) {
            var dry = response.data.data.dry
            var total = response.data.data.total
            this.total = total
            console.log('total', total)
            this.tableData = dry
            const usertype = this.$store.getters.xt_user.user.user_type

            if (usertype === 1 || usertype === 2) {
              this.addShow = true
              this.adjustShow = false
            } else {
              this.addShow = false
              this.adjustShow = false
              return
            }
            if (dry.length === 0) {
              this.addShow = true
              this.adjustShow = false
            } else {
              this.addShow = false
              this.adjustShow = true
            }
            console.log('dry', dry)
          }
        })
      },
      handleSizeChange(limit) {
        this.limit = limit
        const id = this.$route.params && this.$route.params.id
        this.getAllData(id, this.page, this.limit)
      },
      handleCurrentChange(page) {
        this.page = page
        const id = this.$route.params && this.$route.params.id
        this.getAllData(id, this.page, this.limit)
      }
    },
    created() {
      const id = this.$route.params && this.$route.params.id
      console.log('id是设么', id)
      this.patientID = parseInt(id)
      this.getDryWeightData(id)
      this.getAllDoctor()
      this.getAllData(id)
      const usertype = this.$store.getters.xt_user.user.user_type
      // if (usertype === 2) {
      //   this.addShow = true
      //   this.adjustShow = false
      // } else {
      //   this.addShow = false
      //   this.addjustShow = false
      // }

      console.log('usertype', usertype)
    }
  }
</script>

<style>
  #oictable ::-webkit-scrollbar {
    height: 15px;
  }
</style>

<style rel="stylesheet/scss" lang="scss" scoped>

  .printForm {
    width: 960px;
  }

  .printForm .hospital_title {
    font-size: 20px;
    font-weight: 400;
    text-align: center;
    letter-spacing: 5px;
  }

  .printForm .title {
    font-size: 30px;
    font-weight: 500;
    text-align: center;
  }

  .printForm .title {
    font-size: 30px;
    font-weight: 500;
    text-align: center;
  }

  .printForm .info ul {
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    align-items: center;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -o-box-sizing: border-box;
    -ms-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-justify-content: space-around;
    -moz-justify-content: space-around;
    -ms-justify-content: space-around;
    -o-justify-content: space-around;
    justify-content: space-around;
  }

  .printForm .info ul li {
    display: flex;
    box-sizing: border-box;
    justify-content: space-around;
  }

  .printForm .info ul li .InputBox {
    padding: 0;
    border: none;
    border-bottom: 1px #e5e5e5 solid;
    outline: none;
    width: 80px;
  }

  .printForm .printTable tr {
    padding: 2px;
  }

  .printForm .printTable tr > th {
    padding: 6px 4px;
  }

  .printForm .printTable tr > td {
    padding: 6px 4px;
  }

  .es-img {
    height: 25px;
  }

  .advice-container {
    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;
  }

  }
  .el-dropdown-link {
    cursor: pointer;
  }

  }

  .advice-order .ls-title {
    text-align: center;
    font-weight: 600;
    font-size: 30px;
    line-height: 80px;
    margin-bottom: 20px;
  }

  .advice-order .ls-type {
    text-align: center;
    margin-bottom: 20px;
  }

  .advice-order .ls-name {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 30px 2em;
  }
</style>
<style>
  .advice-order .el-table__body {
    border: 1px solid #333;
  }

  .advice-order .el-table__body td {
    border: 1px solid #333;
  }

  .advice-order .item-value {
    flex: 1;
    border-bottom: 1px solid #333;
  }

  .advice-order th,
  .advice-order td {
    padding: 5px 10px;
  }

  #user-advice-name-table .expanded {
    display: table-row !important;
  }

  #user-advice-name-table .el-table__expand-icon {
    -webkit-transform: rotate(90deg) !important;
    transform: rotate(90deg) !important;
  }

  .user-advice-table-row:hover > td {
    background: #fff !important;
  }

  .user-advice-table-row td:hover {
    background: #fff !important;
  }

  #user-advice-select-template-table .el-table__row {
    display: table-row !important;
  }

  #user-advice-select-template-table .el-table__expand-icon {
    -webkit-transform: rotate(90deg) !important;
    transform: rotate(90deg) !important;
  }

  .advicenamedisplay .cell {
    float: left;
    text-align: left;
  }

.el-form-item__error {
    margin-left: 0px;
}
</style>

