love.js 11 KB

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