index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { connect } from 'herculex';
  2. import { getIn } from 'herculex/dist/utils/manipulate';
  3. import { getCourtlistInfo } from './../utils';
  4. import { setPagesQuery } from "../../../../core/utils/index";
  5. const app = getApp();
  6. Component(connect({
  7. mapStateToProps: {
  8. userInfo: state => state.$global.userInfo,
  9. currentCourt: state => state.currentCourt
  10. }
  11. })({
  12. props: {
  13. componentData: {}
  14. },
  15. data: {
  16. imgSrcPrefix: app.globalData.imgSrcPrefix
  17. },
  18. async didMount() {
  19. const {
  20. longitude,
  21. latitude
  22. } = getApp().globalData.regionData;
  23. const [err, res] = await getCourtlistInfo({
  24. lng: longitude,
  25. lat: latitude
  26. });
  27. if (err || !res) return [err, null];
  28. let currentCourt = null;
  29. for (const item of res.list) {
  30. currentCourt = item.list.find(every => every.id === res.currentId);
  31. currentCourt.courtName = item.name;
  32. if (currentCourt) break;
  33. }
  34. this.commit('$global:updateState', {
  35. courtInfo: res
  36. }); // 全部小区列表信息
  37. this.commit('$global:updateState', {
  38. currentCourt
  39. }); // 全部小区列表信息
  40. // 设置app.js中全局的参数
  41. const {
  42. id,
  43. name
  44. } = currentCourt;
  45. setPagesQuery({
  46. communityCode: id,
  47. communityName: name
  48. });
  49. },
  50. didUpdate(preProps) {
  51. // eslint-disable-next-line max-len
  52. if (preProps.componentData.componentExtInfo.memberInfo && this.props.componentData.componentExtInfo.memberInfo) {
  53. const preFlag = preProps.componentData.componentExtInfo.memberInfo.flag || false;
  54. const flag = this.props.componentData.componentExtInfo.memberInfo.flag || false;
  55. if (!preFlag && flag) {
  56. const {
  57. serviceList = []
  58. } = this.props.componentData;
  59. const {
  60. url,
  61. urlType
  62. } = serviceList[0] || {};
  63. const payload = {
  64. urlType,
  65. url
  66. };
  67. if (url) {
  68. return this.$page.dispatchGlobal('handleJumpService', payload);
  69. }
  70. }
  71. }
  72. },
  73. methods: {
  74. async addCard(e) {
  75. const {
  76. componentExtInfo: {
  77. applyUrl,
  78. cardTemplateId
  79. }
  80. } = this.props.componentData;
  81. const index = getIn(e, ['target', 'dataset', 'index']);
  82. const result = await this.dispatch('addCard', {
  83. index,
  84. applyUrl,
  85. cardTemplateId
  86. });
  87. if (result.code && result.code === 'USER_BACK') return; // 失败
  88. if (result !== 'addCardSuccess') {
  89. const {
  90. serviceList = []
  91. } = this.props.componentData;
  92. const {
  93. url,
  94. urlType
  95. } = serviceList[1] || {};
  96. const payload = {
  97. urlType,
  98. url
  99. };
  100. if (url) {
  101. return this.$page.dispatchGlobal('handleJumpService', payload);
  102. }
  103. }
  104. },
  105. goToCardDetail(e) {
  106. const memberInfo = getIn(e, ['target', 'dataset', 'memberInfo'], {});
  107. const {
  108. passId
  109. } = memberInfo;
  110. if (passId) {
  111. this.commit({
  112. memberInfo: {
  113. isOpenCardDeail: true,
  114. ...memberInfo
  115. }
  116. });
  117. my.openCardDetail({
  118. passId
  119. });
  120. }
  121. },
  122. onJumpAreaSelect() {
  123. my.navigateTo({
  124. url: '/antbuilder/industry/smartcommunity/pages/area-select/index'
  125. });
  126. }
  127. }
  128. }));