index.vue 8.0 KB

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