<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>销售合同管理-修改合同信息</title>
    <link rel="stylesheet" type="text/css" href="/css/external/fileUploadBase.css">
    <style>
        .btn-info:active,
        .btn-info:focus {
            background-color: #fff;
        }

        li.notcompanyli:hover {
            color: #333 !important;
        }

        .base-extend .newTabAddUpdateBox td.enter .viewDetailWord {
            width: 0.75rem;
            text-align: center;
            top: 0.1rem;
            color: #333 !important;
            cursor: default;
            font-style: normal;
        }

        .base-extend .newTabAddUpdateBox td.enter .prevDetailWord {
            width: 0.85rem;
            text-align: center;
            top: 0.1rem;
            color: #333 !important;
            cursor: default;
            font-style: normal;
        }

        .error option, select.error {
            color: #333 !important;
        }

        input::-webkit-outer-spin-button,
        input::-webkit-inner-spin-button {
            -webkit-appearance: none;
            appearance: none;
            margin: 0;
        }
    </style>
</head>
<body>
<div class="base-extend">
    <ol class="breadcrumb">
        <i class="icon-chevron-sign-left newBackBtn"></i>
        <li>销售合同管理</li>
        <li>修改合同信息</li>
    </ol>
    <div class="detailContentBox">
        <p class="detailContentBox-title">修改合同信息</p>
        <form class="form-horizontal" id="contractEntryForm" autocomplete="off">
            <input type="hidden" name="basicId" th:value="${salesContractInfo?.businessKey}">
            <input type="hidden" name="taskId" th:value="${taskId}">
            <div class="newTabAddUpdateBox">
                <div class="row">
                    <table>
                        <tr>
                            <td colspan="4">
                                <span class="detailContentBox-tabletitle">业务信息</span>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="required_fileds_star">业务名称</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" name="businessName" readonly
                                       th:value="${salesContractInfo?.businessBasicInfo?.businessName}"
                                       class="form-control">
                            </td>
                            <td width="15%">
                                <span class="required_fileds_star">核心企业名称</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" name="enterpriseName" readonly
                                       th:value="${salesContractInfo?.businessBasicInfo?.customer?.enterpriseName}"
                                       class="form-control">
                            </td>
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="">业务编号</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" readonly name="businessNo"
                                       th:value="${salesContractInfo?.businessBasicInfo?.businessNumber}"
                                       class="form-control">
                            </td>
                            <td width="15%">
                                <span class="required_fileds_star">创建时间</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" name="creatTime" readonly
                                       th:value="${#calendars.format(salesContractInfo?.businessBasicInfo?.gmtCreate,'yyyy-MM-dd')}"
                                       class="form-control">
                            </td>
                        </tr>
                    </table>
                </div>

                <div class="row">
                    <!-- 附件信息回显 -->
                    <div class="fileInfoListOriginal" style="display:none"
                         th:each="file,files:${salesContractInfo?.salesContractFileList}">
                        <input type="text" class="originalId" th:value="${file?.id}">
                        <input type="text" class="originalUrl" th:value="${file?.path}">
                        <input type="text" class="originalType" th:value="${file?.fileType}">
                        <input type="text" class="originalName" th:value="${file?.originalName}">
                        <input type="text" class="originalSize" th:value="${file?.size}">
                    </div>
                    <table class="fileInfoListBox">
                        <tr>
                            <td colspan="3">
                                <span class="detailContentBox-tabletitle">上传合同原文件</span>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="required_fileds_star">合同原文件</span>：
                            </td>
                            <td class="enter addFileList">
                                <input type="file" class="fileinput" multiple style="display:none">
                                <div class="uploaderFile">
                                    <div class="fileContent">
                                        <span class="spanHolder">上传附件</span>
                                    </div>
                                </div>
                            </td>
                            <!--                            <td width="13%" class="choiceFile" style="text-align:center;">-->
                            <!--                                +上传附件-->
                            <!--                            </td>-->
                        </tr>
                    </table>
                </div>

                <div class="row">
                    <table>
                        <tr>
                            <td colspan="4">
                                <span class="detailContentBox-tabletitle">合同信息</span>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="required_fileds_star">合同编号</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" name="contractNumber" readonly class="form-control"
                                       th:value="${salesContractInfo?.salesContractBasicInfo?.contractNumber}">
                            </td>
                            <td width="15%">
                                <span class="required_fileds_star">供方公司名称</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" name="platform" readonly
                                       th:value="${salesContractInfo?.businessBasicInfo?.platform?.platformName}"
                                       class="form-control">
                            </td>
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="required_fileds_star">需方公司名称</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" name="customer" readonly
                                       th:value="${salesContractInfo?.businessBasicInfo?.customer?.enterpriseName}"
                                       class="form-control">
                            </td>
                            <td width="15%">
                                <span class="required_fileds_star">合同期限</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="number" name="contractPeriod" class="form-control" readonly
                                       th:value="${salesContractInfo?.salesContractBasicInfo?.contractPeriod}">
                                <i class="viewDetailWord">天</i>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="required_fileds_star">合同约定金额类型</span>：
                            </td>
                            <td width="35%" class="enter">
                                <select name="contractPlanAmountType" class="form-control" disabled
                                        tag:option="salesContractPlanAmountType"
                                        th:value="${salesContractInfo?.salesContractBasicInfo?.contractPlanAmountTypeDict?.id}"></select>
                            </td>
                            <td width="15%">
                                <span class="required_fileds_star">合同约定金额</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" name="contractPlanAmount" class="form-control amountInput" readonly
                                       th:value="${salesContractInfo?.salesContractBasicInfo?.contractPlanAmount}">
                                <i class="viewDetailWord">元</i>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="required_fileds_star">验收经办人</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" maxlength="50" name="checkOperator" class="form-control" readonly
                                       th:value="${salesContractInfo?.salesContractBasicInfo?.checkOperator}">
                            </td>
                            <td width="15%">
                                <span class="required_fileds_star">结算经办人</span>：
                            </td>
                            <td width="35%" class="enter">
                                <input type="text" maxlength="50" name="settlementOperator" class="form-control"
                                       readonly
                                       th:value="${salesContractInfo?.salesContractBasicInfo?.settlementOperator}">
                            </td>
                        </tr>
                    </table>
                </div>

                <div class="row">
                    <table class="paymentTable">
                        <tr>
                            <td colspan="3">
                                <span class="detailContentBox-tabletitle">付款条件</span>
                                <span id="paymentAdd" class="colorbtn btn" style="float: right;margin-right: 5px">
                                    添加
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td width="12%">
                                <span>编号</span>
                            </td>
                            <td width="75%">
                                <span>付款条件</span>
                            </td>
                            <td width="13%">
                                <span>操作</span>
                            </td>
                        </tr>
                        <tbody>
                        <tr class="paymentListTbody">
                            <td width="12%" style="background-color:#fff;">
                                <span>1</span>
                            </td>
                            <td width="75%" style="background-color:#fff;" class="enter">
                                <input type="text" name="paymentCondition" maxlength="500" class="form-control paymentCondition">
                                <span class="error" style="display:none;font-size:0.12rem;">请输入付款条件</span>
                            </td>
                            <td width="13%" style="background-color:#fff;">
                                <!-- <span class="negativeInformationPlus">+添加</span> -->
                                <span class="negativeInformationReduce">删除</span>
                            </td>
                        </tr>
                        <tr class="paymentListTbody paymentListTbodyBack" th:each="paymentTerm,paymentTermStat:${salesContractInfo?.paymentConditionList}">
                            <td width="12%" style="background-color:#fff;">
                                <span th:text="${paymentTermStat.count}"></span>
                            </td>
                            <td width="75%" style="background-color:#fff;" class="enter">
                                <input type="text" name="paymentCondition" maxlength="500" class="form-control paymentCondition" th:value="${paymentTerm.paymentCondition}">
                                <span class="error" style="display:none;font-size:0.12rem;">请输入付款条件</span>
                            </td>
                            <td width="13%" style="background-color:#fff;">
                                <!-- <span class="negativeInformationPlus">+添加</span> -->
                                <span class="negativeInformationReduce">删除</span>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>


                <div class="row">
                    <table>
                        <tr>
                            <td colspan="4">
                                <span class="detailContentBox-tabletitle">结算</span>
                            </td>
                        </tr>
                        <tr>
