love.js 9.5 KB

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