uploadFace.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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].address}}</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"
  20. style="margin: 30rpx 0 10rpx 0;display: flex;align-items: center;flex-direction: column;">
  21. <upload-img :width="$isEmpty(face_url)?300:560" :height="$isEmpty(face_url)?300:420"
  22. :currentImage="face_url"
  23. bgsrc="https://szsq.nxzhsq.cn/community/miniofile/image/camera1.png">
  24. </upload-img>
  25. <view class="" style="color: #59a5f0;">
  26. <text class="cuIcon-camera padding-right-sm" style="font-size: 30rpx;"></text>
  27. <text v-if="$isEmpty(face_url)">点击上传人脸</text>
  28. <text style="margin-top: 40rpx;display: inline-block;" v-else>点击重新上传</text>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="category">
  34. <view v-for="(item, index) in iconArray" :key="index" class="category_item">
  35. <view class="category_item_wrap" :data-index="item.index">
  36. <view class="icon_wrap">
  37. <image :src="item.iconUrl" class="index_icon"></image>
  38. </view>
  39. <view class="category_item_text">
  40. <text>{{item.iconText}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <canvas canvas-id="photo_canvas"
  46. :style="'width:' + canvasWidth + 'px;height:' + canvasHeight + 'px;position: absolute;left:-300px;top:-300px;'"></canvas>
  47. <view @tap="uploadFace" class=" footer-fixed">
  48. <view class="cu-btn flex text-lg bg-red-btn" style="padding: 46rpx 0;">
  49. 提交人脸信息
  50. </view>
  51. </view>
  52. <u-select z-index="9999999" mode="single-column" value-name="id" label-name="address"
  53. 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": "https://szsq.nxzhsq.cn/community/miniofile/image/zd.png",
  91. "iconText": '不要遮挡',
  92. "index": 1
  93. }, {
  94. "iconUrl": "https://szsq.nxzhsq.cn/community/miniofile/image/mj.png",
  95. "iconText": '不戴墨镜',
  96. "index": 2
  97. }, {
  98. "iconUrl": "https://szsq.nxzhsq.cn/community/miniofile/image/zl.png",
  99. "iconText": '不能仰头俯拍',
  100. "index": 3
  101. }, {
  102. "iconUrl": "https://szsq.nxzhsq.cn/community/miniofile/image/cz.png",
  103. "iconText": '光线充足',
  104. "index": 4
  105. }, {
  106. "iconUrl": "https://szsq.nxzhsq.cn/community/miniofile/image/bg.png",
  107. "iconText": '浅色背景',
  108. "index": 5
  109. }, {
  110. "iconUrl": "https://szsq.nxzhsq.cn/community/miniofile/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. uni.login({
  147. success: res => {
  148. let params = {};
  149. params['js_code'] = res.code;
  150. params['name'] = 'community';
  151. this.$http.getOpenid(params).then(res => {
  152. //获取成功
  153. if (res.data.result_code == 1) {
  154. uni.setStorageSync("appletType", res.data.appletType);
  155. this.appletType = res.data.appletType
  156. this.$u.vuex('vuex_appletType', res.data.appletType)
  157. }
  158. })
  159. }
  160. });
  161. },
  162. //点击模态框选项触发
  163. photoChecked(index) {
  164. if (index == 0) {
  165. //图片上传
  166. this.chooseImage()
  167. } else if (index == 1) {
  168. //拍照上传
  169. uni.navigateTo({
  170. url: "../my-camera/my-camera"
  171. })
  172. }
  173. },
  174. //选择房间
  175. roomChange: function(e) {
  176. // 选中的房屋 id
  177. let id = e[0].value
  178. //选中的房屋名字
  179. this.selectLabel = e[0].label
  180. //选中的房屋列表的下标
  181. this.index = this.list.findIndex(value => value.id === id)
  182. this.face_url=this.list[this.index].faceUrl
  183. },
  184. //获取住户人脸
  185. getFaceImg: function() {
  186. let params = {
  187. memberId: app.globalData.member.id,
  188. residentialId: uni.getStorageSync("residentialId")
  189. };
  190. this.$http.getHouseUserCondition(params).then(res => {
  191. if (this.$isNotEmpty(res.data.data)) {
  192. this.list = res.data.data;
  193. this.face_url = this.list[0].faceUrl
  194. this.index = 0
  195. }
  196. })
  197. },
  198. //点击上传图片事件
  199. chooseImage() {
  200. uni.chooseImage({
  201. count: 1,
  202. //最多可以选择的图片张数,默认9
  203. sourceType: ['album', 'camera'],
  204. sizeType: ['compressed'],
  205. //可选择原图或压缩后的图片
  206. success: res => {
  207. this.handelImg(res.tempFilePaths[0])
  208. }
  209. });
  210. },
  211. //处理照片,拍照上传和相册上传的共同处理方法
  212. handelImg(imgUrl) {
  213. this.$http.uploadFile(imgUrl).then(res => {
  214. this.face_url = res.data.data.link
  215. console.log(this.face_url);
  216. })
  217. },
  218. //上传用户faceImg
  219. uploadFace: function() {
  220. let data= this.list[this.index]
  221. data.faceUrl=this.face_url
  222. if (this.$isEmpty(this.face_url)) {
  223. this.$u.toast('请上传人脸')
  224. return
  225. }
  226. this.$http.modifyFace(data).then(res => {
  227. if (res.data.success) {
  228. this.$u.toast('修改成功')
  229. } else {
  230. this.$u.toast('修改失败')
  231. }
  232. });
  233. }
  234. }
  235. };
  236. </script>
  237. <style lang="scss">
  238. /* pages/ uploadFace/uploadFace.wxss */
  239. page {
  240. background: #fff;
  241. }
  242. .upload_container {
  243. text-align: center;
  244. color: #333;
  245. background: #fff;
  246. border-radius: 10rpx;
  247. }
  248. .upload_bg {
  249. position: relative;
  250. }
  251. .upload_bg .upload_btn {
  252. width: 120rpx;
  253. height: 120rpx;
  254. position: absolute;
  255. left: 50%;
  256. top: 40%;
  257. margin-left: -65rpx;
  258. margin-top: -60rpx;
  259. }
  260. .upload_bg .upload_btn image {
  261. width: 100%;
  262. height: 100%;
  263. }
  264. .upload_text {
  265. position: absolute;
  266. top: 55%;
  267. width: 100%;
  268. color: $base-btn-color;
  269. }
  270. .img_content {
  271. margin-top: 20rpx;
  272. position: relative;
  273. text-align: center;
  274. }
  275. .img_content .upload_bgImg {
  276. width: 560rpx;
  277. height: 420rpx;
  278. max-height: 1;
  279. display: inline-block;
  280. border-radius: 20rpx;
  281. }
  282. .reUpload {
  283. display: flex;
  284. justify-content: flex-end;
  285. align-items: center;
  286. height: 60rpx;
  287. line-height: 60rpx;
  288. color: #333;
  289. padding-right: 40rpx;
  290. }
  291. .img_content .img_icon {
  292. width: 40rpx;
  293. height: 40rpx;
  294. vertical-align: text-top;
  295. margin-right: 6rpx;
  296. border-radius: 20rpx;
  297. }
  298. .tips {
  299. height: 80rpx;
  300. line-height: 80rpx;
  301. padding-left: 30rpx;
  302. background-color: #f5f5f5;
  303. color: #777;
  304. }
  305. .category {
  306. padding: 20px 20rpx 0;
  307. overflow: auto;
  308. background-color: #FFF;
  309. text-align: center;
  310. }
  311. .category_item {
  312. width: 33.3%;
  313. float: left;
  314. margin-bottom: 40rpx;
  315. }
  316. .icon_wrap {
  317. width: 120rpx;
  318. margin: 0 auto;
  319. margin-bottom: 5px;
  320. }
  321. .index_icon {
  322. width: 60rpx;
  323. height: 60rpx;
  324. }
  325. .category_item_text {
  326. text-align: center;
  327. font-size: 24rpx;
  328. color: #999;
  329. }
  330. .form_group {
  331. display: flex;
  332. flex-direction: row;
  333. justify-content: space-between;
  334. margin: 20rpx 20rpx;
  335. line-height: 100rpx;
  336. position: relative;
  337. font-size: 26rpx;
  338. border-bottom: 2rpx solid #ddd;
  339. }
  340. .my-item .iconfont.arrow {
  341. position: absolute;
  342. right: 0;
  343. top: 50%;
  344. transform: translate(0, -50%);
  345. font-size: 32rpx;
  346. vertical-align: top;
  347. }
  348. .my-item {
  349. width: 100%;
  350. position: relative;
  351. background: #fff;
  352. font-size: 28rpx;
  353. box-sizing: border-box;
  354. }
  355. .my-item .status {
  356. position: absolute;
  357. right: 35rpx;
  358. top: 50%;
  359. transform: translate(0, -50%);
  360. font-size: 28rpx;
  361. }
  362. </style>