'use strict';
/**
 * 期计量 - 期列表页面 js
 *
 * @author Mai
 * @date 2018/12/7
 * @version
 */
$(function () {
    // 获取审批流程
    $('a[data-target="#sp-list" ]').on('click', function () {
        const data = {
            order: $(this).attr('m-order'),
        };
        postData('/tender/' + tenderId + '/measure/material/auditors', data, function (result) {
            const materialAuditor = result.materialAuditor;
            const auditors = result.auditors;
            const auditHistory = result.auditHistory;
            // 生成左边列表流程
            const lefthtml = [];
            lefthtml.push('
 '+ materialAuditor.name +'  '+ materialAuditor.role +'原报');
            for (const [index,a] of auditors.entries()) {
                if (index+1 === auditors.length) {
                    lefthtml.push(' '+ a.name +'  '+ a.role +'终审');
                } else {
                    lefthtml.push(' '+ a.name +'  '+ a.role +'' + transFormToChinese(index+1) + '审');
                }
            }
            $('#auditor-list').html(lefthtml.join(''));
            // 生成右边列表流程
            const righthtml = [];
            for(const ah of auditHistory) {
                righthtml.push('');
            }
            $('#auditor-list2').html(righthtml.join(''));
        });
    });
    // 计量期选中
    $('.select-stage-order').on('click', function () {
        const stageList = $('.select-stage-order:checked');
        if (stageList.length === 0) {
            $('#show_order').hide();
            $('#s_order').val('');
        } else {
            const order_array = [];
            for (let s = 0; s < stageList.length; s++) {
                order_array.push(stageList.eq(s).data('order'));
                // console.log(stageList.eq(s));
            }
            $('#show_order').html('第' + order_array.join(',') + '期');
            $('#show_order').show();
            $('#s_order').val(order_array.join(','));
        }
    });
    // 提交表单判断
    $('#addMaterial').click(function () {
        if ($('#s_order').val() == '') {
            toastr.error('请选择计量期');
            return false;
        }
    })
});