love.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. const app = require('../../utils/util.js');
  2. var util = require('../../utils/md5.js')
  3. import WxValidate from '../../utils/WxValidate';
  4. var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
  5. Page({
  6. data: {
  7. time: '',
  8. lng: '', // 经度
  9. lat: '', // 纬度
  10. visitLocation: '',
  11. info: '', //老人锕
  12. imgPath: [{}, {}],
  13. isTrue: true,
  14. index: 0,
  15. visitPhoto: '',
  16. infoId: '',
  17. },
  18. // 老人点击后去跳转采集页面
  19. oldClick(e) {
  20. let fid = e.currentTarget.dataset.infos.fid;
  21. let name = e.currentTarget.dataset.infos.name;
  22. const app = getApp()
  23. app.globalData.id = fid
  24. app.globalData.name = name
  25. wx.switchTab({
  26. url: `/pages/collectInfo/collectInfo`,
  27. success: function (e) {
  28. var page = getCurrentPages().pop();
  29. if (page == undefined || page == null) return;
  30. page.onLoad();
  31. }
  32. })
  33. },
  34. // 获得当前时间
  35. time() {
  36. var timestamp = Date.parse(new Date());
  37. var date = new Date(timestamp);
  38. //获取年份  
  39. var Y = date.getFullYear();
  40. //获取月份  
  41. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  42. //获取当日日期 
  43. var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  44. this.setData({
  45. time: Y + '-' + M + '-' + D
  46. })
  47. },
  48. // 选择照片上传并后台接口
  49. zhaopian() {
  50. wx.chooseImage({
  51. count: 1,
  52. sizeType: ['compressed'],
  53. sourceType: ['camera'],
  54. success: (res) => {
  55. var tempFilePaths = res.tempFilePaths
  56. wx.uploadFile({
  57. url: app.globalData.publicUrl + '/sys/user/upload',
  58. filePath: tempFilePaths[0],
  59. name: 'uploadFile',
  60. formData: {
  61. "user": "test",
  62. },
  63. header: {
  64. appletsId: wx.getStorageSync('openId'),
  65. },
  66. success: (res) => {
  67. console.log(JSON.parse(res.data), "45454545");
  68. let datas = JSON.parse(res.data)
  69. wx.request({
  70. url: app.globalData.publicUrl + '/user/getPeople',
  71. method: "POST",
  72. header: {
  73. appletsId: wx.getStorageSync('openId')
  74. },
  75. data: {
  76. photoPath: datas.data
  77. },
  78. success: (res) => {
  79. console.log(res, '有没有face')
  80. if (res.data.code == 0) {
  81. if (datas.code == 0) {
  82. if (this.data.imgPath.length < 3) {
  83. this.data.imgPath.push(datas.data)
  84. this.setData({
  85. imgPath: this.data.imgPath
  86. })
  87. this.data.visitPhoto = this.data.imgPath.join(',')
  88. if (this.data.imgPath.length == 2) {
  89. this.setData({
  90. isTrue: false
  91. })
  92. }
  93. }
  94. }
  95. } else {
  96. wx.showToast({
  97. title: '人脸识别不通过,请重新上传',
  98. icon: 'none',
  99. duration: 3000,
  100. })
  101. }
  102. }
  103. })
  104. }
  105. })
  106. }
  107. })
  108. },
  109. // 删除照片
  110. closeImage(e) {
  111. console.log(e.currentTarget.dataset.index, "00");
  112. this.data.imgPath.splice(e.currentTarget.dataset.index, 1);
  113. this.setData({
  114. imgPath: this.data.imgPath,
  115. })
  116. let aa = this.data.imgPath.join(',')
  117. this.setData({
  118. visitPhoto: aa,
  119. })
  120. if (this.data.imgPath.length == 0 || this.data.imgPath.length == 1) {
  121. this.setData({
  122. isTrue: true
  123. })
  124. }
  125. console.log(this.data.imgPath, "00000000000");
  126. },
  127. //提交(表单验证)
  128. formSubmit(e) {
  129. console.log(e.detail, "daying");
  130. /***4-3(表单提交校验)*/
  131. const params = e.detail.value
  132. if (!this.WxValidate.checkForm(params)) {
  133. const error = this.WxValidate.errorList[0]
  134. this.showModal(error)
  135. return false
  136. }
  137. /*** 这里添写验证成功以后的逻辑**/
  138. //验证通过以后->
  139. this.submitInfo(params);
  140. },
  141. // 真正提交 人脸比对
  142. submitInfo(params) {
  143. console.log(params);
  144. console.log(this.data.visitPhoto, "照片");
  145. console.log(this.data.infoId);
  146. wx.showLoading({
  147. title: '加载中',
  148. })
  149. if (this.data.visitPhoto.length > 0) {
  150. let obj = {};
  151. obj = {
  152. ...params,
  153. infoId: this.data.infoId,
  154. visitPhoto: this.data.visitPhoto,
  155. lat: this.data.lat,
  156. lng: this.data.lng,
  157. visitLocation: this.data.visitLocation
  158. }
  159. // 比对接口
  160. wx.request({
  161. url: app.globalData.publicUrl + '/visit/doFace3',
  162. method: "POST",
  163. header: {
  164. appletsId: wx.getStorageSync('openId')
  165. },
  166. data: {
  167. infoId: this.data.infoId,
  168. visitPhoto: this.data.visitPhoto,
  169. },
  170. success: (res) => {
  171. // 如果上传不是人脸图片 则没有score
  172. console.log(res)
  173. if (res.data && res.data.data && res.data.data.score) {
  174. console.log(res.data.data.score, "分数是");
  175. if (res.data.data.score > 80) {
  176. console.log("比对成功了");
  177. //提交的接口
  178. wx.request({
  179. url: app.globalData.publicUrl + '/visit/add',
  180. method: "POST",
  181. header: {
  182. appletsId: wx.getStorageSync('openId')
  183. },
  184. data: obj,
  185. success: (res) => {
  186. if (res.data.code == 0) {
  187. wx.hideLoading();
  188. wx.showModal({
  189. showCancel: false,
  190. content: '提交成功',
  191. success() {
  192. wx.switchTab({
  193. url: '/pages/index/index',
  194. })
  195. }
  196. })
  197. } else if (res.data.code == 1) {
  198. wx.showModal({
  199. showCancel: false,
  200. content: res.data.message,
  201. success() {
  202. wx.switchTab({
  203. url: '/pages/index/index',
  204. })
  205. }
  206. })
  207. }
  208. }
  209. })
  210. } else {
  211. wx.showToast({
  212. title: '人脸比对相似度过低,请重新拍照!',
  213. icon: 'none',
  214. duration: 2000,
  215. })
  216. }
  217. } else {
  218. wx.showToast({
  219. title: '人脸比对失败,请传老人现场照片',
  220. icon: 'none',
  221. duration: 2000,
  222. })
  223. }
  224. }
  225. })
  226. } else {
  227. wx.showToast({
  228. title: '请上传现场照片',
  229. icon: 'none',
  230. duration: 2000,
  231. })
  232. }
  233. },
  234. showModal(error) {
  235. wx.showToast({
  236. title: error.msg,
  237. icon: 'none',
  238. duration: 2000,
  239. })
  240. },
  241. //获取位置
  242. getSelfLocation: function (varSendOrgId) {
  243. console.log(this.data.info, "老人的信心呢锕");
  244. // 拿到老人照片中采集时候的定位
  245. let split = this.data.info.photoAndLocation.split("/");
  246. let lon = parseFloat(split[0])
  247. let lat = parseFloat(split[1])
  248. // 实例化API核心类
  249. var qqmapsdk = new QQMapWX({
  250. key: 'B5DBZ-NGIHP-SQMD4-LHMG3-NJ72Z-7KFOV' //申请的开发者秘钥key
  251. });
  252. wx.getLocation({
  253. //type: 'wgs84',
  254. type: 'gcj02',
  255. success: (res) => {
  256. console.log(res, "0000000");
  257. // 返回当前定位的经纬度
  258. var latitude = parseFloat(res.latitude).toFixed(5);
  259. var longitude = parseFloat(res.longitude).toFixed(5);
  260. this.setData({
  261. lng: longitude, //经度
  262. lat: latitude, //纬度
  263. });
  264. // 判断距离
  265. qqmapsdk.calculateDistance({
  266. mode: 'walking', //步行,驾车为'driving'
  267. to: [{
  268. latitude: lat,
  269. longitude: lon
  270. }, {
  271. latitude: latitude,
  272. longitude: longitude
  273. }],
  274. success: (res) => {
  275. console.log(res.result.elements[0].distance, "距离的");
  276. if (res.result.elements[0].distance > 1000) {
  277. wx.showModal({
  278. showCancel: false,
  279. content: '当前位置超出老人家范围,请重新扫码定位',
  280. success() {
  281. wx.switchTab({
  282. url: '/pages/index/index',
  283. })
  284. }
  285. })
  286. }
  287. },
  288. })
  289. qqmapsdk.reverseGeocoder({
  290. location: {
  291. latitude: res.latitude,
  292. longitude: res.longitude
  293. },
  294. success: (res) => {
  295. //获取当前地址成功
  296. console.log(res, "为是都是都是");
  297. this.setData({
  298. visitLocation: res.result.address
  299. })
  300. },
  301. fail: function (res) {
  302. console.log('获取当前地址失败');
  303. }
  304. });
  305. },
  306. fail: function (res) {
  307. }
  308. });
  309. },
  310. // 获取当前扫码老人的id
  311. oldsInfo(id) {
  312. wx.request({
  313. url: app.globalData.publicUrl + '/info/one',
  314. method: "GET",
  315. header: {
  316. appletsId: wx.getStorageSync('openId')
  317. },
  318. data: {
  319. id: id
  320. },
  321. success: (res) => {
  322. console.log(res, "777777");
  323. if (res.data.code == 0) {
  324. this.setData({
  325. info: res.data.data
  326. })
  327. // 去定位
  328. this.getSelfLocation();
  329. } else {
  330. wx.showModal({
  331. showCancel: false,
  332. content: '查询失败,当前二维码过期或失效',
  333. success() {
  334. wx.switchTab({
  335. url: '/pages/index/index',
  336. })
  337. }
  338. })
  339. }
  340. }
  341. })
  342. },
  343. // 表单验证规则
  344. initValidate() {
  345. const rules = {
  346. health: {
  347. required: true,
  348. },
  349. mind: {
  350. required: true,
  351. },
  352. security: {
  353. required: true,
  354. },
  355. hygiene: {
  356. required: true,
  357. },
  358. live: {
  359. required: true,
  360. },
  361. demand: {
  362. required: true,
  363. },
  364. visitMessage: {
  365. required: true,
  366. },
  367. urgency: {
  368. required: true,
  369. }
  370. };
  371. const messages = {
  372. health: {
  373. required: '请选择健康状况',
  374. },
  375. mind: {
  376. required: '请选择精神状态',
  377. },
  378. security: {
  379. required: '请选择安全情况',
  380. },
  381. hygiene: {
  382. required: '请选择卫生环境',
  383. },
  384. live: {
  385. required: '请选择居住环境',
  386. },
  387. visitMessage: {
  388. required: '请输入备注说明',
  389. },
  390. demand: {
  391. required: '请输入老人需求',
  392. },
  393. urgency: {
  394. required: '请选择需求紧急程度',
  395. }
  396. };
  397. // 创建实例对象
  398. this.WxValidate = new WxValidate(rules, messages)
  399. },
  400. onLoad: function (opotions) {
  401. console.log(opotions, "dayin");
  402. // 获得当前时间
  403. this.time();
  404. // 扫码传参 获得老人的id
  405. this.oldsInfo(opotions.id);
  406. this.setData({
  407. imgPath: [],
  408. infoId: opotions.id
  409. })
  410. console.log(this.data.imgPath, "照片啊锕 锕啊 ");
  411. this.initValidate();
  412. },
  413. })