config.js 21.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 139 140 141 142 143 144 145 146 147 148 149 150 151 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            var configIndex = new Vue({
                el: "#configIndex",
                data() {
                    return {
                        activeName: "basic",
                        configData: {
                            basic: [{
                                id: 'groupon',
                                title: '商城信息',
                                tip: '配置商城基本信息',
                                message: '商城名称、Logo',
                                icon: 'groupon-icon',
                                leaf: '#6ACAA5',
                                background: 'linear-gradient(180deg, #BAF0DD 0%, #51BC99 100%)',
                                url: "{:url(groupon.config/platform?type=groupon')}",
                                button: {
                                    background: '#E0F1EB',
                                    color: '#13986C'
                                },
                            }, {
                                id: 'user',
                                title: '会员配置',
                                tip: '配置默认会员信息',
                                message: '默认昵称、头像、分组、余额、积分',
                                icon: 'user-icon',
                                leaf: '#E0B163',
                                background: 'linear-gradient(180deg, #FCE6B7 0%, #E9A848 100%)',
                                button: {
                                    background: '#F7EDDD',
                                    color: '#B07318'
                                },
                            }, {
                                id: 'share',
                                title: '分享配置',
                                tip: '配置默认分享信息',
                                message: '分享标题、图片、海报背景',
                                icon: 'share-icon',
                                leaf: '#915CF9',
                                background: 'linear-gradient(180deg, #D5B8FA 0%, #8F62C9 100%)',
                                button: {
                                    background: '#E7DEF6',
                                    color: '#6625CF'
                                },
                            }, {
                                id: 'withdraw',
                                title: '提现配置',
                                tip: '配置默认提现规则',
                                message: '手续费、最小最大金额',
                                icon: 'withdraw-icon',
                                leaf: '#EA6670',
                                background: 'linear-gradient(180deg, #FCB7BE 0%, #D36068 100%)',
                                button: {
                                    background: '#F3DCDE',
                                    color: '#D61226'
                                },
                            }, {
                                id: 'order',
                                title: '商城配置',
                                tip: '配置默认商城规则',
                                message: '库存预警,订单自动关闭,订单自动收货,订单自动评价',
                                icon: 'order-icon',
                                leaf: '#6991E7',
                                background: 'linear-gradient(180deg, #AFCBFD 0%, #5A7CCF 100%)',
                                button: {
                                    background: '#DBE2F6',
                                    color: '#1B5EE7'
                                },
                            }, {
                                id: 'services',
                                title: '第三方服务',
                                tip: '配置物流及位置信息',
                                message: '快递鸟物流、高德地图',
                                icon: 'services-icon',
                                leaf: '#14B0F3',
                                background: 'linear-gradient(180deg, #A5E2FC 0%, #158CBF 100%)',
                                button: {
                                    background: '#DBE2F6',
                                    color: '#00A3D7'
                                },
                            }, {
                                id: 'store',
                                title: '自提点配置',
                                tip: '配置自提点协议',
                                message: '配置自提点协议',
                                icon: 'store-icon',
                                leaf: '#487EE5',
                                background: 'linear-gradient(180deg, #84C4FF 0%, #3C68BE 100%)',
                                button: {
                                    background: '#DFE7EE',
                                    color: '#1C54BD'
                                },
                            }],
                            platform: [{
                                id: 'wxMiniProgram',
                                title: '小程序',
                                tip: '配置小程序',
                                message: 'AppId、AppSecret、自动登录',
                                icon: 'wxMiniProgram-icon',
                                leaf: '#6962F7',
                                background: 'linear-gradient(180deg, #C1BFFF 0%, #6563C9 100%)',
                                buttonMessage: '小程序设置',
                                button: {
                                    background: '#D8D8F1',
                                    color: '#3932BF'
                                },
                            }],
                            payment: [{
                                id: 'wechat',
                                title: '微信支付',
                                tip: '',
                                message: '',
                                icon: 'wechat-icon',
                                leaf: '#6ACAA4',
                                background: 'linear-gradient(180deg, #AAF0D7 0%, #5DC1A0 100%)',
                                button: {
                                    background: '#DEF0EA',
                                    color: '#0EA753'
                                },
                            }, {
                                id: 'wechatv3',
                                title: '微信支付 v3',
                                tip: '',
                                message: '',
                                icon: 'wechat-icon',
                                leaf: '#6ACAA4',
                                background: 'linear-gradient(180deg, #AAF0D7 0%, #5DC1A0 100%)',
                                button: {
                                    background: '#DEF0EA',
                                    color: '#0EA753'
                                },
                            }, {
                                id: 'wallet',
                                title: '余额支付',
                                tip: '',
                                message: '',
                                icon: 'wallet-icon',
                                leaf: '#EC9371',
                                background: 'linear-gradient(180deg, #FADDC0 0%, #E6816E 100%)',
                                button: {
                                    background: '#F7E6E1',
                                    color: '#D75E37'
                                },
                            }]
                        }
                    }
                },
                mounted() { },
                methods: {
                    tabClick(tab, event) {
                        this.activeName = tab.name;
                    },
                    operation(id, title) {
                        let that = this;
                        Fast.api.open("groupon/config/platform?type=" + id + "&tab=" + that.activeName + "&title=" + title, title);
                    },
                },
            })
        },
        platform: function () {
            var configPlatform = new Vue({
                el: "#configPlatform",
                data() {
                    return {
                        platformData: {
                            groupon: {
                                name: '',
                                version: '',
                                logo: '',
                                logo_arr: [],
                                copyright: ['', '']
                            },
                            user: {
                                nickname: '',
                                avatar: '',
                                avatar_arr: [],
                                group_id: '',
                                money: '',
                            },
                            share: {
                                title: '',
                                image: '',
                                goods_poster_bg: '',
                                user_poster_bg: '',
                                store_poster_bg:'',
                                image_arr: [],
                                goods_poster_bg_arr: [],
                                user_poster_bg_arr: [],
                                store_poster_bg_arr:[]
                            },
                            withdraw: {
                                methods: [],
                                wechat_alipay_auto: 0,
                                service_fee: '',
                                min: '',
                                max: '',
                            },
                            order: {
                                order_auto_close: '',
                                order_auto_confirm: '',
                                order_auto_comment: '',
                                order_comment_content: '',
                                goods: {
                                    stock_warning: 0
                                }
                            },
                            services: {
                                amap: {
                                    appkey: ''
                                },
                                express: {
                                    ebusiness_id: '',
                                    type: 'free',
                                    appkey: '',
                                    jd_code: ''
                                },
                            },
                            store: {
                                intro_image:'',
                                intro_image_arr:[],
                                protocol: '',
                                store_take_type:'money',
                                store_take_money:0,
                                store_take_rate:0,
                                store_price_type: 'goods_price',//goods_price|pay_price
                                store_take_event: 'payed',//payed|confirm|finish|admin
                                store_refund_reduce: '1',//1|0
                            },
                            wxMiniProgram: {
                                name: '',
                                avatar: '',
                                qrcode: '',
                                avatar_arr: [],
                                qrcode_arr: [],
                                app_id: '',
                                secret: '',
                                auto_login: '',
                            },
                            wechat: {
                                platform: [],
                                mch_id: '',
                                key: '',
                                sub_key: '',
                                cert_client: '',
                                cert_key: '',
                                sub_cert_client: '',
                                sub_cert_key: '',
                                mode: 'normal',
                                sub_mch_id: '',
                                app_id: '',
                            },
                            wechatv3: {
                                platform: [],
                                mode: 0, // 0|2
                                app_id: '',
                                mch_id: '',
                                mch_secret_key: '',
                                mch_secret_cert: '',
                                mch_public_cert_path: '',
                                sub_mch_id: '',
                                sub_mch_secret_key: '',
                                sub_mch_secret_cert: '',
                                sub_mch_public_cert_path: '',
                            },
                            wallet: {
                                platform: [],
                            },
                        },
                        type: new URLSearchParams(location.search).get('type'),
                        tab: new URLSearchParams(location.search).get('tab'),
                        title: new URLSearchParams(location.search).get('title'),
                        groupList: [],
                        detailForm: {},
                        must_delete: ['logo_arr', 'avatar_arr', 'image_arr', 'goods_poster_bg_arr', 'user_poster_bg_arr','intro_image_arr', 'qrcode_arr'],
                        expressAddress: window.location.origin + '/addons/groupon/express/callback'
                    }
                },
                mounted() {
                    this.operationData();
                },
                methods: {
                    operationData() {
                        this.detailForm = this.platformData[this.type]
                        if (Config.row) {
                            for (key in this.detailForm) {
                                if (Config.row[key]) {
                                    if(Config.row[key] instanceof Object){
                                        for(inner in Config.row[key]){
                                            if(Config.row[key][inner]){
                                                this.detailForm[key][inner]=Config.row[key][inner]
                                            }
                                        }
                                    }else{
                                        this.detailForm[key] = Config.row[key]
                                    }
                                }
                            }
                        }
                        if (this.type == 'groupon') {
                            this.detailForm.logo_arr = []
                            this.detailForm.logo_arr.push(Fast.api.cdnurl(this.detailForm.logo))
                        } else if (this.type == 'user') {
                            this.groupList = Config.groupList
                            this.detailForm.avatar_arr = []
                            this.detailForm.avatar_arr.push(Fast.api.cdnurl(this.detailForm.avatar))
                        } else if (this.type == 'share') {
                            this.detailForm.image_arr = []
                            this.detailForm.image_arr.push(Fast.api.cdnurl(this.detailForm.image))
                            this.detailForm.goods_poster_bg_arr = []
                            this.detailForm.goods_poster_bg_arr.push(Fast.api.cdnurl(this.detailForm.goods_poster_bg))
                            this.detailForm.user_poster_bg_arr = []
                            this.detailForm.user_poster_bg_arr.push(Fast.api.cdnurl(this.detailForm.user_poster_bg))
                            this.detailForm.store_poster_bg_arr = []
                            this.detailForm.store_poster_bg_arr.push(Fast.api.cdnurl(this.detailForm.store_poster_bg))
                        } else if (this.type == 'withdraw') {
                            this.detailForm.service_fee = this.detailForm.service_fee * 100
                        } else if (this.type == 'wxMiniProgram') {
                            this.detailForm.avatar_arr = []
                            this.detailForm.avatar_arr.push(Fast.api.cdnurl(this.detailForm.avatar))
                            this.detailForm.qrcode_arr = []
                            this.detailForm.qrcode_arr.push(Fast.api.cdnurl(this.detailForm.qrcode))
                        } else if (this.type == 'store') {
                            this.detailForm.intro_image_arr = []
                            this.detailForm.intro_image_arr.push(Fast.api.cdnurl(this.detailForm.intro_image))
                        }
                    },
                    storefile() {
                        let that = this;
                        Fast.api.open("groupon/richtext/select?multiple=false", "选择协议", {
                            callback: function (data) {
                                that.detailForm.protocol = data.data.id;
                            }
                        });
                        return false;
                    },
                    addImg(type, field) {
                        let that = this;
                        Fast.api.open("general/attachment/select?multiple=false", "选择", {
                            callback: function (data) {
                                switch (type) {
                                    case "image":
                                        that.detailForm[field] = data.url;
                                        that.detailForm[field + '_arr'] = data.url;
                                        break;
                                    case "file":
                                        that.detailForm[field] = data.url;
                                        break;
                                    case "ssl":
                                        that.detailForm.system[field] = data.url;
                                        break;
                                }
                            }
                        });
                        return false;
                    },
                    delImg(type, field) {
                        let that = this;
                        switch (type) {
                            case "image":
                                that.detailForm[field] = '';
                                that.detailForm[field + '_arr'] = [];
                                break;
                            case "file":
                                that.detailForm[field] = '';
                                break;
                        }
                    },
                    changeWechatType() {
                        for (key in this.detailForm) {
                            if (key != 'mode' && key != 'platform') {
                                this.detailForm[key] = ''
                            }
                        }
                    },
                    ajaxUpload(id) {
                        let that = this;
                        var formData = new FormData();
                        formData.append("file", $('#' + id)[0].files[0]);
                        $.ajax({
                            type: "post",
                            url: "ajax/upload",
                            data: formData,
                            cache: false,
                            processData: false,
                            contentType: false,
                            success: function (data) {
                                if(data.code==1){
                                    that.detailForm[id] = data.data.url
                                }else{
                                    that.$notify({
                                        title: '警告',
                                        message: data.msg,
                                        type: 'warning'
                                    });
                                }
                            }
                        })
                    },
                    submitFrom(type) {
                        let that = this;
                        if (type == 'yes') {
                            let submitData = JSON.parse(JSON.stringify(that.detailForm))
                            if (that.type == 'withdraw') {
                                submitData.service_fee = (Number(submitData.service_fee) / 100).toFixed(2)
                            }
                            that.must_delete.forEach(i => {
                                if (submitData[i]) {
                                    delete submitData[i]
                                }
                            });
                            Fast.api.ajax({
                                url: 'groupon/config/platform?type=' + that.type,
                                loading: true,
                                type: 'POST',
                                data: {
                                    data: JSON.stringify(submitData),
                                    group: that.tab,
                                    title: that.title
                                },
                            }, function (ret, res) {
                                Fast.api.close()
                            })
                        } else {
                            Fast.api.close()
                        }
                    },
                },
            })
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});