index.js 11 KB

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