var $_GET = (function () {
    var url = window.document.location.href.toString();
    var u = url.split("?");
    if (typeof (u[1]) == "string") {
        u = u[1].split("&");
        var get = {};
        for (var i in u) {
            var j = u[i].split("=");
            get[j[0]] = j[1];
        }
        return get;
    } else {
        return {};
    }
})();

$("#submit").click(function () {
    var gid = $("#gootsp").attr('data-gid');
    var count = $("#gootsp").attr('data-count');
    if (gid == '' || count == '') {
        layer.alert('数据异常,缺失重要数据');
        return false;
    }
    if ($("#num").val() <= 0) {
        layer.alert('下单份数不可低于1份', {icon: 2, anim: 4});
        return false;
    }
    var arr = [];
    var b = 1;
    var conts = '';
    for (let a = 0; a < count; a++) {
        arr[a] = $("#input_val_" + b).val();
        if (arr[a] == '') {
            layer.alert('请把' + $("#var_c" + b).text() + '填写完整哦！');
            return false;
        }
        var inputes = arr[a];
        var namevar = $("#var_c" + b).text();
        checkInput("var_c" + b, 'input_val_' + b);
        if ((namevar == '下单ＱＱ' || namevar == 'ＱＱ账号' || namevar == 'QQ账号' || namevar == '下单QQ') && (inputes.length < 5 || inputes.length > 11 || isNaN(inputes))) {
            layer.alert('请输入正确的ＱＱ号！');
            return false;
        }
        var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        if (namevar == '你的邮箱' && !reg.test(inputes)) {
            layer.alert('邮箱格式不正确！');
            return false;
        }
        reg = /^[1][0-9]{10}$/;
        if (namevar == '手机号码' && !reg.test(inputes)) {
            layer.alert('手机号码格式不正确！');
            return false;
        }

        if (namevar == '说说ID' || namevar == '说说ＩＤ') {
            if (inputes.length != 24) {
                layer.alert('说说必须是原创说说！');
                return false;
            }
        }
        if (namevar == '抖音作品ID' || namevar == '火山作品ID' || namevar == '火山直播ID') {
            if (inputes.length != 19) {
                layer.alert('您输入的作品ID有误！');
                return false;
            }
        }
        if (namevar == '抖音评论ID' || namevar == '抖音ID') {
            if (inputes.length != 19) {
                layer.alert('您输入的评论ID有误！请点击自动获取手动选择评论！');
                return false;
            }
        }

        conts += '<div>' + $("#var_c" + b).text() + '：' + arr[a] + '</div>';
        b = b + 1;
    }
    num = $("#num").val();
    if (num == '') {
        num = 1;
    }
    var indexs = layer.load(3, {time: 9666699})
    $.ajax({
        type: "post",
        url: "ajax.php?act=orders_transit",
        data: {gid: gid, data: arr, num: num, conts: conts},
        dataType: "json",
        success: function (data) {
            layer.close(indexs);
            if (data.code == 1) {
                var inst = layer.msg(data.msg, {
                    btn: ['付款', '取消'], time: 999999, icon: 1, btn1: function (layero, index) {
                        if (data.type == 2) {
                            window.open(data.url, "", "width=800px,height=600px,menubar=no,channelmode=yes");
                        } else window.open(data.url);
                        layer.closeAll();
                        var inde = layer.msg('付款成功了吗?点击下方继续！', {
                            icon: 16, time: 999999, btn: ['查看订单', '关闭'], btn1: function (layero, index) {
                                location.href = '/?mod=query';
                            }, btn2: function (layero, index) {
                                layer.close(inde);
                            }
                        });
                    },
                    btn2: function (layero, index) {
                        layer.close(inst);
                    }
                })
            } else {
                layer.msg(data.msg, {icon: 2});
            }
        },
        error: function () {
            layer.alert('加载失败！');
        }
    });
});

$("#submit_query").click(function () {
    merchandise.query_sep($('#vae').val())
});

//订单管理(新)
var OrderManagement = {
    OrderQuery: function (type, msg = null) { //查询全部订单
        var load = layer.load(2);
        $.ajax({
            type: "post",
            url: "/ajax.php?act=OrderQuery",
            data: {
                type: type,
                msg: msg
            },
            dataType: "json",
            success: function (data) {
                layer.close(load);
                template.query_tem(data);
            },
            error: function () {
                layer.alert('加载失败！');
            }
        });
    },
};


/**
 * 下单所需参数构建
 * @type {{gid_data: merchandise.gid_data, query_data: merchandise.query_data, query_sep: merchandise.query_sep, get_data: merchandise.get_data, cid_data: merchandise.cid_data}}
 */

