uploadFace.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <view>
  3. <view class="" v-if="vuex_appletType==1">
  4. <view>
  5. <view class="cu-list menu" @click="locationShow=true">
  6. <view class="cu-item" >
  7. <view class="content">
  8. <text >我的房屋</text>
  9. </view>
  10. <view class="action">
  11. <text >{{selectLabel?selectLabel:list[0].roomName}}</text>
  12. <text class="cuIcon-right padding-left-10"></text>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="upload_container">
  18. <view>
  19. <view @click="show=true" style="margin: 30rpx 0 10rpx 0;display: flex;align-items: center;flex-direction: column;">
  20. <upload-img
  21. :width="$isEmpty(face_url)?300:560"
  22. :height="$isEmpty(face_url)?300:420"
  23. :currentImage="face_url"
  24. bgsrc="http://139.9.103.171:1888/img/image/camera1.png"
  25. >
  26. </upload-img>
  27. <view class="" style="color: #59a5f0;">
  28. <text class="cuIcon-camera padding-right-sm" style="font-size: 30rpx;"></text>
  29. <text v-if="$isEmpty(face_url)">点击上传人脸</text>
  30. <text style="margin-top: 40rpx;display: inline-block;" v-else>点击重新上传</text>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="category">
  36. <view v-for="(item, index) in iconArray" :key="index" class="category_item">
  37. <view class="category_item_wrap" @tap="top" :data-index="item.index">
  38. <view class="icon_wrap">
  39. <image :src="item.iconUrl" class="index_icon"></image>
  40. </view>
  41. <view class="category_item_text">
  42. <text>{{item.iconText}}</text>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <canvas canvas-id="photo_canvas" :style="'width:' + canvasWidth + 'px;height:' + canvasHeight + 'px;position: absolute;left:-300px;top:-300px;'"></canvas>
  48. <view @tap="uploadFace" class=" footer-fixed" >
  49. <view class="cu-btn flex text-lg bg-red-btn" style="padding: 46rpx 0;">
  50. 提交人脸信息
  51. </view>
  52. </view>
  53. <u-select z-index="9999999" mode="single-column" value-name="id" label-name="roomName" v-model="locationShow" :list="list" @confirm="roomChange"></u-select>
  54. <u-action-sheet @click="photoChecked" z-index="999999" :list="actionList" v-model="show"></u-action-sheet>
  55. </view>
  56. <view v-else >
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import uploadImg from '@/comps/uploadimg/uploadImg.vue'
  62. //获取app实例
  63. var app = getApp();
  64. export default {
  65. components:{
  66. uploadImg
  67. },
  68. data() {
  69. return {
  70. appletType:0,
  71. //显示模态框
  72. locationShow:false,
  73. selectLabel:'',
  74. //上传人脸
  75. actionList: [{
  76. text: '相册上传',
  77. }, {
  78. text: '拍照上传'
  79. }],
  80. show: false,
  81. face_url: null,
  82. //人脸图片地址
  83. face_image: null,
  84. //人脸图片的base64字符串
  85. list: null,
  86. //住户信息列表
  87. index: null,
  88. //当前显示住户信息下标
  89. iconArray: [{
  90. "iconUrl": "http://139.9.103.171:1888/img/image/zd.png",
  91. "iconText": '不要遮挡',
  92. "index": 1
  93. }, {
  94. "iconUrl": "http://139.9.103.171:1888/img/image/mj.png",
  95. "iconText": '不戴墨镜',
  96. "index": 2
  97. }, {
  98. "iconUrl": "http://139.9.103.171:1888/img/image/zl.png",
  99. "iconText": '不能仰头俯拍',
  100. "index": 3
  101. }, {
  102. "iconUrl": "http://139.9.103.171:1888/img/image/cz.png",
  103. "iconText": '光线充足',
  104. "index": 4
  105. }, {
  106. "iconUrl": "http://139.9.103.171:1888/img/image/bg.png",
  107. "iconText": '浅色背景',
  108. "index": 5
  109. }, {
  110. "iconUrl": "http://139.9.103.171:1888/img/image/sh.png",
  111. "iconText": '物业审核生效',
  112. "index": 6
  113. }]
  114. };
  115. },
  116. onShow() {
  117. if (this.vuex_appletType==0) {
  118. uni.setNavigationBarTitle({
  119. title:"功能待开发"
  120. })
  121. }else{
  122. uni.setNavigationBarTitle({
  123. title:"上传人脸"
  124. })
  125. }
  126. //获取当前页面的对象
  127. let currPage=this.$util.getPageCtx()
  128. if(!this.$isEmpty(currPage.data.image)){
  129. this.handelImg(currPage.data.image)
  130. }
  131. },
  132. components: {},
  133. props: {},
  134. /**
  135. * 生命周期函数--监听页面加载
  136. */
  137. onLoad: function (options) {
  138. this.getFaceImg();
  139. },
  140. onShow() {
  141. this.getAppletType()
  142. },
  143. methods: {
  144. //获取小程序是否已经审核通过,通过就开放人脸
  145. getAppletType: function () {
  146. var that = this;
  147. uni.login({
  148. success: res => {
  149. let params = {};
  150. params['js_code'] = res.code;
  151. params['name'] = 'community';
  152. let operation = 'miniprogram/getOpenid'; //发起请求
  153. app.globalData.postRequest(params, operation, function (res) {
  154. //获取成功
  155. if (res.data.result_code == 1) {
  156. uni.setStorageSync("appletType", res.data.appletType);
  157. that.appletType=res.data.appletType
  158. that.$u.vuex('vuex_appletType',res.data.appletType)
  159. }
  160. });
  161. }
  162. });
  163. },
  164. //点击模态框选项触发
  165. photoChecked(index){
  166. if (index==0) {
  167. //图片上传
  168. this.chooseImage()
  169. } else if(index==1){
  170. //拍照上传
  171. uni.navigateTo({
  172. url:"../my-camera/my-camera"
  173. })
  174. }
  175. },
  176. //选择房间
  177. roomChange: function (e) {
  178. // 选中的房屋 id
  179. let id=e[0].value
  180. //选中的房屋名字
  181. this.selectLabel=e[0].label
  182. //选中的房屋列表的下标
  183. let index= this.list.findIndex(value => value.id===id)
  184. let list = this.list;
  185. // let index = e.detail.value;
  186. let url = list[index].imageUri;
  187. console.log(url);
  188. this.setData({
  189. index: index,
  190. face_url: list[index].imageUri
  191. });
  192. },
  193. //获取住户人脸
  194. getFaceImg: function () {
  195. let that = this;
  196. let params = {};
  197. params['member_id'] = app.globalData.member.id;
  198. let operation = 'user/getMyUserByMemberId';
  199. app.globalData.postRequest(params, operation, function (res) {
  200. console.info("查询结果:" + res.data.result_msg); //获取成功
  201. if (res.data.result_code == 1) {
  202. // let list = res.data.list;
  203. console.log(res.data.list);
  204. let list = [];
  205. if (uni.getStorageSync('plotName')) {
  206. res.data.list.map(item => {
  207. if (item.residentialName == uni.getStorageSync('plotName')) {
  208. list.push(item);
  209. }
  210. });
  211. } else {
  212. list = res.data.list;
  213. }
  214. that.setData({
  215. face_url: list[0].imageUri,
  216. list: list,
  217. index: 0
  218. });
  219. }
  220. });
  221. },
  222. //点击上传图片事件
  223. chooseImage: function () {
  224. var that = this;
  225. uni.chooseImage({
  226. count: 1,
  227. //最多可以选择的图片张数,默认9
  228. sourceType: ['album', 'camera'],
  229. sizeType: ['compressed'],
  230. //可选择原图或压缩后的图片
  231. success: res => {
  232. that.handelImg(res.tempFilePaths[0])
  233. }
  234. });
  235. },
  236. //处理照片,拍照上传和相册上传的共同处理方法
  237. handelImg(imgUrl){
  238. var that = this;
  239. that.setData({
  240. //图片回显
  241. face_url: imgUrl
  242. });
  243. uni.getFileSystemManager().readFile({
  244. filePath: imgUrl,
  245. //选择图片返回的相对路径
  246. encoding: 'base64',
  247. //编码格式
  248. success: res => {
  249. //成功的回调
  250. console.log(res);
  251. that.setData({
  252. //图片的base64字符串
  253. face_image: 'data:image/jpeg;base64,' + res.data
  254. });
  255. }
  256. });
  257. },
  258. //上传用户faceImg
  259. uploadFace: function () {
  260. let that = this;
  261. let params = {};
  262. let index = that.index; //let index = 0;
  263. let user = that.list[index];
  264. let user_id = user.id;
  265. params['user_id'] = user_id;
  266. let tel = user.tel;
  267. params['tel'] = tel;
  268. let type = user.type;
  269. params['type'] = type;
  270. let id_card = user.idCard;
  271. params['id_card'] = id_card;
  272. let sex = user.sex; //性别
  273. params['sex'] = sex;
  274. let nationality = user.nationality;
  275. params['nationality'] = nationality;
  276. let face_image = this.face_image;
  277. if (face_image) {
  278. params['face_image_base64'] = that.face_image;
  279. }else{
  280. if(!this.$isEmpty(this.face_url)){
  281. app.globalData.autoFailHint("请重新上传人脸图片");
  282. return;
  283. }else{
  284. app.globalData.autoFailHint("请上传人脸图片");
  285. return;
  286. }
  287. }
  288. params['member_id'] = app.globalData.member.id; //申请来源0-小程序添加 1-后台添加 2-后台导入 3-app添加
  289. params['create_type'] = '0';
  290. let operation = 'user/editUser';
  291. app.globalData.postRequest(params, operation, function (res) {
  292. if (res.data.result_code == 1) {
  293. app.globalData.oneFailHint(res.data.result_msg, function () {
  294. uni.redirectTo({
  295. url: '/pages/uploadFace/uploadFace'
  296. });
  297. });
  298. } else {
  299. app.globalData.oneFailHint(res.data.result_msg);
  300. }
  301. });
  302. }
  303. }
  304. };
  305. </script>
  306. <style lang="scss">
  307. /* pages/ uploadFace/uploadFace.wxss */
  308. page{
  309. background: #fff;
  310. }
  311. .upload_container {
  312. text-align: center;
  313. color: #333;
  314. background: #fff;
  315. border-radius: 10rpx;
  316. }
  317. .upload_bg {
  318. position: relative;
  319. }
  320. .upload_bg .upload_btn {
  321. width: 120rpx;
  322. height: 120rpx;
  323. position: absolute;
  324. left: 50%;
  325. top: 40%;
  326. margin-left: -65rpx;
  327. margin-top: -60rpx;
  328. }
  329. .upload_bg .upload_btn image {
  330. width: 100%;
  331. height: 100%;
  332. }
  333. .upload_text {
  334. position: absolute;
  335. top: 55%;
  336. width: 100%;
  337. color: $base-btn-color;
  338. }
  339. .img_content {
  340. margin-top: 20rpx;
  341. position: relative;
  342. text-align: center;
  343. }
  344. .img_content .upload_bgImg {
  345. width: 560rpx;
  346. height: 420rpx;
  347. max-height: 1;
  348. display: inline-block;
  349. border-radius: 20rpx;
  350. }
  351. .reUpload {
  352. display: flex;
  353. justify-content: flex-end;
  354. align-items: center;
  355. height: 60rpx;
  356. line-height: 60rpx;
  357. color: #333;
  358. padding-right: 40rpx;
  359. }
  360. .img_content .img_icon {
  361. width: 40rpx;
  362. height: 40rpx;
  363. vertical-align: text-top;
  364. margin-right: 6rpx;
  365. border-radius: 20rpx;
  366. }
  367. .tips{
  368. height: 80rpx;
  369. line-height: 80rpx;
  370. padding-left:30rpx;
  371. background-color: #f5f5f5;
  372. color:#777;
  373. }
  374. .category {
  375. padding:20px 20rpx 0;
  376. overflow: auto;
  377. background-color: #FFF;
  378. text-align:center;
  379. }
  380. .category_item {
  381. width: 33.3%;
  382. float: left;
  383. margin-bottom: 40rpx;
  384. }
  385. .icon_wrap {
  386. width: 120rpx;
  387. margin: 0 auto;
  388. margin-bottom: 5px;
  389. }
  390. .index_icon {
  391. width: 60rpx;
  392. height: 60rpx;
  393. }
  394. .category_item_text {
  395. text-align: center;
  396. font-size: 24rpx;
  397. color: #999;
  398. }
  399. .form_group {
  400. display: flex;
  401. flex-direction: row;
  402. justify-content: space-between;
  403. margin: 20rpx 20rpx;
  404. line-height: 100rpx;
  405. position: relative;
  406. font-size: 26rpx;
  407. border-bottom: 2rpx solid #ddd;
  408. }
  409. .my-item .iconfont.arrow {
  410. position: absolute;
  411. right: 0;
  412. top: 50%;
  413. transform: translate(0, -50%);
  414. font-size: 32rpx;
  415. vertical-align: top;
  416. }
  417. .my-item {
  418. width: 100%;
  419. position: relative;
  420. background: #fff;
  421. font-size: 28rpx;
  422. box-sizing: border-box;
  423. }
  424. .my-item .status {
  425. position: absolute;
  426. right: 35rpx;
  427. top: 50%;
  428. transform: translate(0, -50%);
  429. font-size: 28rpx;
  430. }
  431. </style>