addCarbook.js 3.4 KB
import {
  request
} from "../../request/index.js"
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    content: '',
    s4_id: '',
    msg: '',
    type: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //  console.log(options);
    let that = this
    that.setData({
      type: options.type || '',
      s4_id: options.s4_id,
    })
    this.getRuleBook()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  async getRuleBook() {
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: "api/shop4s/Fw",
        data: {
          s4_id: that.data.s4_id
        }
      })
      // //  console.log(data);
      that.setData({
        content: that.text(data.content)
      })
    } catch (err) {
      //  console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }

  },
  popMaskTest() {
    wx.showToast({
      title: this.data.msg,
      icon: 'none',
      duration: 2000,
      mask: true //是否有透明蒙层,默认为false 
      //如果有透明蒙层,弹窗的期间不能点击文档内容 
    })
  },
  // 正则验证图标图片  

  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

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})