/**
* @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.name }}</div>
        </item>
      </list-item>
      <list-item>
        <item>
          <div slot="name">法定代表人</div>
          <div slot="content">\{{ licenseList.person }}</div>
        </item>
        <item>
          <div slot="name">注册资本</div>
          <div slot="content">\{{ licenseList.capital }}</div>
        </item>
        <item>
          <div slot="name">住所</div>
          <div slot="content">\{{ licenseList.address }}</div>
        </item>
        <item>
          <div slot="name">营业期限</div>
          <div slot="content">\{{ licenseList.valid_period }}</div>
        </item>
        <item>
          <div slot="name">注册号</div>
          <div slot="content">\{{ licenseList.reg_num }}</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 : {
          name: "",
          person: "",
          address: "",
          capital: "",
          reg_num: "",
          valid_period: ""
        }
      }
    },
    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_businesslicense',
        }
        hlsHttp.post(url, param).then(function (res) {
          hlsPopup.hideLoading();
          if (res.businessLicense.address) {
            vm.licenseList.address = res.businessLicense.address;
          }
          if (res.businessLicense.capital) {
            vm.licenseList.capital = res.businessLicense.capital;
          }
          if (res.businessLicense.name) {
            vm.licenseList.name = res.businessLicense.name;
          }
          if (res.businessLicense.person) {
            vm.licenseList.person = res.businessLicense.person;
          }
          if (res.businessLicense.reg_num) {
            vm.licenseList.reg_num = res.businessLicense.reg_num;
          }
          if (res.businessLicense.valid_period) {
            vm.licenseList.valid_period = res.businessLicense.valid_period;
          }
        });
      },
    }
  }
</script>

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

    }
  }
</style>
