helper.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. import * as config from '../config'
  2. const selectContractNo = {}
  3. const detailData = {}
  4. const erpWarehouse = {}
  5. let rolesList = []
  6. const gjList = []
  7. const dtList = []
  8. const now = Date.now || function() {
  9. return new Date().getTime();
  10. };
  11. const isArray = Array.isArray || function(obj) {
  12. return obj instanceof Array;
  13. };
  14. const getListByUserId = function() {
  15. let baseUrlNew = config.def().baseUrlNew
  16. var userInfo = uni.getStorageSync("userInfo")
  17. var pcUserInfo = uni.getStorageSync("pcUserInfo")
  18. console.log("------", userInfo)
  19. if (pcUserInfo) {
  20. uni.request({
  21. url: baseUrlNew + '/commonUser/getListByUserId',
  22. data: {
  23. staffMobilePhone: pcUserInfo.userMobilePhone,
  24. compId: pcUserInfo.compId
  25. },
  26. method: 'POST',
  27. success: (res) => {
  28. if (res.statusCode === 200) {
  29. // debugger
  30. rolesList = []
  31. uni.setStorageSync("jurisdiction", res.data.data)
  32. let list = getUserAllRoles(res.data.data);
  33. uni.setStorageSync("rolesList", list)
  34. }
  35. }
  36. })
  37. }
  38. }
  39. const getUserAllRoles = (item) => {
  40. console.log(item)
  41. // debugger
  42. for (let i = 0; i < item.length; i++) {
  43. rolesList.push(item[i].name)
  44. // console.log('用户权限',rolesList)
  45. if (item[i].children && item[i].children.length > 0) {
  46. getUserAllRoles(item[i].children)
  47. }
  48. }
  49. return rolesList;
  50. }
  51. const contactCustomerService = (phone) => {
  52. console.log(phone)
  53. //客服
  54. if (!phone) {
  55. phone = '18241771147'
  56. }
  57. const res = uni.getSystemInfoSync();
  58. // ios系统默认有个模态框
  59. if (res.platform == 'ios') {
  60. uni.makePhoneCall({
  61. phoneNumber: phone,
  62. success() {
  63. console.log('拨打成功了');
  64. },
  65. fail() {
  66. console.log('拨打失败了');
  67. }
  68. })
  69. } else {
  70. //安卓手机手动设置一个showActionSheet
  71. uni.showActionSheet({
  72. itemList: [phone, '呼叫'],
  73. success: function(res) {
  74. console.log(res);
  75. if (res.tapIndex == 1) {
  76. uni.makePhoneCall({
  77. phoneNumber: phone,
  78. success: (res) => {
  79. console.log('调用成功!')
  80. },
  81. // 失败回调
  82. fail: (res) => {
  83. console.log('调用失败!')
  84. // contactCustomerService(item)
  85. }
  86. })
  87. }
  88. }
  89. })
  90. }
  91. // console.log("联系客服")
  92. // uni.makePhoneCall({
  93. // phoneNumber: item,
  94. // success: (res) => {
  95. // console.log('调用成功!')
  96. // },
  97. // // 失败回调
  98. // fail: (res) => {
  99. // console.log('调用失败!')
  100. // contactCustomerService(item)
  101. // }
  102. // });
  103. }
  104. const setAudit = (item) => {
  105. let _list = uni.getStorageSync("copyTaskInfo")
  106. let _isShowbtn = true
  107. if (_list.length == 0) {
  108. _isShowbtn = false
  109. }
  110. for (let i = 0; i < _list.length; i++) {
  111. if (_list[i].businessId == item.id) {
  112. _list.splice(i, 1)
  113. uni.setStorageSync("copyTaskInfo", _list)
  114. }
  115. }
  116. if (_list.length > 0) {
  117. uni.navigateTo({
  118. url: _list[0].itemUrl + '&isShowbtn=' + _isShowbtn,
  119. })
  120. }
  121. console.log(item)
  122. }
  123. //获取当天日期
  124. const getNowFormatDate = () => {
  125. var date = new Date();
  126. var seperator1 = "-";
  127. var year = date.getFullYear();
  128. var month = date.getMonth() + 1;
  129. var strDate = date.getDate();
  130. if (month >= 1 && month <= 9) {
  131. month = "0" + month;
  132. }
  133. if (strDate >= 0 && strDate <= 9) {
  134. strDate = "0" + strDate;
  135. }
  136. var currentdate = year + seperator1 + month + seperator1 + strDate;
  137. return currentdate;
  138. }
  139. //获取当天+N日期
  140. const getNowNumFormatDate = (num) => {
  141. var date = new Date();
  142. var seperator1 = "-";
  143. var year = date.getFullYear();
  144. var month = date.getMonth() + 1;
  145. var strDate = date.getDate() + num;
  146. if (month >= 1 && month <= 9) {
  147. month = "0" + month;
  148. }
  149. if (strDate >= 0 && strDate <= 9) {
  150. strDate = "0" + strDate;
  151. }
  152. var currentdate = year + seperator1 + month + seperator1 + strDate;
  153. return currentdate;
  154. }
  155. const convertCurrency = (money) => {
  156. //汉字的数字
  157. var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
  158. //基本单位
  159. var cnIntRadice = new Array('', '拾', '佰', '仟');
  160. //对应整数部分扩展单位
  161. var cnIntUnits = new Array('', '万', '亿', '兆');
  162. //对应小数部分单位
  163. var cnDecUnits = new Array('角', '分', '毫', '厘');
  164. //整数金额时后面跟的字符
  165. var cnInteger = '整';
  166. //整型完以后的单位
  167. var cnIntLast = '元';
  168. //最大处理的数字
  169. var maxNum = 999999999999999.9999;
  170. //金额整数部分
  171. var integerNum;
  172. //金额小数部分
  173. var decimalNum;
  174. //输出的中文金额字符串
  175. var chineseStr = '';
  176. //分离金额后用的数组,预定义
  177. var parts;
  178. if (money == '') {
  179. return '';
  180. }
  181. money = parseFloat(money);
  182. if (money >= maxNum) {
  183. //超出最大处理数字
  184. return '';
  185. }
  186. if (money == 0) {
  187. chineseStr = cnNums[0] + cnIntLast + cnInteger;
  188. return chineseStr;
  189. }
  190. //转换为字符串
  191. money = money.toString();
  192. if (money.indexOf('.') == -1) {
  193. integerNum = money;
  194. decimalNum = '';
  195. } else {
  196. parts = money.split('.');
  197. integerNum = parts[0];
  198. decimalNum = parts[1].substr(0, 4);
  199. }
  200. //获取整型部分转换
  201. if (parseInt(integerNum, 10) > 0) {
  202. var zeroCount = 0;
  203. var IntLen = integerNum.length;
  204. for (var i = 0; i < IntLen; i++) {
  205. var n = integerNum.substr(i, 1);
  206. var p = IntLen - i - 1;
  207. var q = p / 4;
  208. var m = p % 4;
  209. if (n == '0') {
  210. zeroCount++;
  211. } else {
  212. if (zeroCount > 0) {
  213. chineseStr += cnNums[0];
  214. }
  215. //归零
  216. zeroCount = 0;
  217. chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
  218. }
  219. if (m == 0 && zeroCount < 4) {
  220. chineseStr += cnIntUnits[q];
  221. }
  222. }
  223. chineseStr += cnIntLast;
  224. }
  225. //小数部分
  226. if (decimalNum != '') {
  227. var decLen = decimalNum.length;
  228. for (var i = 0; i < decLen; i++) {
  229. var n = decimalNum.substr(i, 1);
  230. if (n != '0') {
  231. chineseStr += cnNums[Number(n)] + cnDecUnits[i];
  232. }
  233. }
  234. }
  235. if (chineseStr == '') {
  236. chineseStr += cnNums[0] + cnIntLast + cnInteger;
  237. } else if (decimalNum == '') {
  238. chineseStr += cnInteger;
  239. }
  240. return chineseStr;
  241. }
  242. //获取省份简称
  243. const getProvinceAbbreviation = (province) => {
  244. if (province == "北京市" || province == "北京")
  245. return "京";
  246. else if (province == "天津市" || province == "天津")
  247. return "津";
  248. else if (province == "重庆市" || province == "重庆")
  249. return "渝";
  250. else if (province == "上海市" || province == "上海")
  251. return "沪";
  252. else if (province == "河北省" || province == "河北")
  253. return "冀";
  254. else if (province == "山西省" || province == "山西")
  255. return "晋";
  256. else if (province == "辽宁省" || province == "辽宁")
  257. return "辽";
  258. else if (province == "吉林省" || province == "吉林")
  259. return "吉";
  260. else if (province == "黑龙江省" || province == "黑龙江")
  261. return "黑";
  262. else if (province == "江苏省" || province == "江苏")
  263. return "苏";
  264. else if (province == "浙江省" || province == "浙江")
  265. return "浙";
  266. else if (province == "安徽省" || province == "安徽")
  267. return "皖";
  268. else if (province == "福建省" || province == "福建")
  269. return "闽";
  270. else if (province == "江西省" || province == "江西")
  271. return "赣";
  272. else if (province == "山东省" || province == "山东")
  273. return "鲁";
  274. else if (province == "河南省" || province == "河南")
  275. return "豫";
  276. else if (province == "湖北省" || province == "湖北")
  277. return "鄂";
  278. else if (province == "湖南省" || province == "湖南")
  279. return "湘";
  280. else if (province == "广东省" || province == "广东")
  281. return "粤";
  282. else if (province == "海南省" || province == "海南")
  283. return "琼";
  284. else if (province == "四川省" || province == "四川")
  285. return "川";
  286. else if (province == "贵州省" || province == "贵州")
  287. return "贵";
  288. else if (province == "云南省" || province == "云南")
  289. return "云";
  290. else if (province == "陕西省" || province == "陕西")
  291. return "陕";
  292. else if (province == "甘肃省" || province == "甘肃")
  293. return "甘";
  294. else if (province == "青海省" || province == "青海")
  295. return "青";
  296. else if (province == "台湾省" || province == "台湾")
  297. return "台";
  298. else if (province == "内蒙古自治区" || province == "内蒙古")
  299. return "蒙";
  300. else if (province == "广西壮族自治区" || province == "广西")
  301. return "桂";
  302. else if (province == "宁夏回族自治区" || province == "宁夏")
  303. return "宁";
  304. else if (province == "新疆维吾尔自治区" || province == "新疆")
  305. return "新";
  306. else if (province == "西藏自治区" || province == "西藏")
  307. return "藏";
  308. else if (province == "香港特别行政区" || province == "香港")
  309. return "港";
  310. else if (province == "澳门特别行政区" || province == "澳门")
  311. return "澳";
  312. }
  313. // 获取市、区简称
  314. const filterUrban = (s) => {
  315. if(s){
  316. if (s.lastIndexOf('市') != -1) {
  317. return s.substring(0, s.length - 1)
  318. }
  319. return s
  320. }
  321. return ''
  322. }
  323. const filterArea = (q) => {
  324. if(q){
  325. if (q.lastIndexOf('区') != -1) {
  326. return q.substring(0, q.length - 1)
  327. }
  328. return q
  329. }
  330. return ''
  331. }
  332. const fUN_AmapLocation = uni.requireNativePlugin('FUN-AmapLocation');
  333. function getDates() {
  334. // var new_Date = new Date(t2)
  335. var new_Date = new Date()
  336. var timesStamp = new_Date.getTime()
  337. var currenDay = new_Date.getDay()
  338. var dates = []
  339. for (var i = 0; i < 7; i++) {
  340. dates.push(new Date(timesStamp + 24 * 60 * 60 * 1000 * (i - (currenDay + 6) % 7)).toLocaleDateString().replace(
  341. /[年月]/g, '-').replace(/[日上下午]/g, ''));
  342. }
  343. var weekStar = new Date(dates[0] + ' 00:00:00').getTime()
  344. var weekEnd = new Date(dates[dates.length - 1] + ' 23:59:59').getTime()
  345. var week = [weekStar, weekEnd]
  346. return week
  347. }
  348. //判断是否是今天,昨天,明天
  349. function isToday(str, type) {
  350. //type == 0 判断是否是今天,type == 1 判断是否是昨天,type == 2 判断是否是明天
  351. if (type == 0) {
  352. if (new Date(str).toDateString() === new Date().toDateString()) {
  353. // console.log('今天');
  354. return true
  355. } else {
  356. // console.log('不是今天');
  357. return false
  358. }
  359. }
  360. if (type == 1) {
  361. if (new Date(str).toDateString() === new Date(new Date().getTime() - 1000 * 60 * 60 * 24).toDateString()) {
  362. // console.log('昨天');
  363. return true
  364. } else {
  365. // console.log('不是昨天');
  366. return false
  367. }
  368. }
  369. if (type == 2) {
  370. if (new Date(str).toDateString() === new Date(new Date().getTime() + 1000 * 60 * 60 * 24).toDateString()) {
  371. // console.log('明天');
  372. return true
  373. } else {
  374. // console.log('不是明天');
  375. return false
  376. }
  377. }
  378. }
  379. const changeTime = (t1) => {
  380. // console.log(t1)
  381. // t1截止时间 t2当前时间
  382. // 调用getDtes函数把当前时间传过去,获取本周一和本周日时间戳
  383. // var weeks = getDates(t2)
  384. var weeks = getDates()
  385. // console.log(weeks)
  386. var dateBegin = new Date(t1.replace(/-/g, '/')) //解决ios时new Date(2021-04-17 09:50:20)报错
  387. // var dateEnd = new Date(t2)
  388. var dateEnd = new Date()
  389. // 时间戳
  390. var end = dateBegin.getTime()
  391. // console.log(end)
  392. var nows = dateEnd.getTime()
  393. // console.log(nows)
  394. // 获取当天0点时间戳todayStar
  395. const start = new Date(new Date(dateEnd).toLocaleDateString())
  396. start.setTime(start.getTime())
  397. var todayStar = new Date(start).getTime()
  398. // console.log(todayStar)
  399. // 获取当天23点59分59秒时间戳todayEnd
  400. var ends = new Date(new Date(new Date(dateEnd).toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)
  401. var todayEnd = new Date(ends).getTime()
  402. // console.log(todayEnd)
  403. // 时间差的毫秒数
  404. var dateDiff = Math.abs(dateBegin.getTime() - dateEnd.getTime())
  405. // 计算出相差天数
  406. var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000))
  407. // console.log(dayDiff);
  408. // 计算天数后剩余的毫秒数
  409. var leave1 = dateDiff % (24 * 3600 * 1000)
  410. // 计算出小时数
  411. var hours = Math.floor(leave1 / (3600 * 1000))
  412. // console.log(hours);
  413. // 计算相差分钟数
  414. var leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数
  415. // 计算相差分钟数
  416. var minutes = Math.floor(leave2 / (60 * 1000))
  417. // console.log(minutes);
  418. // t1截止时间 t2当前时间
  419. if (dateEnd < dateBegin) {
  420. if ((dayDiff === 0)) {
  421. if (hours === 0) {
  422. if (minutes < 30 || minutes == 30) {
  423. return minutes + '分钟后'
  424. } else {
  425. return '今天' + t1.substring(10, 16)
  426. }
  427. } else {
  428. if (isToday(end, 0)) {
  429. return '今天' + t1.substring(10, 16)
  430. } else {
  431. return '明天' + t1.substring(10, 16)
  432. }
  433. }
  434. } else if (dayDiff === 1) {
  435. if (isToday(end, 2)) {
  436. return '明天' + t1.substring(10, 16)
  437. } else {
  438. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  439. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  440. var week = weekArray[new Date(t1.replace(/-/g, '/')).getDay()] // 注意此处必须是先new一个Date
  441. return '周' + week + t1.substring(10, 16)
  442. } else {
  443. return t1.substring(0, 16).replace(/-/g, '/')
  444. }
  445. }
  446. } else {
  447. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  448. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  449. var week = weekArray[new Date(t1.replace(/-/g, '/')).getDay()] // 注意此处必须是先new一个Date
  450. return '周' + week + t1.substring(10, 16)
  451. } else {
  452. return t1.substring(0, 16).replace(/-/g, '/')
  453. }
  454. }
  455. }
  456. if (dateEnd === dateBegin) {
  457. return '刚刚'
  458. }
  459. if (dateEnd > dateBegin) {
  460. if (dayDiff === 0) {
  461. if (hours === 0) {
  462. if (minutes < 60 || minutes == 60) {
  463. if (minutes < 5 || minutes == 5) {
  464. return '刚刚'
  465. } else {
  466. return minutes + '分钟前'
  467. }
  468. } else {
  469. return '今天' + t1.substring(10, 16)
  470. }
  471. } else {
  472. if (isToday(end, 0)) {
  473. return hours + '小时前'
  474. } else {
  475. return '昨天' + t1.substring(10, 16)
  476. }
  477. }
  478. } else if (dayDiff === 1) {
  479. if (isToday(end, 1)) {
  480. // return '昨天' + t1.substring(10, 16)
  481. return dayDiff + '天前'
  482. } else {
  483. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  484. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  485. var week = weekArray[new Date(t1.replace(/-/g, '/')).getDay()] // 注意此处必须是先new一个Date
  486. return '周' + week + t1.substring(10, 16)
  487. } else {
  488. return t1.substring(0, 16).replace(/-/g, '/')
  489. }
  490. }
  491. } else if (dayDiff < 30) {
  492. // return dayDiff +'天前'+ t1.substring(10, 16)
  493. return dayDiff + '天前'
  494. } else if (dayDiff > 30 && dayDiff < 365) {
  495. return t1.substring(5, 10)
  496. } else if (dayDiff > 365) {
  497. return t1.substring(0, 4)
  498. } else {
  499. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  500. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  501. var week = weekArray[new Date(t1.replace(/-/g, '/')).getDay()] // 注意此处必须是先new一个Date
  502. return '周' + week + t1.substring(10, 16)
  503. } else {
  504. return t1.substring(0, 16).replace(/-/g, '/')
  505. }
  506. }
  507. }
  508. }
  509. export default {
  510. changeTime,
  511. detailData,
  512. selectContractNo,
  513. contactCustomerService,
  514. now,
  515. isArray,
  516. erpWarehouse,
  517. getListByUserId,
  518. setAudit,
  519. getNowFormatDate,
  520. getNowNumFormatDate,
  521. getProvinceAbbreviation,
  522. convertCurrency,
  523. filterUrban,
  524. filterArea,
  525. gjList,
  526. dtList,
  527. fUN_AmapLocation
  528. }