业务交流通
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

myAttention.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // pages/myModule/components/myCollect/myAttention.js
  2. const $request = require('../../../../utils/request.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. pageLoading: false,
  9. types: [],
  10. selectedTags: [],
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. const eventChannel = this.getOpenerEventChannel()
  17. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  18. eventChannel.on('customerid', data => {
  19. console.log(data)
  20. this.setData({
  21. customerId: data.customerid,
  22. pageLoading: true,
  23. })
  24. this.getAllType();
  25. })
  26. },
  27. // 获取tab数据
  28. getAllType() {
  29. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  30. if (res.status == 0) {
  31. let datas = res.data;
  32. this.setData({
  33. types: datas,
  34. })
  35. this.getAttentionTypeIds();
  36. }
  37. }).catch(error => {
  38. console.log(error, 'error appletLogin')
  39. })
  40. },
  41. // 获取关注类型
  42. getAttentionTypeIds() {
  43. let customerId = this.data.customerId;
  44. $request.get(`/businessCommunicationCustomer/getAttentionTypeIds.action`,
  45. { customerId }
  46. ).then(res => {
  47. // console.log(res);
  48. if (res.status == 0) {
  49. let selectedTags = res.data ? res.data.split(',') : [];
  50. this.setData({ selectedTags })
  51. this.initSelectedTags();
  52. }
  53. this.setData({
  54. pageLoading: false,
  55. })
  56. }).catch(error => {
  57. console.log(error, 'error appletLogin')
  58. })
  59. },
  60. // 选中类型变化
  61. changeTags(e) {
  62. let typename = e.currentTarget.dataset.typename;
  63. let selectedTags = this.data.selectedTags;
  64. // 1 如果选中的数组里没有当前type
  65. if (selectedTags.indexOf(typename) == -1) {
  66. // 2 如果选中的数组的长度小于3 直接push
  67. if (selectedTags.length < 5) {
  68. selectedTags.push(typename)
  69. }
  70. }
  71. // 3 如果选中的数组里有它,直接删除
  72. else {
  73. selectedTags.forEach((el, inx) => {
  74. if (el == typename) {
  75. selectedTags.splice(inx, 1);
  76. }
  77. })
  78. }
  79. this.setData({ selectedTags })
  80. this.initSelectedTags();
  81. },
  82. // 初始化选中
  83. initSelectedTags() {
  84. let { types, selectedTags } = this.data;
  85. types.forEach(el => {
  86. el.isActive = false;
  87. if (selectedTags.indexOf(el.typeName) != -1) {
  88. el.isActive = true;
  89. }
  90. })
  91. this.setData({ types })
  92. console.log(types, 'types')
  93. },
  94. // 设置关注类型
  95. setAttentionTypeIds() {
  96. let { customerId, selectedTags } = this.data;
  97. wx.showLoading({
  98. title: '数据保存中...',
  99. mask: true
  100. })
  101. $request.post(`/businessCommunicationCustomer/setAttentionTypeIds.action`,
  102. { customerId, type: selectedTags.join(',') }
  103. ).then(res => {
  104. console.log(res);
  105. if (res.status == 0) {
  106. wx.showToast({
  107. title: '保存成功',
  108. icon: 'success',
  109. duration: 2000
  110. })
  111. }
  112. wx.hideLoading()
  113. }).catch(error => {
  114. console.log(error, 'error appletLogin')
  115. wx.hideLoading()
  116. })
  117. },
  118. /**
  119. * 用户点击右上角分享
  120. */
  121. onShareAppMessage: function () {
  122. }
  123. })