signIn.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. const _Http = getApp().globalData.http;
  2. const QQMapWX = require('../../utils/qqmap-wx-jssdk.min'),
  3. qqmapsdk = new QQMapWX({
  4. key: 'QF6BZ-4IQC5-SN2IH-QL5BW-U4IJO-R3BY4' // 必填
  5. });
  6. import {
  7. formatTime
  8. } from "../../utils/getTime";
  9. let timing = null;
  10. Page({
  11. data: {
  12. markers: [],
  13. content: {},
  14. time: formatTime(new Date(), '-'),
  15. form: null,
  16. continue1: null,
  17. },
  18. onLoad(options) {
  19. this.getLocation();
  20. timing = setInterval(() => {
  21. this.setData({
  22. time: formatTime(new Date(), '-')
  23. })
  24. }, 1000);
  25. this.rander();
  26. },
  27. submit() {
  28. let data = this.selectComponent("#Form").submit(),
  29. content = JSON.parse(JSON.stringify(this.data.content)),
  30. that = this;
  31. content.remarks = data.remarks;
  32. if (data.sys_enterprise) content.sys_enterpriseid = data.sys_enterprise[1][0];
  33. if (data.sa_project) content.sa_projectid = data.sa_project[1][0];
  34. console.log(content)
  35. wx.showModal({
  36. title: '提示',
  37. content: '是否确认本次签到',
  38. complete: ({
  39. confirm
  40. }) => {
  41. if (confirm) that.onConfirm(content);
  42. }
  43. })
  44. },
  45. onConfirm(content) {
  46. _Http.basic({
  47. id: 20221229145901,
  48. content
  49. }).then(res => {
  50. console.log("签到", res)
  51. wx.showToast({
  52. title: res.msg == '成功' ? '签到成功' : res.msg,
  53. icon: "none"
  54. })
  55. if (res.msg == '成功') setTimeout(() => {
  56. getCurrentPages()[getCurrentPages().length - 2].toDate(this.data.time.split(" ")[0]);
  57. wx.navigateBack();
  58. }, 500)
  59. })
  60. },
  61. rander() {
  62. this.setData({
  63. form: [{
  64. label: "客户",
  65. error: false,
  66. errMsg: "",
  67. type: "route",
  68. url: "/packageA/select/setclient/select",
  69. value: "",
  70. params: {
  71. id: 20221012164402,
  72. content: {
  73. nocache: true,
  74. type: 0,
  75. isExport: 0,
  76. where: {
  77. condition: "",
  78. },
  79. sort: [{
  80. sortname: "默认",
  81. sorted: 1,
  82. sortid: 67,
  83. reversed: 0
  84. }]
  85. },
  86. },
  87. query: "&radio=true",
  88. interrupt: true,
  89. placeholder: "选择客户",
  90. valueName: "sys_enterprise",
  91. checking: "base",
  92. required: false
  93. }, {
  94. label: "项目",
  95. error: false,
  96. errMsg: "",
  97. type: "route",
  98. url: "/packageA/select/project/select",
  99. value: "",
  100. params: {
  101. id: 20221020143502,
  102. content: {
  103. nocache: true,
  104. type: 0,
  105. where: {
  106. condition: "", //模糊搜索
  107. },
  108. },
  109. },
  110. query: "&radio=true",
  111. interrupt: true,
  112. placeholder: "选择项目",
  113. valueName: "sa_project",
  114. checking: "base",
  115. required: false
  116. }, {
  117. label: "说明",
  118. error: false,
  119. errMsg: "",
  120. type: "textarea",
  121. value: "",
  122. placeholder: "请填写",
  123. valueName: "remarks",
  124. required: false, //必填
  125. }]
  126. });
  127. },
  128. /* 打断处理form */
  129. interrupt(e) {
  130. console.log(e)
  131. let {
  132. data,
  133. form,
  134. temporary
  135. } = e.detail;
  136. if (temporary.item.value[0] == data.value[0]) return wx.navigateBack()
  137. temporary.item.value = data.value;
  138. if (temporary.item.label == '客户') {
  139. form[0] = temporary.item;
  140. form[1].label = '客户关联项目';
  141. form[1].interrupt = false;
  142. form[1].params = {
  143. id: 20221020143502,
  144. content: {
  145. nocache: true,
  146. type: 0,
  147. where: {
  148. condition: "", //模糊搜索
  149. sys_enterpriseid: data.value[1][0],
  150. },
  151. },
  152. }
  153. form[1].value = "";
  154. this.setData({
  155. form,
  156. continue1: "sa_project"
  157. })
  158. } else if (temporary.item.label == '项目') {
  159. form.splice(0, 1, temporary.item);
  160. form.splice(1, 1, {
  161. label: "项目关联客户",
  162. error: false,
  163. errMsg: "",
  164. type: "route",
  165. url: "/packageA/select/setclient/select",
  166. value: "",
  167. params: {
  168. "id": 20221012164402,
  169. content: {
  170. nocache: true,
  171. type: 0,
  172. isExport: 0,
  173. where: {
  174. condition: "",
  175. sa_projectid: data.value[1][0],
  176. },
  177. sort: [{
  178. sortname: "默认",
  179. sorted: 1,
  180. sortid: 67,
  181. reversed: 0
  182. }]
  183. },
  184. },
  185. query: "&radio=true",
  186. placeholder: "选择客户",
  187. valueName: "sys_enterprise",
  188. checking: "base",
  189. required: false
  190. });
  191. this.setData({
  192. form,
  193. continue1: "sys_enterprise"
  194. })
  195. };
  196. wx.navigateBack()
  197. },
  198. /* 获取定位 */
  199. getLocation() {
  200. let that = this;
  201. wx.showLoading({
  202. title: '定位中...',
  203. });
  204. wx.getLocation({
  205. type: 'gcj02',
  206. isHighAccuracy: true,
  207. highAccuracyExpireTime: 8000,
  208. success({
  209. latitude,
  210. longitude
  211. }) {
  212. wx.hideLoading();
  213. that.setData({
  214. 'markers[0]': {
  215. id: 1,
  216. latitude,
  217. longitude,
  218. }
  219. });
  220. qqmapsdk.reverseGeocoder({
  221. location: {
  222. latitude,
  223. longitude
  224. },
  225. success(s) {
  226. console.log("逆解析", s)
  227. that.setData({
  228. content: {
  229. province: s.result.address_component.province,
  230. city: s.result.address_component.city,
  231. county: s.result.address_component.district,
  232. address: s.result.address,
  233. longitude,
  234. latitude,
  235. remarks: "",
  236. sa_projectid: 0,
  237. sys_enterpriseid: 0
  238. }
  239. })
  240. },
  241. fail(err) {
  242. console.log(err)
  243. wx.showToast({
  244. title: '定位失败,请查看手机是否开启定位服务',
  245. icon: "none"
  246. })
  247. }
  248. })
  249. },
  250. fail: function (e) {
  251. //这里是获取失败的时候
  252. wx.hideLoading();
  253. wx.getSetting({
  254. success: res => {
  255. if (typeof (res.authSetting['scope.userLocation']) != 'undefined' && !res.authSetting['scope.userLocation']) {
  256. wx.showModal({
  257. title: '提示',
  258. content: '您拒绝了定位权限,将无法使用签到功能 是否前往开启',
  259. success: res => {
  260. if (res.confirm) {
  261. wx.openSetting({
  262. success: res => {
  263. if (res.authSetting['scope.userLocation']) {
  264. that.getLocation();
  265. } else {
  266. // 没有允许定位权限
  267. wx.showToast({
  268. title: '没有允许定位权限',
  269. icon: 'none'
  270. });
  271. }
  272. }
  273. });
  274. }
  275. }
  276. });
  277. }
  278. }
  279. })
  280. },
  281. })
  282. },
  283. onUnload() {
  284. clearInterval(timing)
  285. },
  286. onReady() {
  287. },
  288. })