var merchandise = {
    query_goods: function (name) {
        location.href = '?name=' + name;
    },
    get_data: function (gid, arr, type, mode = null) {
        var paytype = $("input[name=pay]:checked").val();
        var order = JSON.parse($("body").attr('order'));
        mode = 'alipay';
        type = 1;
        if (paytype == undefined) {
            swal({
                title: '注意',
                type: 'warning',
                html: '<h4>请选择付款方式！</h4>',
                confirmButtonText: '好的',
            });
            return false;
        }
        switch (paytype) {
            case '1'://支付宝
                mode = 'alipay';
                break;
            case '2': //微信
                mode = 'wxpay';
                break;
            case '3': //QQ
                mode = 'qqpay';
                break;
            case '4': //余额
                type = 2;
                break;
            case '5': //积分
                type = 3;
                break;
            case '6':
                //demo_url
                var content = $("#demo_url").attr('data-url');
                var clipboard = new Clipboard('.btssn', {
                    text: function () {
                        return content;
                    }
                });
                layer.open({
                    title: '代付订单创建成功',
                    btn: false,
                    content: '<center style="color: seagreen">代付订单已经创建成功，发给好友帮你付款吧~</center><hr><textarea  class="layui-textarea">' + content + '</textarea><hr>' +
                        '<center><button class="layui-btn layui-btn-fluid layui-btn-radius layui-btn-sm layui-btn-normal btssn">点击复制</button></center>',
                });
                clipboard.on('success', function (e) {
                    swal({
                        title: '恭喜',
                        type: 'success',
                        html: '代付订单链接已经帮您复制到剪切板上啦，快去发送给朋友让他帮你付款吧~',
                        confirmButtonText: '好的',
                    });
                    layer.closeAll();
                });
                clipboard.on('error', function (e) {
                    console.log(e);
                    swal({
                        title: '异常',
                        type: 'warning',
                        html: '复制功能好像出了点问题，去手动复制代付订单链接发给朋友吧',
                        confirmButtonText: '好的',
                    });
                    layer.closeAll();
                });
                return false;
                break;
        }
        var index = layer.msg('加载中...', {icon: 16, time: 9999999});
        $.ajax({
            type: "post",
            url: "ajax.php?act=submit_input",
            data: {type: type, mode: mode, orders: order},
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code == 1) {
                    if (data.khamwi != undefined) {
                        var kam = '';
                        for (let a = 0; a < data.khamwi.length; a++) {
                            kam += '<br>卡' + (a + 1) + '：' + data.khamwi[a];
                        }
                        layer.alert('您的卡密内容为：' + kam, {
                            title: data.msg,
                            icon: 1, btn1: function (layero, index) {
                                location.href = '/?mod=query';
                            }
                        });
                    } else {
                        layer.alert(data.msg, {
                            icon: 1, btn1: function (layero, index) {
                                location.href = '/?mod=query';
                            }
                        });
                    }
                } else if (data.code == 2) {
                    var inst = layer.msg('付款链接创建成功，点击下方按钮付款!', {
                        btn: ['付款', '取消'], time: 9999999, icon: 1, btn1: function (layero, index) {
                            window.open(data.url);
                            var inde = layer.msg(data.msg, {
                                icon: 16, time: 999999, btn: ['查看订单', '关闭'], btn1: function (layero, index) {
                                    location.href = '/?mod=query';
                                }, btn2: function (layero, index) {
                                    layer.close(inde);
                                }
                            });
                        },
                        btn2: function (layero, index) {
                            layer.close(inst);
                        }
                    })


                } else if (data.code == -3) { //返回首页
                    layer.alert(data.msg, {
                        icon: 2, end: function (layero, index) {
                            location.href = '/'
                        }
                    });
                } else if (data.code == -2) { //进入后台
                    layer.alert(data.msg, {
                        icon: 2, end: function (layero, index) {
                            location.href = '/user'
                        }
                    });
                } else if (data.code == -4) { //刷新一下
                    layer.alert(data.msg, {
                        icon: 2, end: function (layero, index) {
                            location.reload();
                        }
                    });
                } else {
                    layer.alert(data.msg, {icon: 3});
                }
            },
            error: function () {
                layer.msg('兑换失败！');
                layer.close(index);
            }
        });
    },
    query_data: function (id) { //查单
        var index = layer.msg('订单查询中...', {icon: 16, time: 9999999});
        $.ajax({
            type: "post",
            url: "ajax.php?act=order_details",
            data: {id: id},
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code == 1) {
                    var content = '<div style="overflow:auto;max-height: 80vh">';
                    $.each(data.data, function (index, item) {
                        if (index == '') {
                            content += item;
                        } else {
                            if (item != null && item != '' && item != undefined) {
                                content += '<font color=' + '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(18)).substr(-6) + '>' + index + '</font> ：' + item + '<br>';
                            }
                        }
                    });
                    content += '</div>';
                    var area = [$(window).width() > 480 ? '480px' : '80%'];
                    layer.open({
                        type: 0,
                        area: area,
                        title: data['name'] + ' 订单详情！',
                        content: content
                    });
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.alert('查询失败！');
                layer.close(index);
            }
        });
    },
    cid_data: function () { //获取分类数据  通用类
        var index = layer.load(3, {time: 10 * 1000});
        $.ajax({
            type: "post",
            url: "ajax.php?act=getclass",
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code >= 0) {
                    if (data.data.length == 0) {
                        layer.alert('当前无任何分类', {icon: 2})
                    } else {
                        var content = '';
                        $.each(data.data, function (i, item) {
                            content += template.data_class(item);
                        });
                        $("#cid").html(content);
                        $("#cid").show();
                        setTimeout(function () {
                            operation();
                        }, 300);
                        //layer.msg('加载完成,共'+data.data.length+'个分类！',{icon:1});
                    }
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.msg('数据获取失败！');
            }
        });
    },
    gid_data: function (cid = null, name = null, type = null) { //获取商品数据 通用类
        if (name == null) {
            var url = "ajax.php?act=getgoods";
        } else var url = "ajax.php?act=query_goods";
        var index = layer.load(3, {time: 10 * 1000});
        $.ajax({
            type: "post",
            url: url,
            data: {cid: cid, name: decodeURI(name)},
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code >= 0) {
                    if (data.data.length == 0) {
                        if (name == null) {
                            layer.msg('当前分类下无任何商品', {icon: 2})
                        } else {
                            layer.msg('没有查询到相关商品', {
                                icon: 2, btn: '返回', btn1: function (layero, index) {
                                    location.href = './';
                                }
                            })
                        }
                    } else {
                        var content = '';
                        $.each(data.data, function (i, item) {
                            content += template.data_goods(item);
                        });
                        $("#gid").html(content);
                        $("#gid").show();
                        if (type == null) {
                            $("#cid").html('');
                        }
                        setTimeout(function () {
                            operation();
                        }, 600);
                        //layer.msg('加载完成,共'+data.data.length+'个商品！',{icon:1});
                    }
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.msg('数据获取失败！');
            }
        });
    },
    shop_data: function (gid) {
        var index = layer.load(3, {time: 10 * 100000});
        $.ajax({
            type: "post",
            url: "ajax.php?act=getgoods_details",
            data: {
                gid: gid
            },
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code >= 0) {
                    console.log(data);
                    $("#gootsp").attr({
                        'data-gid': gid,
                        'data-count': data.data['count'],
                        'data-count_quota': data.data['count_quota'],
                        'value': data.data['name'] + ' * 1份 ⇨ ' + data.data['quantity'] + '个',
                        'data-points': data.data['points'],
                        'data-method': data.data.method,
                        'data-image': data.data['image'],
                        'data-currency': data.data['currency'], //货币名称
                        'data-cid': data.data['cid'],
                        'data-price': data.data['price'],
                        'data-level': data.data['level'],
                        'data-pay': data.data['pay'],
                        'data-quantity': data.data['quantity'],
                        'data-picture': data.data['picture'],
                        'data-min': data.data['min'],
                        'data-max': data.data['max'],
                    });

                    var contents = '';
                    count = 1;
                    count_arr = 0;
                    $.each(data.data['level_arr'], function (key, val) {
                        if (count == 1) {
                            tips = '<span style="float:right;margin-right: 1em;" >当前 <font color=red>' + val.price.toFixed(2) + '元</font></span>';
                        } else {
                            tips = '<span style="float:right;margin-right: 1em;color:seagreen;" >' + val.price.toFixed(2) + '元</span>';
                        }
                        contents += '<p>等级：' + val.name + tips + '</p>';
                        ++count;
                        ++count_arr;
                    });
                    if (count_arr > 1) {
                        $("#gootsp").attr({
                            'data-level_arr': escape(contents),
                        });
                    } else {
                        $("#gootsp").attr({
                            'data-level_arr': -1,
                        })
                    }
                    $("#moneys").val((data.data['price'] - 0).toFixed(2) + ' 元');
                    $("#residue").val(data.data['count_quota'] + ' 份');
                    $("#points").val(data.data['points'] + data.data['currency']);
                    $("#classImg").attr('src', data.data['image']);
                    if (data.data['docs'] != '' && data.data['docs'] != 'null' && data.data['docs'] != null && data.data['docs'] != undefined) { //商品说明
                        $("#alert_frame").html(data.data['docs']);
                        $("#alert_frame").show(200);
                    }

                    if (data.data.alert != '' && data.data.alert != 'null' && data.data['alert'] != null && data.data['alert'] != undefined) { //商品弹窗
                        swal({
                            title: '购买须知',
                            type: 'info',
                            html: '<h4>' + data.data['alert'] + '</h4>',
                            animation: false,
                            customClass: 'rubberBand animated',
                            confirmButtonText: '朕已阅',
                        })
                    }
                    /**
                     * 解析下单需填写字段
                     */

                    var method = data.data.method; //商品状态
                    var inputsname = data.data.value;

                    if (method.indexOf(7) != -1) { //是否开启数量选择框和价格监控！
                        $('#input_value').append(template.num());
                        $("#num").click(function () {
                            var prome = layer.prompt({
                                formType: 3,
                                value: $("#num").val(),
                                title: '填写需要的商品份数',
                            }, function (value, index, elem) {
                                $("#num").val(value);
                                ddo = 1;
                                var nums = $("#num").val();
                                if ((nums * (data.data['quantity'] - 0)) < (data.data['min'] - 0) && data.data.min != 0) {
                                    swal({
                                        title: '注意',
                                        type: 'warning',
                                        html: '<h4>商品' + data.data.name + '最少购买' + data.data['min'] + '个(' + (data.data['min'] - 0) / (data.data['quantity'] - 0) + '份)！</h4>',
                                        confirmButtonText: '好的',
                                    });
                                    $("#num").val((data.data['min'] - 0) / (data.data['quantity'] - 0));
                                    layer.close(prome);
                                    ddo = 2;
                                }

                                if ((nums * (data.data['quantity'] - 0)) > (data.data['max'] - 0) && data.data.max != 0) {
                                    swal({
                                        title: '注意',
                                        type: 'warning',
                                        html: '<h4>商品' + data.data.name + '最多购买' + data.data['max'] + '个(' + (data.data['max'] - 0) / (data.data['quantity'] - 0) + '份)！</h4>',
                                        confirmButtonText: '好的',
                                    });
                                    $("#num").val((data.data['max'] - 0) / (data.data['quantity'] - 0));
                                    layer.close(prome);
                                    ddo = 2;
                                }

                                var quota = $("#gootsp").attr('data-count_quota') - 0;
                                if ($("#num").val() > quota) {
                                    $("#num").val(quota);
                                    swal({
                                        title: '抱歉,库存不足',
                                        type: 'warning',
                                        html: '<h4>今日库存不足' + value + '份！<br>请减少购买份数！</h4>',
                                        confirmButtonText: '好的',
                                    });
                                    $("#points").val((data.data['points'] * quota).toFixed(0) + data.data['currency']);
                                    $("#gootsp").val(data.data['name'] + ' * ' + quota + '份 ⇨ ' + data.data['quantity'] * quota + '个');
                                    $("#moneys").val((data.data['price'] * quota).toFixed(2) + ' 元');
                                    layer.close(prome);
                                    return false;
                                }

                                if (ddo == 2) return false;

                                if (nums == '' || nums == 0) nums = 0;
                                $("#points").val((data.data['points'] * nums).toFixed(0) + data.data['currency']);
                                $("#gootsp").val(data.data['name'] + ' * ' + nums + '份 ⇨ ' + data.data['quantity'] * nums + '个');
                                $("#moneys").val((data.data['price'] * nums).toFixed(2) + ' 元');
                                layer.close(prome);
                            });
                        })
                    }
                    if (inputsname == '') {
                        inputsname = '下单ＱＱ';
                    }
                    if (inputsname != '') {
                        $.each(inputsname.split('|'), function (i, value) {
                            if (value.indexOf('{') > 0 && value.indexOf('}') > 0) {
                                var addstr = '';
                                var selectname = value.split('{')[0];
                                var selectstr = value.split('{')[1].split('}')[0];
                                $.each(selectstr.split(','), function (i, v) {
                                    if (v.indexOf(':') > 0) {
                                        i = v.split(':')[0];
                                        v = v.split(':')[1];
                                    } else {
                                        i = v;
                                    }
                                    addstr += '<option value="' + i + '">' + v + '</option>';
                                });
                                $('#input_value').append(template.select_data(selectname, addstr, (i + 1)));
                            } else {
                                if (value == '说说ID' || value == '说说ＩＤ')
                                    var addstr = '<div class="layui-btn layui-btn-sm layui-btn-normal btnee" onclick="get_shuoshuo(\'input_val_' + (i + 1) + '\',$(\'#input_val_' + (i) + '\').val())">自动获取</div>'; //已搞定
                                else if (value == '作品ID' || value == '作品ＩＤ' || value == '快手作品ID')
                                    var addstr = '<div class="layui-btn layui-btn-sm layui-btn-normal btnee" onclick="get_kuaishou(\'input_val_' + (i + 1) + '\',\'input_val_' + (i) + '\')">自动获取</div>'; //已搞定
                                else if (value == '签收' || value == '寄送' || value == '地址' || value == '收货地址' || value == '收货人地址' || value == '地址信息' || value == '联系地址' || value == '家庭地址') {
                                    var addstr = '<div class="layui-btn layui-btn-sm layui-btn-normal btnee" onclick="getCity(\'input_val_' + (i + 1) + '\')">点此选择</div>';
                                    //调用运费模板配置
                                    if (data['freight'] != '-1') {
                                        data.data['CarriageTem'] = 'input_val_' + (i + 1);
                                    }
                                } else
                                    var addstr = '';
                                $('#input_value').append(template.input_data(value, placeholder_auto(value), i + 1, addstr));
                            }
                        });
                    }

                    if (data['freight'] != '-1' && data.data['CarriageTem'] == undefined) {
                        data.data['CarriageTem'] = 'input_val_1';
                    }

                    if (method.indexOf(1) != -1 || method.indexOf(2) != -1) { //是否关闭金额显示！
                        $("#moneys_os").show(10);
                    }
                    if (method.indexOf(3) != -1) { //是否关闭积分显示！
                        $("#points_os").show();
                    }
                    $("#repertory").show();
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });

                    template.success(data); //商品数据加载完成后执行

                    return true;
                } else {
                    if (data.code == -4) {
                        layer.alert(data.msg, {
                            icon: 1, title: false, btn1: function (layero, index) {
                                location.reload();
                            }
                        });
                    } else layer.msg(data.msg);
                }
            },
            error: function () {
                layer.msg('数据获取失败！');
            }
        });
    }
};

