helper.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import * as config from '../config'
  2. const rolesList = []
  3. const ossUploadUrl = 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/';
  4. const chooseImage = {
  5. count: '1',
  6. sizeType: ['original', 'compressed'],
  7. sourceType: ['album'],
  8. }
  9. const imgType = '请选择图片来源'
  10. const imgTypeList = [{
  11. name: '相册',
  12. },
  13. {
  14. name: '拍照',
  15. }
  16. ]
  17. const makeValidityPeriod = function(type,name) {
  18. //获取当前年
  19. let nowDate = new Date();
  20. let year = nowDate.getFullYear()
  21. let _list = []
  22. let _list1 = []
  23. // let _list2 = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
  24. let _list2 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
  25. let _list3 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
  26. "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
  27. "31"
  28. ]
  29. let _ValidityPeriod = []
  30. for (let i = 0; i < 30; i++) {
  31. _list1.push(year + i)
  32. }
  33. if (type == 0) {
  34. _list1.unshift(name)
  35. _list2.unshift('')
  36. _list3.unshift('')
  37. }
  38. _list.push(_list1, _list2, _list3)
  39. return _list
  40. }
  41. const getListByUserId = function() {
  42. let baseUrlNew = config.def().baseUrlNew
  43. var userInfo = uni.getStorageSync("userInfo")
  44. console.log("------", userInfo)
  45. if (userInfo) {
  46. uni.request({
  47. url: baseUrlNew + '/roleMenu/query/getListByUserId',
  48. data: {
  49. userId: userInfo.id ? userInfo.id : userInfo.data.id
  50. },
  51. method: 'GET',
  52. success: (res) => {
  53. if (res.statusCode === 200) {
  54. uni.setStorageSync("jurisdiction", res.data.data)
  55. let list = getUserAllRoles(res.data.data);
  56. uni.setStorageSync("rolesList", list)
  57. }
  58. }
  59. })
  60. }
  61. }
  62. const getUserAllRoles = (item) => {
  63. console.log(item)
  64. for (let i = 0; i < item.length; i++) {
  65. rolesList.push(item[i].name)
  66. // console.log('用户权限',rolesList)
  67. if (item[i].children && item[i].children.length > 0) {
  68. getUserAllRoles(item[i].children)
  69. }
  70. }
  71. return rolesList;
  72. }
  73. const setAudit = (item) => {
  74. let _list = uni.getStorageSync("copyTaskInfo")
  75. let _isShowbtn = true
  76. if (_list.length == 0) {
  77. _isShowbtn = false
  78. }
  79. for (let i = 0; i < _list.length; i++) {
  80. if (_list[i].businessId == item.id) {
  81. _list.splice(i, 1)
  82. uni.setStorageSync("copyTaskInfo", _list)
  83. }
  84. }
  85. if (_list.length > 0) {
  86. uni.navigateTo({
  87. url: _list[0].itemUrl + '&isShowbtn=' + _isShowbtn,
  88. })
  89. }
  90. console.log(item)
  91. }
  92. const contactCustomerService = (item) => {
  93. console.log(item)
  94. console.log("联系客服")
  95. uni.makePhoneCall({
  96. phoneNumber: '114' //仅为示例
  97. });
  98. }
  99. // const getAddress = (item) => {
  100. // let regex = "(?<province>[^省]+省|.+自治区)(?<city>[^自治州]+自治州|[^市]+市|[^盟]+盟|[^地区]+地区|.+区划)(?<county>[^市]+市|[^县]+县|[^旗]+旗|.+区)?(?<town>[^区]+区|.+镇)?(?<village>.*)";
  101. // return item.match(regex).groups
  102. // }
  103. const formatLocation = (res) => {
  104. var regex = /^(北京市|天津市|重庆市|上海市|香港特别行政区|澳门特别行政区)/;
  105. var REGION_PROVINCE = [];
  106. var addressBean = {
  107. REGION_PROVINCE: null,
  108. REGION_COUNTRY: null,
  109. REGION_CITY: null,
  110. ADDRESS: null
  111. };
  112. function regexAddressBean(address, addressBean) {
  113. // regex = /^(.*?[市州]|.*?地区|.*?特别行政区)(.*?[市区县])(.*?)$/g;
  114. regex = /^(.*?[市]|.*?地区|.*?特别行政区)(.*?[市区县])(.*?)$/g;
  115. var addxress = regex.exec(address);
  116. addressBean.REGION_CITY = addxress[1];
  117. addressBean.REGION_COUNTRY = addxress[2];
  118. addressBean.ADDRESS = addxress[3] + "(" + res.name + ")";
  119. // console.log(addxress);
  120. };
  121. if (!(REGION_PROVINCE = regex.exec(res.address))) {
  122. regex = /^(.*?(省|自治区))(.*?)$/;
  123. REGION_PROVINCE = regex.exec(res.address);
  124. addressBean.REGION_PROVINCE = REGION_PROVINCE[1];
  125. regexAddressBean(REGION_PROVINCE[3], addressBean);
  126. } else {
  127. addressBean.REGION_PROVINCE = REGION_PROVINCE[1];
  128. regexAddressBean(res.address, addressBean);
  129. }
  130. return addressBean
  131. }
  132. //获取省份简称
  133. const getProvinceAbbreviation = (province) => {
  134. // console.log(province)
  135. if (province == "北京市" || province == "北京")
  136. return "京";
  137. else if (province == "天津市" || province == "天津")
  138. return "津";
  139. else if (province == "重庆市" || province == "重庆")
  140. return "渝";
  141. else if (province == "上海市" || province == "上海")
  142. return "沪";
  143. else if (province == "河北省" || province == "河北")
  144. return "冀";
  145. else if (province == "山西省" || province == "山西")
  146. return "晋";
  147. else if (province == "辽宁省" || province == "辽宁")
  148. return "辽";
  149. else if (province == "吉林省" || province == "吉林")
  150. return "吉";
  151. else if (province == "黑龙江省" || province == "黑龙江")
  152. return "黑";
  153. else if (province == "江苏省" || province == "江苏")
  154. return "苏";
  155. else if (province == "浙江省" || province == "浙江")
  156. return "浙";
  157. else if (province == "安徽省" || province == "安徽")
  158. return "皖";
  159. else if (province == "福建省" || province == "福建")
  160. return "闽";
  161. else if (province == "江西省" || province == "江西")
  162. return "赣";
  163. else if (province == "山东省" || province == "山东")
  164. return "鲁";
  165. else if (province == "河南省" || province == "河南")
  166. return "豫";
  167. else if (province == "湖北省" || province == "湖北")
  168. return "鄂";
  169. else if (province == "湖南省" || province == "湖南")
  170. return "湘";
  171. else if (province == "广东省" || province == "广东")
  172. return "粤";
  173. else if (province == "海南省" || province == "海南")
  174. return "琼";
  175. else if (province == "四川省" || province == "四川")
  176. return "川";
  177. else if (province == "贵州省" || province == "贵州")
  178. return "贵";
  179. else if (province == "云南省" || province == "云南")
  180. return "云";
  181. else if (province == "陕西省" || province == "陕西")
  182. return "陕";
  183. else if (province == "甘肃省" || province == "甘肃")
  184. return "甘";
  185. else if (province == "青海省" || province == "青海")
  186. return "青";
  187. else if (province == "台湾省" || province == "台湾")
  188. return "台";
  189. else if (province == "内蒙古自治区" || province == "内蒙古")
  190. return "蒙";
  191. else if (province == "广西壮族自治区" || province == "广西")
  192. return "桂";
  193. else if (province == "宁夏回族自治区" || province == "宁夏")
  194. return "宁";
  195. else if (province == "新疆维吾尔自治区" || province == "新疆")
  196. return "新";
  197. else if (province == "西藏自治区" || province == "西藏")
  198. return "藏";
  199. else if (province == "香港特别行政区" || province == "香港")
  200. return "港";
  201. else if (province == "澳门特别行政区" || province == "澳门")
  202. return "澳";
  203. }
  204. export default {
  205. getListByUserId,
  206. setAudit,
  207. ossUploadUrl,
  208. contactCustomerService,
  209. chooseImage,
  210. imgType,
  211. imgTypeList,
  212. makeValidityPeriod,
  213. getProvinceAbbreviation,
  214. // getAddress,
  215. formatLocation
  216. }