signIn.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. loading: false,
  13. markers: [],
  14. content: {},
  15. time: formatTime(new Date(), '-'),
  16. form: null,
  17. continue1: null,
  18. count: 0
  19. },
  20. onLoad(options) {
  21. this.getLocation();
  22. timing = setInterval(() => {
  23. this.setData({
  24. time: formatTime(new Date(), '-')
  25. })
  26. }, 1000);
  27. this.rander();
  28. },
  29. submit() {
  30. let data = this.selectComponent("#Form").submit(),
  31. content = JSON.parse(JSON.stringify(this.data.content)),
  32. that = this;
  33. content.remarks = data.remarks;
  34. if (data.sys_enterprise) content.sys_enterpriseid = data.sys_enterprise[1][0];
  35. if (data.sa_project) content.sa_projectid = data.sa_project[1][0];
  36. wx.showModal({
  37. title: '提示',
  38. content: '是否确认本次签到',
  39. complete: ({
  40. confirm
  41. }) => {
  42. if (confirm) that.onConfirm(content);
  43. }
  44. })
  45. },
  46. onConfirm(content) {
  47. this.setData({
  48. loading: true
  49. })
  50. _Http.basic({
  51. id: 20221229145901,
  52. content
  53. }).then(res => {
  54. console.log("签到", res)
  55. this.setData({
  56. loading: false
  57. })
  58. wx.showToast({
  59. title: res.msg == '成功' ? '签到成功' : res.msg,
  60. icon: "none"
  61. })
  62. if (res.msg != '成功') return;
  63. let {
  64. attachmentids
  65. } = this.selectComponent("#Yl_Files").getFiles();
  66. if (attachmentids.length == 0) return setTimeout(() => {
  67. getCurrentPages()[getCurrentPages().length - 2].toDate(this.data.time.split(" ")[0]);
  68. wx.navigateBack();
  69. }, 500)
  70. _Http.basic({
  71. "classname": "system.attachment.Attachment",
  72. "method": "createFileLink",
  73. "content": {
  74. "ownertable": "sys_signin",
  75. "ownerid": res.data.sys_signinid,
  76. "usetype": "default",
  77. attachmentids
  78. }
  79. }).then(s => {
  80. console.log('附件改绑', s)
  81. if (s.msg != '成功') wx.showToast({
  82. title: s.msg,
  83. icon: "none",
  84. mask: true
  85. });
  86. setTimeout(() => {
  87. getCurrentPages()[getCurrentPages().length - 2].toDate(this.data.time.split(" ")[0]);
  88. wx.navigateBack();
  89. }, 500)
  90. })
  91. })
  92. },
  93. rander() {
  94. this.setData({
  95. form: [{
  96. label: "客户",
  97. error: false,
  98. errMsg: "",
  99. type: "route",
  100. url: "/packageA/select/setclient/select",
  101. value: "",
  102. params: {
  103. id: 20221012164402,
  104. content: {
  105. pageNumber: 1,
  106. pageTotal: 1,
  107. nocache: true,
  108. type: 7,
  109. isExport: 0,
  110. where: {
  111. condition: "",
  112. },
  113. sort: [{
  114. sortname: "默认",
  115. sorted: 1,
  116. sortid: 67,
  117. reversed: 0
  118. }]
  119. },
  120. },
  121. query: "&radio=true&idname=sys_enterpriseid",
  122. interrupt: true,
  123. placeholder: "选择客户",
  124. valueName: "sys_enterprise",
  125. checking: "base",
  126. required: false
  127. }, {
  128. label: "项目",
  129. error: false,
  130. errMsg: "",
  131. type: "route",
  132. url: "/packageA/select/project/select",
  133. value: "",
  134. params: {
  135. id: 20221020143502,
  136. content: {
  137. nocache: true,
  138. type: 7,
  139. where: {
  140. condition: "", //模糊搜索
  141. },
  142. },
  143. },
  144. query: "&radio=true",
  145. interrupt: true,
  146. placeholder: "选择项目",
  147. valueName: "sa_project",
  148. checking: "base",
  149. required: false
  150. }, {
  151. label: "说明",
  152. error: false,
  153. errMsg: "",
  154. type: "textarea",
  155. value: "",
  156. placeholder: "请填写",
  157. valueName: "remarks",
  158. required: false, //必填
  159. }]
  160. });
  161. },
  162. /* 打断处理form */
  163. interrupt(e) {
  164. console.log(e)
  165. let {
  166. data,
  167. form,
  168. temporary
  169. } = e.detail;
  170. if (temporary.item.value[0] == data.value[0]) return wx.navigateBack()
  171. temporary.item.value = data.value;
  172. if (temporary.item.label == '客户') {
  173. form[0] = temporary.item;
  174. form[1].label = '客户关联项目';
  175. form[1].interrupt = false;
  176. form[1].params = {
  177. id: 20221020143502,
  178. content: {
  179. nocache: true,
  180. type: 0,
  181. where: {
  182. condition: "", //模糊搜索
  183. sys_enterpriseid: data.value[1][0],
  184. },
  185. },
  186. }
  187. form[1].value = "";
  188. this.setData({
  189. form,
  190. continue1: "sa_project"
  191. })
  192. } else if (temporary.item.label == '项目') {
  193. form.splice(0, 1, temporary.item);
  194. form.splice(1, 1, {
  195. label: "项目关联客户",
  196. error: false,
  197. errMsg: "",
  198. type: "route",
  199. url: "/packageA/select/setclient/select",
  200. value: "",
  201. params: {
  202. "id": 20221012164402,
  203. content: {
  204. nocache: true,
  205. type: 0,
  206. isExport: 0,
  207. where: {
  208. condition: "",
  209. sa_projectid: data.value[1][0],
  210. },
  211. sort: [{
  212. sortname: "默认",
  213. sorted: 1,
  214. sortid: 67,
  215. reversed: 0
  216. }]
  217. },
  218. },
  219. query: "&radio=true&idname=sys_enterpriseid",
  220. placeholder: "选择客户",
  221. valueName: "sys_enterprise",
  222. checking: "base",
  223. required: false
  224. });
  225. this.setData({
  226. form,
  227. continue1: "sys_enterprise"
  228. })
  229. };
  230. wx.navigateBack()
  231. },
  232. /* 获取定位 */
  233. getLocation() {
  234. let that = this;
  235. wx.showLoading({
  236. title: '定位中...',
  237. });
  238. wx.getLocation({
  239. type: 'gcj02',
  240. isHighAccuracy: true,
  241. highAccuracyExpireTime: 8000,
  242. success({
  243. latitude,
  244. longitude
  245. }) {
  246. console.log('精确', latitude, longitude)
  247. that.setData({
  248. 'markers[0]': {
  249. id: 1,
  250. latitude,
  251. longitude,
  252. }
  253. });
  254. }
  255. })
  256. wx.getLocation({
  257. success({
  258. latitude,
  259. longitude
  260. }) {
  261. console.log('bu精确', latitude, longitude)
  262. wx.hideLoading();
  263. _Http.basic({
  264. "id": "10027201",
  265. "content": {
  266. "lon": longitude,
  267. "lat": latitude
  268. }
  269. }).then(res => {
  270. console.log("获取逆解析地址", res)
  271. if (res.msg != '成功') return wx.showToast({
  272. title: res.msg,
  273. icon: "none"
  274. })
  275. if (res.data.msg != 'ok') return wx.showToast({
  276. title: '定位失败,请查看手机是否开启定位服务',
  277. icon: "none"
  278. })
  279. let result = res.data.result;
  280. that.setData({
  281. content: {
  282. province: result.addressComponent.province,
  283. city: result.addressComponent.city,
  284. county: result.addressComponent.county,
  285. address: result.formatted_address,
  286. latitude,
  287. longitude,
  288. remarks: "",
  289. sa_projectid: 0,
  290. sys_enterpriseid: 0
  291. }
  292. })
  293. })
  294. /* qqmapsdk.reverseGeocoder({
  295. location: {
  296. latitude,
  297. longitude
  298. },
  299. success(s) {
  300. console.log("逆解析", s)
  301. that.setData({
  302. content: {
  303. province: s.result.address_component.province,
  304. city: s.result.address_component.city,
  305. county: s.result.address_component.district,
  306. address: s.result.address,
  307. longitude,
  308. latitude,
  309. remarks: "",
  310. sa_projectid: 0,
  311. sys_enterpriseid: 0
  312. }
  313. })
  314. },
  315. fail(err) {
  316. console.log(err)
  317. wx.showToast({
  318. title: '定位失败,请查看手机是否开启定位服务',
  319. icon: "none"
  320. })
  321. }
  322. }) */
  323. },
  324. fail: function (e) {
  325. //这里是获取失败的时候
  326. wx.hideLoading();
  327. wx.getSetting({
  328. success: res => {
  329. if (typeof (res.authSetting['scope.userLocation']) != 'undefined' && !res.authSetting['scope.userLocation']) {
  330. wx.showModal({
  331. title: '提示',
  332. content: '您拒绝了定位权限,将无法使用签到功能 是否前往开启',
  333. success: res => {
  334. if (res.confirm) {
  335. wx.openSetting({
  336. success: res => {
  337. if (res.authSetting['scope.userLocation']) {
  338. that.getLocation();
  339. } else {
  340. // 没有允许定位权限
  341. wx.showToast({
  342. title: '没有允许定位权限',
  343. icon: 'none'
  344. });
  345. }
  346. }
  347. });
  348. }
  349. }
  350. });
  351. }
  352. }
  353. })
  354. },
  355. })
  356. },
  357. onUnload() {
  358. clearInterval(timing)
  359. },
  360. /* 绑定媒体 */
  361. insertImgEdit({
  362. detail
  363. }) {
  364. _Http.basic({
  365. "classname": "system.attachment.Attachment",
  366. "method": "createFileLink",
  367. "content": {
  368. "ownertable": "sys_signin",
  369. "ownerid": 0,
  370. "usetype": "default",
  371. "attachmentids": detail
  372. }
  373. }).then(res => {
  374. console.log('跟进记录绑定附件', res)
  375. if (res.msg != '成功') return wx.showToast({
  376. title: res.msg,
  377. icon: "none"
  378. })
  379. this.selectComponent("#Yl_Files").handleFiles(res.data)
  380. this.setData({
  381. count: this.data.count + detail.length
  382. })
  383. })
  384. },
  385. /* 监听删除附件 */
  386. onDeteleFiles({
  387. detail
  388. }) {
  389. this.setData({
  390. count: detail.attachmentids.length
  391. })
  392. }
  393. })