Program.js 4.3 KB
// pages/Program/Program.js
const app=getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
   list: [],
   temobj:{
    name:'',
    firm:'',
    text:''
   }
  },
 getlist() {
  let that=this;
  let url = 'counselor/SchemeList';
  let params = {
   userId: app.globalData.UserId
  }
  app.post(url, params).then((res) => {
   if (res.data.code == 200) {
    that.setData({
     list: res.data.data.list
    })
   }
  }).catch((err) => {
   console.log(err)
  })
 },
 setname(e){
  let that = this;
  let list = that.data.list;
  let index = e.currentTarget.dataset.index;
  list[index].name = e.detail.value;
  that.setData({
   list: list
  })
 },
 setfirm(e){
  let that = this;
  let list = that.data.list;
  let index = e.currentTarget.dataset.index;
  list[index].firm = e.detail.value;
  that.setData({
   list: list
  })
 },
 settemname(e){
  let that=this;
  let temobj = that.data.temobj;
  temobj.name = e.detail.value;
  that.setData({
   temobj: temobj
  })
 },
 settemfirm(e) {
  let that = this;
  let temobj = that.data.temobj;
  temobj.firm = e.detail.value;
  that.setData({
   temobj: temobj
  })
 },
 settemtext(e) {
  let that = this;
  let temobj = that.data.temobj;
  temobj.text = e.detail.value;
  that.setData({
   temobj: temobj
  })
 },
 settext(e){
  let that=this;
  let list = that.data.list;
  let index = e.currentTarget.dataset.index;
  list[index].text = e.detail.value;
  that.setData({
   list: list
  })
 },
 deltemobj(){
  let that=this;
  let temobj={
   name: '',
   firm: '',
   text: '',
  }
  that.setData({
   temobj: temobj
  })
 },
 addtemobj(){
  
  let that=this;
  let url ='counselor/SchemeSave';
  let params={
   userId: app.globalData.UserId,
   name: that.data.temobj.name,
   firm: that.data.temobj.firm,
   text: that.data.temobj.text
  }
  app.post(url, params).then((res)=>{
   if(res.data.code==200){
    that.getlist();
    let temobj = {
     name: '',
     firm: '',
     text: '',
    }
    that.setData({
     temobj: temobj
    })
   }
  }).catch((err)=>{
   console.log(err)
  })
 },
 //保存按钮
 del(e){
  let that=this;
  let index = e.currentTarget.dataset.index;
  let list=that.data.list;
  let id = e.currentTarget.id;
  wx.showModal({
   title: '提示',
   content: '是否删除预设方案',
   cancelColor:'#000000',
   confirmColor:'#3cc51f',
   showCancel:true,
   cancelText:'取消',
   confirmText:'确定',
   success(res) {
    if (res.confirm) {
     let url ='counselor/SchemeDelete';
     app.post(url, { SchemeId:id}).then((res)=>{
      if(res.data.code==200){
       if(res.data.data.type==1){
        that.getlist();
       
        wx.showToast({
         title: '操作成功',
         icon: 'none',
         duration: 2000
        })
       }
      
      }
     })
    } else if (res.cancel) {
     console.log('用户点击取消')
    }
   }
  })
 },
 //保存所有
 allsave(){
  
  let that=this;
  let list = this.data.list;
  for (let i = 0; i < list.length;i++){
   if (i == (list.length-1)){
    wx.showToast({
     title: '保存成功',
     icon: 'success',
     duration: 2000,
     mask: true,
    })
    setTimeout(function(){
     wx.navigateBack({
      delta: 1
     })
    },1000) 
   }else{
    let url = 'counselor/SchemeSave';
    let params = {
     userId: app.globalData.UserId,
     schemeId: list[i].id,
     name: list[i].name,
     firm: list[i].firm,
     text: list[i].text
    }
    app.post(url, params).then((res) => {
     if (res.data.code == 200) {

     }
    }).catch((err) => {
     console.log(err)
    })
   }
  }
 },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   let that=this;
   that.getlist();
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   let that = this;
   that.getlist();
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})