<!--                            <td width="15%">-->
<!--                                <span class="required_fileds_star">发货时间</span>：-->
<!--                            </td>-->
<!--                            <td width="35%" class="enter">-->
<!--                                <input type="text" name="deliveryDate" class="form-control" readonly-->
<!--                                       th:value="${salesContractInfo?.salesContractSettleInfo?.deliveryDate}">-->
<!--                            </td>-->
<!--                            <td width="15%">-->
<!--                                <span class="required_fileds_star">签收时间</span>：-->
<!--                            </td>-->
<!--                            <td width="35%" class="enter">-->
<!--                                <input type="text" name="signDate" class="form-control" readonly-->
<!--                                       th:value="${salesContractInfo?.salesContractSettleInfo?.signDate}">-->
<!--                            </td>-->
<!--                        </tr>-->
<!--                        <tr>-->
<!--                            <td width="15%">-->
<!--                                <span class="required_fileds_star">第一次结算时间</span>：-->
<!--                            </td>-->
<!--                            <td colspan="3" class="enter">-->
<!--                                <input type="text" readonly name="firstSettleDate" class="form-control"-->
<!--                                       th:value="${#calendars.format(salesContractInfo?.salesContractSettleInfo?.firstSettleDate,'yyyy-MM-dd')}">-->
<!--                            </td>-->
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="required_fileds_star">结算周期方式</span>：
                            </td>
                            <td width="35%" class="enter">
                                <select name="settleCycleMethodDict" class="form-control"
                                        tag:option="salesContractSettleCycleMethod" disabled
                                        th:value="${salesContractInfo?.salesContractSettleInfo?.settleCycleMethodDict?.id}"></select>
                            </td>
                            <td width="15%">
                                <span class="required_fileds_star">结算周期</span>：
                            </td>
                            <td width="35%" class="enter">
                                <i class="prevDetailWord">上一次结算后</i>
                                <input type="number" min="0" name="settleCycle" class="form-control"
                                       style="padding-left: 0.85rem;padding-right: 0.75rem" readonly
                                       th:value="${salesContractInfo?.salesContractSettleInfo?.settleCycle}">
                                <i class="viewDetailWord">个自然月</i>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="required_fileds_star">约定回款时间</span>：
                            </td>
                            <td width="35%" class="enter">
                                <i class="prevDetailWord" style="width: 0.6rem">结算后</i>
                                <input type="number" min="0" name="planPaybackDays" class="form-control"
                                       style="padding-left: 0.6rem;padding-right: 0.75rem" readonly
                                       th:value="${salesContractInfo?.salesContractSettleInfo?.planPaybackDays}">
                                <i class="viewDetailWord">天</i>
                            </td>
                            <td width="15%">
                                <span class="required_fileds_star">预估回款时间</span>：
                            </td>
                            <td width="35%" class="enter">
                                <i class="prevDetailWord" style="width: 0.5rem">结算后</i>
                                <input type="number" min="0" name="estimatePayBackDays" class="form-control"
                                       style="padding-left: 0.5rem;padding-right: 0.75rem" readonly
                                       th:value="${salesContractInfo?.salesContractSettleInfo?.estimatePaybackDays}">
                                <i class="viewDetailWord">天</i>
                            </td>
                        </tr>
                    </table>
                </div>

                <div class="row">
                    <table>
                        <tr>
                            <td colspan="4">
                                <span class="detailContentBox-tabletitle">质保金</span>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%">
                                <span class="required_fileds_star">是否有质保金</span>：
                            </td>
                            <td width="35%" class="enter">
                                <select name="retention" class="form-control" disabled>
                                    <option value="">请选择</option>
                                    <option value="1"
                                            th:selected="${salesContractInfo?.salesContractRetentionInfo?.retention==1}">
                                        是
                                    </option>
                                    <option value="0"
                                            th:selected="${salesContractInfo?.salesContractRetentionInfo?.retention==0}">
                                        否
                                    </option>
                                </select>
                            </td>
                            <td width="15%" class="retentionTr">
                                <span class="required_fileds_star">质保金比例</span>：
                            </td>
                            <td width="35%" class="enter retentionTr">
                                <input type="text" name="retentionPercent" class="form-control" readonly
                                       th:value="${salesContractInfo?.salesContractRetentionInfo?.retentionPercent}">
                                <i class="viewDetailWord">%</i>
                            </td>
                        </tr>
                        <tr class="retentionTr">
                            <td width="15%">
                                <span class="required_fileds_star">质保金是否有上限</span>：
                            </td>
                            <td width="35%" class="enter">
                                <select name="limit" class="form-control" disabled>
                                    <option value="">请选择</option>
                                    <option value="1"
                                            th:selected="${salesContractInfo?.salesContractRetentionInfo?.limit==1}">是
                                    </option>
                                    <option value="0"
                                            th:selected="${salesContractInfo?.salesContractRetentionInfo?.limit==0}">否
                                    </option>
                                </select>
                            </td>
                            <td width="15%" class="retentionLimitTr">
                                <span class="required_fileds_star">质保金上限</span>：
                            </td>
                            <td width="35%" class="enter retentionLimitTr">
                                <input type="text" name="retentionLimit" class="form-control amountInput" readonly
                                       th:value="${salesContractInfo?.salesContractRetentionInfo?.retentionLimit}">
                                <i class="viewDetailWord">元</i>
                            </td>
                        </tr>
                        <tr class="retentionTr">
                            <td width="15%">
                                <span class="required_fileds_star">质保金释放时间</span>：
                            </td>
                            <td colspan="3" class="enter">
                                <select name="releaseMethodDict" class="form-control" disabled
                                        tag:option="salesContractReleaseMethod"
                                        th:value="${salesContractInfo?.salesContractRetentionInfo?.releaseMethodDict?.id}"></select>
                            </td>
                            <td width="15%" class="releaseDate" hidden>
                                <span class="required_fileds_star">释放日期</span>：
                            </td>
                            <td width="35%" class="enter releaseDate" hidden>
                                <input type="text" readonly name="releaseDate" class="form-control"
                                       th:value="${#calendars.format(salesContractInfo?.salesContractRetentionInfo?.releaseDate,'yyyy-MM-dd')}">
                            </td>
                            <td width="15%" class="releaseDays" hidden>
                                <span class="required_fileds_star">释放天数</span>：
                            </td>
                            <td width="35%" class="enter releaseDays" hidden>
                                <input type="number" name="releaseDays" class="form-control" readonly min="0"
                                       th:value="${salesContractInfo?.salesContractRetentionInfo?.releaseDays}">
                                <i class="viewDetailWord">天</i>
                            </td>
                        </tr>
                    </table>
                </div>

                <div class="row">
                    <table class="goodsTable">
                        <tr>
                            <td colspan="10">
                                <span class="detailContentBox-tabletitle">货物信息</span>
                                <span id="importButton" class="colorbtn btn" style="float: right;">
                                    模板导入
                                </span>
                                <input type="file" accept="xls, .xlsx, .excel" id="importFile" style="display: none">
                                <span id="addGoods" class="colorbtn btn" style="float: right;margin-right: 5px">
                                    添加
                                </span>

                            </td>
                        </tr>
                        <tr>
                            <td width="5%">
                                <span>编号</span>
                            </td>
                            <td width="10%">
                                <span>名称</span>
                            </td>
                            <td width="10%">
                                <span>厂家</span>
                            </td>
                            <td width="10%">
                                <span>型号</span>
                            </td>
                            <td width="10%">
                                <span>单位</span>
                            </td>
                            <td width="10%">
                                <span>数量</span>
                            </td>
                            <td width="10%">
                                <span>是否明确单价</span>
                            </td>
                            <td width="10%">
                                <span>销售单价</span>
                            </td>
                            <td width="14%">
                                <span>备注</span>
                            </td>
                            <td width="10%">
                                <span>操作</span>
                            </td>
                        </tr>
                        <tr class="goodsListTbody" style="display: none">
                            <td width="5%" style="background-color:#fff;">
                                <span>1</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput">
                                <span class="error" style="display:none;">请填写名称</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput">
                                <span class="error" style="display:none;">请填写厂家</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput">
                                <span class="error" style="display:none;">请填写型号</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput">
                                <span class="error" style="display:none;">请填写单位</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="number" min="0" class="form-control validInput">
                                <span class="error" style="display:none;">请填写数量</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <select class="form-control validInput">
                                    <option value="">请选择</option>
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                                <span class="error" style="display:none;">请选择是否明确单价</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput">
                                <span class="error" style="display:none;">请填写单价</span>
                            </td>
                            <td width="14%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control">
                            </td>
                            <td width="10%" style="background-color:#fff;">
                                <!--                                <span class="negativeInformationPlus">+添加</span>-->
                                <span class="negativeInformationReduce">-删除</span>
                            </td>
                        </tr>
                        <tbody class="goodsListTable">
                        <tr class="goodsListTbody" th:each="goods,goodsStat:${salesContractInfo?.goodsInfoList}">
                            <td width="5%" style="background-color:#fff;">
                                <span th:text="${goodsStat.count}"></span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput" readonly th:value="${goods?.goodsName}">
                                <span class="error" style="display:none;">请填写名称</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput" readonly th:value="${goods?.goodsFactory}">
                                <span class="error" style="display:none;">请填写厂家</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput" readonly th:value="${goods?.modelNumber}">
                                <span class="error" style="display:none;">请填写型号</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput" readonly th:value="${goods?.units}">
                                <span class="error" style="display:none;">请填写单位</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="number" min="0" class="form-control validInput" readonly th:value="${goods?.quantity}">
                                <span class="error" style="display:none;">请填写数量</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <select class="form-control validInput" disabled>
                                    <option value="0" th:selected="${goods?.clearPrice==0}">否</option>
                                    <option value="1" th:selected="${goods?.clearPrice==1}">是</option>
                                </select>
                                <span class="error" style="display:none;">请选择是否明确单价</span>
                            </td>
                            <td width="10%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control validInput" readonly th:value="${goods?.salesPrice}">
                                <span class="error" style="display:none;">请填写单价</span>
                            </td>
                            <td width="14%" style="background-color:#fff;" class="enter">
                                <input type="text" class="form-control" readonly th:value="${goods?.remark}">
                            </td>
                            <td width="10%" style="background-color:#fff;">
                                <!--                                <span class="negativeInformationPlus">+添加</span>-->
                                <!--                                <span class="negativeInformationReduce">-删除</span>-->
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>

            </div>
            <div class="yk_addBtns yk_addNewMsg newTabAddUpdateBtnBox">
                <button class="btn btn-white btn-info colorbtn submitBusiness">提交</button>
                <button class="btn btn-white btn-info btn-cancel">关闭</button>
            </div>
        </form>
    </div>
