const {
  checkTraderEmpAuth
} = require('../api/api');
function checkPermission (perm) {
  return new Promise((resolve, reject) => {
    let userType = wx.getStorageSync('userType');
    if(userType != 'TRADER_EMP'){ //非代理商员工不检验权限字段
      resolve(true);
      return;
    }
    //perm权限关键字
    checkTraderEmpAuth({
      userId:wx.getStorageSync('userId'),
      permission:perm
    }).then(res=>{
      if(res.code == 200){
        if(!res.data){
          wx.showToast({
            title: "暂无权限",
            icon:'none'
          });
          resolve(false);
        }else{
          resolve(true);
        }
      }else{
        wx.showToast({
          title: res.errMsg,
          icon:'none'
        });
        resolve(false);
      }
    });
  });
}
module.exports = {
  checkPermission
}