templateMethod.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. var app = getApp(); //获取应用实例
  2. const util = require('@/static/utils/util.js');
  3. const config = require('@/static/config.js');
  4. import requestConfig from '@/static/lib/requestConfig';
  5. import Bus from '@/common/bus';
  6. export default {
  7. data(){
  8. return {
  9. doubleClick:false,
  10. height: 0,
  11. selfTabbarBottom: '0px',
  12. computerHeight: 'calc(100vh - 58px)',
  13. statusBarHeight: 0,
  14. _scrollDistance: 0, //滑动的距离
  15. showShareOptions: false,
  16. showOption: true,
  17. }
  18. },
  19. watch:{
  20. },
  21. methods:{
  22. scrollExp(e) {
  23. if (e.detail) {
  24. this._scrollDistance = e.detail.scrollTop;
  25. if (this._scrollDistance >= 30) {
  26. this.showNav = true;
  27. if(this.hasOwnProperty('myNavBarData') && this.myNavBarData){
  28. this.myNavBarData.navBarColor = (this.globalCityListConfig && this.globalCityListConfig.backgroundColor) ? this.globalCityListConfig.backgroundColor: '#fff';
  29. if(!this.currentData){
  30. this.pageThemeColor = {
  31. textColor1:'#000'
  32. };
  33. }
  34. this.myNavBarData.titleColor = this.pageThemeColor.textColor1;
  35. this.myNavBarData.title = "城市列表";
  36. }
  37. } else {
  38. this.showNav = false;
  39. if(this.hasOwnProperty('myNavBarData') && this.myNavBarData){
  40. this.myNavBarData.navBarColor = 0;
  41. this.myNavBarData.titleColor = '#fff';
  42. this.myNavBarData.title = "";
  43. if(!this.currentData){
  44. this.pageThemeColor = {
  45. textColor1:'#fff'
  46. };
  47. }
  48. }
  49. }
  50. }
  51. },
  52. //顶部搜索按钮
  53. goToSearch(type=1) {
  54. // let url = '/subPackage/pages/searchCondition/searchCondition';
  55. let url = "/subPackage/pages/searchNewModule/searchNewModule";
  56. if(type==2){//新版的搜索页面
  57. url = "/subPackage/pages/searchNewModule/searchNewModule"
  58. }
  59. uni.navigateTo({
  60. url: url,
  61. success: () => {},
  62. });
  63. },
  64. //切换城市
  65. navigateToCity(e) {
  66. uni.navigateTo({
  67. url: '/subPackage/pages/addressModule/addressModule'
  68. });
  69. },
  70. //跳转到筛选页面
  71. // navigateToSearch(type) {
  72. // var _url = '/pages/screenSearchListModule/screenSearchListModule';
  73. // if (type) {
  74. // _url = _url + "?openType=" + type;
  75. // }
  76. // uni.navigateTo({
  77. // url: _url
  78. // });
  79. // },
  80. navigateFuc(e) {
  81. let eventOption = {};
  82. if (e) {
  83. // this.$emit("navigateFuc", e, eventOption);
  84. // 发送 navigateFucFromNav 主题 的Bus消息
  85. Bus.$emit('navigateFucFromNav', e);
  86. }
  87. },
  88. //颜色值转换
  89. hexToRgba(color, opacity) {
  90. return util.hexToRgba(color, opacity)
  91. },
  92. /**
  93. * 单页模式
  94. */
  95. showSingleModel() {
  96. app = getApp();
  97. let _scene = (app.globalData.launchInfo && app.globalData.launchInfo.scene) ? app.globalData.launchInfo
  98. .scene : '';
  99. if (_scene == '1154') { //单页模式下设置自定义导航栏无效
  100. this.specialHeight = (app.globalData.navigateStatusContainerHeight + 'px');
  101. this.specialTop = (app.globalData.navigateStatusContainerHeight + 'px');
  102. console.log("this.specialTop", this.specialTop);
  103. }
  104. this.singlePageStatus = app.globalData.singlePageStatus;
  105. },
  106. showShareOption() {
  107. this.showShareOptions = true;
  108. },
  109. hidenOption() {
  110. this.showOption = true;
  111. },
  112. getRandomArrayElements(arr, count) {
  113. var shuffled = arr.slice(0),
  114. i = arr.length,
  115. min = i - count,
  116. temp, index;
  117. while (i-- > min) {
  118. index = Math.floor((i + 1) * Math.random());
  119. temp = shuffled[index];
  120. shuffled[index] = shuffled[i];
  121. shuffled[i] = temp;
  122. }
  123. return shuffled.slice(min);
  124. },
  125. catchTouchMove: function() {
  126. return false;
  127. },
  128. //跳转到项目
  129. async navigateToProject(e) {
  130. var self = this;
  131. let houseId = e.currentTarget.dataset.houseid || e.currentTarget.dataset.houseid;
  132. let requestData = {
  133. houseId: houseId,
  134. requestCount: 1,
  135. componentCount: 1,
  136. };
  137. if(this.doubleClick){
  138. return false;
  139. }
  140. this.doubleClick = true;
  141. const res = await requestConfig('queryXcxPage', requestData, true);
  142. if (res && res.success && res.single && res.single.jsonString != null) {
  143. uni.navigateTo({
  144. url: '/pages/index/index?houseId=' + houseId,
  145. success: function() {},
  146. fail: function(res) {
  147. console.log(res)
  148. },
  149. complete() {
  150. self.doubleClick = false;
  151. }
  152. })
  153. } else {
  154. uni.showToast({
  155. title: '敬请期待',
  156. icon: 'none',
  157. duration: 1500,
  158. })
  159. this.doubleClick = false;
  160. }
  161. },
  162. async queryCityNews() {
  163. let res = await requestConfig('queryCityNews', {
  164. brandId: config.brandId,
  165. cityName: this.currentCity
  166. })
  167. if (res && res.success) {
  168. res.list.sort((a, b) => {
  169. return a.orderNumber - b.orderNumber
  170. })
  171. this.newsList = res.list.splice(0, 2)
  172. }
  173. },
  174. async goNews(e) {
  175. const data = e;
  176. var _link = "";
  177. var _title = "";
  178. if (data.type == 3) {
  179. _link = data.newsUrl;
  180. _title = data.title;
  181. } else if (data.type == 1 || !data.type) {
  182. _link = data.linkUrl;
  183. _title = data.title;
  184. } else {
  185. let res = await requestConfig('queryNewsById', {
  186. id: data.referNewsId
  187. })
  188. if (res.success && res.single) {
  189. if (res.single.type == 5) {
  190. _link = res.single.newsUrl;
  191. _title = res.single.title;
  192. } else {
  193. _link = res.single.linkUrl;
  194. _title = res.single.title;
  195. }
  196. }
  197. }
  198. let token = data.linkUrl.split('?newsToken=')[1] || '';
  199. app.checkNewsStatus(token, () => {
  200. if (data.content && data.content.length > 0) {
  201. let path = '/subPackage/pages/news/newsDetail/newsDetail?newsToken=' + token;
  202. console.log("path", path);
  203. uni.navigateTo({
  204. url: path,
  205. fail: function(res) {
  206. console.log(res)
  207. },
  208. })
  209. } else {
  210. if (app.checkWebviewLink(_link)) {
  211. uni.showToast({
  212. title: '敬请期待',
  213. icon: 'none',
  214. duration: 1500,
  215. })
  216. } else {
  217. uni.navigateTo({
  218. url: '/pages/webView/webView?view=' + encodeURIComponent(_link) +
  219. '&title=' + _title,
  220. fail: function(res) {
  221. console.log(res)
  222. },
  223. })
  224. }
  225. }
  226. }, () => {
  227. uni.showToast({
  228. title: '该页面已下线',
  229. icon: 'none',
  230. duration: 1500,
  231. })
  232. });
  233. },
  234. getDeviceInfor: function() {
  235. const res = uni.getSystemInfoSync();
  236. if (res.model.indexOf('iPhone') >= 0) {
  237. this.selfTabbarBottom = '0px';
  238. this.computerHeight = 'calc(100vh - 58px - 0px)';
  239. }
  240. this.height = app.globalData.navigateStatusContainerHeight;
  241. this.statusBarHeight = app.globalData.statusBarHeight;
  242. console.log("getDeviceInfor", res);
  243. },
  244. }
  245. }