signIn.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. radio: true,
  70. value: "",
  71. params: {
  72. "id": 20221012164402,
  73. content: {
  74. nocache: true,
  75. "type": 0,
  76. "pageNumber": 1,
  77. "pageSize": 20,
  78. "isExport": 0,
  79. "where": {
  80. "condition": "",
  81. },
  82. "sort": [{
  83. sortname: "默认",
  84. sorted: 1,
  85. sortid: 67,
  86. reversed: 0
  87. }]
  88. },
  89. },
  90. placeholder: "选择客户",
  91. valueName: "sys_enterprise",
  92. checking: "base",
  93. required: false
  94. }, {
  95. label: "项目",
  96. error: false,
  97. errMsg: "",
  98. type: "route",
  99. url: "/packageA/select/project/select",
  100. radio: true,
  101. value: "",
  102. params: {
  103. "id": 20221020143502,
  104. content: {
  105. nocache: true,
  106. "type": 0,
  107. "pageNumber": 1,
  108. "pageSize": 20,
  109. "where": {
  110. "condition": "", //模糊搜索
  111. },
  112. },
  113. },
  114. placeholder: "选择项目",
  115. valueName: "sa_project",
  116. checking: "base",
  117. required: false
  118. }, {
  119. label: "说明",
  120. error: false,
  121. errMsg: "",
  122. type: "textarea",
  123. value: "",
  124. placeholder: "请填写",
  125. valueName: "remarks",
  126. required: false, //必填
  127. }]
  128. });
  129. },
  130. /* 打断处理form */
  131. interrupt(e) {
  132. let {
  133. data,
  134. form
  135. } = e.detail;
  136. console.log("处理", data, form)
  137. data.params.content.pageNumber = 1;
  138. if (data.label == '客户') {
  139. form[1].label = '客户关联项目'
  140. form[1].params = {
  141. "id": 20221020143502,
  142. content: {
  143. nocache: true,
  144. "type": 0,
  145. "pageNumber": 1,
  146. "pageSize": 20,
  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 (data.label == '项目') {
  159. form.splice(0, 1, data);
  160. form.splice(1, 1, {
  161. label: "项目关联客户",
  162. error: false,
  163. errMsg: "",
  164. type: "route",
  165. url: "/packageA/select/setclient/select",
  166. radio: true,
  167. value: "",
  168. params: {
  169. "id": 20221012164402,
  170. content: {
  171. nocache: true,
  172. "type": 0,
  173. "pageNumber": 1,
  174. "pageSize": 20,
  175. "isExport": 0,
  176. "where": {
  177. "condition": "",
  178. sa_projectid: data.value[1][0],
  179. },
  180. "sort": [{
  181. sortname: "默认",
  182. sorted: 1,
  183. sortid: 67,
  184. reversed: 0
  185. }]
  186. },
  187. },
  188. placeholder: "选择客户",
  189. valueName: "sys_enterprise",
  190. checking: "base",
  191. required: false
  192. });
  193. this.setData({
  194. form,
  195. continue1: "sys_enterprise"
  196. })
  197. }
  198. },
  199. /* 获取定位 */
  200. getLocation() {
  201. let that = this;
  202. wx.showLoading({
  203. title: '定位中...',
  204. });
  205. wx.getLocation({
  206. type: 'gcj02',
  207. isHighAccuracy: true,
  208. highAccuracyExpireTime: 8000,
  209. success({
  210. latitude,
  211. longitude
  212. }) {
  213. wx.hideLoading();
  214. that.setData({
  215. 'markers[0]': {
  216. id: 1,
  217. latitude,
  218. longitude,
  219. }
  220. });
  221. qqmapsdk.reverseGeocoder({
  222. location: {
  223. latitude,
  224. longitude
  225. },
  226. success(s) {
  227. console.log("逆解析", s)
  228. that.setData({
  229. content: {
  230. province: s.result.address_component.province,
  231. city: s.result.address_component.city,
  232. county: s.result.address_component.district,
  233. address: s.result.address,
  234. longitude,
  235. latitude,
  236. remarks: "",
  237. sa_projectid: 0,
  238. sys_enterpriseid: 0
  239. }
  240. })
  241. },
  242. fail(err) {
  243. console.log(err)
  244. wx.showToast({
  245. title: '定位失败,请查看手机是否开启定位服务',
  246. icon: "none"
  247. })
  248. }
  249. })
  250. },
  251. fail: function (e) {
  252. //这里是获取失败的时候
  253. wx.hideLoading();
  254. wx.getSetting({
  255. success: res => {
  256. if (typeof (res.authSetting['scope.userLocation']) != 'undefined' && !res.authSetting['scope.userLocation']) {
  257. wx.showModal({
  258. title: '提示',
  259. content: '您拒绝了定位权限,将无法使用签到功能 是否前往开启',
  260. success: res => {
  261. if (res.confirm) {
  262. wx.openSetting({
  263. success: res => {
  264. if (res.authSetting['scope.userLocation']) {
  265. that.getLocation();
  266. } else {
  267. // 没有允许定位权限
  268. wx.showToast({
  269. title: '没有允许定位权限',
  270. icon: 'none'
  271. });
  272. }
  273. }
  274. });
  275. }
  276. }
  277. });
  278. }
  279. }
  280. })
  281. },
  282. })
  283. },
  284. onUnload() {
  285. clearInterval(timing)
  286. },
  287. onReady() {
  288. },
  289. })