NAFSearch.vue 1.49 KB
Newer Older
1
<template>
2
  <div id="NAFSearch">
3 4
    <div class="container">
      <div class="row">
5 6 7 8
        <div class="col-md-12">
					<h2>NAF</h2>
          <input type="text" ref="naf" placeholder="Code NAF" v-model="naf" class="form-control"><br>
          <input @click="search()" type="button" class="btn main-button pull-right" value="Chercher">
9
        </div>
10 11 12 13 14
      </div>
      <br>
      <div class="row">
        <div class="col-md-12 results">
          <div v-if="this.naf && Object.keys(this.results).length">
15 16
            <ul class="dash">
              <li v-for="(result,code) in this.results" :key="code">
17
                {{ result.name }}
18 19 20
              </li>
            </ul>
          </div>
21 22
          <div v-if="this.naf && this.resultsIsEmpty">
            <p> Aucune activité principale trouvée avec l'identifiant «{{ this.naf }}».</p>
23 24 25 26 27 28 29 30
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
31
		name: 'NAFSearch',
32 33
		data: function () {
			return {
34
        naf: "",
35 36 37 38 39 40
        results: {},
        resultsIsEmpty: false,
			}
		},
		methods: {
			search: function () {
41 42 43 44 45 46 47
        this.$http
          .get('/naf?q='+this.naf)
          .then(response => {
            this.results = response.body;
            this.resultsIsEmpty = this.isEmpty(this.results);
          })
          .created;
48 49 50
			},
      isEmpty: function (obj) {
        for(var key in obj) {
51
          if(obj.hasOwnProperty(key)) return false;
52 53 54
        }
        return true;
      }
55
		}
56 57
  }
</script>