<template>
   <v-layout class="fill-height" column>
      
      <v-card   class="mb-2 pa-2 searchbox">
         <v-layout >
               <v-text-field class="xs6 ma-1"
                             label=""
                             placeholder="Pencarian"
                             single-line
                             outline
                             v-model="query_mou"
                             hide-details
                             ></v-text-field>

               <v-select class="xs6 ma-1" :items="companies" 
                  item-text="M_CompanyName"
                  item-value="M_CompanyID"
                  return-object
                  v-model="selected_company"
                  label="Company" outline   hide-details></v-select>
            <v-btn class="xs3 ma-1" color="success"  @click="search_mou" >Search</v-btn>
            <!-- <v-btn class="xs3 ma-1" color="info"  @click="set" >Baru</v-btn> -->
         </v-layout>
      </v-card>
      <v-card >
         <v-layout row>
            <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
               <v-data-table 
                  :headers="headers" 
                  :items="mous"
                  :loading="isLoading"
                  :pagination.sync="pagination"
                   class="elevation-1">
                  <template slot="items" slot-scope="props">
                     <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.M_MouName }}</td>
                     <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.M_MouStartDate }}</td>
                     <td class="text-xs-center pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.M_MouEndDate }}</td>
                     <!-- <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.status}}</td> -->
                  </template>
                  <template>
                     <div class="text-xs-center">
                        <v-pagination
                           
                           :length="15"
                           :total-visible="7"
                        ></v-pagination>
                     </div>
                  </template>
               </v-data-table>
            </v-flex>
         </v-layout>
      </v-card>
       
   </v-layout>
</template>

<style scoped>
.searchbox .v-input.v-text-field .v-input__slot{
   min-height:60px;
}
.searchbox .v-btn {
   min-height:60px;
}
table.v-table tbody td,table.v-table tbody th {
   height: 40px;
}

table.v-table thead tr {
   height: 40px;
}

</style>

<script>
module.exports = {
components : {
      
   },

   mounted() {
      this.$store.dispatch("priceref/search_company")
   },

   methods : {
      isSelected(p) {
         return false
      },

      search_mou() {
         this.$store.dispatch("priceref/search_mou")
      },

      selectMe(doc) {
         this.$store.commit('priceref/update_selected_mou', doc)
         this.$store.dispatch('priceref/search_price')
      }
   },

   computed: {
      companies : {
         get () {
            return this.$store.state.priceref.companies
         },
         set (v) {
            this.$store.commit('priceref/update_companies', v)
         }
      },

      mous : {
         get () {
            return this.$store.state.priceref.mous
         },
         set (v) {
            this.$store.commit('priceref/update_mous', v)
         }
      },

      selected_company : {
         get () {
            return this.$store.state.priceref.selected_company
         },
         set (v) {
            this.$store.commit('priceref/update_selected_company', v)
         }
      },

      selected_mou : {
         get () {
            return this.$store.state.priceref.selected_mou
         },
         set (v) {
            this.$store.commit('priceref/update_selected_mou', v)
         }
      },

      query_mou : {
         get () {
            return this.$store.state.priceref.query_mou
         },
         set (v) {
            this.$store.commit('priceref/update_query_mou', v)
         }
      },

      isLoading () {
         return false
      }
   },
   data() {
      return {
         headers: [
            {
               text: "NAMA",
               align: "left",
               sortable: false,
               value: "mr",
               width: "25%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "START DATE",
               align: "center",
               sortable: false,
               value: "lab",
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "END DATE",
               align: "center",
               sortable: false,
               value: "name",
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            }
         ],
         
         pagination:{
            descending: false,
            page: 1,
            rowsPerPage: 5,
            sortBy: 'M_MouName',
            totalItems: this.$store.state.priceref.total_mous
         }
      };
   }
}
</script>
