templateMethod.js 9.4 KB

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