helper.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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.lastIndexOf('市') != -1) {
  316. return s.substring(0, s.length - 1)
  317. }
  318. return s
  319. }
  320. const filterArea = (q) => {
  321. if (q.lastIndexOf('区') != -1) {
  322. return q.substring(0, q.length - 1)
  323. }
  324. return q
  325. }
  326. const fUN_AmapLocation = uni.requireNativePlugin('FUN-AmapLocation');
  327. function getDates() {
  328. // var new_Date = new Date(t2)
  329. var new_Date = new Date()
  330. var timesStamp = new_Date.getTime()
  331. var currenDay = new_Date.getDay()
  332. var dates = []
  333. for (var i = 0; i < 7; i++) {
  334. dates.push(new Date(timesStamp + 24 * 60 * 60 * 1000 * (i - (currenDay + 6) % 7)).toLocaleDateString().replace(
  335. /[年月]/g, '-').replace(/[日上下午]/g, ''));
  336. }
  337. var weekStar = new Date(dates[0] + ' 00:00:00').getTime()
  338. var weekEnd = new Date(dates[dates.length - 1] + ' 23:59:59').getTime()
  339. var week = [weekStar, weekEnd]
  340. return week
  341. }
  342. //判断是否是今天,昨天,明天
  343. function isToday(str, type) {
  344. //type == 0 判断是否是今天,type == 1 判断是否是昨天,type == 2 判断是否是明天
  345. if (type == 0) {
  346. if (new Date(str).toDateString() === new Date().toDateString()) {
  347. // console.log('今天');
  348. return true
  349. } else {
  350. // console.log('不是今天');
  351. return false
  352. }
  353. }
  354. if (type == 1) {
  355. if (new Date(str).toDateString() === new Date(new Date().getTime() - 1000 * 60 * 60 * 24).toDateString()) {
  356. // console.log('昨天');
  357. return true
  358. } else {
  359. // console.log('不是昨天');
  360. return false
  361. }
  362. }
  363. if (type == 2) {
  364. if (new Date(str).toDateString() === new Date(new Date().getTime() + 1000 * 60 * 60 * 24).toDateString()) {
  365. // console.log('明天');
  366. return true
  367. } else {
  368. // console.log('不是明天');
  369. return false
  370. }
  371. }
  372. }
  373. const changeTime = (t1) => {
  374. // console.log(t1)
  375. // t1截止时间 t2当前时间
  376. // 调用getDtes函数把当前时间传过去,获取本周一和本周日时间戳
  377. // var weeks = getDates(t2)
  378. var weeks = getDates()
  379. // console.log(weeks)
  380. var dateBegin = new Date(t1.replace(/-/g, '/')) //解决ios时new Date(2021-04-17 09:50:20)报错
  381. // var dateEnd = new Date(t2)
  382. var dateEnd = new Date()
  383. // 时间戳
  384. var end = dateBegin.getTime()
  385. // console.log(end)
  386. var nows = dateEnd.getTime()
  387. // console.log(nows)
  388. // 获取当天0点时间戳todayStar
  389. const start = new Date(new Date(dateEnd).toLocaleDateString())
  390. start.setTime(start.getTime())
  391. var todayStar = new Date(start).getTime()
  392. // console.log(todayStar)
  393. // 获取当天23点59分59秒时间戳todayEnd
  394. var ends = new Date(new Date(new Date(dateEnd).toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)
  395. var todayEnd = new Date(ends).getTime()
  396. // console.log(todayEnd)
  397. // 时间差的毫秒数
  398. var dateDiff = Math.abs(dateBegin.getTime() - dateEnd.getTime())
  399. // 计算出相差天数
  400. var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000))
  401. // console.log(dayDiff);
  402. // 计算天数后剩余的毫秒数
  403. var leave1 = dateDiff % (24 * 3600 * 1000)
  404. // 计算出小时数
  405. var hours = Math.floor(leave1 / (3600 * 1000))
  406. // console.log(hours);
  407. // 计算相差分钟数
  408. var leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数
  409. // 计算相差分钟数
  410. var minutes = Math.floor(leave2 / (60 * 1000))
  411. // console.log(minutes);
  412. // t1截止时间 t2当前时间
  413. if (dateEnd < dateBegin) {
  414. if ((dayDiff === 0)) {
  415. if (hours === 0) {
  416. if (minutes < 30 || minutes == 30) {
  417. return minutes + '分钟后'
  418. } else {
  419. return '今天' + t1.substring(10, 16)
  420. }
  421. } else {
  422. if (isToday(end, 0)) {
  423. return '今天' + t1.substring(10, 16)
  424. } else {
  425. return '明天' + t1.substring(10, 16)
  426. }
  427. }
  428. } else if (dayDiff === 1) {
  429. if (isToday(end, 2)) {
  430. return '明天' + t1.substring(10, 16)
  431. } else {
  432. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  433. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  434. var week = weekArray[new Date(t1.replace(/-/g, '/')).getDay()] // 注意此处必须是先new一个Date
  435. return '周' + week + t1.substring(10, 16)
  436. } else {
  437. return t1.substring(0, 16).replace(/-/g, '/')
  438. }
  439. }
  440. } else {
  441. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  442. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  443. var week = weekArray[new Date(t1.replace(/-/g, '/')).getDay()] // 注意此处必须是先new一个Date
  444. return '周' + week + t1.substring(10, 16)
  445. } else {
  446. return t1.substring(0, 16).replace(/-/g, '/')
  447. }
  448. }
  449. }
  450. if (dateEnd === dateBegin) {
  451. return '刚刚'
  452. }
  453. if (dateEnd > dateBegin) {
  454. if (dayDiff === 0) {
  455. if (hours === 0) {
  456. if (minutes < 60 || minutes == 60) {
  457. if (minutes < 5 || minutes == 5) {
  458. return '刚刚'
  459. } else {
  460. return minutes + '分钟前'
  461. }
  462. } else {
  463. return '今天' + t1.substring(10, 16)
  464. }
  465. } else {
  466. if (isToday(end, 0)) {
  467. return hours + '小时前'
  468. } else {
  469. return '昨天' + t1.substring(10, 16)
  470. }
  471. }
  472. } else if (dayDiff === 1) {
  473. if (isToday(end, 1)) {
  474. // return '昨天' + t1.substring(10, 16)
  475. return dayDiff + '天前'
  476. } else {
  477. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  478. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  479. var week = weekArray[new Date(t1.replace(/-/g, '/')).getDay()] // 注意此处必须是先new一个Date
  480. return '周' + week + t1.substring(10, 16)
  481. } else {
  482. return t1.substring(0, 16).replace(/-/g, '/')
  483. }
  484. }
  485. } else if (dayDiff < 30) {
  486. // return dayDiff +'天前'+ t1.substring(10, 16)
  487. return dayDiff + '天前'
  488. } else if (dayDiff > 30 && dayDiff < 365) {
  489. return t1.substring(5, 10)
  490. } else if (dayDiff > 365) {
  491. return t1.substring(0, 4)
  492. } else {
  493. if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
  494. var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
  495. var week = weekArray[new Date(t1.replace(/-/g, '/')).getDay()] // 注意此处必须是先new一个Date
  496. return '周' + week + t1.substring(10, 16)
  497. } else {
  498. return t1.substring(0, 16).replace(/-/g, '/')
  499. }
  500. }
  501. }
  502. }
  503. export default {
  504. changeTime,
  505. detailData,
  506. selectContractNo,
  507. contactCustomerService,
  508. now,
  509. isArray,
  510. erpWarehouse,
  511. getListByUserId,
  512. setAudit,
  513. getNowFormatDate,
  514. getNowNumFormatDate,
  515. getProvinceAbbreviation,
  516. convertCurrency,
  517. filterUrban,
  518. filterArea,
  519. gjList,
  520. dtList,
  521. fUN_AmapLocation
  522. }