</div>
</body>
<!--<script src="/js/salesContractManage/entryContract.js"></script>-->
<script>
    $(function () {

        // 附件相关dom
        var fileWrapperbasic = '<div class="file-wrapper"><div class="file-icon" style="color: #5AC4FC;"><div class="file-icon-image"></div></div>' +
            '<div class="content"><div class="file-name"></div><div class="file-size small text-muted"></div></div>' +
            '<div class="actions" style="width:0.5rem"><a target="_blank" class="btn-yulan-file">' +
            '<em style="font-style:normal">预览</em><i class="operateIconfont operateIcon-yulan"></i></a></div>' +
            '<div class="actions" style="width:0.5rem"><a class="btn-xiazai-file">' +
            '<em style="font-style:normal">下载</em><i class="operateIconfont operateIcon-xiazai"></i></a></div></div>';


        // 在附件元素的data上存放选择的附件数据,初始为空
        $('.addFileList').each(function (i, ele) {
            $(ele).data('filearray', []);
            $(ele).data('deletefileid', []);
        });

        // 展示原先有的附件
        function showOriginalFile(source, insert) {
            for (var j = 0; j < $(source).length; j++) {
                var originalFileWrapper = $(fileWrapperbasic).clone();
                originalFileWrapper.find('.file-name').text($(source).eq(j).find('.originalName').val());
                originalFileWrapper.find('.file-name').attr('originalid', $(source).eq(j).find('.originalId').val());
                if (parseFloat($(source).eq(j).find('.originalSize').val()) < 1048576) {
                    originalFileWrapper.find('.file-size').text(($(source).eq(j).find('.originalSize').val() / 1024).toFixed(2) + "KB");
                } else {
                    originalFileWrapper.find('.file-size').text(($(source).eq(j).find('.originalSize').val() / 1024 / 1024).toFixed(2) + "MB");
                }
                ;
                var originaltype = $(source).eq(j).find('.originalType').val().toUpperCase();
                if (originaltype == '.JPG' || originaltype == '.JPEG' || originaltype == '.PNG' || originaltype == '.BMP') {
                    originalFileWrapper.find('.file-icon-image').css('background-image', 'url(' + $(source).eq(j).find('.originalUrl').val() + ')');
                } else {
                    originalFileWrapper.find('.file-icon-image').append('<i class="icon icon-file-pdf"></i>');
                }
                ;
                originalFileWrapper.find('.btn-delete-file').addClass('btn-delete-originalfile').removeClass("btn-delete-file");

                originalFileWrapper.find('.btn-yulan-file').attr('href', '/fileStorage/preview?fileId=' + $(source).eq(j).find('.originalId').val());
                originalFileWrapper.find('.btn-xiazai-file').attr('href', '/fileStorage/downloadFile?fileId=' + $(source).eq(j).find('.originalId').val());
                $(insert).find('.fileContent').append(originalFileWrapper)
            }
            ;
            j = null;
            if ($(insert).find('.file-wrapper').length > 0) {
                $(insert).find('.spanHolder').remove();
            }
            ;
        };

        // 展示原附件
        showOriginalFile('.fileInfoListOriginal', '.addFileList');

        // 排序-付款条件
        function sortReceiptInfo() {
            $(".paymentListTbody").each(function (i, ele) {
                $(ele).find('td:first span').text(i + 1);
            });
            if ($(".paymentListTbody").length <= 1) {
                $('.paymentTable .negativeInformationReduce').hide();
            } else {
                $('.paymentTable .negativeInformationReduce').show();
            }
            ;
        };
        sortReceiptInfo();

        // 排序-货物
        function sortIGoodsnfo() {
            $(".goodsListTbody").each(function (i, ele) {
                $(ele).find('td:first span').text(i);
            });
            if( $(".goodsListTbody").length <= 1 ){
                $('.goodsTable .negativeInformationReduce').hide();
            }else{
                $('.goodsTable .negativeInformationReduce').show();
            };
        };
        sortIGoodsnfo();

        // 添加行-货物
        $("#contractEntryForm").on('click', '.goodsTable #addGoods', function () {
            var supplierTrClone = $(".goodsListTbody:first").clone();
            supplierTrClone.find('.negativeInformationReduce').show();
            supplierTrClone.find('.error').hide();
            supplierTrClone.find('input').val('');
            supplierTrClone.find('select').val('');
            supplierTrClone.show();
            $('.goodsListTable').append(supplierTrClone);
            sortIGoodsnfo();
        });

        // 删除行
        $("#contractEntryForm").on('click', '.goodsTable .negativeInformationReduce', function () {
            $(this).parents('.goodsListTbody').remove();
            sortIGoodsnfo();
        });

        //导入
        $("#importButton").click(function () {
            $('#importFile').click();
        })

        $("#contractEntryForm").on("change", "#importFile", function (e) {
            var that = $(this);
            var file = e.target.files[0] || e.dataTransfer.files[0];//用于提交
            var postData = new FormData();
            postData.append('file', file);
            m = null;
            $.ajax({
                url: '/salesContract/doImportGoodsInfo',
                type: 'post',
                data: postData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.success) {
                        for (var n = 0; n < data.data.length; n++) {

                            var supplierTrClone1 = $(".goodsListTbody:first").clone();
                            supplierTrClone1.show();
                            supplierTrClone1.find('td').eq(1).find('input').val(data.data[n].goodsName)
                            supplierTrClone1.find('td').eq(2).find('input').val(data.data[n].goodsFactory)
                            supplierTrClone1.find('td').eq(3).find('input').val(data.data[n].modelNumber)
                            supplierTrClone1.find('td').eq(4).find('input').val(data.data[n].units)
                            supplierTrClone1.find('td').eq(5).find('input').val(data.data[n].quantity)
                            supplierTrClone1.find('td').eq(6).find('select').val(data.data[n].clearPrice)
                            supplierTrClone1.find('td').eq(7).find('input').val(data.data[n].salesPrice)
                            supplierTrClone1.find('td').eq(8).find('input').val(data.data[n].remark)
                            supplierTrClone1.find('.error').hide();

                            $('.goodsListTable').append(supplierTrClone1);
                            $("#importFile").val('')
                        }
                        n = null;
                        sortIGoodsnfo();
                    } else {
                        new $.zui.Messager('导入失败:' + data.msg, {
                            type: 'danger'
                        }).show();
                    }
                },
                error: function (status) {
                    new $.zui.Messager('导入时发生错误:' + status, {
                        type: 'danger'
                    }).show();
                }
            });
            return false;
        });

        //保存
        function submitFunction(e) {
            var postdata = new FormData();

            postdata.append('taskId', $("[name=taskId]").val());
            postdata.append('businessKey', $("[name=basicId]").val());
            postdata.append('salesContractBasicInfo.businessNumber', $("[name=businessNo]").val());
            postdata.append('salesContractBasicInfo.contractNumber', $("[name=contractNumber]").val());
            postdata.append('salesContractBasicInfo.contractPeriod', $("[name=contractPeriod]").val());
            postdata.append('salesContractBasicInfo.contractPlanAmountType', $("[name=contractPlanAmountType]").val());
            postdata.append('salesContractBasicInfo.contractPlanAmount', $("[name=contractPlanAmount]").val().split(",").join(''));
            postdata.append('salesContractBasicInfo.checkOperator', $("[name=checkOperator]").val());
            postdata.append('salesContractBasicInfo.settlementOperator', $("[name=settlementOperator]").val());

            //付款条件
            for (var i = 0; i < $(".paymentListTbody").length; i++) {
                postdata.append('paymentConditionList[' + i + '].paymentCondition', $(".paymentListTbody").eq(i).find('.paymentCondition').text());
            }
            i = null;

            postdata.append('salesContractSettleInfo.deliveryDate', $("[name=deliveryDate]").val());
            postdata.append('salesContractSettleInfo.signDate', $("[name=signDate]").val());
            postdata.append('salesContractSettleInfo.firstSettleDate', $("[name=firstSettleDate]").val());
            postdata.append('salesContractSettleInfo.settleCycleMethod', $("[name=settleCycleMethodDict]").val());
            postdata.append('salesContractSettleInfo.settleCycle', $("[name=settleCycle]").val());
            postdata.append('salesContractSettleInfo.planPaybackDays', $("[name=planPaybackDays]").val());
            postdata.append('salesContractSettleInfo.estimatePaybackDays', $("[name=estimatePayBackDays]").val());

            postdata.append('salesContractRetentionInfo.retention', $("[name=retention]").val());
            postdata.append('salesContractRetentionInfo.retentionPercent', $("[name=retentionPercent]").val());
            postdata.append('salesContractRetentionInfo.limit', $("[name=limit]").val());
            postdata.append('salesContractRetentionInfo.retentionLimit', $("[name=retentionLimit]").val().split(",").join(''));
            postdata.append('salesContractRetentionInfo.releaseMethod', $("[name=releaseMethodDict]").val());
            if ($("[name=releaseMethodDict] option:selected").text() == '固定日期') {
                postdata.append('salesContractRetentionInfo.releaseDate', $("[name=releaseDate]").val());
            }
            if ($("[name=releaseMethodDict] option:selected").text() == '回款后固定天数') {
                postdata.append('salesContractRetentionInfo.releaseDays', $("[name=releaseDays]").val());
            }

            //货物信息
            for (var i = 1; i < $(".goodsListTbody").length; i++) {
                postdata.append('goodsInfoList[' + (i-1) + '].goodsName', $(".goodsListTbody").eq(i).find('td').eq(1).find('input').val());
                postdata.append('goodsInfoList[' + (i-1) + '].goodsFactory', $(".goodsListTbody").eq(i).find('td').eq(2).find('input').val());
                postdata.append('goodsInfoList[' + (i-1) + '].modelNumber', $(".goodsListTbody").eq(i).find('td').eq(3).find('input').val());
                postdata.append('goodsInfoList[' + (i-1) + '].units', $(".goodsListTbody").eq(i).find('td').eq(4).find('input').val());
                postdata.append('goodsInfoList[' + (i-1) + '].quantity', $(".goodsListTbody").eq(i).find('td').eq(5).find('input').val());
                postdata.append('goodsInfoList[' + (i-1) + '].clearPrice', $(".goodsListTbody").eq(i).find('td').eq(6).find('select').val());
                postdata.append('goodsInfoList[' + (i-1) + '].salesPrice', $(".goodsListTbody").eq(i).find('td').eq(7).find('input').val());
                postdata.append('goodsInfoList[' + (i-1) + '].remark', $(".goodsListTbody").eq(i).find('td').eq(8).find('input').val());
            }
            i = null;

            // 附件信息
            // for( var m=0;m<$('.fileInfoListOriginal').find('.').length;m++ ){
            //     postdata.append('salesContractFile',$('.fileInfoListBox').attr('data')[m]);
            // };
            // m = null;
            $('.fileInfoListOriginal').each(function (i, ele) {
                postdata.append('fileIdList[' + i + ']', $(ele).find('.originalId').val())
            })

            var url = '/salesContract/doAdd', tip = '变更';

            $.ajax({
                url: url,
                type: 'post',
                data: postdata,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.success) {
                        new $.zui.Messager(tip + '合同成功', {
                            type: 'success'
                        }).show();
                        $.get('/salesContract/list', function (data) {
                            $(".yk_rightcontent").empty().append(data);
                        });
                    } else {
                        new $.zui.Messager(tip + '失败:' + data.msg, {
                            type: 'danger'
                        }).show();
                    }
                },
                error: function (status) {
                    new $.zui.Messager(tip + '合同时发生错误:' + status, {
                        type: 'danger'
                    }).show();
                }
            });
            return false;
        };

        var formRules = {
            'contractNumber':{
                required:true
            },
            'platform':{
                required:true
            },
            'customer':{
                required:true
            },
            'contractPeriod':{
                required:true
            },
            'contractPlanAmountType':{
                required:true
            },
            'contractPlanAmount':{
                required:true
            },
            'checkOperator':{
                required:true
            },
            'settlementOperator':{
                required:true
            },
            'settleCycleMethodDict':{
                required:true
            },
            'settleCycle':{
                required:true
            },
            'planPaybackDays':{
                required:true
            },
            'estimatePayBackDays':{
                required:true
            },
            'retention':{
                required:true
            },
            'retentionPercent':{
                required:true
            },
            'limit':{
                required:true
            },
            'retentionLimit':{
                required:true
            },
            'releaseMethodDict':{
                required:true
            },
            'releaseDate':{
                required:true
            },
        };

        var formMessages = {
            'contractNumber':{
                required:'请输入合同编号'
            },
            'platform':{
                required:'请输入供方公司名称'
            },
            'customer':{
                required:'请输入需方公司名称'
            },
            'contractPeriod':{
                required:'请输入合同期限'
            },
            'contractPlanAmountType':{
                required:'请选择合同约定金额类型'
            },
            'contractPlanAmount':{
                required:'请输入合同约定金额',
            },
            'checkOperator':{
                required:'请输入验收经办人'
            },
            'settlementOperator':{
                required:'请输入结算经办人'
            },
            'settleCycleMethodDict':{
                required:'请选择结算周期方式'
            },
            'settleCycle':{
                required:'请输入结算周期'
            },
            'planPaybackDays':{
                required:'请输入约定回款时间'
            },
            'estimatePayBackDays':{
                required:'请输入预估回款时间',
            },
            'retention':{
                required:'请选择是否有质保金'
            },
            'retentionPercent':{
                required:'请输入质保金比例'
            },
            'limit':{
                required:'请选择质保金是否有上限'
            },
            'retentionLimit':{
                required:'请输入质保金上限',
            },
            'releaseMethodDict':{
                required:'请选择质保金释放时间'
            },
            'releaseDate':{
                required:'请选择释放日期'
            },

        };

        //表单验证
        function addNewCustomer(e) {



            $("#contractEntryForm").validate({
                promptPosition: "bottomLeft",
                submitHandler: function (form) {
                    //货物必填验证
                    if($(".goodsListTable .goodsListTbody").length) {
                        $('.goodsListTable .validInput').change();
                    }else {
                        new $.zui.Messager('请添加货物信息。' , {
                            type: 'danger'
                        }).show();
                        return false;
                    }
                    if ($('.error.shows').length > 0) {
                        $('.error.shows:first').prev().focus();
                        return;
                    }
                    ;
                    submitFunction(e);
                },
                rules: formRules,
                messages: formMessages
            });
        };

        $(".amountInput").each(function (i, ele) {
            $(ele).val(commaDelimiter($(this).val()))
        })
        $(".amountInput").keyup(function () {
            $(this).val(commaDelimiter($(this).val()))
        })

        //结算周期方式
        $("[name=settleCycleMethodDict]").change(function () {
            if ($("[name=settleCycleMethodDict] option:selected").text() == '自然月') {
                $("[name=settleCycle]").parent().find('.viewDetailWord').text('个自然月')
            } else {
                $("[name=settleCycle]").parent().find('.viewDetailWord').text('天')
            }
        })
        $("[name=settleCycleMethodDict]").change()

        //是否有质保金
        $("[name=retention]").change(function () {
            if($("[name=retention] option:selected").val() == 0) {
                $(".retentionTr").hide();
                $("[name=retention]").parent().css('width','0').attr('colspan',3)
            }else {
                $(".retentionTr").show();
                $("[name=retention]").parent().removeAttr('colspan').css('width','35%')
            }
        })
        $("[name=retention]").change()

        //质保金上限
        $("[name=limit]").change(function () {
            if($("[name=limit] option:selected").val() == 0) {
                $(".retentionLimitTr").hide();
                $("[name=limit]").parent().css('width','0').attr('colspan',3)
            }else {
                $(".retentionLimitTr").show();
                $("[name=limit]").parent().removeAttr('colspan').css('width','35%')
            }
        })
        $("[name=limit]").change()

        //质保金释放方式
        $("[name=releaseMethodDict]").change(function () {
            if ($("[name=releaseMethodDict] option:selected").text() == '固定日期') {
                $("[name=releaseMethodDict]").parent().removeAttr('colspan').css('width', '35%')
                $(".releaseDate").show();
                $(".releaseDays").hide();
            } else if ($("[name=releaseMethodDict] option:selected").text() == '回款后固定天数') {
                $("[name=releaseMethodDict]").parent().removeAttr('colspan').css('width', '35%')
                $(".releaseDate").hide();
                $(".releaseDays").show();
            } else {
                $("[name=releaseMethodDict]").parent().css('width', '0').attr('colspan', '3')
                $(".releaseDate").hide();
                $(".releaseDays").hide();
            }
        })
        $("[name=releaseMethodDict]").change()

        //货物必填验证
        $(".goodsListTable").on("change", ".validInput", function (e) {
            if ($(this).val() == '') {
                $(this).next().addClass('shows').show();
            } else {
                $(this).next().removeClass('shows').hide();
            }
        })

        //提交按钮
        $(".yk_addNewMsg .submitBusiness").click(addNewCustomer);

        //关闭按钮
        $(".yk_addNewMsg .btn-cancel, .newBackBtn").click(function () {
            $.get('/salesContract/list', function (data) {
                $(".yk_rightcontent").empty().append(data);
            });
            return false;
        });


    })
</script>
</html>