var CarriageTem = {
    start: function (id, data, price) {
        setInterval(function () {
            CarriageTem.matching($("#" + id).val(), data, price);
        }, 1000);
    }, matching: function (val, data, price) {
        var num = ($('#num').val() == undefined ? 1 : $('#num').val() - 0);
        if ($("#matching_msg").attr('data-value') != undefined && $("#matching_msg").attr('data-num') != undefined) {
            if ($("#matching_msg").attr('data-value') == val && $("#matching_msg").attr('data-num') == num) return false;
        }
        $("#matching_msg").attr({
            'data-value': val,
            'data-num': num
        });
        var arr_region = data['region'].split('|');
        var matching_region = false;
        $.each(arr_region, function (index, value) {
            if (matching_region == false) matching_region = CarriageTem.matching_region(value, val);
        });

        if (matching_region != false) {
            data['exceed'] = matching_region[2];
            data['money'] = matching_region[1];
            data['regionarr'] = matching_region[0];
        }

        if ((price * num).toFixed(2) >= (data['threshold'] - 0)) {
            CarriageTem.matching_msg(0, '您需付款的金额已经高出<font color="#ff6347">' + data['threshold'] + '</font>元,已经帮您免除运费！');
            return false;
        }
        if (num <= (data['nums'] - 0)) {
            var money = data['money'];
            if (data['regionarr'] != undefined) {
                CarriageTem.matching_msg(money, '<font color="#40e0d0">' + data['regionarr'] + '地区</font>用户购买此商品需额外缴纳<font color="red">' + money + '</font>元运费<br>如果付款金额超出<font color="red">' + data['threshold'] + '</font>元可免除运费哦~');
            } else {
                CarriageTem.matching_msg(money, '购买此商品需额外缴纳<font color="red">' + money + '</font>元运费<br>如果付款金额超出<font color="red">' + data['threshold'] + '</font>元可免除运费哦~');
            }
        } else {
            var money = ((num - (data['nums'] - 0)) * data['exceed']).toFixed(2);
            if (data['regionarr'] != undefined) {
                CarriageTem.matching_msg((money + data['money']), '<font color="#40e0d0">' + data['regionarr'] + '地区</font>用户购买此商品需额外缴纳<font color="red">' + data['money'] + '</font>元运费<br>您已超出<font color="red">' + (num - (data['nums'] - 0)) + '</font>份<br>需额外加<font color="red">' + money + '</font>元运费！<br>每超出1件加<font color="red">' + data['exceed'] + '</font>元！');
            } else {
                CarriageTem.matching_msg((money + data['money']), '购买此商品需额外缴纳<font color="red">' + data['money'] + '</font>元运费<br>您已超出<font color="red">' + (num - (data['nums'] - 0)) + '</font>份,需额外加<font color="red">' + money + '</font>元运费！<br>每超出1份需加<font color="red">' + data['exceed'] + '</font>元！');
            }
        }
    },
    matching_region: function (arr_rage, val) {
        var arr_rage = arr_rage.split(',');
        if (val.indexOf(arr_rage[0]) != -1) {
            return arr_rage;
        } else {
            return false;
        }
    },
    matching_msg(money = 0, msg) {
        $("#matching_msg").show(100);
        $("#matching_msg").html(msg);
        $("#matching_msg").attr({
            'data-price': money,
        });
    }
};

