love.js 9.6 KB

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