/**
* @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">\{{ bp_info.name }}</div>
        </item>
      </list-item>
      <list-item>
        <item>
          <div slot="name">性别</div>
          <div slot="content">\{{ bp_info.gender }}</div>
        </item>
        <item>
          <div slot="name">民族</div>
          <div slot="content">\{{ bp_info.people }}</div>
        </item>
        <item>
          <div slot="name">出生日期</div>
          <div slot="content">\{{ bp_info.birthdays }}</div>
        </item>
        <item>
          <div slot="name">住址</div>
          <div slot="content">\{{ bp_info.address }}</div>
        </item>
        <item>
          <div slot="name">身份证号</div>
          <div slot="content">\{{ bp_info.idnumber }}</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 {
        bp_info: {
          name: "",
          gender: "",
          people: "",
          byear: "",
          bmonth: "",
          bday: "",
          birthdays: "",
          address: "",
          idnumber: "",
          authority: "",
          validdate: "",
          cropped_image: ""
        },
      }
    },
    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_idcard',
        }
        hlsHttp.post(url, param).then(function (res) {
          hlsPopup.hideLoading();
          if (res.name) {
            vm.bp_info.name = res.name;
          }
          if (res.gender) {
            vm.bp_info.gender = res.gender;
          }
          if (res.people) {
            vm.bp_info.people = res.people;
          }
          if (res.byear) {
            vm.bp_info.byear = res.byear;
          }
          if (res.bmonth) {
            vm.bp_info.bmonth = res.bmonth;
          }
          if (res.bday) {
            vm.bp_info.bday = res.bday;
          }
          if (res.address) {
            vm.bp_info.address = res.address;
          }
          if (res.idnumber) {
            vm.bp_info.idnumber = res.idnumber;
          }
          if (res.authority) {
            vm.bp_info.authority = res.authority;
          }
          if (res.validdate) {
            vm.bp_info.validdate = res.validdate;
          }
          if (res.cropped_image) {
            vm.bp_info.cropped_image = res.cropped_image;
          }
          if (res.byear && res.bmonth && res.bday) {
            vm.bp_info.birthdays = res.byear + "-" + res.bmonth + "-" + res.bday;
          }
        })
      },
    }
  }
</script>

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

    }
  }
</style>
