Advertisement
Guest User

Untitled

a guest
May 4th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 4.01 KB | None | 0 0
  1. <template>
  2.   <el-card class="box-card">
  3.     <el-row type="flex" justify="center">
  4.       <el-col :span="12">
  5.         <el-form ref="addValidateForm"
  6.        :model="formAddPaciente"
  7.         label-position="left"
  8.         label-width="100px">
  9.          <el-form-item label="Nome" prop="nomePaciente">
  10.            <el-input v-model="formAddPaciente.nomePaciente" ></el-input>
  11.          </el-form-item>
  12.          <el-form-item label="Médico Responsável" prop="nomeMedico">
  13.            <el-input v-model="formAddPaciente.nomeMedico" ></el-input>
  14.          </el-form-item>
  15.          <el-form-item label="Data de Nascimento" prop="dataDeNascimento">
  16.            <el-date-picker
  17.             v-model="formAddPaciente.dataSelecionada"
  18.             type="date"
  19.             format="dd/MM/yyyy"
  20.            width="120px">
  21.            </el-date-picker>
  22.          </el-form-item>
  23.          <el-form-item label="Causa da Internação" prop="causaDaInternacao">
  24.            <el-input v-model="formAddPaciente.causaDaInternacao" ></el-input>
  25.          </el-form-item>
  26.           <el-form-item label="Hospital" prop="telefone">
  27.             <el-input v-model="formAddPaciente.telefone" ></el-input>
  28.           </el-form-item>
  29.           <el-form-item label="Foto" prop="foto">
  30.             <file-base64
  31.                v-bind:multiple="true"
  32.                v-bind:done="getFiles"
  33.                v-model="formAddPaciente.foto">
  34.             </file-base64>
  35.           </el-form-item>
  36.           <el-form-item>
  37.             <el-button type="primary" @click="addPaciente()">Cadastrar Paciente</el-button>
  38.             <el-button>Cancelar</el-button>
  39.           </el-form-item>
  40.         </el-form>
  41.       </el-col>
  42.     </el-row>
  43.   </el-card>
  44. </template>
  45.  
  46. <script>
  47. import api from '../axios'
  48. import { mapState, mapGetters } from 'vuex'
  49. import fileBase64 from 'vue-file-base64'
  50. import moment from "moment"
  51.  
  52. export default{
  53.   components: {
  54.     fileBase64
  55.   },
  56.   data(){
  57.  
  58.     return {
  59.       formAddPaciente:{
  60.             nomePaciente: '',
  61.             nomeMedico:'',
  62.             dataSelecionada:'',
  63.             dataDeNascimento:'',
  64.             causaDaInternacao:'',
  65.             telefone: '',
  66.             numeroDoProntuario: 2222,
  67.             foto:null,
  68.           }
  69.     }
  70.   },
  71.  
  72.   computed:{
  73.     ...mapGetters(['idMedico'])
  74.   },
  75.  
  76.   methods:{
  77.  
  78.     getFiles(files){
  79.  
  80.       this.formAddPaciente.foto = files[0].base64  // Pego a posição referente a base64
  81.       this.formAddPaciente.foto = this.formAddPaciente.foto.split(',') // Transformo ela em uma base64 válida
  82.       this.formAddPaciente.foto = this.formAddPaciente.foto[1] // Pego a posição 1 do array
  83.  
  84.     },
  85.  
  86.     addPaciente: function(){
  87.  
  88.       let dados = this.formAddPaciente;
  89.       dados.idMedico = this.idMedico;
  90.       dados.dataDeNascimento = dados.dataSelecionada.toJSON().substring(0, 10);
  91.       // let teste = this.files.base64;
  92.       console.log(dados);
  93.  
  94.       if(dados.nomePaciente ==''|| dados.telefone ==''|| dados.nomeMedico ==''|| dados.senha ==''|| dados.dataDeNascimento ==''|| dados.causaDaInternacao == '')
  95.       {
  96.         this.$message({
  97.           type:'info',
  98.           message:'Preencha todos os campos!',
  99.           showClose: true,
  100.           duration: 2000
  101.         })
  102.  
  103.       } else {
  104.  
  105.  
  106.       api.addPaciente(dados).then(({
  107.           data
  108.       }) => {
  109.           if (data) {
  110.               this.$message({
  111.                   type: 'success',
  112.                   message: 'Paciente cadastrado com sucesso.',
  113.                   showClose: true,
  114.                   duration: 2000
  115.               })
  116.  
  117.           } else {
  118.               this.$message({
  119.                   type: 'info',
  120.                   message: 'Erro no cadastro do paciente.',
  121.                   showClose: true,
  122.                   duration: 2000
  123.               })
  124.  
  125.           }
  126.  
  127.       }).catch((err) => {
  128.           console.log(err);
  129.       })
  130.     }
  131.     }
  132.   }
  133. }
  134. </script>
  135.  
  136. <style>
  137.   .el-date-picker{
  138.     min-width: 320px;
  139.   }
  140.   .el-date-editor.el-input{
  141.     width: 297px;
  142.   }
  143. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement