1. 程式人生 > >微信商城小程式WeiMall

微信商城小程式WeiMall

import ServiceBase from 'ServiceBase'

class Service extends ServiceBase {
    constructor() {
        super()
        this.$$prefix = ''
        this.$$path = {
      wechatSignUp: '/index/wechatSignUp',
      wechatSignIn: '/index/wechatSignIn',
      decryptData: '/index/decryptData',
      signIn: '/index/signIn',
      signOut: '/index/signOut',
      data:'/index/data',
      detail: '/index/detail',
      add: '/index/add', 
      del: '/index/del', 
      update: '/index/update'
    }
    }

    wechatSignUp(params) {
        return this.postRequest(this.$$path.wechatSignUp, params)
    }

    wechatSignIn(params) {
        return this.postRequest(this.$$path.wechatSignIn, params)
    }

    wechatDecryptData(params) {
        return this.postRequest(this.$$path.decryptData, params)
    }


    signIn(params) {
        return this.postRequest(this.$$path.signIn, params) 
    }

    signOut() {
        return this.postRequest(this.$$path.signOut) 
    }

  //獲取表格分頁資料
  getData(params) {
    return this.getRequest(this.$$path.data, params)
  }

  //獲取單條資料
  getDetail(params) {
    return this.getRequest(this.$$path.detail, params)
  }

  //新增資料
  addData(params){
    return this.postRequest(this.$$path.add, params)
  }

  //刪除資料
  delData(params) {
    return this.getRequest(this.$$path.del, params)
  }

  //更新資料
  updateData(params) {
    return this.getRequest(this.$$path.update, params)
  }

}

export default Service
     //呼叫資料
      App.HttpService.getData({
          table:'banner',
          page:1
      }).then(data=>{
        if(data.code==0){
          data.data.forEach(n => n.path = App.renderImage(n.img));
          this.setData({
            images: data.data
          });
        }else{
          this.showModal(data.message);
        }
      });

    //新增資料
    App.HttpService.addData(params).then(data => {
      if (data.code == 0) {
        this.showToast(data.message)
      }
    }); 

   //更新資料
    App.HttpService.updateData(params).then(data => {
      if (data.code == 0) {
        this.showToast(data.message);
      }
    });

  //刪除資料
    App.WxService.showModal({
      title: '友情提示',
      content: '確定要刪除這個地址嗎?',
    })
      .then(data => {
        if (data.confirm == 1) {
          App.HttpService.delData({
            table: 'address',
            id: id
          }).then(() => App.WxService.navigateBack());
        }
      })