<script>
    layui.use(['table', 'form', 'element', 'layer', 'admin', 'upload', 'index'], function () {
        let layer = layui.layer;
        let supplierId = getQueryVariable('supplier_id')

        $('#updateSupplierUrl').click(function () {
            layer.load(1);
            let tabName = $('.layui-this').attr('id');
            window.location.href = "/supplier/UpdateSupplier?view=iframe&supplier_id={{$supplier['supplier_id']}}&tab=" + tabName;
        })

        $('#cancel_block_supplier').click(function () {
            layer.confirm('对应的供应商设为取消拉黑后,该供应商将重新走审核流程,通过后将重新启用,是否执行当前操作?', function (index) {
                let supplierId = getQueryVariable('supplier_id');
                let res = ajax('/api/supplier/CancelBlockSupplier', {supplier_id: supplierId, is_type: 0})
                if (res.err_code === 0) {
                    layer.closeAll();
                    layer.msg(res.err_msg, {icon: 6})
                    location.reload();
                } else {
                    layer.msg(res.err_msg, {icon: 5})
                }
            });
        });

        //取消禁用
        $('#cancel_disable_supplier').click(function () {
            layer.confirm('确定要取消禁用当前供应商吗?', function (index) {
                let supplierId = getQueryVariable('supplier_id');
                let res = ajax('/api/supplier/CancelDisableSupplier', {supplier_id: supplierId, is_type: 0})
                if (res.err_code === 0) {
                    layer.closeAll();
                    layer.msg(res.err_msg, {icon: 6})
                    location.reload();
                } else {
                    layer.msg(res.err_msg, {icon: 5})
                }
            });
        });

        {{--index.setTabTitle('供应商详情 - {{$supplier['supplier_code'] or ''}}');--}}

        function openLogView() {
            // 打开右侧面板
            layer.open({
                type: 2,
                content: '/log/SupplierLog?view=iframe&supplier_id=' + supplierId,
                area: ['400px', '85%'],
                shade: 0,
                offset: 'rb',
                title: '操作日志',
            });
        }

        @if(checkPerm('SupplierLog'))
        setTimeout(function () {
            openLogView();
        }, 100);
        @endif

        //判断是否要切换tab
        let tab = '{{request()->get('tab')}}';
        if (tab) {
            $('#' + tab).click();
        }
    });
</script>