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. console.log(res)
  154. if (res.data && res.data.data && res.data.data.score) {
  155. console.log(res.data.data.score, "分数是");
  156. if (res.data.data.score > 80) {
  157. console.log("比对成功了");
  158. //提交的接口
  159. wx.request({
  160. url: app.globalData.publicUrl + '/visit/add',
  161. method: "POST",
  162. header: {
  163. appletsId: wx.getStorageSync('openId')
  164. },
  165. data: obj,
  166. success: (res) => {
  167. if (res.data.code == 0) {
  168. wx.hideLoading();
  169. wx.showModal({
  170. showCancel: false,
  171. content: '提交成功',
  172. success() {
  173. wx.switchTab({
  174. url: '/pages/index/index',
  175. })
  176. }
  177. })
  178. } else if (res.data.code == 1) {
  179. wx.showModal({
  180. showCancel: false,
  181. content: res.data.message,
  182. success() {
  183. wx.switchTab({
  184. url: '/pages/index/index',
  185. })
  186. }
  187. })
  188. }
  189. }
  190. })
  191. } else {
  192. wx.showToast({
  193. title: '人脸比对相似度过低,请重新拍照!',
  194. icon: 'none',
  195. duration: 2000,
  196. })
  197. }
  198. } else {
  199. wx.showToast({
  200. title: '人脸比对失败,请传老人现场照片',
  201. icon: 'none',
  202. duration: 2000,
  203. })
  204. }
  205. }
  206. })
  207. } else {
  208. wx.showToast({
  209. title: '请上传现场照片',
  210. icon: 'none',
  211. duration: 2000,
  212. })
  213. }
  214. },
  215. showModal(error) {
  216. wx.showToast({
  217. title: error.msg,
  218. icon: 'none',
  219. duration: 2000,
  220. })
  221. },
  222. //获取位置
  223. getSelfLocation: function (varSendOrgId) {
  224. console.log(this.data.info, "老人的信心呢锕");
  225. // 拿到老人照片中采集时候的定位
  226. let split = this.data.info.photoAndLocation.split("/");
  227. let lon = parseFloat(split[0])
  228. let lat = parseFloat(split[1])
  229. // 实例化API核心类
  230. var qqmapsdk = new QQMapWX({
  231. key: 'B5DBZ-NGIHP-SQMD4-LHMG3-NJ72Z-7KFOV' //申请的开发者秘钥key
  232. });
  233. var that = this; //用户授权过可以直接获取位置
  234. wx.getLocation({
  235. //type: 'wgs84',
  236. type: 'gcj02',
  237. success: function (res) {
  238. console.log(res, "0000000");
  239. // 返回当前定位的经纬度
  240. var latitude = parseFloat(res.latitude).toFixed(5);
  241. var longitude = parseFloat(res.longitude).toFixed(5);
  242. that.setData({
  243. lng: longitude, //经度
  244. lat: latitude, //纬度
  245. });
  246. // 判断距离
  247. qqmapsdk.calculateDistance({
  248. mode: 'walking', //步行,驾车为'driving'
  249. to: [{
  250. latitude: lat,
  251. longitude: lon
  252. }, {
  253. latitude: latitude,
  254. longitude: longitude
  255. }],
  256. success: function (res) {
  257. console.log(res.result.elements[0].distance, "距离的");
  258. if (res.result.elements[0].distance > 1000) {
  259. wx.showModal({
  260. showCancel: false,
  261. content: '当前位置超出老人家范围,请重新扫码定位',
  262. success() {
  263. wx.switchTab({
  264. url: '/pages/index/index',
  265. })
  266. }
  267. })
  268. }
  269. },
  270. })
  271. qqmapsdk.reverseGeocoder({
  272. location: {
  273. latitude: res.latitude,
  274. longitude: res.longitude
  275. },
  276. success: function (res) {
  277. //获取当前地址成功
  278. console.log(res, "为是都是都是");
  279. that.setData({
  280. visitLocation: res.result.address
  281. })
  282. },
  283. fail: function (res) {
  284. console.log('获取当前地址失败');
  285. }
  286. });
  287. },
  288. fail: function (res) {
  289. }
  290. });
  291. },
  292. // 获取当前扫码老人的id
  293. oldsInfo(id) {
  294. wx.request({
  295. url: app.globalData.publicUrl + '/info/one',
  296. method: "GET",
  297. header: {
  298. appletsId: wx.getStorageSync('openId')
  299. },
  300. data: {
  301. id: id
  302. },
  303. success: (res) => {
  304. console.log(res, "777777");
  305. if (res.data.code == 0) {
  306. this.setData({
  307. info: res.data.data
  308. })
  309. // 去定位
  310. this.getSelfLocation();
  311. } else {
  312. wx.showModal({
  313. showCancel: false,
  314. content: '查询失败,当前二维码过期或失效',
  315. success() {
  316. wx.switchTab({
  317. url: '/pages/index/index',
  318. })
  319. }
  320. })
  321. }
  322. }
  323. })
  324. },
  325. // 表单验证规则
  326. initValidate() {
  327. const rules = {
  328. health: {
  329. required: true,
  330. },
  331. mind: {
  332. required: true,
  333. },
  334. security: {
  335. required: true,
  336. },
  337. hygiene: {
  338. required: true,
  339. },
  340. live: {
  341. required: true,
  342. },
  343. demand: {
  344. required: true,
  345. },
  346. visitMessage: {
  347. required: true,
  348. },
  349. };
  350. const messages = {
  351. health: {
  352. required: '请选择健康状况',
  353. },
  354. mind: {
  355. required: '请选择精神状态',
  356. },
  357. security: {
  358. required: '请选择安全情况',
  359. },
  360. hygiene: {
  361. required: '请选择卫生环境',
  362. },
  363. live: {
  364. required: '请选择居住环境',
  365. },
  366. visitMessage: {
  367. required: '请输入备注说明',
  368. },
  369. demand: {
  370. required: '请输入老人需求',
  371. },
  372. };
  373. // 创建实例对象
  374. this.WxValidate = new WxValidate(rules, messages)
  375. },
  376. onLoad: function (opotions) {
  377. console.log(opotions, "dayin");
  378. // 获得当前时间
  379. this.time();
  380. // 扫码传参 获得老人的id
  381. this.oldsInfo(opotions.id);
  382. this.setData({
  383. imgPath: [],
  384. infoId: opotions.id
  385. })
  386. console.log(this.data.imgPath, "照片啊锕 锕啊 ");
  387. this.initValidate();
  388. },
  389. })