signIn.js 12 KB

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