VmyTeam.js 4.1 KB
import {
  request
} from "../../request/index.js"
const a = getApp()
Page({
  data: {
    baseUrl: a.globalData.baseUrl,
    statusTop: a.globalData.statusHeight,
    imagesUrl: a.globalData.imagesUrl,
    four: 3,
    msg: '',
    id: '',
    myTeam: [],
    shen_id: '',
    dui_id: '',
  },
  onLoad: function (options) {
    let that = this
    console.log(options);
    that.setData({
      id: options.che_id,
    })
    that.getMyTeam()
  },
  onShow: function () {

  },
  goback() {
    wx.navigateBack()
  },
  goNoticeDetail(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/VnoticeDetail/VnoticeDetail'
    })
  },
  goVapplicationList() {
    let che_id = this.data.id
    this.setData({
      shen_id: 0
    })
    wx.navigateTo({
      url: '/pages/VapplicationList/VapplicationList?che_id=' + che_id
    })
  },
  async getMyTeam() {
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/my2/cheDui',
        data: {
          id: that.data.id
        }
      })
      console.log(data);
      that.setData({
        myTeam: data.dui_arr,
        shen_id: data.shen_id,
        dui_id: data.dui_id,
      })
    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popTest()
    }
  },
  delPerons(e) {
    let that = this
    let id = e.currentTarget.dataset.id
    let che_id = that.data.id
    wx.showModal({
      title: '',
      content: '确认将该用户移出团队',
      success: async function (res) {
        if (res.confirm) {
          try {
            const {
              data
            } = await request({
              url: 'api/my2/delCheUser',
              data: {
                id: id,
                che_id: che_id
              }
            })
            console.log(data);
            if (data.code == 1) {
              that.setData({
                msg: data.msg
              })
              that.popSuccessTest()
              setTimeout(() => {
                that.getMyTeam()
              }, 1000);
            } else {
              that.setData({
                msg: data.msg
              })
            }
            that.popTest()

          } catch (err) {
            console.log(err);
            that.setData({
              msg: err.msg
            })
            that.popTest()
          }
        } else {
          wx.switchTab({
            url: '/pages/home/home'
          })
        }
      }
    })
  },
  async leaveTeam() {
    let that = this
    let che_id = that.data.che_id
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/my2/userLeave',
        data: {
          che_id: che_id
        }
      })
      console.log(data);
      that.setData({
        public: data
      })
    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popTest()
    }

  },











  async public() {
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: '',
        data: {
          goods_id: that.data.goods_id
        }
      })
      console.log(data);
      that.setData({
        public: data
      })
    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popTest()
    }
  },
  popTest() {
    wx.showToast({
      title: this.data.msg,
      icon: 'none', //如果要纯文本,不要icon,将值设为'none'
      duration: 1300
    })
  },
  goLogin() {
    wx.showModal({
      title: '提示',
      content: '您尚未登录,前往登录',
      success: function (res) {
        if (res.confirm) {
          wx.navigateTo({
            // url: '/pages/authorization/authorization'
          })

        } else {
          wx.switchTab({
            url: '/pages/home/home'
          })
        }
      }
    })
  },
  popSuccessTest() {
    wx.showToast({
      title: this.data.msg,
      icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
      duration: 1300, //停留时间
    })
  },
})