$(".picture_img").click(function () {
    alert('picture_img');
    console.log(this.src)
});

function operation() { //完成后的操作
    layui.use('flow', function () {
        var flow = layui.flow;
        flow.lazyimg();
    });
}

function checkInput(name_id, value_id) { //二次解析

    if ($("#" + name_id).html() == '抖音ＩＤ' || $("#" + name_id).html() == '抖音视频ＩＤ' || $("#" + name_id).html() == '抖音ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getshareid(value_id);
        }
    } else if ($("#" + name_id).html() == '火山ID' || $("#" + name_id).html() == '火山作品ID' || $("#" + name_id).html() == '火山视频ID' || $("#" + name_id).html() == '火山ＩＤ') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            gethuoshanid(value_id);
        }
    } else if ($("#" + name_id).html() == '微视ID' || $("#" + name_id).html() == '微视作品ID' || $("#" + name_id).html() == '微视ＩＤ' || $("#" + name_id).html() == '微视主页ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getweishiid(value_id);
        }
    } else if ($("#" + name_id).html() == '头条ID' || $("#" + name_id).html() == '头条ＩＤ') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            gettoutiaoid(value_id);
        }
    } else if ($("#" + name_id).html() == '小红书ID' || $("#" + name_id).html() == '小红书作品ID' || $("#" + name_id).html() == '皮皮虾ID' || $("#" + name_id).html() == '皮皮虾作品ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getxiaohongshuid(value_id);
        }
    } else if ($("#" + name_id).html() == '美拍ID' || $("#" + name_id).html() == '美拍ＩＤ' || $("#" + name_id).html() == '美拍作品ID' || $("#" + name_id).html() == '美拍视频ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getmeipaiid(value_id);
        }
    } else if ($("#" + name_id).html() == '哔哩哔哩视频ID' || $("#" + name_id).html() == '哔哩哔哩ID' || $("#" + name_id).html() == '哔哩视频ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getbilibiliid(value_id);
        }
    } else if ($("#" + name_id).html() == '最右帖子ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getzuiyouid(value_id);
        }
    } else if ($("#" + name_id).html() == '全民ID' || $("#" + name_id).html() == '全民K歌ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getquanminid(value_id);
        }
    } else if ($("#" + name_id).html() == '美图作品ID' || $("#" + name_id).html() == '美图视频ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getmeituid(value_id);
        }
    } else if ($("#" + name_id).html() == '绿洲作品ID' || $("#" + name_id).html() == '绿洲视频ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getoasisid(value_id);
        }
    } else if ($("#" + name_id).html() == '视频链接' || $("#" + name_id).html() == '作品链接' || $("#" + name_id).html() == '分享链接') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getsharelink(value_id);
        }
    }
}

