index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { connect } from 'herculex';
  2. import { reportCourtInfo, getCourtlistInfo } from './../utils';
  3. import { setPagesQuery } from "../../../../core/utils/index";
  4. const app = getApp();
  5. Component(connect({
  6. mapStateToProps: {
  7. currentCourt: state => state.$global.currentCourt
  8. }
  9. })({
  10. props: {
  11. componentData: {}
  12. },
  13. data: {
  14. imgSrcPrefix: app.globalData.imgSrcPrefix,
  15. courtInfo: {
  16. id: ''
  17. }
  18. },
  19. async didMount() {
  20. const {
  21. longitude,
  22. latitude
  23. } = getApp().globalData.regionData;
  24. const [err, res] = await getCourtlistInfo({
  25. lng: longitude,
  26. lat: latitude
  27. });
  28. if (err || !res) return [err, null];
  29. let currentCourt = null;
  30. for (const item of res.list) {
  31. currentCourt = item.list.find(every => every.id === res.currentId);
  32. currentCourt.courtName = item.name;
  33. if (currentCourt) break;
  34. }
  35. this.commit('$global:updateState', {
  36. courtInfo: res
  37. }); // 全部小区列表信息
  38. this.commit('$global:updateState', {
  39. currentCourt
  40. }); // 全部小区列表信息
  41. // 设置app.js中全局的参数
  42. const {
  43. id,
  44. name
  45. } = currentCourt;
  46. setPagesQuery({
  47. communityCode: id,
  48. communityName: name
  49. });
  50. },
  51. didUpdate() {
  52. // eslint-disable-next-line prefer-const
  53. let {
  54. currentCourt,
  55. courtInfo
  56. } = this.data;
  57. if (currentCourt && currentCourt.id !== courtInfo.id) {
  58. courtInfo = {
  59. id: currentCourt.id,
  60. name: currentCourt.name
  61. };
  62. this.setData({
  63. courtInfo
  64. });
  65. this.report();
  66. }
  67. },
  68. methods: {
  69. // eslint-disable-next-line no-unused-vars
  70. async addCard(e) {
  71. const {
  72. serviceList = []
  73. } = this.props.componentData;
  74. const {
  75. url,
  76. urlType
  77. } = serviceList[0] || {};
  78. const payload = {
  79. urlType,
  80. url
  81. };
  82. if (url) {
  83. return this.$page.dispatchGlobal('handleJumpService', payload);
  84. }
  85. },
  86. onJumpAreaSelect() {
  87. my.navigateTo({
  88. url: '/antbuilder/industry/smartcommunity/pages/area-select/index'
  89. });
  90. },
  91. async report() {
  92. const {
  93. currentCourt
  94. } = this.data;
  95. if (currentCourt && currentCourt.id && currentCourt.name) {
  96. const data = {
  97. dataType: 1,
  98. dataKey: currentCourt.id,
  99. dataTitle: currentCourt.name
  100. };
  101. await reportCourtInfo(data);
  102. }
  103. }
  104. }
  105. }));