UploadPhoto.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div>
  3. <common @asynCallBack="asynCallBack"></common>
  4. <top-header :pageTitle="pageTitle"></top-header>
  5. <div class="mui-content">
  6. <div class="mui-content-padded">
  7. <div class="mui-content-padded">
  8. <h5>请上传照片</h5>
  9. <div class="mui-h5 color999">
  10. 照片将用于人脸识别设备,请上传清晰的免冠登记照或肩部以上近照。
  11. </div>
  12. </div>
  13. <div class="mui-content-padded vongi-photo" @click="chooseImage">
  14. <div class="faceaifyy-content-region" :style="subForm.faceImageUrl?'background:none':''">
  15. <a v-if="!subForm.faceImageUrl"><span class="mui-icon iconfont icon-weibiaoti1"></span></a>
  16. <img v-if="subForm.faceImageUrl" :src="subForm.faceImageUrl" width="100%" />
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="fyy-footer">
  22. <div class="bindfyy-btn"><button type="submit" class="mui-btn mui-btn-primary" @click="submit">提交</button></div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. import * as API_Person from '@/apis/person'
  28. import Common from '$project/components/Common.vue'
  29. import Loading from '$project/components/Loading.vue'
  30. import TopHeader from '$project/components/TopHeader.vue'
  31. import {
  32. mapGetters,
  33. mapMutations
  34. } from 'vuex'
  35. import * as WxJsApi from '$project/utils/wxJsApi'
  36. export default {
  37. name: 'UploadPhoto',
  38. components: {
  39. Common,
  40. Loading,
  41. TopHeader
  42. },
  43. data() {
  44. return {
  45. pageTitle: '上传登记照',
  46. isLoading: false,
  47. subForm: {
  48. personId: this.$route.query.personId,
  49. openId: '',
  50. faceImageUrl: ''
  51. },
  52. }
  53. },
  54. created() {
  55. this.subForm.openId = this.openId;
  56. },
  57. methods: {
  58. //微信选择图片
  59. chooseImage() {
  60. WxJsApi.chooseImage().then(res => {
  61. var localData = res.localData;
  62. if (localData.indexOf('data:image') != 0) {
  63. //判断是否有这样的头部
  64. localData = 'data:image/jpeg;base64,' + localData
  65. }
  66. localData = localData.replace(/\r|\n/g, '').replace('data:image/jgp', 'data:image/jpeg')
  67. this.imgBase64 = localData;
  68. //显示裁剪图片
  69. //_this.showCropper(field);
  70. this.uploadpic();
  71. }).catch(error => {
  72. mui.toast(error);
  73. })
  74. },
  75. //上传图片
  76. uploadpic() {
  77. this.isLoading = true;
  78. WxJsApi.uploadPic(this.imgBase64).then(response => {
  79. this.isLoading = false;
  80. this.subForm.faceImageUrl = response;
  81. }).catch(error => {
  82. this.isLoading = false;
  83. mui.toast(error);
  84. })
  85. },
  86. //表单检测
  87. checkFrom() {
  88. if (!this.subForm.personId) {
  89. mui.toast('用户id未定义');
  90. return false;
  91. } else if (!this.subForm.openId) {
  92. mui.toast('openId未获取到');
  93. return false;
  94. } else if (!this.subForm.faceImageUrl) {
  95. mui.toast('请上传人脸照片');
  96. return false;
  97. } else {
  98. return true;
  99. }
  100. },
  101. //提交
  102. submit() {
  103. if (this.checkFrom()) {
  104. this.isLoading = true;
  105. API_Person.save(this.subForm).then(response => {
  106. this.isLoading = false;
  107. this.$router.push({
  108. name: 'Home',
  109. query: {}
  110. })
  111. }).catch(error => {
  112. this.isLoading = false;
  113. mui.toast(error);
  114. })
  115. }
  116. },
  117. asynCallBack() {
  118. },
  119. },
  120. mounted() {
  121. //获取微信配置
  122. WxJsApi.getWxConfig();
  123. },
  124. destroyed() {},
  125. computed: {
  126. ...mapGetters({
  127. openId: 'wx_openid',
  128. token: 'token',
  129. })
  130. }
  131. }
  132. </script>
  133. <style scoped src="$project/assets/css/xpwyfyy.css"></style>
  134. <style src="$project/assets/css/iconfont.css"></style>
  135. <style>
  136. </style>