123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- const api = require('../../../../utils/api.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- checkText:'请选择'
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- let that=this
- wx.request({
- url: api.setImg,
- data:{userId:wx.getStorageSync('userId')},
- success(res){
- that.data.arr=[]
- that.data.arr1=[]
- for(var i=0;i<res.data.data.items.length;i++){
- 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}] }
- that.data.arr1.push(list)
- for(var j=0;j<res.data.data.items.length;j++){
- if (res.data.data.items[i].materialName == res.data.data.items[j].materialName && i!=j){
- var objList={}
- objList.url = res.data.data.items[j].materialUrl
- objList.id = res.data.data.items[j].id
- list.materialUrl.push(objList)
- list.isno = 1
- that.data.arr.push(list)
- res.data.data.items[j]=''
- }
- }
-
- }
- for(var i=0;i<that.data.arr1.length;i++){
- if(!that.data.arr1[i].id){
- that.data.arr1.splice(i,1);
- i--
- }
- }
- console.log(that.data.arr1)
- that.setData({
- image: that.data.arr1,
- url:res.data.data.prefix
- })
- }
- })
- },
- checkImg:function(e){
- let that=this
- console.log(e)
- var ishave=false
- for(var i=0;i<that.data.image.length;i++){
- for (var j = 0; j < that.data.image[i].materialUrl.length;j++){
- if (that.data.image[i].materialUrl[j].id == e.currentTarget.dataset.id&&that.data.image[i].materialUrl[j].isno){
- that.data.image[i].materialUrl[j].isno = false
- }else if (that.data.image[i].materialUrl[j].id == e.currentTarget.dataset.id){
- that.data.image[i].materialUrl[j].isno=true
- }
- if (that.data.image[i].materialUrl[j].isno){
- ishave=true
- }else{
- if(!ishave){
- }
- }
- }
- }
- that.setData({
- image: that.data.image,
- checkText:ishave?'完成':'请选择',
- ishave:ishave
- })
- },
- // 选择完成
- nav:function(e){
- let that=this
- var arr=[]
- for (var i = 0; i < that.data.image.length; i++) {
- for (var j = 0; j < that.data.image[i].materialUrl.length; j++) {
- if (that.data.image[i].materialUrl[j].isno) {
- arr.push(that.data.image[i].materialUrl[j].url)
- }
- }
- }
- wx.setStorageSync('imgUrl', arr);
- wx.setStorageSync('httpUrl', e.currentTarget.dataset.httpurl)
- wx.navigateBack({
- url:1
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|