index.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. //index.js
  2. //获取应用实例
  3. import { getRequirementsApi, } from "../../service/hwRequirement";
  4. import { bannerApi } from "../../service/hwUser";
  5. const app = getApp()
  6. let cover_animation: any = {}
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. 'indicator_dots': false, //轮播指示点
  13. 'autoplay': true, //轮播自动播放
  14. 'circular': true, //轮播衔接动画
  15. 'interval': 3000, //轮播间隔时间
  16. 'duration': 1500, //轮播动画时间
  17. 'condition_animation': {}, //上方条件动画
  18. 'list_animation': {}, //下方列表动画
  19. 'cover_animation': {}, //选择地址动画
  20. 'swiper': [], // 轮播列表
  21. 'industry': '行业', //行业
  22. 'price': '单价', //单价
  23. 'district': '不限区域', //区域
  24. 'conditionList': [], //现行条件列表
  25. 'condition': '', //现行条件
  26. 'action_index': 0, //现行条件索引
  27. 'industry_index': 0, //行业索引
  28. 'industry_id': '', //行业id
  29. 'price_index': 0, //单价索引
  30. 'price_id': '', //单价id
  31. 'province_id': '', //省份ID
  32. 'city_id': '', //城市ID
  33. 'area_id': '', //地区ID
  34. 'industryList': [{
  35. id: '',
  36. name: '不限行业'
  37. },
  38. {
  39. id: 0,
  40. name: '教育培训'
  41. },
  42. {
  43. id: 1,
  44. name: 'IT互联网'
  45. },
  46. {
  47. id: 2,
  48. name: '仓储物流'
  49. },
  50. {
  51. id: 3,
  52. name: '酒店餐饮'
  53. },
  54. {
  55. id: 4,
  56. name: '家政保洁'
  57. },
  58. {
  59. id: 5,
  60. name: '维修保养'
  61. },
  62. {
  63. id: 6,
  64. name: '会务会展'
  65. },
  66. {
  67. id: 7,
  68. name: '专业服务'
  69. },
  70. {
  71. id: 8,
  72. name: '生产制造'
  73. },
  74. {
  75. id: 9,
  76. name: '其他行业'
  77. },
  78. ], //行业列表
  79. 'priceList': [{
  80. id: '',
  81. name: '不限'
  82. },
  83. {
  84. id: 1,
  85. name: '3K以下'
  86. },
  87. {
  88. id: 2,
  89. name: '3K-5K'
  90. },
  91. {
  92. id: 3,
  93. name: '5K-8K'
  94. },
  95. {
  96. id: 4,
  97. name: '8K-12K'
  98. },
  99. {
  100. id: 5,
  101. name: '12K-20K'
  102. },
  103. {
  104. id: 6,
  105. name: '20K-30K'
  106. },
  107. {
  108. id: 7,
  109. name: '30K以上'
  110. },
  111. ], // 单价列表
  112. 'list': [], //需求列表
  113. 'pageNo': 1,
  114. 'isLast': false,
  115. 'offline': false,
  116. 'loading': true,
  117. 'list_length': false,
  118. 'show': false,
  119. 'transition': true,
  120. 'fixTop': 0,
  121. 'scrollTop': 0,
  122. swiperIndex: 0
  123. },
  124. swiperChange(e: any) {
  125. this.setData({
  126. swiperIndex: e.detail.current
  127. })
  128. },
  129. /**
  130. * 展示删选条件
  131. * @condition {string} 条件 当获取的条件不等于data里面的条件时 不做改变 不等时 改变条件 以及对应的展示条件
  132. */
  133. chooseCondition(e: any) {
  134. const condition = e.currentTarget.dataset.condition === this.data.condition ? '' : e.currentTarget.dataset.condition;
  135. this.doAnimation(e.currentTarget.dataset.condition === this.data.condition)
  136. // this.doAnimation(false)
  137. // let action_index = this.data.condition === this.data.action_index ? [] : this.data[`${condition}_index`];
  138. this.setData({
  139. condition,
  140. // action_index
  141. })
  142. },
  143. /**
  144. * 展开区域选择
  145. *
  146. */
  147. openArea() {
  148. this.doAnimation(true)
  149. cover_animation.left(0).step();
  150. this.setData({
  151. cover_animation: cover_animation.export(),
  152. condition: '',
  153. })
  154. },
  155. /**
  156. * 点击选择条件
  157. * 根据不同的条件插入不同的值
  158. */
  159. choose(e: any) {
  160. const index = e.currentTarget.dataset.index;
  161. const id = e.currentTarget.dataset.id;
  162. let condition = this.data.condition;
  163. let list: any[] = []
  164. if (condition === 'industry') {
  165. list = this.data.industryList
  166. } else {
  167. list = this.data.priceList
  168. }
  169. this.setData({
  170. [condition]: list[index].name,
  171. [`${condition}_index`]: index,
  172. [`${condition}_id`]: id,
  173. condition: '',
  174. list: [],
  175. loading: true
  176. }, () => {
  177. this.getList(1)
  178. })
  179. this.doAnimation(true)
  180. },
  181. /**
  182. * 保存地区
  183. * @district {string} 地区
  184. * @province_id {} 省份ID
  185. * @city_id {} 城市ID
  186. * @area_id {} 地区ID
  187. */
  188. saveDistrict(e: any) {
  189. cover_animation.left(750 + 'rpx').step();
  190. this.setData({
  191. cover_animation: cover_animation.export(),
  192. district: e.detail.area_name,
  193. province_id: e.detail.province_id,
  194. city_id: e.detail.city_id,
  195. area_id: e.detail.area_id,
  196. list: []
  197. }, () => {
  198. this.getList(1)
  199. })
  200. },
  201. /**
  202. * 关闭地区选择
  203. * @cover_animation 地区选择动画
  204. */
  205. coloseDistrict() {
  206. cover_animation.left(750 + 'rpx').step();
  207. this.setData({
  208. cover_animation: cover_animation.export()
  209. })
  210. this.doAnimation(true)
  211. },
  212. /**
  213. * 执行条件动画
  214. */
  215. doAnimation(status: boolean) {
  216. // const condition_animation = this.condition_animation;
  217. // const list_animation = this.list_animation;
  218. // const condition_length = status ? 0 : -412 + 'rpx'
  219. // const list_length = status ? 548 + 'rpx' : 201 + 'rpx'
  220. // condition_animation.top(condition_length).step();
  221. // list_animation.top(list_length).step();
  222. // this.setData({
  223. // condition_animation: condition_animation.export(),
  224. // list_animation: list_animation.export(),
  225. // })
  226. const fixTop = this.data.fixTop;
  227. const scrollTop = this.data.scrollTop;
  228. if (fixTop > scrollTop) {
  229. this.setData({
  230. transition: status
  231. })
  232. }
  233. },
  234. /**
  235. * 跳转个人中心
  236. */
  237. toPerson() {
  238. if (wx.getStorageSync('userId') && wx.getStorageSync('userToken')) {
  239. wx.navigateTo({
  240. url: '/pages/person/person',
  241. })
  242. } else {
  243. wx.showModal({
  244. title: '提示',
  245. content: '你还未登陆,是否立即登录',
  246. cancelColor: '#888A8E',
  247. confirmColor: '#31364C',
  248. success: res => {
  249. if (res.confirm) {
  250. wx.navigateTo({
  251. url: '/pages/login/login',
  252. })
  253. }
  254. }
  255. })
  256. }
  257. },
  258. /**
  259. * 跳转详情页
  260. */
  261. toDetail(e: any) {
  262. const id = e.currentTarget.dataset.id;
  263. wx.navigateTo({
  264. url: `/pages/detail/detail?id=${id}&&status=1`,
  265. })
  266. },
  267. /**
  268. * 获取需求列表
  269. * @pageNo {number} 页码
  270. * @pageSize {number} 数据条数
  271. * @province_code {number} 省份代码
  272. * @city_code {number} 城市代码
  273. * @country_code {number} 地区代码
  274. * @trade_type {number} 行业类型
  275. * @priceType {number} 价格代号(1-7)(不限的话不传此参数)
  276. * @platform_id {number} 接单人用户所属平台id
  277. */
  278. getList(pageNo?: number, province_code?: number, city_code?: number, country_code?: number, trade_type?: number, priceType?: number) {
  279. let _pageNo: number = pageNo || this.data.pageNo
  280. const param = Object.assign({
  281. pageNo: _pageNo,
  282. province_code: this.data.province_id,
  283. city_code: this.data.city_id,
  284. country_code: this.data.area_id,
  285. trade_type: this.data.industry_id,
  286. priceType: this.data.price_id
  287. }, {
  288. pageNo,
  289. pageSize: 10,
  290. province_code,
  291. city_code,
  292. country_code,
  293. trade_type,
  294. priceType,
  295. platform_id: app.globalData.platformId
  296. })
  297. getRequirementsApi(param).then(res => {
  298. if (typeof res === 'string') {
  299. // 如果没有网络 展示网络故障界面
  300. if (res === 'offline' && this.data.list.length === 0) {
  301. this.setData({
  302. offline: true,
  303. loading: false,
  304. list_length: false
  305. })
  306. }
  307. }
  308. const data = <responseOptionsType>res
  309. if (data.errcode === 0) {
  310. if (pageNo === 1 && data.data.requirements.length === 0) {
  311. // this.doAnimation(false);
  312. this.setData({
  313. loading: false,
  314. list_length: true,
  315. offline: false
  316. })
  317. return
  318. }
  319. // 在成功后页数加一方便日后调用
  320. _pageNo++;
  321. this.setData({
  322. pageNo: _pageNo,
  323. [`list[${_pageNo - 2}]`]: data.data.requirements,
  324. isLast: data.data.isLast,
  325. offline: false,
  326. list_length: false,
  327. loading: false
  328. })
  329. }
  330. }).catch(() => {
  331. this.setData({
  332. loading: false,
  333. list_length: true,
  334. offline: false
  335. })
  336. })
  337. },
  338. /**
  339. * 获取首页banner图
  340. */
  341. getBanner() {
  342. bannerApi().then(res => {
  343. const data = <responseOptionsType>res
  344. if (data.errcode === 0) {
  345. this.setData({
  346. swiper: data.data.bannerList
  347. })
  348. }
  349. })
  350. },
  351. reload() {
  352. // 获取需求列表
  353. this.setData({
  354. list: [],
  355. pageNo: 1,
  356. scrollTop: 0
  357. }, () => {
  358. // 获取首页banner图
  359. this.getBanner();
  360. this.getList();
  361. })
  362. // app.utils.getHwUserInfo();
  363. },
  364. checkLogin() {
  365. if (wx.getStorageSync('userId') && wx.getStorageSync('userToken')) {
  366. if (wx.getStorageSync('userInfo').registerFrom === 0) {
  367. wx.reLaunch({
  368. url: '/pages/success/success',
  369. })
  370. } else {
  371. this.reload();
  372. this.setData({
  373. show: false
  374. })
  375. }
  376. } else {
  377. wx.navigateTo({
  378. url: '/pages/login/login',
  379. })
  380. }
  381. },
  382. /**
  383. * 生命周期函数--监听页面加载
  384. */
  385. onLoad: function () { this.getBanner(); },
  386. /**
  387. * 生命周期函数--监听页面初次渲染完成
  388. */
  389. onReady: function () {
  390. },
  391. /**
  392. * 生命周期函数--监听页面显示
  393. */
  394. onShow: function () {
  395. this.setData({
  396. route: this.route
  397. })
  398. this.checkLogin()
  399. // this.reload()
  400. /**
  401. * 初始化动画
  402. * @condition_animation 条件框动画
  403. * @list_animation 需求列表动画
  404. * @cover_animation 地址选择动画
  405. */
  406. // this.condition_animation = wx.createAnimation({
  407. // duration: 700,
  408. // timingFunction: 'ease',
  409. // })
  410. // this.list_animation = wx.createAnimation({
  411. // duration: 600,
  412. // timingFunction: 'ease',
  413. // })
  414. cover_animation = wx.createAnimation({
  415. duration: 600,
  416. timingFunction: 'ease',
  417. })
  418. // 获取系统信息算出像素比
  419. wx.getSystemInfo({
  420. success: res => {
  421. this.setData({
  422. per: 750 / res.windowWidth
  423. })
  424. }
  425. })
  426. // 获取绝对定位的高度
  427. wx.createSelectorQuery().select('.choose-area').boundingClientRect((rect) => {
  428. this.setData({
  429. fixTop: rect.top,
  430. })
  431. }).exec();
  432. if (app.globalData.webview) {
  433. wx.navigateTo({
  434. url: app.globalData.webview,
  435. success: () => {
  436. app.globalData.webview = null
  437. }
  438. })
  439. }
  440. },
  441. /**
  442. * 生命周期函数--监听页面隐藏
  443. */
  444. onHide: function () {
  445. },
  446. /**
  447. * 生命周期函数--监听页面卸载
  448. */
  449. onUnload: function () {
  450. },
  451. /**
  452. * 页面相关事件处理函数--监听用户下拉动作
  453. */
  454. onPullDownRefresh: function () {
  455. this.setData({
  456. list: [],
  457. pageNo: 1,
  458. scrollTop: 0
  459. }, () => {
  460. this.getList()
  461. })
  462. },
  463. /**
  464. * 页面上拉触底事件的处理函数
  465. */
  466. onReachBottom: function () {
  467. const isLast = this.data.isLast;
  468. if (isLast) {
  469. // wx.showToast({
  470. // icon: 'none',
  471. // title: '已经是最后一页了',
  472. // })
  473. } else {
  474. this.getList()
  475. }
  476. },
  477. /**
  478. * 用户点击右上角分享
  479. */
  480. onShareAppMessage: function () {
  481. },
  482. onPageScroll: function (res) {
  483. let top = res.scrollTop;
  484. this.setData({
  485. scrollTop: top
  486. });
  487. }
  488. })