fenxiaoModel.js 7.32 KB
Newer Older
张卓 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

class fenxiaoModel{
    fenxiaoApi = {
        query_login_spoken: null,//查询分销信息
        becomepokesmanCustomer: null,//绑定商上级分销关系
        saveCustomerInviterInviteeRel: null,//绑定商上级客户关系
        getHomePageQuickAccess: null,//查询个人名片入口
        query_isEntry: null,//查询成为分销弹框
        getDistributorHomepage: null,//查询是否有自己的小店
        getDistributorHomepageGoodsList: null,//首页分销商货架信息
        getSpokesmanidByShare: null,//获取分销分享信息
        oneClickShopQuickCopy: null,//一键开店快速复制
        apply_for_withdraw: null,//关闭分销弹框
    }
    spokesmanInfo = null;//分销信息
张卓 committed
16
    applySucessEntry = {};//分销弹框信息
张卓 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    spokesmanidByShareInfo = null;//获取分享信息
    distributorHomepageInfo = null;//小店详情
    constructor({
        query_login_spoken,
        becomepokesmanCustomer,
        saveCustomerInviterInviteeRel,
        getHomePageQuickAccess,
        query_isEntry,
        getDistributorHomepage,
        getDistributorHomepageGoodsList,
        getSpokesmanidByShare,
        oneClickShopQuickCopy,
        apply_for_withdraw,
    }){
        this.fenxiaoApi.query_login_spoken = query_login_spoken;
        this.fenxiaoApi.becomepokesmanCustomer = becomepokesmanCustomer;
        this.fenxiaoApi.saveCustomerInviterInviteeRel = saveCustomerInviterInviteeRel;
        this.fenxiaoApi.getHomePageQuickAccess = getHomePageQuickAccess;
        this.fenxiaoApi.query_isEntry = query_isEntry;
        this.fenxiaoApi.getDistributorHomepage = getDistributorHomepage;
        this.fenxiaoApi.getDistributorHomepageGoodsList = getDistributorHomepageGoodsList;
        this.fenxiaoApi.getSpokesmanidByShare = getSpokesmanidByShare;
        this.fenxiaoApi.oneClickShopQuickCopy = oneClickShopQuickCopy;
        this.fenxiaoApi.apply_for_withdraw = apply_for_withdraw;
    }
    //获取分销信息
    getSpokesmanInfo(replace = false){
        let _this = this
        return new Promise(function (resolve, reject) {
            if(_this.spokesmanInfo&&!replace) {
                resolve(_this.spokesmanInfo)
            }else {
                _this.setSpokesmanInfo().then(res=>{
                    resolve(res)
                }).catch(res=>{
                    reject(res)
                })
            }
        });
    }
    //设置分销信息
    setSpokesmanInfo() {
        let _this = this
        return new Promise(function (resolve, reject) {
            _this.fenxiaoApi.query_login_spoken().then(res=>{
                if(res.data.code == '200') {
                    _this.spokesmanInfo = res.data.data;
                }
李嘉林 committed
65
                resolve(res.data.data) 
张卓 committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
            });
        });
    }
    //绑定分销关系
    becomeRelation(extConfig) {
        let _this = this
        return new Promise(function (resolve, reject) {
            if(extConfig&&extConfig.spokesmanRelId) {
                _this.fenxiaoApi.becomepokesmanCustomer(extConfig.spokesmanRelId).then(res=>{
                    if(res.data.code == '200') {
                        resolve(res)
                    }else {
                        reject(res)
                    }
                })
            }else if(extConfig&&extConfig.userId) {
                _this.fenxiaoApi.saveCustomerInviterInviteeRel(extConfig.userId).then(res=>{
                    if(res.data.code == '200') {
                        resolve(res)
                    }else {
                        reject(res)
                    }
                })
            }else {
张卓 committed
90
                resolve(false)
张卓 committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
            }
        })
    }
    //查询个人名片入口
    getHomePageQuickAccess() {
        let _this = this
        return new Promise(function (resolve, reject) {
            _this.fenxiaoApi.getHomePageQuickAccess().then(res=>{
                if(res.data.code == '200' && res.data.data == 'true') {
                    resolve(true)
                }else {
                    reject(false)
                }
            })
        })
    }
    //查询是否有自己的小店
    getDistributorHomepage(spokesmanInfo,replace=false) {
        let _this = this
        return new Promise(function (resolve, reject) {
            if(_this.distributorHomepageInfo&&!replace) {
                resolve(_this.distributorHomepageInfo)
            }else {
                _this.fenxiaoApi.getDistributorHomepage(spokesmanInfo.id).then(res=>{
                    if (
                        res.data.code == "200" &&
                        res.data.data &&
                        res.data.data != "null" &&
                        res.data.data != "false"
                    ) {
                        _this.distributorHomepageInfo = res.data.data
                        resolve(res.data.data)
                    }
                })
            }
        })
    }
    //查询成为分销弹框
    query_isEntry() {
        let _this = this
        return new Promise(function (resolve, reject) {
            _this.fenxiaoApi.query_isEntry().then(res=>{
                if (
                    res.data.code == "200" &&
                    res.data.data &&
                    res.data.data != "null" &&
                    res.data.data != "false"
                ) {
张卓 committed
139
                    _this.applySucessEntry = res.data.data;
张卓 committed
140 141 142 143 144 145 146 147
                    resolve(res.data.data)
                }else{
                    reject(res)
                }
            })
        })
    }
    //查询分销商货架
张卓 committed
148
    getDistributorHomepageGoodsList(data) {
张卓 committed
149 150
        let _this = this
        return new Promise(function (resolve, reject) {
张卓 committed
151
            _this.fenxiaoApi.getDistributorHomepageGoodsList(data).then(res=>{
张卓 committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
                if(res.data.code == '200') {
                    resolve(res.data.data)
                }else {
                    reject(res)
                }
            })
        })
    }
    //获取分享信息
    getSpokesmanidByShare(replace=false) {//replace是否更新数据
        let _this = this
        return new Promise(function (resolve, reject) {
            if(_this.spokesmanidByShareInfo&&!replace) {
                resolve(_this.spokesmanidByShareInfo)
            }else {
                _this.fenxiaoApi.getSpokesmanidByShare().then(res=>{
                    if(res.data.code == '200') {
                        _this.spokesmanidByShareInfo = res.data.data;
                        resolve(res.data.data)
                    }else {
                        reject(res)
                    }
                })
            }
        })
    }
    //一键复制店铺
    oneClickShopQuickCopy(data) {
        let _this = this
        return new Promise(function (resolve, reject) {
            _this.fenxiaoApi.oneClickShopQuickCopy(data).then(res=>{
                if(res.data.code == '200') {
                    resolve(res.data.data)
                }else {
                    reject(res)
                }
            })
        })
    }
    //关闭分销成功弹框
    apply_for_withdraw(data) {
        let _this = this
        return new Promise(function (resolve, reject) {
            _this.fenxiaoApi.apply_for_withdraw(data).then(res=>{
                if(res.data.code == '200') {
                    resolve(res.data.data)
                }else {
                    reject(res)
                }
            })
        })
    }
}
export default fenxiaoModel