uploadFace.vue 11 KB

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