love.js 11 KB

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