setData.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const api = require('../../../../utils/api.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. checkText:'请选择'
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad: function (options) {
  13. },
  14. /**
  15. * 生命周期函数--监听页面初次渲染完成
  16. */
  17. onReady: function () {
  18. let that=this
  19. wx.request({
  20. url: api.setImg,
  21. data:{userId:wx.getStorageSync('userId')},
  22. success(res){
  23. that.data.arr=[]
  24. that.data.arr1=[]
  25. for(var i=0;i<res.data.data.items.length;i++){
  26. var list = { 'id': res.data.data.items[i].id, 'materialName': res.data.data.items[i].materialName, isno: 0, 'materialUrl': [{ 'url': res.data.data.items[i].materialUrl, 'id': res.data.data.items[i].id}] }
  27. that.data.arr1.push(list)
  28. for(var j=0;j<res.data.data.items.length;j++){
  29. if (res.data.data.items[i].materialName == res.data.data.items[j].materialName && i!=j){
  30. var objList={}
  31. objList.url = res.data.data.items[j].materialUrl
  32. objList.id = res.data.data.items[j].id
  33. list.materialUrl.push(objList)
  34. list.isno = 1
  35. that.data.arr.push(list)
  36. res.data.data.items[j]=''
  37. }
  38. }
  39. }
  40. for(var i=0;i<that.data.arr1.length;i++){
  41. if(!that.data.arr1[i].id){
  42. that.data.arr1.splice(i,1);
  43. i--
  44. }
  45. }
  46. console.log(that.data.arr1)
  47. that.setData({
  48. image: that.data.arr1,
  49. url:res.data.data.prefix
  50. })
  51. }
  52. })
  53. },
  54. checkImg:function(e){
  55. let that=this
  56. console.log(e)
  57. var ishave=false
  58. for(var i=0;i<that.data.image.length;i++){
  59. for (var j = 0; j < that.data.image[i].materialUrl.length;j++){
  60. if (that.data.image[i].materialUrl[j].id == e.currentTarget.dataset.id&&that.data.image[i].materialUrl[j].isno){
  61. that.data.image[i].materialUrl[j].isno = false
  62. }else if (that.data.image[i].materialUrl[j].id == e.currentTarget.dataset.id){
  63. that.data.image[i].materialUrl[j].isno=true
  64. }
  65. if (that.data.image[i].materialUrl[j].isno){
  66. ishave=true
  67. }else{
  68. if(!ishave){
  69. }
  70. }
  71. }
  72. }
  73. that.setData({
  74. image: that.data.image,
  75. checkText:ishave?'完成':'请选择',
  76. ishave:ishave
  77. })
  78. },
  79. // 选择完成
  80. nav:function(e){
  81. let that=this
  82. var arr=[]
  83. for (var i = 0; i < that.data.image.length; i++) {
  84. for (var j = 0; j < that.data.image[i].materialUrl.length; j++) {
  85. if (that.data.image[i].materialUrl[j].isno) {
  86. arr.push(that.data.image[i].materialUrl[j].url)
  87. }
  88. }
  89. }
  90. wx.setStorageSync('imgUrl', arr);
  91. wx.setStorageSync('httpUrl', e.currentTarget.dataset.httpurl)
  92. wx.navigateBack({
  93. url:1
  94. })
  95. },
  96. /**
  97. * 生命周期函数--监听页面显示
  98. */
  99. onShow: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面隐藏
  103. */
  104. onHide: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面卸载
  108. */
  109. onUnload: function () {
  110. },
  111. /**
  112. * 页面相关事件处理函数--监听用户下拉动作
  113. */
  114. onPullDownRefresh: function () {
  115. },
  116. /**
  117. * 页面上拉触底事件的处理函数
  118. */
  119. onReachBottom: function () {
  120. },
  121. /**
  122. * 用户点击右上角分享
  123. */
  124. onShareAppMessage: function () {
  125. }
  126. })