index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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" />
  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. let that = this;
  135. uni.chooseImage({
  136. count: 1,
  137. success: (chooseImageRes) => {
  138. const tempFilePaths = chooseImageRes.tempFilePaths;
  139. uni.uploadFile({
  140. url: that.$baseUrl + '/resource/oss/upload',
  141. filePath: tempFilePaths[0],
  142. name: 'file',
  143. header: {
  144. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  145. },
  146. success: (uploadFileRes) => {
  147. console.log("uploadFileRes:"+uploadFileRes)
  148. let res = JSON.parse(uploadFileRes.data)
  149. that.ossId = res.data.ossId;
  150. that.facePhotoUrl = res.data.url.replace("http", "https");
  151. that.reqParm.facePath = res.data.ossId;
  152. }
  153. });
  154. }
  155. });
  156. },
  157. uploadCropImg(e){
  158. uni.compressImage({
  159. src: e,
  160. success: res => {
  161. uni.uploadFile({
  162. url: this.$baseUrl + '/resource/oss/upload',
  163. filePath:res.tempFilePath,
  164. name: 'file',
  165. header: {
  166. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  167. },
  168. success: (uploadFileRes) => {
  169. let res = JSON.parse(uploadFileRes.data)
  170. console.log(res,'成功回调')
  171. if(res.code !== 200){
  172. uni.showToast({
  173. icon: 'none',
  174. duration: 3000,
  175. title: res.msg || '系统繁忙,请重试!'
  176. });
  177. }
  178. this.ossId = res.data.ossId;
  179. this.facePhotoUrl = res.data.url.replace("http", "https");
  180. this.reqParm.facePath = res.data.ossId;
  181. }
  182. });
  183. }
  184. })
  185. }
  186. }
  187. }
  188. </script>
  189. <style scoped lang="scss">
  190. .container{
  191. padding: 12px;
  192. background: #F6F6F6;
  193. }
  194. .h-title{
  195. height: 22px;
  196. font-size: 14px;
  197. font-family: PingFangSC-Regular, PingFang SC;
  198. font-weight: 400;
  199. color: #333333;
  200. line-height: 22px;
  201. }
  202. // 弹窗
  203. .h-popo-content{
  204. height: 170px;
  205. padding: 12px;
  206. width: 300px;
  207. text-align: center;
  208. font-size: 14px;
  209. font-family: PingFangSC-Semibold, PingFang SC;
  210. .h-img{
  211. display: flex;
  212. justify-content: center;
  213. }
  214. .h-text{
  215. margin-top: 12px;
  216. font-weight: 400;
  217. color: #666666;
  218. }
  219. .text{
  220. margin-top: 6px;
  221. font-weight: 400;
  222. color: #666666;
  223. }
  224. .h-btn-wrap{
  225. display: flex;
  226. justify-content: space-between;
  227. color: #333333;
  228. text-align: center;
  229. margin-top: 20px;
  230. .h-left-btn{
  231. height: 32px;
  232. line-height: 30px;
  233. background: #EEEEEE;
  234. width: 100px;
  235. text-align: center;
  236. border-radius: 16px;
  237. margin: 0 auto;
  238. }
  239. .h-right-btn{
  240. height: 32px;
  241. line-height: 30px;
  242. background: #FFE05C;
  243. width: 100px;
  244. border-radius: 16px;
  245. margin: 0 auto;
  246. }
  247. }
  248. }
  249. .h-upload-wrap{
  250. .h-item-row{
  251. width: 100%;
  252. display: flex;
  253. align-items: center;
  254. justify-content: center;
  255. margin-top: 12px;
  256. font-family: PingFangSC-Regular, PingFang SC;
  257. .h-item{
  258. background: #fff;
  259. width: 48%;
  260. text-align: center;
  261. height: 164px;
  262. display: flex;
  263. align-items: center;
  264. justify-content: center;
  265. border-radius: 6px;
  266. .h-content{
  267. image{
  268. height: 48px;
  269. width: 48px;
  270. }
  271. .h-text{
  272. margin-top: 10px;
  273. font-size: 12px;
  274. font-weight: 400;
  275. color: #999999;
  276. line-height: 20px;
  277. }
  278. }
  279. .h-upload-img{
  280. width: 100%;
  281. height: 164px;
  282. padding: 4px;
  283. .imgBox{
  284. width: 164px;
  285. height: 164px;
  286. }
  287. }
  288. }
  289. }
  290. }
  291. .uploadBox {
  292. width: 100%;
  293. margin-top: 30px;
  294. height: 42px;
  295. background: #FFE05C;
  296. border-radius: 27px;
  297. color: #333333;
  298. line-height: 42px;
  299. text-align: center;
  300. }
  301. .btnTitle{
  302. font-size: 24rpx;
  303. font-weight: 400;
  304. color: #333333;
  305. line-height: 50px;
  306. padding-left: 32rpx;
  307. }
  308. @import '/common/css/common.css';
  309. </style>