index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <template>
  2. <view class="u-p-l-10 u-p-r-10">
  3. <u-navbar :is-back="false">
  4. <view style="display: flex;justify-content: center;align-items: center;">
  5. <view class="u-p-20" @click="location">
  6. {{ vuex_city == '' ? '选择' : vuex_city }}
  7. <u-icon class="u-p-l-10" color="#515356" name="arrow-down-fill"></u-icon>
  8. </view>
  9. <!-- #ifdef MP-WEIXIN -->
  10. <u-search v-model="keyword" :clearabled="true" :disabled="true" :show-action="false"
  11. input-align="center"
  12. placeholder="你想住在哪儿" style="width: 380rpx;" @click="search"></u-search>
  13. <!-- #endif -->
  14. <!-- #ifndef MP-WEIXIN -->
  15. <u-search v-model="keyword" :clearabled="true" :disabled="true" :show-action="false"
  16. input-align="center"
  17. placeholder="你想住在哪儿" style="width: 580rpx;" @click="search"></u-search>
  18. <!-- #endif -->
  19. </view>
  20. </u-navbar>
  21. <view>
  22. <!-- 流量主-腾讯banner广告 -->
  23. <!-- <ad unit-id="adunit-fcfdcc4d7095b6b1" ad-intervals="30"></ad> -->
  24. <!-- 轮播图 -->
  25. <!-- #ifndef MP-WEIXIN -->
  26. <!-- <u-swiper :list="swiperList" height="350"></u-swiper> -->
  27. <!-- #endif -->
  28. <u-swiper :list="swiperList" height="350" @click="moreInfo"></u-swiper>
  29. </view>
  30. <view>
  31. <view class="rowClass">
  32. <u-row>
  33. <u-col v-for="(item,index) in navList" :key="index" span="3" text-align="center">
  34. <view class="u-padding-20" hover-class="hoverClass" @tap="clickNav(item)">
  35. <image :src="item.src" mode="widthFix" style="width: 90rpx;height: 90rpx;"></image>
  36. <view class="tabName">{{ item.name }}</view>
  37. </view>
  38. </u-col>
  39. </u-row>
  40. </view>
  41. <u-gap height="10"></u-gap>
  42. <view @click="notice">
  43. <u-notice-bar :duration="5000" :list="noticeList" bg-color="#fff" border-radius="15"
  44. mode="vertical" more-icon type="primary"></u-notice-bar>
  45. </view>
  46. <u-gap height="5"></u-gap>
  47. <u-waterfall ref="uWaterfall" v-model="flowList">
  48. <template v-slot:left="{leftList}">
  49. <view v-for="(item, index) in leftList" :key="index" class="demo-warter">
  50. <u-lazy-load :image="item.image" :index="index" border-radius="12" threshold="750"
  51. @click="clickImage(item.id)"></u-lazy-load>
  52. <view class="item-title">{{ item.villageName }}
  53. {{ item.type == '整租' ? item.houseNum + item.houseHall + item.toiletNum : item.roomType }}
  54. </view>
  55. <view class="item-price">¥{{ item.price }}</view>
  56. <view class="item-desc">{{ item.type }} | {{ item.type == '整租' ? item.houseArea : item.roomArea }}㎡ |
  57. {{ item.decoration }}
  58. </view>
  59. </view>
  60. </template>
  61. <template v-slot:right="{rightList}">
  62. <view v-for="(item, index) in rightList" :key="index" class="demo-warter">
  63. <u-lazy-load :image="item.image" :index="index" border-radius="10" threshold="750"
  64. @click="clickImage(item.id)"></u-lazy-load>
  65. <view class="item-title">{{ item.villageName }}
  66. {{ item.type == '整租' ? item.houseNum + item.houseHall + item.toiletNum : item.roomType }}
  67. </view>
  68. <view class="item-price">¥{{ item.price }}</view>
  69. <view class="item-desc">{{ item.type }} | {{ item.type == '整租' ? item.houseArea : item.roomArea }}㎡ |
  70. {{ item.decoration }}
  71. </view>
  72. </view>
  73. </template>
  74. </u-waterfall>
  75. </view>
  76. <u-loadmore :status="loadStatus" bg-color="rgb(240, 240, 240)" style="height: 80rpx;line-height: 80rpx;"
  77. @loadmore="findHouseList"></u-loadmore>
  78. <u-back-top :scroll-top="scrollTop" top="1000"></u-back-top>
  79. <u-no-network></u-no-network>
  80. <view class="buttom">
  81. <view class="loginType">
  82. <view class="wechat item">
  83. <view class="icon">
  84. <u-icon color="#999" name="server-man" size="60" @click="server"></u-icon>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. </template>
  91. <script>
  92. import config from "@/common/config.js" // 全局配置文件
  93. export default {
  94. data() {
  95. return {
  96. keyword: '',
  97. pageNum: 1,
  98. pageSize: 20,
  99. scrollTop: 0,
  100. houseList: [],
  101. swiperList: [
  102. {
  103. image: '/static/img/index/swiper/swiper2.png',
  104. title: '身无彩凤双飞翼,心有灵犀一点通'
  105. },
  106. {
  107. image: '/static/img/index/swiper/swiper.jpg',
  108. title: '身无彩凤双飞翼,心有灵犀一点通'
  109. },
  110. ],
  111. noticeList: [],
  112. navList: [
  113. {name: "整租", src: "/static/img/index/cover_2022/index_cover1.png", type: "0"},
  114. {name: "合租", src: "/static/img/index/cover_2022/index_cover2.png", type: "1"},
  115. {name: "避坑指南", src: "/static/img/index/cover_2022/index_cover3.png", url: "/pages/center/tips"},
  116. {name: "委托房源", src: "/static/img/index/cover_2022/index_cover4.png", type: "2"}
  117. ],
  118. loadStatus: 'loadmore',
  119. flowList: [],
  120. uvCode: uni.getStorageSync('uvCode')
  121. }
  122. },
  123. onLoad() {
  124. // 检查是否已选择城市,如果未选择,跳转到选择城市页面
  125. this.checkCity();
  126. // 获取数据
  127. this.findHouseList();
  128. this.getNoticecList();
  129. // 流量统计
  130. this.appSysFlowInfo();
  131. uni.$on('findIndexHouseList', (obj) => {
  132. // 获取数据
  133. this.findHouseList(1);
  134. })
  135. },
  136. onUnload() {
  137. // 移除监听事件
  138. uni.$off('findIndexHouseList');
  139. },
  140. onPageScroll(e) {
  141. this.scrollTop = e.scrollTop;
  142. },
  143. onReachBottom() {
  144. this.loadStatus = 'loading';
  145. // 获取数据
  146. this.findHouseList()
  147. },
  148. // 下拉刷新
  149. onPullDownRefresh() {
  150. // 获取数据
  151. this.findHouseList(1);
  152. // 关闭刷新
  153. uni.stopPullDownRefresh();
  154. },
  155. methods: {
  156. checkCity() {
  157. // 检查是否已选择城市,如果未选择,跳转到选择城市页面
  158. let lifeData = uni.getStorageSync('lifeData');
  159. let vuex_city = lifeData.vuex_city
  160. // console.log(vuex_city.length);
  161. if (!vuex_city || vuex_city.length == 0) {
  162. // 没有token 则跳转到登录
  163. return this.$u.route('/pages/location/location');
  164. }
  165. },
  166. location() {
  167. this.$u.route({
  168. url: 'pages/location/location',
  169. })
  170. },
  171. search() {
  172. this.$u.route({
  173. url: 'pages/search/search',
  174. })
  175. },
  176. notice() {
  177. this.$u.route({
  178. url: 'pages/notice/notice'
  179. })
  180. },
  181. findHouseList(type = 0) {
  182. if (type == 1) {
  183. this.pageNum = 1
  184. this.flowList = []
  185. this.$refs.uWaterfall.clear();
  186. }
  187. let url = "/api/houseApi/findHouseRoomList";
  188. this.$u.get(url, {
  189. state: 1,
  190. villageCity: uni.getStorageSync('lifeData').vuex_city,
  191. pageNum: this.pageNum,
  192. pageSize: this.pageSize,
  193. orderByColumn: 'update_time,create_time',
  194. isAsc: 'desc'
  195. }).then(result => {
  196. const data = result.rows;
  197. if (this.pageNum > 1 && data.length < this.pageSize) {
  198. return this.loadStatus = 'nomore';
  199. }
  200. this.houseList = data;
  201. for (let i = 0; i < this.houseList.length; i++) {
  202. // 先转成字符串再转成对象,避免数组对象引用导致数据混乱
  203. let item = this.houseList[i]
  204. if (!item.faceUrl.includes(config.staticUrl)) {
  205. item.image = config.staticUrl + item.faceUrl
  206. } else {
  207. item.image = item.faceUrl
  208. }
  209. if (item.type == 0) {
  210. item.type = '整租'
  211. } else if (item.type == 1) {
  212. item.type = '合租'
  213. }
  214. if (item.roomType == 1) {
  215. item.roomType = '主卧'
  216. } else if (item.roomType == 2) {
  217. item.roomType = '次卧'
  218. } else {
  219. item.roomType = '未知'
  220. }
  221. if (this.$u.test.isEmpty(item.houseNum)) {
  222. item.houseNum = ''
  223. }
  224. if (this.$u.test.isEmpty(item.houseHall)) {
  225. item.houseHall = ''
  226. }
  227. if (this.$u.test.isEmpty(item.toiletNum)) {
  228. item.toiletNum = ''
  229. }
  230. this.flowList.push(item);
  231. }
  232. ++this.pageNum
  233. this.loadStatus = 'loadmore';
  234. });
  235. },
  236. clickSearch() {
  237. this.$u.route('/pages/search/search');
  238. },
  239. clickImage(houseId) {
  240. this.$u.route({
  241. url: '/pages/detail/detail',
  242. params: {
  243. houseId: houseId
  244. }
  245. })
  246. },
  247. clickNav(item) {
  248. if (item.url) {
  249. return this.$u.route(item.url);
  250. }
  251. if (item.type === "2") {
  252. // 判断是否有token
  253. let lifeData = uni.getStorageSync('lifeData');
  254. let token = lifeData.vuex_token
  255. if (!token) {
  256. // 没有token 则跳转到登录
  257. return uni.reLaunch({
  258. url: '../login/login'
  259. })
  260. } else {
  261. // 判断Token是否有效
  262. let url = "/api/profile/isExpiration";
  263. return this.$u.get(url, {
  264. token: token
  265. }).then(obj => {
  266. if (obj.data) {
  267. // 没有token过期则跳转到登录
  268. return uni.reLaunch({
  269. url: '../login/login'
  270. })
  271. } else {
  272. return this.$u.route('/pages/detail/preHouse');
  273. }
  274. });
  275. }
  276. } else if (item.type) {
  277. // return this.$u.route('/pages/search/searchList');
  278. return this.$u.route({
  279. url: '/pages/search/searchList',
  280. params: {
  281. type: item.type
  282. }
  283. })
  284. }
  285. },
  286. code() {
  287. this.$mytip.toast('请咨询作者')
  288. },
  289. appSysFlowInfo() {
  290. // 流量统计
  291. let uvCode = uni.getStorageSync("uvCode");
  292. let url = "https://sourcebyte.cn/api/flow/upFlow?type=MINI&uvCode=" + uvCode;
  293. uni.request({
  294. url: url,
  295. method: "POST",
  296. success: (res) => {
  297. uni.setStorageSync("uvCode", res.data.data);
  298. },
  299. });
  300. },
  301. server() {
  302. // window.open ('https://sourcebyte.cn')
  303. uni.makePhoneCall({
  304. phoneNumber: "18720989281",
  305. });
  306. },
  307. getNoticecList() {
  308. let url = "/api/notice/findNoticeList";
  309. this.$u.get(url, {
  310. pageNum: 1,
  311. pageSize: 50,
  312. orderByColumn: 'create_time',
  313. isAsc: 'desc'
  314. }).then(obj => {
  315. let data = obj.rows
  316. data.filter(item => {
  317. this.noticeList.push(item.noticeTitle)
  318. })
  319. });
  320. },
  321. moreInfo() {
  322. uni.navigateToMiniProgram({
  323. appId: 'wxbca64173e772915e',// 此为开源字节appid
  324. path: '/pages/index/index',// 此为开源字节首页路径
  325. envVersion: "release",
  326. success: res => {
  327. // 打开成功
  328. console.log("打开成功", res);
  329. },
  330. fail: err => {
  331. console.log(err);
  332. }
  333. })
  334. },
  335. }
  336. }
  337. </script>
  338. <style lang="scss" scoped>
  339. .nomore {
  340. background-color: $u-bg-color;
  341. }
  342. .search {
  343. width: 54px;
  344. height: 44px;
  345. &:active {
  346. background-color: $u-bg-color;
  347. }
  348. }
  349. .rowClass {
  350. border-radius: 8px;
  351. background-color: rgb(255, 255, 255);
  352. margin-top: 10 rpx;
  353. }
  354. .hoverClass {
  355. background-color: #E4E7ED;
  356. }
  357. .tabName {
  358. font-size: 28 rpx;
  359. color: $u-main-color;
  360. }
  361. .demo-warter {
  362. border-radius: 8px;
  363. margin-top: 3px;
  364. background-color: #ffffff;
  365. padding: 3px;
  366. position: relative;
  367. }
  368. .u-close {
  369. position: absolute;
  370. top: 20 rpx;
  371. right: 20 rpx;
  372. }
  373. .item-cover {
  374. font-size: 55 rpx;
  375. color: $u-type-warning;
  376. }
  377. .item-title {
  378. font-size: 28 rpx;
  379. color: $u-main-color;
  380. font-weight: bold;
  381. padding-top: 5 rpx;
  382. padding-left: 10 rpx;
  383. }
  384. .item-price {
  385. font-weight: normal;
  386. font-size: 32 rpx;
  387. color: $u-type-warning;
  388. }
  389. .item-desc {
  390. font-weight: normal;
  391. font-size: 26 rpx;
  392. color: $u-tips-color;
  393. padding-bottom: 5 rpx;
  394. padding-left: 10 rpx;
  395. }
  396. .item-tag {
  397. font-size: 24 rpx;
  398. color: $u-tips-color;
  399. margin-top: 3px;
  400. }
  401. .buttom {
  402. .loginType {
  403. font-size: 14px;
  404. position: fixed;
  405. right: 30 rpx;
  406. bottom: 300 rpx;
  407. width: 60px;
  408. height: 60px;
  409. padding: 4px;
  410. cursor: pointer;
  411. background: #FFF;
  412. text-align: center;
  413. line-height: 60px;
  414. border-radius: 100%;
  415. -webkit-box-shadow: 0px 1px 20px 0px rgba(0, 0, 0, 0.1), inset 0px -1px 0px 0px rgba(0, 0, 0, 0.1);
  416. box-shadow: 0px 1px 20px 0px rgba(0, 0, 0, 0.1), inset 0px -1px 0px 0px rgba(0, 0, 0, 0.1);
  417. }
  418. }
  419. </style>