@{
    ViewBag.Title = "客户变价销售详情界面";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<div class="wrapper wrapper-content">
        <div class="ibox-content form-inline ">
                <table class="table table-bordered table-striped table-hover">
                    <tr>
                        <td style="width:120px">单据日期:</td>
                        <td>
                              <input type="text" name="txtBillDate" class="form-control" id="txtBillDate"   />
                        </td>
                        <td style="width:120px">单据编号:</td>
                        <td>
                            <input type="text" name="txtBillCode" class="form-control"  id="txtBillCode"   />
                        </td>
                        <td style="width:120px">往来单位:</td>
                         <td>
                            <input type="text" name="txtBFullName" class="form-control" id="txtBFullName"   />
                        </td>
                         <td style="width:120px">经手人:</td>
                         <td>
                            <input type="text" name="txtEFullName" class="form-control"  id="txtEFullName"   />
                        </td>
                    </tr>
                    <tr>
                        <td>仓库:</td>
                         <td>
                            <input type="text" name="txtKFullName" class="form-control" id="txtKFullName"   />
                        </td>
                        <td>附加说明:</td>
                         <td colspan="4">
                             <input type="hidden" id="hiBillid" />
                            <input type="text" name="txtComment"  style="width:100%" id="txtComment"   />
                        </td>
                        <td>
                            <button class="btn btn-default btn-w-m" id="btnExcel">导出</button>
                        </td>
                    </tr>
                </table>
                
        </div>
        <div class="ibox-content">
            <table id="GetDetailTable"></table>
        </div>
    </div>
<script type="text/javascript">
    $(function () {
        var datarows = parent.$('#GetSaleReportPriceTable').bootstrapTable("getData");
        var index = parent.$("#rowIndex").val();
        var datarow = datarows[index];
        $("#txtBillDate").val(datarow["BillDate"]);
        $("#txtBillCode").val(datarow["BillCode"]);
        $("#txtBFullName").val(datarow["BFullName"]);
        $("#txtEFullName").val(datarow["EFullName"]);
        $("#txtKFullName").val(datarow["KFullname"]);
        $("#txtComment").val(datarow["Comment"]);
        $("#hiBillid").val(datarow["BillNumberId"]);
       
        $('#GetDetailTable').bootstrapTable({
            url: '../DataQuery/GetSaleReportPriceDetail',         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: true,                   //是否显示分页（*）
            sortOrder: "asc",
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 15,                       //每页的记录行数（*）
            pageList: [15, 30, 50],        //可供选择的每页的行数（*）
            minimumCountColumns: 2,  //最少允许的列数
            //height: "100%",               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "nub",            //每一行的唯一标识，一般为主键列
            clickToSelect: true,              //是否启用点击选中行
            sortable: true,                     //是否启用排序
            silentSort: true,
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: false,
            paginationFirstText: '首页',
            paginationLastText: '末页',
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            showColumns: false,            //是否显示所有的列
            showRefresh: false,              //是否显示刷新按钮
            showToggle: false,                     //是否显示详细视图和列表视图的切换按钮
             cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            queryParams: function (params) {
                return {
                    pagesize: params.limit,//页面大小
                    page: params.offset, //页码
                    billid: $("#hiBillid").val(),
                };
            },//传递参数（*）
            columns: [
                {
                    field: "index", title: "序号",formatter: function (value, row, index) {
                        if (value == "合计：") {
                            return value;
                        }
                        return row.index = index + 1; //返回行号
                    }
                },
               { field: 'UserCode', title: '商品编号' },
               { field: 'FullName', title: '商品名称' },
               { field: 'Standard', title: '规格' },
               { field: 'Type', title: '型号' },
               { field: 'UnitName', title: '单位' },
               { field: 'SaleQty', title: '数量' },
               { field: 'SalePrice', title: '单价' },
               { field: 'DiscountPrice', title: '折扣单价' },
               { field: 'SaleTotal', title: '销售金额' },
               { field: 'NewTotal', title: '原价金额' },
               { field: 'Total', title: '变价差额' },
               {
                   field: 'DetailSign', title: '是否赠品', formatter: function (value, row, index) {
                       if (row["index"] == "合计：") {
                           return "";
                       }
                       if (value == "1") {
                           return '<a style="color:red">是</a>';
                       } else {
                           return '<a style="color:green">否</a>';
                       }
                   }
               },
               { field: 'Comment', title: '备注' }
            ],
            onLoadSuccess: function (data) {
                console.log(JSON.stringify(data));
                if (data.total < 1) return;
                var SaleQty = 0;
                var NewTotal = 0;
                var Total = 0;
                var SaleTotal = 0;
                for (var i = 0; i < data["rows"].length; i++) {
                    if (data["rows"][i]["SaleQty"]) {
                        SaleQty = SaleQty + parseFloat(data["rows"][i]["SaleQty"]);
                    } if (data["rows"][i]["NewTotal"]) {
                        NewTotal = NewTotal + parseFloat(data["rows"][i]["NewTotal"]);
                    } if (data["rows"][i]["Total"]) {
                        Total = Total + parseFloat(data["rows"][i]["Total"]);
                    } if (data["rows"][i]["SaleTotal"]) {
                        SaleTotal = SaleTotal + parseFloat(data["rows"][i]["SaleTotal"]);
                    }
                }
                var row = [
                    {
                        "billDate": "",
                        "BillCode": "",
                        "ptypeid": "",
                        "FullName": "",
                        "Type": "",
                        "Standard": "",
                        "UserCode": "",
                        "SaleQty": SaleQty,
                        "SalePrice": "",
                        "DiscountPrice": "",
                        "SaleTotal": SaleTotal,
                        "btypeid": "",
                        "UnitName": "",
                        "DetailSign": "",
                        "NewTotal1":"",
                        "Comment": "",
                        "Total": Total,
                        "NewTotal": NewTotal,
                        "index": "合计："
                    }];
                $('#GetDetailTable').bootstrapTable("append", row);
            }
        });
    });
    
    //Excel导出
    $("#btnExcel").on("click", function () {
        var stardate = $("#pmStartDate").val();
        var enddate = $("#pmEndDate").val();
        var loginUser = $("#logionUser option:selected").val();
        var rsNum = $("#btypeid").val();
        window.location.href = '../DataQuery/GetExcelSaleReportPriceDetail?billid=' + $("#hiBillid").val()
    });

</script>
