details.js 6.4 KB
import {
  request
} from "../../request/index.js";
// import {
//   WxParse
// } from "../../wxParse/wxParse.js";
const a = getApp()
var WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    time: 30 * 60 * 60 * 1000,
    timeData: {},
    four: 10,
    content: '',
    showDialog: false,
    messageAlert: '',
    names: '',
    phone: '',
    msg: '',
    klist: [],
    id: '',
    type: '',
    time_data: '',
    obj: '',
    texts: 0,
    code: '',
    avatar_arr: [], // 头像数组
    can_num: 0, // 参加人数
  },
  onShow: function () {},

  onLoad: function (options) {
    let that = this
    let token = wx.getStorageSync('token')
    that.setData({
      id: options.id,
      type: options.type,
    })
    if (!token) {
      wx.showModal({
        title: '提示',
        content: '您尚未登录,请登录后操作',
        success: function (res) {
          if (res.confirm) {
            // that.showModal()
            that.selectComponent('#lfyLogin').getLogin('hh')
          } else {
            wx.switchTab({
              url: '/pages/home/home'
            })
          }
        }
      })
    } else {
      that.gethuodong()
    }
  },
  async gethuodong() {
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/active/detail4s',
        data: {
          id: that.data.id,
          type: that.data.type
          // id: 40,
          // type: 2
        },
      })
      console.log(data, "活动兴趣");
      that.setData({
        klist: data,
        time_data: data.time_num,
        content: data.content,
        time: data.time_num,
        content2: that.text(data.say),
        avatar_arr: data.avatar_arr,
        can_num: data.can_num
      })
      WxParse.wxParse('content', 'html', that.data.content, that, 5);
    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },
  onChange(e) {
    this.setData({
      timeData: e.detail,
    });
  },
  toggleDialog(e) {
    let id = this.data.id
    wx.navigateTo({
      url: '/pages/distributionChanged/distributionChanged?id=' + id
    })
  },
  formSubmit(e) {
    let phone = e.detail.value.phone
    let that = this
    if (!(/^1[34578]\d{9}$/.test(phone))) {
      if (phone.length >= 11) {
        wx.showToast({
          title: '手机号有误',
          icon: 'none',
          duration: 1300
        })
      }
    } else {
      that.setData({
        obj: e.detail.value
      })
      // console.log(that.data.obj);
      that.getsubmit()
    }
  },
  async getsubmit() {
    let that = this
    let obj = that.data.obj
    try {
      const {
        data
      } = await request({
        url: 'api/active/baoMing',
        data: {
          name: obj.names,
          phone: obj.phone,
          id: that.data.id
        }
      })
      that.setData({
        msg: data.msg,
        texts: 1
      })
      that.popSuccessTest()
      console.log(data);
      setTimeout(() => {
        that.toggleDialog()
      }, 1000);
    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },
  // 正则验证图标图片  
  text(details) {

    var texts = ''; //待拼接的内容

    while (details.indexOf('<img') != -1) { //寻找img 循环

      texts += details.substring('0', details.indexOf('<img') + 4); //截取到<img前面的内容

      details = details.substring(details.indexOf('<img') + 4); //<img 后面的内容

      if (details.indexOf('style=') != -1 && details.indexOf('style=') < details.indexOf('>')) {

        texts += details.substring(0, details.indexOf('style="') + 7) + "max-width:100%;height:auto;margin:0 auto;"; //从 <img 后面的内容 截取到style= 加上自己要加的内容

        details = details.substring(details.indexOf('style="') + 7); //style后面的内容拼接

      } else {

        texts += ' style="max-width:100%;height:auto;margin:0 auto;" ';

      }
    }

    while (details.indexOf('<td') != -1) { //寻找img 循环

      texts += details.substring('0', details.indexOf('<td') + 4); //截取到<img前面的内容

      details = details.substring(details.indexOf('<td') + 4); //<img 后面的内容

      if (details.indexOf('style=') != -1 && details.indexOf('style=') < details.indexOf('>')) {

        texts += details.substring(0, details.indexOf('style="') + 7) + "max-width:74!important;height:auto;margin:0 auto;"; //从 <img 后面的内容 截取到style= 加上自己要加的内容

        details = details.substring(details.indexOf('style="') + 7); //style后面的内容拼接

      } else {

        texts += ' style="max-width:100%;height:auto;margin:0 auto;" ';

      }



    }


    texts += details; //最后拼接的内容

    return texts

  },
  onShareAppMessage: function (options) {
    var that = this;
    // 设置菜单中的转发按钮触发转发事件时的转发内容
    var shareObj = {
      title: "分享", // 默认是小程序的名称(可以写slogan等)
      path: '/pages/details/details?id=' + that.data.id + '&type=' + that.data.type, // 默认是当前页面,必须是以‘/’开头的完整路径
      imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
      success: function (res) {
        if (res.errMsg == 'shareAppMessage:ok') {}
      },
      fail: function () {
        // 转发失败之后的回调
        if (res.errMsg == 'shareAppMessage:fail cancel') {
          // 用户取消转发
        } else if (res.errMsg == 'shareAppMessage:fail') {
          // 转发失败,其中 detail message 为详细失败信息
        }
      },
    };
    return shareObj;
  },
  popMaskTest() {
    wx.showToast({
      title: this.data.msg,
      icon: 'none',
      duration: 1300,
      mask: true //是否有透明蒙层,默认为false 
      //如果有透明蒙层,弹窗的期间不能点击文档内容 
    })
  },
  popSuccessTest() {
    wx.showToast({
      title: this.data.msg,
      icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
      duration: 1300, //停留时间
    })
  },
  bindistoken() {
    this.gethuodong()
    console.log('我回来了');
  },




})