index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <view class="container" :style="{'height':'100vh'}">
  3. <!-- 提示内容 -->
  4. <!-- <view class="h-title">-->
  5. <!-- <text>*请选择1张服务对象头像</text>-->
  6. <!-- </view>-->
  7. <view class="h-upload-wrap">
  8. <view class="h-item-row">
  9. <view @click="choose" class="h-item">
  10. <view v-if="!facePhotoUrl" class="h-content">
  11. <image src="/static/me/u01.png" mode="aspectFill"></image>
  12. <view class="h-text">
  13. <!-- <text>添加头像</text>-->
  14. </view>
  15. </view>
  16. <view v-else class="h-upload-img">
  17. <image mode="aspectFit" class="imgBox" :src="facePhotoUrl"></image>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 保存备案信息 -->
  23. <view class="uploadBox" @click="verifyFace()">
  24. <text>下一步</text>
  25. </view>
  26. <view class="btnTitle flex-row">
  27. <u-icon v-if="selectIcon" name="checkmark-circle-fill" color="#FFE52C" size="18" @click="selectChange"></u-icon>
  28. <u-icon v-else name="/static/order/ud9.png" color="#FFE52C" size="18" @click="selectChange"></u-icon>
  29. <text :style="{'margin-left':'10rpx'}">请阅读并同意</text>
  30. <text :style="{'color':'red'}" @click="goTermsOfService">《服务对象协议》</text>
  31. </view>
  32. <cropper selWidth="660rpx" selHeight="660rpx" ref="cropper" quality="0.5" @uploadImg="uploadCropImg" @upload="facePhotoUrl" avatarStyle="width:100vw;height:100vw;"/>
  33. </view>
  34. </template>
  35. <script>
  36. import cropper from '@/components/lxiaoxiao-cropper/lxiaoxiao-cropper.vue';
  37. export default {
  38. components: {
  39. cropper
  40. },
  41. data() {
  42. return {
  43. requestStatus:false,
  44. selectIcon:false,
  45. ossId:'',
  46. facePhotoUrl:'',
  47. height:'',
  48. reqParm: {
  49. auth: true,
  50. facePath: '',
  51. businessId: ''
  52. },
  53. userInfo: {},
  54. }
  55. },
  56. onReady() {
  57. },
  58. onLoad(option) {
  59. },
  60. methods: {
  61. //上传返回图片
  62. myUpload(rsp) {
  63. const self = this;
  64. self.imgurl = rsp.path; //更新头像方式一
  65. // rsp.avatar.imgSrc = rsp.path; //更新头像方式二
  66. },
  67. choose() {
  68. // 调用实例的chooseImg方法,拉起图片选择界面,待图片选择完毕后直接进入图片截取界面
  69. this.$refs.cropper.fSelect();
  70. },
  71. goTermsOfService(){
  72. uni.navigateTo({
  73. url:'/myPages/TermsOfService/index?name='+'服务对象协议'+'&type=' + 6
  74. })
  75. },
  76. selectChange(){
  77. this.selectIcon = !this.selectIcon
  78. },
  79. // 连接已上传的图片地址
  80. verifyImgUpload(){
  81. if(!this.ossId){
  82. uni.showToast({
  83. title: "请上传人脸照片"
  84. })
  85. return false;
  86. }
  87. return true;
  88. },
  89. // 验证人象
  90. verifyFace(){
  91. let that = this;
  92. if(!this.selectIcon){
  93. uni.$u.toast('请阅读并同意《服务对象协议》')
  94. return;
  95. }
  96. // 验证图片是否全上传
  97. if(!that.verifyImgUpload()){
  98. return;
  99. }
  100. uni.showLoading({
  101. title: '人脸识别中'
  102. })
  103. if(this.requestStatus){
  104. return;
  105. }
  106. this.requestStatus=true
  107. this.$api.verifyFace(that.reqParm).then((res)=>{
  108. this.requestStatus=false
  109. uni.hideLoading();
  110. if(res.data.data.code == '500'){ //人脸不存在
  111. let serviceObject = {}
  112. serviceObject.facePhoto= this.ossId
  113. serviceObject.facePhotoUrl=this.facePhotoUrl
  114. console.log(JSON.stringify(serviceObject))
  115. uni.redirectTo({
  116. url: '/myPages/serviceObjectAllInfo/index?data='+ JSON.stringify(serviceObject),
  117. })
  118. } else { // 人脸存在
  119. let serviceObject = res.data.data
  120. serviceObject.opType = "1";
  121. serviceObject.facePhotoUrl = that.facePhotoUrl;
  122. serviceObject.facePhoto = that.reqParm.facePath;
  123. uni.redirectTo({
  124. url: '/myPages/serviceObjectInfo/index?data=' + JSON.stringify(serviceObject),
  125. })
  126. }
  127. }).catch((err) =>{
  128. this.requestStatus=false
  129. uni.$u.toast(err.data.msg||'识别失败,请重新上传照片')
  130. });
  131. },
  132. //头像上传
  133. uploadImg() {
  134. console.log(1111111111111111111111)
  135. let that = this;
  136. uni.chooseImage({
  137. count: 1,
  138. success: (chooseImageRes) => {
  139. const tempFilePaths = chooseImageRes.tempFilePaths;
  140. uni.uploadFile({
  141. url: that.$baseUrl + '/resource/oss/upload',
  142. filePath: tempFilePaths[0],
  143. name: 'file',
  144. header: {
  145. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  146. },
  147. success: (uploadFileRes) => {
  148. console.log("uploadFileRes:"+uploadFileRes)
  149. let res = JSON.parse(uploadFileRes.data)
  150. that.ossId = res.data.ossId;
  151. that.facePhotoUrl = res.data.url.replace("http", "https");
  152. that.reqParm.facePath = res.data.ossId;
  153. }
  154. });
  155. }
  156. });
  157. },
  158. uploadCropImg(e){
  159. uni.compressImage({
  160. src: e,
  161. success: res => {
  162. uni.uploadFile({
  163. url: this.$baseUrl + '/resource/oss/upload',
  164. filePath:res.tempFilePath,
  165. name: 'file',
  166. header: {
  167. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  168. },
  169. success: (uploadFileRes) => {
  170. console.log("uploadFileRes:"+uploadFileRes)
  171. let res = JSON.parse(uploadFileRes.data)
  172. this.ossId = res.data.ossId;
  173. this.facePhotoUrl = res.data.url.replace("http", "https");
  174. this.reqParm.facePath = res.data.ossId;
  175. }
  176. });
  177. }
  178. })
  179. }
  180. }
  181. }
  182. </script>
  183. <style scoped lang="scss">
  184. .container{
  185. padding: 12px;
  186. background: #F6F6F6;
  187. }
  188. .h-title{
  189. height: 22px;
  190. font-size: 14px;
  191. font-family: PingFangSC-Regular, PingFang SC;
  192. font-weight: 400;
  193. color: #333333;
  194. line-height: 22px;
  195. }
  196. // 弹窗
  197. .h-popo-content{
  198. height: 170px;
  199. padding: 12px;
  200. width: 300px;
  201. text-align: center;
  202. font-size: 14px;
  203. font-family: PingFangSC-Semibold, PingFang SC;
  204. .h-img{
  205. display: flex;
  206. justify-content: center;
  207. }
  208. .h-text{
  209. margin-top: 12px;
  210. font-weight: 400;
  211. color: #666666;
  212. }
  213. .text{
  214. margin-top: 6px;
  215. font-weight: 400;
  216. color: #666666;
  217. }
  218. .h-btn-wrap{
  219. display: flex;
  220. justify-content: space-between;
  221. color: #333333;
  222. text-align: center;
  223. margin-top: 20px;
  224. .h-left-btn{
  225. height: 32px;
  226. line-height: 30px;
  227. background: #EEEEEE;
  228. width: 100px;
  229. text-align: center;
  230. border-radius: 16px;
  231. margin: 0 auto;
  232. }
  233. .h-right-btn{
  234. height: 32px;
  235. line-height: 30px;
  236. background: #FFE05C;
  237. width: 100px;
  238. border-radius: 16px;
  239. margin: 0 auto;
  240. }
  241. }
  242. }
  243. .h-upload-wrap{
  244. .h-item-row{
  245. width: 100%;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. margin-top: 12px;
  250. font-family: PingFangSC-Regular, PingFang SC;
  251. .h-item{
  252. background: #fff;
  253. width: 48%;
  254. text-align: center;
  255. height: 164px;
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. border-radius: 6px;
  260. .h-content{
  261. image{
  262. height: 48px;
  263. width: 48px;
  264. }
  265. .h-text{
  266. margin-top: 10px;
  267. font-size: 12px;
  268. font-weight: 400;
  269. color: #999999;
  270. line-height: 20px;
  271. }
  272. }
  273. .h-upload-img{
  274. width: 100%;
  275. height: 164px;
  276. padding: 4px;
  277. .imgBox{
  278. width: 164px;
  279. height: 164px;
  280. }
  281. }
  282. }
  283. }
  284. }
  285. .uploadBox {
  286. width: 100%;
  287. margin-top: 30px;
  288. height: 42px;
  289. background: #FFE05C;
  290. border-radius: 27px;
  291. color: #333333;
  292. line-height: 42px;
  293. text-align: center;
  294. }
  295. .btnTitle{
  296. font-size: 24rpx;
  297. font-weight: 400;
  298. color: #333333;
  299. line-height: 50px;
  300. padding-left: 32rpx;
  301. }
  302. @import '/common/css/common.css';
  303. </style>