业务交流通
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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. 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. if (res.status == 0) {
  48. let selectedTags = res.data ? res.data.split(',') : [];
  49. this.setData({ selectedTags })
  50. this.initSelectedTags();
  51. }
  52. this.setData({
  53. pageLoading: false,
  54. })
  55. }).catch(error => {
  56. console.log(error, 'error appletLogin')
  57. })
  58. },
  59. // 选中类型变化
  60. changeTags(e) {
  61. let typename = e.currentTarget.dataset.typename;
  62. let selectedTags = this.data.selectedTags;
  63. // 1 如果选中的数组里没有当前type
  64. if (selectedTags.indexOf(typename) == -1) {
  65. // 2 如果选中的数组的长度小于3 直接push
  66. if (selectedTags.length < 5) {
  67. selectedTags.push(typename)
  68. }
  69. }
  70. // 3 如果选中的数组里有它,直接删除
  71. else {
  72. selectedTags.forEach((el, inx) => {
  73. if (el == typename) {
  74. selectedTags.splice(inx, 1);
  75. }
  76. })
  77. }
  78. this.setData({ selectedTags })
  79. this.initSelectedTags();
  80. },
  81. // 初始化选中
  82. initSelectedTags() {
  83. let { types, selectedTags } = this.data;
  84. types.forEach(el => {
  85. el.isActive = false;
  86. if (selectedTags.indexOf(el.typeName) != -1) {
  87. el.isActive = true;
  88. }
  89. })
  90. this.setData({ types })
  91. },
  92. // 设置关注类型
  93. setAttentionTypeIds() {
  94. let { customerId, selectedTags } = this.data;
  95. wx.showLoading({
  96. title: '数据保存中...',
  97. mask: true
  98. })
  99. $request.post(`/businessCommunicationCustomer/setAttentionTypeIds.action`,
  100. { customerId, type: selectedTags.join(',') }
  101. ).then(res => {
  102. console.log(res);
  103. if (res.status == 0) {
  104. const businessCommunicationCustomer = wx.getStorageSync('businessCommunicationCustomer');
  105. if(businessCommunicationCustomer){
  106. businessCommunicationCustomer.attentionTypeIds = selectedTags.join(',');
  107. wx.setStorageSync('businessCommunicationCustomer',businessCommunicationCustomer);
  108. app.globalData.businessCommunicationCustomer = businessCommunicationCustomer;
  109. }
  110. wx.showToast({
  111. title: '保存成功',
  112. icon: 'success',
  113. duration: 2000
  114. })
  115. wx.navigateBack()
  116. }
  117. wx.hideLoading()
  118. }).catch(error => {
  119. console.log(error, 'error appletLogin')
  120. wx.hideLoading()
  121. })
  122. },
  123. })