<template>
  <div class="x-grade" v-if="gradData">
    <div class="x-grade-list">
      <x-image width="45rpx" height="45rpx" :src="getImg(gradData.Icon)" v-if="gradData.Icon"></x-image>
      <x-image width="45rpx" height="45rpx" :src="getImg(gradData.icon)" v-else></x-image>
      <div class="grade-name">{{gradData.Name? gradData.Name:gradData.name}}</div>
    </div>
  </div>
</template>

<script>
import ala from '@/service/ala.js'
export default {
    model: {
      prop: 'dataModel',
      event: 'change'
    },
    props: {
      dataModel: {}
    },
    data () {
      return {
        viewModel: null,
        gradData: null
      }
    },
    mounted () {
      this.init()
    },
    methods: {
      async init () {
        var gradData = ala.vuexLocalGet('grade_local_data',true)
        if (!gradData) {
          var response = await ala.httpGet('api/Grade/GetAllGrade')
          this.viewModel = response
          ala.vuexLocalSet('grade_local_data', this.viewModel,true)
        } else {
          this.viewModel = gradData
        }
        this.gradData = this.viewModel.find(r => r.id === this.dataModel)
      },
	  getImg(image) {
		  return ala.urlImage(image)
	  }
    },
    watch: {
      'dataModel': {
        deep: true,
        handler: 'init'
      }
    }
  }
</script>

<style  lang="scss" scoped>
  @import "./var.scss";
</style>
