love.js 9.8 KB

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