/**
* @Author Sean
* @Date 2019/4/23
*/
<template>
  <h-view class="public-style" style="height: 100%" title="行驶证识别">
    <h-content>
      <list-item>
        <item>
          <div slot="name">车牌号码</div>
          <div slot="content">{{ licenseList.plateno }}</div>
        </item>
      </list-item>
      <list-item>
        <item>
          <div slot="name">车辆类型</div>
          <div slot="content">{{ licenseList.vehicletype }}</div>
        </item>
        <item>
          <div slot="name">所有人</div>
          <div slot="content">{{ licenseList.owner }}</div>
        </item>
        <item>
          <div slot="name">住址</div>
          <div slot="content">{{ licenseList.veaddress }}</div>
        </item>
        <item>
          <div slot="name">使用性质</div>
          <div slot="content">{{ licenseList.usecharacter }}</div>
        </item>
        <item>
          <div slot="name">发动机号码</div>
          <div slot="content">{{ licenseList.engineno }}</div>
        </item>
        <item>
          <div slot="name">品牌型号</div>
          <div slot="content">{{ licenseList.model }}</div>
        </item>
        <item>
          <div slot="name">车辆识别代码</div>
          <div slot="content">{{ licenseList.vin }}</div>
        </item>
        <item>
          <div slot="name">注册日期</div>
          <div slot="content">{{ licenseList.registerdate }}</div>
        </item>
        <item>
          <div slot="name">发证日期</div>
          <div slot="content">{{ licenseList.issuedate }}</div>
        </item>
      </list-item>
    </h-content>
    <bottom-tab>
      <tab-button @click.native="openShow" >
        识别
      </tab-button>
    </bottom-tab>
  </h-view>
</template>

<script>
  export default {
    data() {
      return {
        licenseList : {
          plateno: "",
          vehicletype: "",
          owner: "",
          veaddress: "",
          usecharacter: "",
          engineno: "",
          model: "",
          vin: "",
          registerdate: "",
          issuedate: "",
          cropped_image: "",
          created_by: "",
          last_updated_by: ""
        }
      }
    },
    created: function () {
    },
    mounted: function () {
    },
    updated: function () {
    },
    destroyed: function () {
    },
    methods: {
      // 打开sheet操作
      openShow (checkId) {
        let vm = this
        wx.chooseImage({
          count: 1, // 微信最多能选择9张图片
          sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
          sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
          success: function (data) {
            hlsPopup.showLoading('请稍候')
            vm.localIds = data.localIds // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
            /*   data.localIds.forEach((localId, index) => {
                 wx.getLocalImgData({
                   localId: localId, // 图片的localID
                   alert('localId '+ localId)
                   success: function (res) {
                     vm.getHanwanyun(res.localData);
                     alert('路径 '+res.localData)
                   },
                 })
               })*/
            vm.wxImageUpload()
          },
        })
      },
      // 图片上传到微信服务器
      wxImageUpload () {
        let vm = this
        let localId = vm.localIds.pop()
        wx.uploadImage({
          localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得
          isShowProgressTips: 0, // 默认为1，显示进度提示
          success: function (res) {

            /* else {
               hlsPopup.hideLoading()
               hlsPopup.showLongCenter('图片上传成功')
             }*/
            vm.getHanwanyun(res.serverId)

          },
        })
      },
      //识别
      getHanwanyun(serverId) {
        let vm = this
        let url = process.env.rootPath + '/havon/media' + '?index=' + serverId
        let param = {
          'wechatCode': process.env.wxCode,
          'mediaId': serverId,
          'sysName': 'HLS_HANVON',
          'apiName': 'hanvon_vehiclecard',
        }
        hlsHttp.post(url, param).then(function (res) {
          hlsPopup.hideLoading();
          if (res.vehicleCard.plateno) {
            vm.licenseList.plateno = res.vehicleCard.plateno;
          }
          if (res.vehicleCard.vehicletype) {
            vm.licenseList.vehicletype = res.vehicleCard.vehicletype;
          }
          if (res.vehicleCard.owner) {
            vm.licenseList.owner = res.vehicleCard.owner;
          }
          if (res.vehicleCard.veaddress) {
            vm.licenseList.veaddress = res.vehicleCard.veaddress;
          }
          if (res.vehicleCard.usecharacter) {
            vm.licenseList.usecharacter = res.vehicleCard.usecharacter;
          }
          if (res.vehicleCard.engineno) {
            vm.licenseList.engineno = res.vehicleCard.engineno;
          }
          if (res.vehicleCard.model) {
            vm.licenseList.model = res.vehicleCard.model;
          }
          if (res.vehicleCard.vin) {
            vm.licenseList.vin = res.vehicleCard.vin;
          }
          if (res.vehicleCard.registerdate) {
            vm.licenseList.registerdate = res.vehicleCard.registerdate;
          }
          if (res.vehicleCard.issuedate) {
            vm.licenseList.issuedate = res.vehicleCard.issuedate;
          }
          if (res.vehicleCard.cropped_image) {
            vm.licenseList.cropped_image = res.vehicleCard.cropped_image;
          }
        });
      },
    }
  }
</script>

<style scoped lang="less" rel="stylesheet">
  .public-style {
    .content {

    }
  }
</style>
