accendant.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // pages/ucenter/myworksheet/accendant.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. items: []
  8. },
  9. checkboxChange(e) {
  10. console.log('checkbox发生change事件,携带value值为:', e.detail.value);
  11. let accendants = [];
  12. e.detail.value.forEach((item,index) => {
  13. this.data.items.forEach((item1,index1)=>{
  14. if(item1.userId == item){
  15. accendants.push(item1.userName);
  16. }
  17. });
  18. });
  19. let pages = getCurrentPages();
  20. let prevPage = pages[pages.length - 2]; //上一个页面
  21. let worksheetinfo = prevPage.data.worksheetinfo;
  22. prevPage.accendantids = []
  23. worksheetinfo.accendant = accendants.join(",");
  24. prevPage.setData({
  25. accendantids: e.detail.value,
  26. worksheetinfo
  27. });
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. let { chargstationid, accendant} = options;
  34. let userInfo = wx.getStorageSync('userInfo');
  35. //let accendants = `${userInfo.userName},${accendant}`.split(",");
  36. let accendants = accendant.split(",");
  37. let that = this;
  38. wx.request({
  39. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/getuserstation',
  40. data: chargstationid,
  41. method: 'POST',
  42. success(res) {
  43. //console.log(res);
  44. let {
  45. data: items
  46. } = res;
  47. items.forEach((item, index) => {
  48. if (accendants.indexOf(item.userName) != -1){
  49. item.checked= true;
  50. }
  51. });
  52. that.setData({
  53. items
  54. });
  55. }
  56. });
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面显示
  65. */
  66. onShow: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面隐藏
  70. */
  71. onHide: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面卸载
  75. */
  76. onUnload: function () {
  77. },
  78. /**
  79. * 页面相关事件处理函数--监听用户下拉动作
  80. */
  81. onPullDownRefresh: function () {
  82. },
  83. /**
  84. * 页面上拉触底事件的处理函数
  85. */
  86. onReachBottom: function () {
  87. },
  88. /**
  89. * 用户点击右上角分享
  90. */
  91. onShareAppMessage: function () {
  92. }
  93. })