signIn.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. wx.hideLoading();
  247. that.setData({
  248. 'markers[0]': {
  249. id: 1,
  250. latitude,
  251. longitude,
  252. }
  253. });
  254. qqmapsdk.reverseGeocoder({
  255. location: {
  256. latitude,
  257. longitude
  258. },
  259. success(s) {
  260. console.log("逆解析", s)
  261. that.setData({
  262. content: {
  263. province: s.result.address_component.province,
  264. city: s.result.address_component.city,
  265. county: s.result.address_component.district,
  266. address: s.result.address,
  267. longitude,
  268. latitude,
  269. remarks: "",
  270. sa_projectid: 0,
  271. sys_enterpriseid: 0
  272. }
  273. })
  274. },
  275. fail(err) {
  276. console.log(err)
  277. wx.showToast({
  278. title: '定位失败,请查看手机是否开启定位服务',
  279. icon: "none"
  280. })
  281. }
  282. })
  283. },
  284. fail: function (e) {
  285. //这里是获取失败的时候
  286. wx.hideLoading();
  287. wx.getSetting({
  288. success: res => {
  289. if (typeof (res.authSetting['scope.userLocation']) != 'undefined' && !res.authSetting['scope.userLocation']) {
  290. wx.showModal({
  291. title: '提示',
  292. content: '您拒绝了定位权限,将无法使用签到功能 是否前往开启',
  293. success: res => {
  294. if (res.confirm) {
  295. wx.openSetting({
  296. success: res => {
  297. if (res.authSetting['scope.userLocation']) {
  298. that.getLocation();
  299. } else {
  300. // 没有允许定位权限
  301. wx.showToast({
  302. title: '没有允许定位权限',
  303. icon: 'none'
  304. });
  305. }
  306. }
  307. });
  308. }
  309. }
  310. });
  311. }
  312. }
  313. })
  314. },
  315. })
  316. },
  317. onUnload() {
  318. clearInterval(timing)
  319. },
  320. /* 绑定媒体 */
  321. insertImgEdit({
  322. detail
  323. }) {
  324. _Http.basic({
  325. "classname": "system.attachment.Attachment",
  326. "method": "createFileLink",
  327. "content": {
  328. "ownertable": "sys_signin",
  329. "ownerid": 0,
  330. "usetype": "default",
  331. "attachmentids": detail
  332. }
  333. }).then(res => {
  334. console.log('跟进记录绑定附件', res)
  335. if (res.msg != '成功') return wx.showToast({
  336. title: res.msg,
  337. icon: "none"
  338. })
  339. this.selectComponent("#Yl_Files").handleFiles(res.data)
  340. this.setData({
  341. count: this.data.count + detail.length
  342. })
  343. })
  344. },
  345. /* 监听删除附件 */
  346. onDeteleFiles({
  347. detail
  348. }) {
  349. this.setData({
  350. count: detail.attachmentids.length
  351. })
  352. }
  353. })