function getshareid(value_id) {
    var input_id = value_id.split('_');
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('http') < 0) {
        layer.alert('请输入正确的内容！');
        return false;
    }
    try {
        if (songurl.indexOf('http://') >= 0) {
            var songurl = 'http://' + songurl.split('http://')[1].split(' ')[0].split('，')[0];
        } else if (songurl.indexOf('https://') >= 0) {
            var songurl = 'https://' + songurl.split('https://')[1].split(' ')[0].split('，')[0];
        } else {
            throw false;
        }
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=getshareid",
            data: {url: songurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    if (typeof data.songid != "undefined" && $('#' + value_id).length > 0) $('#' + value_id).val(data.songid);
                    layer.msg('ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } catch (e) {
        layer.alert('请输入正确的内容！');
        return false;
    }
}

function gethuoshanid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('.huoshan.com') < 0) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    if (songurl.indexOf('/s/') > 0) {
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=gethuoshan",
            data: {url: songurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + value_id).val(data.songid);
                    layer.msg('火山小视频ID获取成功', {icon: 1})
                } else {
                    layer.alert(data.msg, {icon: 2});
                    return false;
                }
            }
        });
    } else {
        try {
            if (songurl.indexOf('video/') > 0) {
                var songid = songurl.split('video/')[1].split('/')[0];
            } else if (songurl.indexOf('item/') > 0) {
                var songid = songurl.split('item/')[1].split('/')[0];
            } else if (songurl.indexOf('room/') > 0) {
                var songid = songurl.split('room/')[1].split('/')[0];
            } else {
                var songid = songurl.split('user/')[1].split('/')[0];
            }
            layer.msg('ID获取成功！下单即可');
        } catch (e) {
            layer.alert('请输入正确的链接！');
            return false;
        }
        $('#' + value_id).val(songid);
    }
}

