/*
 * The Hefei Ceshi RDC(Research and Development Centre) Group.
 * __________________
 *
 *    Copyright 2015-2020
 *    All Rights Reserved.
 *
 *    NOTICE:  All information contained herein is, and remains
 *    the property of Ceshi Company and its suppliers,
 *    if any.
 */

var page = {
    submitFlag: 0,
    getChecked: function () {
        return $("#agreement_checked").is(":checked");
    },
    join: function (call, id) {
        var a = page.getChecked();
        if (a) {
            page.postData(undefined, call, id, 1, "")
        } else {
            topWin.layer.alert(tenderTxt.agreeOffer, {
                icon: 2,
                closeBtn: 0,
                yes: function (index) {
                    topWin.layer.close(index);
                }
            });
        }

    },
    noJoin: function (call, id) {
        topWin.layer.prompt({title: '请输入不参与原因', formType: 2}, function (content, index) {
            if (content === '') {
                topWin.layer.alert("请填写不参加原因", {
                    icon: 3,
                    closeBtn: 0,
                    yes: function (iindex) {
                        topWin.layer.close(iindex);
                    }
                });
                return;
            }
            page.postData(index, call, id, 0, content)
        });
    },
    postData: function (index, call, id, status, remark) {
        if (page.submitFlag === 1) {
            return
        }
        page.submitFlag = 1
        $.ajax({
            url: g.ctx + 'pc/tender/bid/rest/submitBidStatus',
            method: "post",
            data: {id: id, status: status, remark: remark},
            complete: function () {
                page.submitFlag = 0
            },
            success: function (data) {
                topWin.layer.alert(commonTxt.operateSuccess, {
                    icon: 1,
                    closeBtn: 0,
                    yes: function (iindex) {
                        if (index !== undefined) {
                            topWin.layer.close(index);
                        }
                        topWin.layer.close(iindex);
                        call();
                    }
                });
            },
            error: function (data) {
                topWin.layer.alert(data.responseJSON.message, {icon: 2});
            }
        });
    }
}