智慧申请系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
6.3 KiB

  1. //app.js
  2. let key = 'MUZBZ-5OF33-BVO3Y-YDTEZ-2GLLK-KVFTF',
  3. gdKey = 'bca18d221a666f2c70387e0c8e669f1e',
  4. apiPath = __wxConfig.envVersion == 'release' ? "https://www.jjyl.top/api/v1/" : "http://39.98.128.49:8086/api/v1/";
  5. App({
  6. onLaunch: function() {
  7. // 展示本地存储能力
  8. var logs = wx.getStorageSync('logs') || []
  9. logs.unshift(Date.now())
  10. wx.setStorageSync('logs', logs)
  11. // 获取用户信息
  12. wx.getSetting({
  13. success: res => {
  14. if (res.authSetting['scope.userInfo']) {
  15. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  16. wx.getUserInfo({
  17. success: res => {
  18. // 可以将 res 发送给后台解码出 unionId
  19. this.globalData.userInfo = res.userInfo
  20. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  21. // 所以此处加入 callback 以防止这种情况
  22. if (this.userInfoReadyCallback) {
  23. this.userInfoReadyCallback(res)
  24. }
  25. }
  26. })
  27. }
  28. }
  29. })
  30. // 检查更新
  31. if (wx.getUpdateManager) {
  32. var updateManager_1 = wx.getUpdateManager();
  33. updateManager_1.onCheckForUpdate(function(res) {
  34. console.log(res.hasUpdate);
  35. });
  36. updateManager_1.onUpdateReady(function() {
  37. wx.showModal({
  38. title: '更新提示',
  39. content: '新版本已经准备好,是否重启应用?',
  40. success: function(res) {
  41. if (res.confirm) {
  42. updateManager_1.applyUpdate();
  43. }
  44. }
  45. });
  46. });
  47. updateManager_1.onUpdateFailed(function() {
  48. console.log('新版本下载失败');
  49. });
  50. } else {}
  51. },
  52. globalData: {
  53. userInfo: null,
  54. apiPath: apiPath,
  55. header: "",
  56. token: "JJYLeyJhbGciOiJIUzUxMiJ9.eyJ1c2VyUmVnaW9uIjoiMTk4MiIsInVzZXJOYW1lIjoi6K-E5Lyw5ZGYIiwidHlwZSI6IjEiLCJ1c2VySUQiOjEwNiwidXNlclJlZ2lvblN0cmluZyI6Iuaxn-axieWMuizmrabmsYnluIIs5rmW5YyX55yBIiwibG9naW5Vc2VyTmFtZSI6Indoal9wZ3kiLCJ1c2VyTGV2ZWwiOiIzIiwiamdkbSI6IjQyMDEwMzAxMTAwMSIsImpneGgiOiIxIiwiZXhwIjoxNzEwNTI2NDQyLCJpYXQiOjE3MTA0ODMyNDIsImFnZW5jeVR5cGUiOiIyIiwib3JnUGFyZW50Q29kZSI6IjQyMDEwMyJ9.rcatN7nLZd2lNKY3R5t9wMPaWKT4XOEbh6aKcdwQbL-tHePpxqT7v6zrhFab_-isSX8DDHAJX0F6XEw75fcJtw",
  57. providerNo: "F000002",
  58. personNo: "R000016",
  59. serviceParty: 2,
  60. orderStatus: 2,
  61. loginType: "",
  62. apiType: "",
  63. disablePhoto: 0, //1是 0否,就是1 禁止使用相册
  64. apiList: {
  65. fws: {
  66. login: "serviceProviderLogin",
  67. tongji: ""
  68. },
  69. fwz: {
  70. login: "servicePersonLogin",
  71. tongji: ""
  72. }
  73. },
  74. userId: '', // 当前登录用户id
  75. userName: '评估员',
  76. },
  77. ajax: function(url, type, data, dataType, successcallback, errorcallbak, contentType) {
  78. var header = {},
  79. token = this.globalData.token;
  80. if (token) {
  81. header["token"] = token;
  82. }
  83. // wx.showLoading();
  84. wx.request({
  85. url: apiPath + url,
  86. method: type || "get",
  87. data: data || {},
  88. header: header,
  89. dataType: dataType || "JSON",
  90. success: function(res) {
  91. var data = JSON.parse(res.data);
  92. if (data.code == "200") {
  93. successcallback && successcallback(data.data);
  94. } else {
  95. errorcallbak && errorcallbak(data);
  96. }
  97. },
  98. error: function(res) {
  99. errorcallbak && errorcallbak(res);
  100. },
  101. complete: () => {
  102. // wx.hideLoading()
  103. }
  104. })
  105. },
  106. tips: function(tips, icon = 'none', duration = 2000) {
  107. wx.showToast({
  108. title: tips,
  109. icon,
  110. duration,
  111. })
  112. },
  113. justpage: function(url) {
  114. wx.navigateTo({
  115. url: url
  116. })
  117. },
  118. getOrderList: function(data, successcallback, errorcallbak) {
  119. if (data) {
  120. data.sourceTag = "small";
  121. }
  122. this.ajax("serviceOrder/selectServiceOrders", "POST", data, null, successcallback, errorcallbak)
  123. },
  124. getEventData: function(e) {
  125. return e.currentTarget.dataset;
  126. },
  127. getDict: function(jgxh, success) {
  128. this.ajax("dict/detail", "GET", {
  129. zdbh: jgxh
  130. }, null, function(res) {
  131. success && success(res)
  132. })
  133. },
  134. chooseImage: function(type, callback) {
  135. const sourceType = this.globalData.disablePhoto && type == 1 ? ['camera'] : ['camera', 'album']
  136. wx.chooseImage({
  137. count: 1,
  138. sizeType: ['original', 'compressed'],
  139. sourceType: sourceType,
  140. success(res) {
  141. callback && callback(res.tempFilePaths)
  142. }
  143. })
  144. },
  145. chooseImage2: function(count, type, callback) {
  146. const sourceType = this.globalData.disablePhoto && type == 1 ? ['camera'] : ['camera', 'album']
  147. wx.chooseImage({
  148. count: count,
  149. sizeType: ['original', 'compressed'],
  150. sourceType: sourceType,
  151. success(res) {
  152. callback && callback(res.tempFilePaths)
  153. }
  154. })
  155. },
  156. chooseVideo: function(callback) {
  157. const sourceType = this.globalData.disablePhoto ? ['camera'] : ['camera', 'album']
  158. wx.chooseVideo({
  159. sourceType: ['camera', 'album'],
  160. success(res) {
  161. callback && callback(res)
  162. }
  163. })
  164. },
  165. uploadFile: function(filePath, uploadType, fileType, successcallback, errorcallbak) {
  166. this.ajax("serviceOrder/uploadFile2Small", "POST", {
  167. uploadFiles: filePath,
  168. fileJson: JSON.stringify({
  169. uploadType: uploadType,
  170. fileType: fileType
  171. })
  172. }, null, successcallback, errorcallbak)
  173. },
  174. // 获取省市区
  175. getAdmin(regionId) {
  176. let that = this
  177. return new Promise((resolve, reject) => {
  178. this.ajax("region/selectRegionByRegionId", 'GET', {
  179. regionId
  180. }, '', function(res) {
  181. resolve(res)
  182. }, err => {
  183. that.tips(err.msg);
  184. })
  185. })
  186. },
  187. // 获取服务中心
  188. getServiceCenterList(params) {
  189. let that = this
  190. return new Promise((resolve, reject) => {
  191. this.ajax("organization/queryByOrg", 'POST', params, '', res => {
  192. resolve(res)
  193. }, err => {
  194. that.tips(err.msg);
  195. })
  196. })
  197. },
  198. // 获取验证码
  199. getCode(mobile) {
  200. let that = this
  201. return new Promise((resolve, reject) => {
  202. this.ajax("volunteer/getMsgCode", 'POST', {
  203. mobile
  204. }, '', res => {
  205. resolve(res)
  206. }, err => {
  207. that.tips(err.msg);
  208. resolve(err)
  209. })
  210. })
  211. },
  212. // 获取字典代码
  213. getZddm() {
  214. let that = this
  215. return new Promise((resolve, reject) => {
  216. this.ajax("dict/detail/user", 'GET', null, '', function(res) {
  217. resolve(res)
  218. }, function(err) {
  219. that.tips(err.message);
  220. })
  221. });
  222. },
  223. // 上传图片
  224. uploadImageFile(url, filePath, name = 'file') {
  225. return new Promise((resolve, reject) => {
  226. wx.uploadFile({
  227. url: `${apiPath}${url}`,
  228. header: {
  229. 'content-type': 'multipart/form-data'
  230. },
  231. filePath,
  232. name,
  233. success(res) {
  234. resolve(res)
  235. },
  236. fail(err) {
  237. reject(err)
  238. }
  239. })
  240. })
  241. },
  242. })