signIn.js 12 KB

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