helper.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. import * as config from '../config'
  2. const rolesList = []
  3. const gjList=[]
  4. const ossUploadUrl = 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/';
  5. const chooseImage = {
  6. count: '1',
  7. sizeType: ['original', 'compressed'],
  8. sourceType: ['album'],
  9. }
  10. const imgType = '请选择图片来源'
  11. const imgTypeList = [{
  12. name: '相册',
  13. },
  14. {
  15. name: '拍照',
  16. }
  17. ]
  18. const makeValidityPeriod = function(type) {
  19. //获取当前年
  20. let nowDate = new Date();
  21. let year = nowDate.getFullYear()
  22. let _list = []
  23. let _list1 = []
  24. // let _list2 = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
  25. let _list2 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
  26. let _list3 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
  27. "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
  28. "31"
  29. ]
  30. let _ValidityPeriod = []
  31. for (let i = 0; i < 30; i++) {
  32. _list1.push(year + i)
  33. }
  34. if (type == 0) {
  35. _list1.unshift('长期')
  36. _list2.unshift('')
  37. _list3.unshift('')
  38. }
  39. _list.push(_list1, _list2, _list3)
  40. return _list
  41. }
  42. const fUN_AmapLocation = uni.requireNativePlugin('FUN-AmapLocation');
  43. const getListByUserId = function() {
  44. let baseUrlNew = config.def().baseUrlNew
  45. var userInfo = uni.getStorageSync("userInfo")
  46. console.log("------", userInfo)
  47. if (userInfo) {
  48. uni.request({
  49. url: baseUrlNew + '/roleMenu/query/getListByUserId',
  50. data: {
  51. userId: userInfo.id ? userInfo.id : userInfo.data.id
  52. },
  53. method: 'GET',
  54. success: (res) => {
  55. if (res.statusCode === 200) {
  56. uni.setStorageSync("jurisdiction", res.data.data)
  57. let list = getUserAllRoles(res.data.data);
  58. uni.setStorageSync("rolesList", list)
  59. }
  60. }
  61. })
  62. }
  63. }
  64. const getUserAllRoles = (item) => {
  65. console.log(item)
  66. for (let i = 0; i < item.length; i++) {
  67. rolesList.push(item[i].name)
  68. // console.log('用户权限',rolesList)
  69. if (item[i].children && item[i].children.length > 0) {
  70. getUserAllRoles(item[i].children)
  71. }
  72. }
  73. return rolesList;
  74. }
  75. const setAudit = (item) => {
  76. let _list = uni.getStorageSync("copyTaskInfo")
  77. let _isShowbtn = true
  78. if (_list.length == 0) {
  79. _isShowbtn = false
  80. }
  81. for (let i = 0; i < _list.length; i++) {
  82. if (_list[i].businessId == item.id) {
  83. _list.splice(i, 1)
  84. uni.setStorageSync("copyTaskInfo", _list)
  85. }
  86. }
  87. if (_list.length > 0) {
  88. uni.navigateTo({
  89. url: _list[0].itemUrl + '&isShowbtn=' + _isShowbtn,
  90. })
  91. }
  92. console.log(item)
  93. }
  94. const contactCustomerService = (phone) => {
  95. console.log(phone)
  96. //客服
  97. if (!phone) {
  98. phone = '400123123'
  99. }
  100. const res = uni.getSystemInfoSync();
  101. // ios系统默认有个模态框
  102. if(res.platform=='ios'){
  103. uni.makePhoneCall({
  104. phoneNumber:phone,
  105. success(){
  106. console.log('拨打成功了');
  107. },
  108. fail() {
  109. console.log('拨打失败了');
  110. }
  111. })
  112. }else{
  113. //安卓手机手动设置一个showActionSheet
  114. uni.showActionSheet({
  115. itemList: [phone,'呼叫'],
  116. success:function(res){
  117. console.log(res);
  118. if(res.tapIndex==1){
  119. uni.makePhoneCall({
  120. phoneNumber: phone,
  121. success: (res) => {
  122. console.log('调用成功!')
  123. },
  124. // 失败回调
  125. fail: (res) => {
  126. console.log('调用失败!')
  127. // contactCustomerService(item)
  128. }
  129. })
  130. }
  131. }
  132. })
  133. }
  134. // console.log("联系客服")
  135. // uni.makePhoneCall({
  136. // phoneNumber: item,
  137. // success: (res) => {
  138. // console.log('调用成功!')
  139. // },
  140. // // 失败回调
  141. // fail: (res) => {
  142. // console.log('调用失败!')
  143. // contactCustomerService(item)
  144. // }
  145. // });
  146. }
  147. // 获取市、区简称
  148. const filterUrban = (s) => {
  149. if (s.lastIndexOf('市') != -1) {
  150. return s.substring(0, s.length - 1)
  151. }
  152. return s
  153. }
  154. const filterArea = (q) => {
  155. if (q.lastIndexOf('区') != -1) {
  156. return q.substring(0, q.length - 1)
  157. }
  158. return q
  159. }
  160. // 根据当前时间获取本周一到本周日日期
  161. function getDates() {
  162. // var new_Date = new Date(t2)
  163. var new_Date = new Date()
  164. var timesStamp = new_Date.getTime()
  165. var currenDay = new_Date.getDay()
  166. var dates = []
  167. for (var i = 0; i < 7; i++) {
  168. dates.push(new Date(timesStamp + 24 * 60 * 60 * 1000 * (i - (currenDay + 6) % 7)).toLocaleDateString().replace(
  169. /[年月]/g, '-').replace(/[日上下午]/g, ''));
  170. }
  171. var weekStar = new Date(dates[0] + ' 00:00:00').getTime()
  172. var weekEnd = new Date(dates[dates.length - 1] + ' 23:59:59').getTime()
  173. var week = [weekStar, weekEnd]
  174. return week
  175. }
  176. //判断是否是今天,昨天,明天
  177. function isToday(str,type) {
  178. //type == 0 判断是否是今天,type == 1 判断是否是昨天,type == 2 判断是否是明天
  179. if (type == 0){
  180. if (new Date(str).toDateString() === new Date().toDateString()) {
  181. // console.log('今天');
  182. return true
  183. } else{
  184. // console.log('不是今天');
  185. return false
  186. }
  187. }if (type == 1) {
  188. if (new Date(str).toDateString() === new Date(new Date().getTime() -1000 * 60 * 60 * 24).toDateString()) {
  189. // console.log('昨天');
  190. return true
  191. } else{
  192. // console.log('不是昨天');
  193. return false
  194. }
  195. }
  196. if (type == 2) {
  197. if (new Date(str).toDateString() === new Date(new Date().getTime() +1000 * 60 * 60 * 24).toDateString()) {
  198. // console.log('明天');
  199. return true
  200. } else{
  201. // console.log('不是明天');
  202. return false
  203. }
  204. }
  205. }
  206. const changeTime = (t1) => {
  207. // console.log(t1)
  208. // t1截止时间 t2当前时间
  209. // 调用getDtes函数把当前时间传过去,获取本周一和本周日时间戳
  210. // var weeks = getDates(t2)
  211. var weeks = getDates()
  212. // console.log(weeks)
  213. var dateBegin = new Date(t1.replace(/-/g,'/'))//解决ios时new Date(2021-04-17 09:50:20)报错
  214. // var dateEnd = new Date(t2)
  215. var dateEnd = new Date()
  216. // 时间戳
  217. var end = dateBegin.getTime()
  218. // console.log(end)
  219. var nows = dateEnd.getTime()
  220. // console.log(nows)
  221. // 获取当天0点时间戳todayStar
  222. const start = new Date(new Date(dateEnd).toLocaleDateString())
  223. start.setTime(start.getTime())
  224. var todayStar = new Date(start).getTime()
  225. // console.log(todayStar)
  226. // 获取当天23点59分59秒时间戳todayEnd
  227. var ends = new Date(new Date(new Date(dateEnd).toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)
  228. var todayEnd = new Date(ends).getTime()
  229. // console.log(todayEnd)
  230. // 时间差的毫秒数
  231. var dateDiff = Math.abs(dateBegin.getTime() - dateEnd.getTime())
  232. // 计算出相差天数
  233. var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000))
  234. // console.log(dayDiff);
  235. // 计算天数后剩余的毫秒数
  236. var leave1 = dateDiff % (24 * 3600 * 1000)
  237. // 计算出小时数
  238. var hours = Math.floor(leave1 / (3600 * 1000))
  239. // console.log(hours);
  240. // 计算相差分钟数
  241. var leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数
  242. // 计算相差分钟数
  243. var minutes = Math.floor(leave2 / (60 * 1000))
  244. // console.log(minutes);
  245. // t1截止时间 t2当前时间
  246. if (dateEnd < dateBegin) {
  247. if ((dayDiff === 0)) {
  248. if (hours === 0) {
  249. if (minutes < 30 || minutes == 30) {
  250. return minutes + '分钟后'
  251. }else{
  252. return '今天' + t1.substring(10, 16)
  253. }
  254. } else {
  255. if (isToday(end,0)) {
  256. return '今天' + t1.substring(10, 16)
  257. }else{
  258. return '明天' + t1.substring(10, 16)
  259. }
  260. }
  261. } else if (dayDiff === 1) {
  262. if (isToday(end,2)){
  263. return '明天' + t1.substring(10, 16)
  264. }else{
  265. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  266. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  267. var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date
  268. return '周' + week + t1.substring(10, 16)
  269. } else {
  270. return t1.substring(0, 16).replace(/-/g, '/')
  271. }
  272. }
  273. } else {
  274. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  275. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  276. var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date
  277. return '周' + week + t1.substring(10, 16)
  278. } else {
  279. return t1.substring(0, 16).replace(/-/g, '/')
  280. }
  281. }
  282. }
  283. if (dateEnd === dateBegin) {
  284. return '刚刚'
  285. }
  286. if (dateEnd > dateBegin) {
  287. if (dayDiff === 0) {
  288. if (hours === 0) {
  289. if (minutes < 60 || minutes == 60) {
  290. if (minutes < 5 || minutes == 5) {
  291. return '刚刚'
  292. } else {
  293. return minutes + '分钟前'
  294. }
  295. } else {
  296. return '今天' + t1.substring(10, 16)
  297. }
  298. } else {
  299. if (isToday(end,0)) {
  300. return hours+'小时前'
  301. }else{
  302. return '昨天' + t1.substring(10, 16)
  303. }
  304. }
  305. } else if (dayDiff === 1) {
  306. if (isToday(end,1)){
  307. // return '昨天' + t1.substring(10, 16)
  308. return dayDiff + '天前'
  309. }else{
  310. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  311. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  312. var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date
  313. return '周' + week + t1.substring(10, 16)
  314. } else {
  315. return t1.substring(0, 16).replace(/-/g, '/')
  316. }
  317. }
  318. }else if (dayDiff < 30){
  319. // return dayDiff +'天前'+ t1.substring(10, 16)
  320. return dayDiff +'天前'
  321. }else if (dayDiff > 30 && dayDiff < 365){
  322. return t1.substring(5, 10)
  323. }else if (dayDiff > 365){
  324. return t1.substring(0, 4)
  325. }else {
  326. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  327. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  328. var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date
  329. return '周' + week + t1.substring(10, 16)
  330. } else {
  331. return t1.substring(0, 16).replace(/-/g, '/')
  332. }
  333. }
  334. }
  335. }
  336. //获取省份简称
  337. const getProvinceAbbreviation = (province) => {
  338. if (province == "北京市" || province == "北京")
  339. return "京";
  340. else if (province == "天津市" || province == "天津")
  341. return "津";
  342. else if (province == "重庆市" || province == "重庆")
  343. return "渝";
  344. else if (province == "上海市" || province == "上海")
  345. return "沪";
  346. else if (province == "河北省" || province == "河北")
  347. return "冀";
  348. else if (province == "山西省" || province == "山西")
  349. return "晋";
  350. else if (province == "辽宁省" || province == "辽宁")
  351. return "辽";
  352. else if (province == "吉林省" || province == "吉林")
  353. return "吉";
  354. else if (province == "黑龙江省" || province == "黑龙江")
  355. return "黑";
  356. else if (province == "江苏省" || province == "江苏")
  357. return "苏";
  358. else if (province == "浙江省" || province == "浙江")
  359. return "浙";
  360. else if (province == "安徽省" || province == "安徽")
  361. return "皖";
  362. else if (province == "福建省" || province == "福建")
  363. return "闽";
  364. else if (province == "江西省" || province == "江西")
  365. return "赣";
  366. else if (province == "山东省" || province == "山东")
  367. return "鲁";
  368. else if (province == "河南省" || province == "河南")
  369. return "豫";
  370. else if (province == "湖北省" || province == "湖北")
  371. return "鄂";
  372. else if (province == "湖南省" || province == "湖南")
  373. return "湘";
  374. else if (province == "广东省" || province == "广东")
  375. return "粤";
  376. else if (province == "海南省" || province == "海南")
  377. return "琼";
  378. else if (province == "四川省" || province == "四川")
  379. return "川";
  380. else if (province == "贵州省" || province == "贵州")
  381. return "贵";
  382. else if (province == "云南省" || province == "云南")
  383. return "云";
  384. else if (province == "陕西省" || province == "陕西")
  385. return "陕";
  386. else if (province == "甘肃省" || province == "甘肃")
  387. return "甘";
  388. else if (province == "青海省" || province == "青海")
  389. return "青";
  390. else if (province == "台湾省" || province == "台湾")
  391. return "台";
  392. else if (province == "内蒙古自治区" || province == "内蒙古")
  393. return "蒙";
  394. else if (province == "广西壮族自治区" || province == "广西")
  395. return "桂";
  396. else if (province == "宁夏回族自治区" || province == "宁夏")
  397. return "宁";
  398. else if (province == "新疆维吾尔自治区" || province == "新疆")
  399. return "新";
  400. else if (province == "西藏自治区" || province == "西藏")
  401. return "藏";
  402. else if (province == "香港特别行政区" || province == "香港")
  403. return "港";
  404. else if (province == "澳门特别行政区" || province == "澳门")
  405. return "澳";
  406. }
  407. export default {
  408. getListByUserId,
  409. setAudit,
  410. ossUploadUrl,
  411. contactCustomerService,
  412. chooseImage,
  413. imgType,
  414. imgTypeList,
  415. makeValidityPeriod,
  416. getProvinceAbbreviation,
  417. filterUrban,
  418. filterArea,
  419. fUN_AmapLocation,
  420. changeTime,
  421. gjList
  422. }