index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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_company_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_company_id: wx.getStorageSync('userinfo').platformCompanyId
  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: [...this.data.list, ...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. complete: () => {
  303. wx.stopPullDownRefresh({
  304. success: () => {
  305. console.log('stopPullDownRefresh')
  306. }
  307. });
  308. }
  309. })
  310. },
  311. /**
  312. * 获取首页banner图
  313. */
  314. getBanner() {
  315. wx.kx_request({
  316. url: wx.kx_api.hwUser.banner,
  317. success: res => {
  318. if (res.errcode === 0) {
  319. this.setData({
  320. swiper: res.data.bannerList
  321. })
  322. }
  323. }
  324. })
  325. },
  326. /**
  327. * 生命周期函数--监听页面加载
  328. */
  329. onLoad: function(options) {
  330. if (wx.getStorageSync('userid')) {
  331. if (wx.getStorageSync('userinfo').registerFrom === 0) {
  332. wx.reLaunch({
  333. url: '/pages/success/success',
  334. })
  335. } else {
  336. // 获取需求列表
  337. this.getList();
  338. // 获取首页banner图
  339. this.getBanner();
  340. this.setData({
  341. show: false
  342. })
  343. }
  344. } else {
  345. wx.redirectTo({
  346. url: '/pages/login/login',
  347. })
  348. }
  349. },
  350. /**
  351. * 生命周期函数--监听页面初次渲染完成
  352. */
  353. onReady: function() {
  354. },
  355. /**
  356. * 生命周期函数--监听页面显示
  357. */
  358. onShow: function() {
  359. /**
  360. * 初始化动画
  361. * @condition_animation 条件框动画
  362. * @list_animation 需求列表动画
  363. * @cover_animation 地址选择动画
  364. */
  365. // this.condition_animation = wx.createAnimation({
  366. // duration: 700,
  367. // timingFunction: 'ease',
  368. // })
  369. // this.list_animation = wx.createAnimation({
  370. // duration: 600,
  371. // timingFunction: 'ease',
  372. // })
  373. this.cover_animation = wx.createAnimation({
  374. duration: 600,
  375. timingFunction: 'ease',
  376. })
  377. wx.getSystemInfo({
  378. success: res => {
  379. this.setData({
  380. per: 750 / res.windowWidth
  381. })
  382. }
  383. })
  384. wx.createSelectorQuery().select('.choose-area').boundingClientRect((rect) => {
  385. this.setData({
  386. fixTop: rect.top,
  387. })
  388. }).exec();
  389. },
  390. /**
  391. * 生命周期函数--监听页面隐藏
  392. */
  393. onHide: function() {
  394. },
  395. /**
  396. * 生命周期函数--监听页面卸载
  397. */
  398. onUnload: function() {
  399. },
  400. /**
  401. * 页面相关事件处理函数--监听用户下拉动作
  402. */
  403. onPullDownRefresh: function() {
  404. this.setData({
  405. list: [],
  406. pageNo: 1,
  407. scrollTop: 0
  408. }, _ => {
  409. this.getList()
  410. })
  411. },
  412. /**
  413. * 页面上拉触底事件的处理函数
  414. */
  415. onReachBottom: function() {
  416. const isLast = this.data.isLast;
  417. if (isLast) {
  418. // wx.showToast({
  419. // icon: 'none',
  420. // title: '已经是最后一页了',
  421. // })
  422. } else {
  423. this.getList()
  424. }
  425. },
  426. /**
  427. * 用户点击右上角分享
  428. */
  429. onShareAppMessage: function() {
  430. },
  431. onPageScroll: function(res) {
  432. let top = res.scrollTop;
  433. this.setData({
  434. scrollTop: top
  435. });
  436. }
  437. })