<template>
   <v-layout fil-height column>
      <v-card v-if="xshow === 'Y'">
         <v-subheader>
            PILIH DATA YANG BELUM SESUAI
            
            <v-flex text-md-right>
                <v-btn v-if="(status.id === '2' || status.id === 2) && seen_button === true" @click="tolak()" small color="info">Simpan</v-btn>

            </v-flex>
         </v-subheader>
         <v-divider></v-divider>
         <v-flex pb-3 xs12 >
            <v-layout wrap>
               <v-flex xs12 pa-2 v-for="(vp,idx) in vdoctor" :key="vp.id">
                  <!--<one-field-verification-patient-doctor
                     :xdatalabel="vp.label"
                     :xdatacbx="vp.chex"
                     :xdatatxt="vp.note"
                     @update-data-txt="(val) => updateDataTxtParentDoctor(idx,val)"
                     @update-data-cbx="(val) => updateDataCbxParentDoctor(idx,val)"
                  ></one-field-verification-patient-doctor>-->
                  <v-layout pl-2 row>
                     <v-flex xs6>
                        <v-layout row>
                           <v-flex pt-1 xs2>
                              <span @click="changeCheck(vp.chex,idx)" v-if="vp.chex === true" style="background: rgb(252, 252, 252);border: 2px solid #767575;" class="icon-medium-fill-base-small white--text"></span>
                              <span @click="changeCheck(vp.chex,idx)" v-if="vp.chex === false" style="background:#9e9e9e7a" class="icon-medium-fill-base-small white--text red"><v-icon dark>close</v-icon></span>
                           </v-flex>
                           <v-flex xs12>
                              <v-text-field
                                 :label="vp.label"
                                 hide-details
                                 placeholder="Isikan alasan di sini"
                                 v-model="vp.note"
                                 outline
                              ></v-text-field>
                           </v-flex>
                        </v-layout>
                     </v-flex>
                  </v-layout>
               </v-flex>
            </v-layout>
         </v-flex>
      </v-card>
      <v-dialog v-model="dialogvalidation" persistent width="500">
        <v-card>
            <v-card-title class="headline">Peringatan !</v-card-title>
            <v-card-text>
                <v-alert v-for="item in msgdialogvalidation"
                    :value="true"
                    type="error"
                    >
                   {{item}} [ Belum ada alasan ]
                </v-alert>
            </v-card-text>
            <v-card-actions>
            <v-spacer></v-spacer>
            <v-btn color="green darken-1" flat @click="dialogvalidation = false">OK</v-btn>
            </v-card-actions>
        </v-card>
        </v-dialog>
   </v-layout>
</template>

<style scoped>
</style>

<script>
module.exports = {
   components : {
      'one-field-verification' : httpVueLoader('../../common/oneFieldVerification.1.vue'),
      'one-testing-component':httpVueLoader('../../common/oneTestingComponent.vue'),
      'one-field-verification-patient-doctor':httpVueLoader('../../common/oneFieldVerificationPatientDoctor.vue')
   },
   data () {
      return {
        dialogvalidation: false,
        msgdialogvalidation:[]
      }
    },
   computed: {
      patient_age() {
         if ( this.patient == undefined) {
            return ''
         }
         return window.calculate_age(this.patient.M_PatientDOB)
      },
      xshow() {
         return this.$store.state.patient.show_right
      },
      patient() {
         return this.$store.state.patient.selected_patient
      },
      vpatient() {
         return this.$store.state.verification.verification_patient
      },
      vdoctor() {
         return this.$store.state.patient.verifications
      },
      status(){
          return this.$store.state.status.selected_status
      },
      seen_button: {
            get() {
                return this.$store.state.patient.btn_save_seen
            },
            set(val) {
                this.$store.commit("patient/update_btn_save_seen",false)
            }
        },
   },
   methods : {
      changeCheck(val,idx){
         console.log(val)
         console.log(idx)
         var xxx = this.$store.state.patient.verifications
         console.log(xxx)
         var xnew = val === true ?false:true
         xxx[idx].chex = xnew
         this.$store.commit("patient/update_verifications",xxx)
      },
      updateDataTxtParentDoctor(idx, val) { 
          var verifications = this.$store.state.patient.verifications
          verifications[idx].note = val
          this.$store.commit("patient/update_verifications",verifications)
          var xcount = this.$store.state.patient.no_save + 1
          this.$store.commit("patient/update_no_save",xcount)
        // var idx = _.findIndex(arrtrx, item => item.T_SampleStorageID === this.$store.state.samplestorage.last_id)
      },
      updateDataCbxParentDoctor(idx, val) {
          var verifications = this.$store.state.patient.verifications
          verifications[idx].chex = val
          this.$store.commit("patient/update_verifications",verifications)
          var xcount = this.$store.state.patient.no_save + 1
          this.$store.commit("patient/update_no_save",xcount)
      },
      tolak(){
         //this.disabled_button = true
         //this.$store.commit("patient/disabled_button",true)
        var xerrors = []
        var allArr = this.$store.state.patient.selected_patient 
        allArr.verifications.forEach(function(value) {
            if(value.chex === false && value.note === "")
                xerrors.push(value.label);
        });
        
        if(xerrors.length === 0){
                var prm = this.$store.state.patient.selected_patient 
                prm.act = 'N'
                prm.name = this.$store.state.patient.name
               prm.nolab = this.$store.state.patient.nolab
              // prm.status = this.$store.state.status.selected_status.id
                this.$store.dispatch("patient/verify",prm)
            }
            else{
                var msg = ""
                xerrors.forEach(function(value) {
                    msg += '<v-alert :value="true" type="error">'+value+'</v-alert>'
                });
                this.msgdialogvalidation = xerrors
                this.dialogvalidation = true
            }
      },
      
   }
}
</script>