function getweishiid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('.qq.com') < 0) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    try {
        if (songurl.indexOf('feed/') > 0) {
            var songid = songurl.split('feed/')[1].split('/')[0];
        } else if (songurl.indexOf('personal/') > 0) {
            var songid = songurl.split('personal/')[1].split('/')[0];
        } else {
            var songid = songurl.split('id=')[1].split('&')[0];
        }
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function gettoutiaoid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('.toutiaocdn.com') < 0) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    try {
        if (songurl.indexOf('group/') > 0) {
            var songid = songurl.split('group/')[1].split('/')[0];
        } else {
            var songid = songurl.split('group_id=')[1].split('=')[0];
        }
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getxiaohongshuid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('/t.cn/') > 0 || songurl.indexOf('/xhsurl.com/') > 0) {
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=getxiaohongshu",
            data: {url: songurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + value_id).val(data.songid);
                    layer.msg('小红书ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } else {
        if (songurl.indexOf('xiaohongshu.com') < 0 && songurl.indexOf('pipix.com') < 0) {
            layer.alert('请输入正确的链接！');
            return false;
        }
        try {
            var songid = songurl.split('item/')[1].split('?')[0];
            layer.msg('小红书ID获取成功！下单即可', {icon: 1});
        } catch (e) {
            layer.alert('请输入正确的链接！');
            return false;
        }
    }
    $('#' + value_id).val(songid);
}

function getmeipaiid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('meipai.com') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    if (songurl.indexOf('/s/') > 0) {
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=gethuoshan",
            data: {url: songurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + value_id).val(data.songid);
                    layer.msg('ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } else {
        try {
            var songid = songurl.split('media/')[1].split('?')[0];
            layer.msg('ID获取成功！下单即可', {icon: 1});
        } catch (e) {
            layer.alert('请输入正确的视频链接！');
            return false;
        }
    }
    $('#' + value_id).val(songid);
}

