index.ts 14 KB

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