index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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: true,
  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(false)
  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. wx.navigateTo({
  227. url: '/pages/person/person',
  228. })
  229. },
  230. /**
  231. * 跳转详情页
  232. */
  233. toDetail(e) {
  234. const id = e.currentTarget.dataset.id;
  235. wx.navigateTo({
  236. url: `/pages/detail/detail?id=${id}&&status=1`,
  237. })
  238. },
  239. /**
  240. * 获取需求列表
  241. * @pageNo {number} 页码
  242. * @pageSize {number} 数据条数
  243. * @province_code {number} 省份代码
  244. * @city_code {number} 城市代码
  245. * @country_code {number} 地区代码
  246. * @trade_type {number} 行业类型
  247. * @priceType {number} 价格代号(1-7)(不限的话不传此参数)
  248. * @platform_id {number} 接单人用户所属平台id
  249. */
  250. 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) {
  251. wx.kx_request({
  252. url: wx.kx_api.hwRequirement.getRequirements,
  253. data: {
  254. pageNo,
  255. pageSize: 10,
  256. province_code,
  257. city_code,
  258. country_code,
  259. trade_type,
  260. priceType,
  261. platform_id: wx.getStorageSync('userinfo').platformId
  262. },
  263. success: res => {
  264. // 如果没有网络 展示网络故障界面
  265. if (res === 'offline' && this.data.list.length === 0) {
  266. this.setData({
  267. offline: true,
  268. loading: false,
  269. list_length: false
  270. })
  271. }
  272. if (res.errcode === 0) {
  273. if (pageNo === 1 && res.data.requirements.length === 0) {
  274. // this.doAnimation(false);
  275. this.setData({
  276. loading: false,
  277. list_length: true,
  278. offline: false
  279. })
  280. return
  281. }
  282. // 在成功后页数加一方便日后调用
  283. pageNo++;
  284. this.setData({
  285. pageNo,
  286. [`list[${pageNo - 2}]`]: res.data.requirements,
  287. isLast: res.data.isLast,
  288. offline: false,
  289. list_length: false,
  290. loading: false
  291. })
  292. }
  293. },
  294. fail: res => {
  295. this.setData({
  296. loading: false,
  297. list_length: true,
  298. offline: false
  299. })
  300. // this.doAnimation(false);
  301. }
  302. })
  303. },
  304. /**
  305. * 获取首页banner图
  306. */
  307. getBanner() {
  308. wx.kx_request({
  309. url: wx.kx_api.hwUser.banner,
  310. success: res => {
  311. if (res.errcode === 0) {
  312. this.setData({
  313. swiper: res.data.bannerList
  314. })
  315. }
  316. }
  317. })
  318. },
  319. reload() {
  320. // 获取需求列表
  321. this.setData({
  322. list: [],
  323. pageNo: 1,
  324. scrollTop: 0
  325. }, _ => {
  326. this.getList()
  327. })
  328. // 获取首页banner图
  329. this.getBanner();
  330. app.utils.getHwUserInfo();
  331. },
  332. /**
  333. * 生命周期函数--监听页面加载
  334. */
  335. onLoad: function(options) {
  336. if (wx.getStorageSync('userid')) {
  337. if (wx.getStorageSync('userinfo').registerFrom === 0) {
  338. wx.reLaunch({
  339. url: '/pages/success/success',
  340. })
  341. } else {
  342. this.reload();
  343. this.setData({
  344. show: false
  345. })
  346. }
  347. } else {
  348. wx.redirectTo({
  349. url: '/pages/login/login',
  350. })
  351. }
  352. },
  353. /**
  354. * 生命周期函数--监听页面初次渲染完成
  355. */
  356. onReady: function() {
  357. },
  358. /**
  359. * 生命周期函数--监听页面显示
  360. */
  361. onShow: function() {
  362. /**
  363. * 初始化动画
  364. * @condition_animation 条件框动画
  365. * @list_animation 需求列表动画
  366. * @cover_animation 地址选择动画
  367. */
  368. // this.condition_animation = wx.createAnimation({
  369. // duration: 700,
  370. // timingFunction: 'ease',
  371. // })
  372. // this.list_animation = wx.createAnimation({
  373. // duration: 600,
  374. // timingFunction: 'ease',
  375. // })
  376. this.cover_animation = wx.createAnimation({
  377. duration: 600,
  378. timingFunction: 'ease',
  379. })
  380. // 获取系统信息算出像素比
  381. wx.getSystemInfo({
  382. success: res => {
  383. this.setData({
  384. per: 750 / res.windowWidth
  385. })
  386. }
  387. })
  388. // 获取绝对定位的高度
  389. wx.createSelectorQuery().select('.choose-area').boundingClientRect((rect) => {
  390. this.setData({
  391. fixTop: rect.top,
  392. })
  393. }).exec();
  394. if (app.globalData.webview) {
  395. wx.navigateTo({
  396. url: app.globalData.webview,
  397. success: res => {
  398. app.globalData.webview = null
  399. }
  400. })
  401. }
  402. },
  403. /**
  404. * 生命周期函数--监听页面隐藏
  405. */
  406. onHide: function() {
  407. },
  408. /**
  409. * 生命周期函数--监听页面卸载
  410. */
  411. onUnload: function() {
  412. },
  413. /**
  414. * 页面相关事件处理函数--监听用户下拉动作
  415. */
  416. onPullDownRefresh: function() {
  417. this.setData({
  418. list: [],
  419. pageNo: 1,
  420. scrollTop: 0
  421. }, _ => {
  422. this.getList()
  423. })
  424. },
  425. /**
  426. * 页面上拉触底事件的处理函数
  427. */
  428. onReachBottom: function() {
  429. const isLast = this.data.isLast;
  430. if (isLast) {
  431. // wx.showToast({
  432. // icon: 'none',
  433. // title: '已经是最后一页了',
  434. // })
  435. } else {
  436. this.getList()
  437. }
  438. },
  439. /**
  440. * 用户点击右上角分享
  441. */
  442. onShareAppMessage: function() {
  443. },
  444. onPageScroll: function(res) {
  445. let top = res.scrollTop;
  446. this.setData({
  447. scrollTop: top
  448. });
  449. }
  450. })