index.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. const id = e.currentTarget.dataset.id;
  264. wx.navigateTo({
  265. url: `/pages/detail/detail?id=${id}&&status=1`,
  266. })
  267. },
  268. /**
  269. * 获取需求列表
  270. * @pageNo {number} 页码
  271. * @pageSize {number} 数据条数
  272. * @province_code {number} 省份代码
  273. * @city_code {number} 城市代码
  274. * @country_code {number} 地区代码
  275. * @trade_type {number} 行业类型
  276. * @priceType {number} 价格代号(1-7)(不限的话不传此参数)
  277. * @platform_id {number} 接单人用户所属平台id
  278. */
  279. getList(pageNo?: number, province_code?: number, city_code?: number, country_code?: number, trade_type?: number, priceType?: number) {
  280. let _pageNo: number = pageNo || this.data.pageNo
  281. let platform_id = 1
  282. const userInfo = wx.getStorageSync('userInfo')
  283. if (userInfo) {
  284. platform_id = userInfo.platformId
  285. }
  286. const param = Object.assign({
  287. pageNo,
  288. pageSize: 10,
  289. province_code,
  290. city_code,
  291. country_code,
  292. trade_type,
  293. priceType,
  294. platform_id
  295. }, {
  296. pageNo: _pageNo,
  297. province_code: this.data.province_id,
  298. city_code: this.data.city_id,
  299. country_code: this.data.area_id,
  300. trade_type: this.data.industry_id,
  301. priceType: this.data.price_id
  302. })
  303. getRequirementsImpl(param).then(res => {
  304. console.log('res=>', res);
  305. if (typeof res === 'string') {
  306. // 如果没有网络 展示网络故障界面
  307. if (res === 'offline' && this.data.list.length === 0) {
  308. this.setData({
  309. offline: true,
  310. loading: false,
  311. list_length: false
  312. })
  313. }
  314. }
  315. if (<responseOptionsType>res) {
  316. const data = <responseOptionsType>res
  317. if (data.errCode === 0) {
  318. if (_pageNo === 1 && data.data.requirements.length === 0) {
  319. // this.doAnimation(false);
  320. this.setData({
  321. loading: false,
  322. list_length: true,
  323. offline: false
  324. })
  325. return
  326. }
  327. // 在成功后页数加一方便日后调用
  328. _pageNo++;
  329. data.data.requirements = data.data.requirements.map((value: any) => {
  330. if (getStorageSync(`orderDetail_${value.id}`)) {
  331. value.status = 5
  332. }
  333. return value
  334. })
  335. this.setData({
  336. pageNo: _pageNo,
  337. [`list[${_pageNo - 2}]`]: data.data.requirements,
  338. isLast: data.data.isLast,
  339. offline: false,
  340. list_length: false,
  341. loading: false
  342. })
  343. }
  344. }
  345. }).catch(() => {
  346. this.setData({
  347. loading: false,
  348. list_length: true,
  349. offline: false
  350. })
  351. })
  352. },
  353. /**
  354. * 获取首页banner图
  355. */
  356. getBanner() {
  357. bannerApi().then(res => {
  358. const data = <responseOptionsType>res
  359. if (data.errCode === 0) {
  360. this.setData({
  361. swiper: data.data.bannerList
  362. })
  363. }
  364. })
  365. },
  366. reload() {
  367. // 获取需求列表
  368. this.setData({
  369. list: [],
  370. pageNo: 1,
  371. scrollTop: 0
  372. }, () => {
  373. // 获取首页banner图
  374. this.getBanner();
  375. this.getList();
  376. })
  377. // app.utils.getHwUserInfo();
  378. },
  379. checkLogin() {
  380. if (wx.getStorageSync('userId') && wx.getStorageSync('userToken')) {
  381. if (wx.getStorageSync('userInfo').registerFrom === 0) {
  382. wx.reLaunch({
  383. url: '/pages/success/success',
  384. })
  385. } else {
  386. this.reload();
  387. this.setData({
  388. show: false
  389. })
  390. }
  391. } else {
  392. wx.reLaunch({
  393. url: '/pages/login/login',
  394. })
  395. }
  396. },
  397. /**
  398. * 生命周期函数--监听页面加载
  399. */
  400. onLoad: function () { this.getBanner(); },
  401. /**
  402. * 生命周期函数--监听页面初次渲染完成
  403. */
  404. onReady: function () {
  405. },
  406. /**
  407. * 生命周期函数--监听页面显示
  408. */
  409. onShow: function () {
  410. this.setData({
  411. route: this.route
  412. })
  413. this.checkLogin()
  414. // this.reload()
  415. /**
  416. * 初始化动画
  417. * @condition_animation 条件框动画
  418. * @list_animation 需求列表动画
  419. * @cover_animation 地址选择动画
  420. */
  421. // this.condition_animation = wx.createAnimation({
  422. // duration: 700,
  423. // timingFunction: 'ease',
  424. // })
  425. // this.list_animation = wx.createAnimation({
  426. // duration: 600,
  427. // timingFunction: 'ease',
  428. // })
  429. cover_animation = wx.createAnimation({
  430. duration: 600,
  431. timingFunction: 'ease',
  432. })
  433. // 获取系统信息算出像素比
  434. wx.getSystemInfo({
  435. success: res => {
  436. this.setData({
  437. per: 750 / res.windowWidth
  438. })
  439. }
  440. })
  441. // 获取绝对定位的高度
  442. wx.createSelectorQuery().select('.choose-area').boundingClientRect((rect) => {
  443. this.setData({
  444. fixTop: rect.top,
  445. })
  446. }).exec();
  447. if (app.globalData.webview) {
  448. wx.navigateTo({
  449. url: app.globalData.webview,
  450. success: () => {
  451. app.globalData.webview = null
  452. }
  453. })
  454. }
  455. },
  456. /**
  457. * 生命周期函数--监听页面隐藏
  458. */
  459. onHide: function () {
  460. },
  461. /**
  462. * 生命周期函数--监听页面卸载
  463. */
  464. onUnload: function () {
  465. },
  466. /**
  467. * 页面相关事件处理函数--监听用户下拉动作
  468. */
  469. onPullDownRefresh: function () {
  470. this.setData({
  471. list: [],
  472. pageNo: 1,
  473. scrollTop: 0
  474. }, () => {
  475. this.getList()
  476. })
  477. },
  478. /**
  479. * 页面上拉触底事件的处理函数
  480. */
  481. onReachBottom: function () {
  482. const isLast = this.data.isLast;
  483. if (isLast) {
  484. // wx.showToast({
  485. // icon: 'none',
  486. // title: '已经是最后一页了',
  487. // })
  488. } else {
  489. this.getList()
  490. }
  491. },
  492. /**
  493. * 用户点击右上角分享
  494. */
  495. onShareAppMessage: function () {
  496. },
  497. onPageScroll: function (res) {
  498. let top = res.scrollTop;
  499. this.setData({
  500. scrollTop: top
  501. });
  502. }
  503. })