function getbilibiliid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('bilibili.com') < 0 && songurl.indexOf('b23.tv') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    try {
        if (songurl.indexOf('bilibili.com') > 0) {
            var songid = songurl.split('video/av')[1].split('/')[0];
        } else {
            var songid = songurl.split('/av')[1].split('/')[0];
        }
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getzuiyouid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('izuiyou.com') < 0) {
        layer.alert('请输入正确的帖子链接！');
        return false;
    }
    try {
        var songid = songurl.split('detail/')[1].split('?')[0];
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的帖子链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getquanminid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('kg2.qq.com') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    try {
        var songid = songurl.split('play?s=')[1].split('&shareuid')[0];
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getmeituid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('meitu.com') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    try {
        var songid = songurl.split('feed_id=')[1].split('&')[0];
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getoasisid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('weibo.cn') < 0 && songurl.indexOf('weibo.com') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    try {
        var songid = songurl.split('sid=')[1].split('&')[0];
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getsharelink(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('http') < 0) {
        layer.alert('请输入正确的内容！');
        return false;
    }
    try {
        if (songurl.indexOf('http://') >= 0) {
            var songid = 'http://' + songurl.split('http://')[1].split(' ')[0].split('，')[0];
        } else if (songurl.indexOf('https://') >= 0) {
            var songid = 'https://' + songurl.split('https://')[1].split(' ')[0].split('，')[0];
        }
        if (songid != $("#" + value_id).val()) layer.msg('链接转换成功！下单即可');
    } catch (e) {
        layer.alert('请输入正确的内容！');
        return false;
    }
    $('#' + value_id).val(songid);
}


function get_shuoshuo(id, uin, km, page) {
    km = km || 0;
    page = page || 1;
    if (uin == '') {
        layer.alert('请先填写ＱＱ号！');
        return false;
    }
    var ii = layer.load(2, {shade: [0.1, '#fff']});
    $.ajax({
        type: "GET",
        url: "ajax.php?act=getshuoshuo&uin=" + uin + "&page=" + page,
        dataType: 'json',
        success: function (data) {
            layer.close(ii);
            if (data.code >= 0) {
                var addstr = '<div class="layui-row layui-col-space15">';
                $.each(data.data, function (i, item) {
                    if (item['content'] == null) {
                        item['content'] = '';
                    }
                    if (item.image == '') {
                        image = '';
                    } else {
                        image = '';
                        $.each(item.image, function (s, images) {
                            image += '<img class="layui-col-xs4" src="' + images + '" />';
                        })
                    }
                    addstr += '' +
                        '<div class="layui-col-xs6 layui-col-sm5 layui-col-md3" onclick="insertion(\'' + item['ssid'] + '\',\'' + id + '\')">' +
                        '<div class="layui-card" style="cursor: pointer;box-shadow: 3px 3px 16px #ccc;border-radius: 0.5em">' +
                        '<div class="layui-card-hader layui-elip bg-cyan" style="text-align: center;color: white;background: linear-gradient(to right, #ff4e50, #f9d423)">' + item['name'] + '发布于：' + item['addtime'] + '</div>' +
                        '<div class="layui-card-body">' +
                        '<div class="layui-text">' + item['content'] + '</div>' +
                        '<div class="layui-row layui-col-space1">' + image + '</div>' +
                        '</div>' +
                        '</div>' +
                        '</div>';
                });
                addstr += '</div>';
                if (addstr == '<div class="layui-row layui-col-space15"></div>') {
                    layer.alert('请先发布一条说说', {icon: 2});
                    return false;
                }
                var nextpage = page + 1;
                var lastpage = page > 1 ? page - 1 : 1;
                layer.open({
                    title: 'ＱＱ' + uin + '的说说,点击说说选择~'
                    , content: addstr
                    , area: ['96%', '96%']
                    , btnAlign: 'c'
                    , btn: ['关闭', '上一页', '下一页']
                    , btn2: function f(layero, index) {
                        get_shuoshuo(id, uin, km, lastpage)
                    }, btn3: function f(layero, index) {
                        get_shuoshuo(id, uin, km, nextpage)
                    }
                });
            } else {
                layer.alert(data.msg);
            }
        }
    });
}

function get_kuaishou(id, ksid) {
    if (ksid == '') {
        ksid = $('#' + ksid).val();
        if (ksid == '') {
            layer.alert('请先填写作品链接！');
            return false;
        }
    }
    var zpid = $('#' + ksid).val();
    if (ksid.indexOf('http') >= 0) {
        var kuauishouurl = ksid;
    } else if (zpid.indexOf('http') >= 0) {
        var kuauishouurl = zpid;
    } else if (zpid == '') {
        layer.alert('请先填写作品链接！');
        return false;
    } else {
        return true;
    }
    if (kuauishouurl.indexOf('http') < 0) {
        layer.alert('请输入正确的KF作品链接！');
        return false;
    }
    if (kuauishouurl.indexOf('/s/') > 0) {
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=getkuaishou",
            data: {url: kuauishouurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + ksid).val(data.authorid);
                    $('#' + id).val(data.videoid);
                    layer.msg('ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } else if (kuauishouurl.indexOf('f.kuaishou.com') > 0) {
        var kuais_id = 1;
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=getkuaishou2",
            data: {url: kuauishouurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + ksid).val(data.authorid);
                    $('#' + id).val(data.videoid);
                    layer.msg('ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } else {
        try {
            if (kuauishouurl.indexOf('userId=') > 0) {
                var authorid = kuauishouurl.split('userId=')[1].split('&')[0];
            } else {
                var authorid = kuauishouurl.split('photo/')[1].split('/')[0];
            }
            if (kuauishouurl.indexOf('photoId=') > 0) {
                var videoid = kuauishouurl.split('photoId=')[1].split('&')[0];
            } else {
                var videoid = kuauishouurl.split('photo/')[1].split('/')[1].split('?')[0];
            }
            layer.msg('ID获取成功！下单即可');
        } catch (e) {
            layer.alert('请输入正确的作品链接！');
            return false;
        }
        $('#' + ksid).val(authorid);
        $('#' + id).val(videoid);
    }
}

function getCity(inputid, fid, i) {
    i = i || 0;
    fid = fid || 0;
    if (i == 0) {
        var options = '<select class="form-control" id="biaozhi_' + (i + 1) + '" onchange="getCity(\'' + inputid + '\',this.value,' + (i + 1) + ')">';
        options += '<option>请选择地址</option>';
        $.each("\u5317\u4eac|1|72|1,\u4e0a\u6d77|2|78|1,\u5929\u6d25|3|51035|1,\u91cd\u5e86|4|113|1,\u6cb3\u5317|5|142,\u5c71\u897f|6|303,\u6cb3\u5357|7|412,\u8fbd\u5b81|8|560,\u5409\u6797|9|639,\u9ed1\u9f99\u6c5f|10|698,\u5185\u8499\u53e4|11|799,\u6c5f\u82cf|12|904,\u5c71\u4e1c|13|1000,\u5b89\u5fbd|14|1116,\u6d59\u6c5f|15|1158,\u798f\u5efa|16|1303,\u6e56\u5317|17|1381,\u6e56\u5357|18|1482,\u5e7f\u4e1c|19|1601,\u5e7f\u897f|20|1715,\u6c5f\u897f|21|1827,\u56db\u5ddd|22|1930,\u6d77\u5357|23|2121,\u8d35\u5dde|24|2144,\u4e91\u5357|25|2235,\u897f\u85cf|26|2951,\u9655\u897f|27|2376,\u7518\u8083|28|2487,\u9752\u6d77|29|2580,\u5b81\u590f|30|2628,\u65b0\u7586|31|2652,\u6e2f\u6fb3|52993|52994,\u53f0\u6e7e|32|2768,\u9493\u9c7c\u5c9b|84|84".split(","), function (a, c) {
            c = c.split("|"),
                options += '<option value="' + c[1] + '">' + c[0] + '</option>'
        });
        options += '</select>';
        layer.alert('<div id="layer_button">' + options + '</div>', {icon: 3, title: '地址选择'}, function (index) {
            var con = '';
            $("#layer_button select").each(function () {
                con += $(this.options[this.selectedIndex]).text();
            });
            if ($("#more_dizhi").length > 0) con += $("#more_dizhi").val();
            if (con.length < 7) return layer.alert('请选择完整的收货地址！');
            $("#" + inputid).val(con).show();
            $("#button_" + inputid).hide();
            layer.close(index);
        });
    } else {
        $.ajax({
            type: "get",
            url: "https://fts.jd.com/area/get?fid=" + fid,
            dataType: "jsonp",
            success: function (data) {
                if (data.length < 1) {
                    if ($("#layer_button").html().indexOf("getCity('" + inputid + "',this.value," + (i + 1) + ")") != -1) {
                        $("#biaozhi_" + (i + 1)).remove();
                    }
                    if ($("#more_dizhi").length > 0) {
                    } else $("#layer_button").append('<input class="form-control" id="more_dizhi" placeholder="详细地址(村、门牌号)">');
                    return false;
                }
                var options = '<select class="form-control" id="biaozhi_' + (i + 1) + '" onchange="getCity(\'' + inputid + '\',this.value,' + (i + 1) + ')">';
                options += '<option>请选择地址</option>';
                $.each(data, function (index, res) {
                    options += '<option value="' + res.id + '">' + res.name + '</option>';
                });
                options += '</select>';
                if ($("#layer_button").html().indexOf("getCity('" + inputid + "',this.value," + (i + 1) + ")") != -1) {
                    $("#more_dizhi").remove();
                    $("#biaozhi_" + (i + 1)).html(options);
                } else {
                    $("#layer_button").append(options);
                }
            }
        });
    }
}

function insertion(v, id) { //插入
    $('#' + id).val(v);
    layer.closeAll();
    layer.msg('数据插入成功', {icon: 1});
}

function placeholder_auto(inputname) { //可自动匹配提示语
    switch (inputname) {
        case '说说ID':
        case '说说ＩＤ':
            return '上方填写ＱＱ账号后点击→';
            break;
        case '抖音ＩＤ':
        case '抖音视频ＩＤ':
        case '抖音ID':
            return '在此输入分享链接 可自动获取';
            break;
        case '火山ID':
        case '火山作品ID':
        case '火山视频ID':
        case '火山作品ID':
        case '火山ＩＤ':
        case '火山作品ＩＤ':
            return '在此输入火山视频的链接 可自动获取';
            break;
        case '微视ID':
        case '微视作品ID':
        case '微视ＩＤ':
            return '在此输入微视的作品链接 可自动获取';
            break;
        case '小红书ID':
        case '小红书作品ID':
        case '小红书ＩＤ':
            return '在此输入小红书的作品链接 可自动获取';
            break;
        case '皮皮虾ID':
        case '皮皮虾作品ID':
            return '在此输入皮皮虾的作品链接 可自动获取';
            break;
        case '微视主页ID':
            return '在此输入微视的主页链接 可自动获取';
            break;
        case '头条ID':
        case '头条ＩＤ':
            return '在此输入今日头条的链接 可自动获取';
            break;
        case '美拍ID':
        case '美拍ＩＤ':
        case '美拍作品ID':
        case '美拍视频ID':
            return '在此输入美拍视频链接 可自动获取';
            break;
        case '哔哩哔哩视频ID':
        case '哔哩哔哩ID':
        case '哔哩视频ID':
            return '在此输入哔哩哔哩视频链接 可自动获取';
            break;
        case '最右帖子ID':
            return '在此输入最右帖子链接 可自动获取';
            break;
        case '全民视频ID':
        case '全民小视频ID':
            return '在此输入全民小视频链接 可自动获取';
            break;
        case '美图作品ID':
        case '美图视频ID':
            return '在此输入美图作品链接 可自动获取';
            break;
        case '绿洲作品ID':
        case '绿洲视频ID':
            return '在此输入绿洲作品分享链接 可自动获取';
            break;
        case '作品链接':
        case '视频链接':
        case '分享链接':
            return '在此输入复制后的链接 可自动转换';
            break;
        default:
            return '请将' + inputname + '填写完整！';
            break;
    }
}


