业务交流通
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

myAttention.js 4.2KB

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