signIn.js 12 KB

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