<div class="row rt-margin-bottom-before-box">
    <div class="col-sm-8">
        <div class="btn-group">
            <button class="btn btn-link" ng-click="vm.actions.del()" ng-show="vm.privilege.IsDelete">
                <i class="fa fa-trash"></i> 删除
            </button>
            <button class="btn btn-link dropdown-toggle" id="dropdownMenuImportSelect" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
                ng-show="vm.privilege.IsWrite" ng-if="vm.operatingPrivilege['btnImportDrugflow_0648F78F-7BC3-43B9-B35D-1614DAE4194B'] || vm.operatingPrivilege['btnImportDrugflow_9A2D2593-F0B2-4B0D-97B8-25C6DF08BE69'] || vm.operatingPrivilege['btnImportDrugflow_5AFFD8B6-94BF-4F4B-884A-1EAC875020E6']">
                <i class="fa fa-upload"></i>导入
                <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" aria-labelledby="dropdownMenuImportSelect" ng-show="vm.privilege.IsWrite">
                <li ng-if="vm.operatingPrivilege['btnImportDrugflow_0648F78F-7BC3-43B9-B35D-1614DAE4194B']">
                    <a href="javascript:void(0)" ng-click='vm.actions.import({
                            Title:"流向数据",
                            ModuleName:"DrugFlowImport",
                            EntityName:"drug_flow",
                            Columns:[
                                {ColumnName:"fromentcode",DisplayName:"上游企业编码",IsRequired:false,IsKey:false},
                                {ColumnName:"fromaccountid",DisplayName:"上游企业名称*",IsRequired:true,IsKey:true},
                                {ColumnName:"business_unit_id",DisplayName:"上游部门",IsRequired:false,IsKey:false},
                                {ColumnName:"from_ownerid",DisplayName:"商务代表*",IsRequired:true,IsKey:false},
                                {ColumnName:"toentcode",DisplayName:"下游企业编码",IsRequired:false,IsKey:true},
                                {ColumnName:"saleto_entname",DisplayName:"下游企业名称*",IsRequired:true,IsKey:false},
                                {ColumnName:"saleto_business_unit_id",DisplayName:"下游部门",IsRequired:false,IsKey:false},
                                {ColumnName:"to_ownerid",DisplayName:"下游负责人",IsRequired:false,IsKey:false},
                                {ColumnName:"toenttype",DisplayName:"下游企业类型*",IsRequired:true,IsKey:false},
                                {ColumnName:"toprovinceid",DisplayName:"下游企业省份",IsRequired:false,IsKey:false},
                                {ColumnName:"tocityid",DisplayName:"下游企业城市",IsRequired:false,IsKey:false},
                                {ColumnName:"tocountyid",DisplayName:"下游企业区县",IsRequired:false,IsKey:false},
                                {ColumnName:"drugid",DisplayName:"产品名称*",IsRequired:true,IsKey:false},
                                {ColumnName:"saleto_productsize",DisplayName:"规格*",IsRequired:true,IsKey:false},
                                {ColumnName:"lotno",DisplayName:"批号",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_unit",DisplayName:"单位",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_price",DisplayName:"单价",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_count",DisplayName:"销量*",IsRequired:true,IsKey:false},
                                {ColumnName:"billdate",DisplayName:"交易日期*",IsRequired:true,IsKey:false},
                                {ColumnName:"agent_accountid",DisplayName:"代理商",IsRequired:false,IsKey:false},
                                {ColumnName:"remark",DisplayName:"备注",IsRequired:false,IsKey:false}
                            ]
                        },1)'>
                        <i class="fa fa-upload"></i>导入(按年月)</a>
                </li>
                <li ng-if="vm.operatingPrivilege['btnImportDrugflow_9A2D2593-F0B2-4B0D-97B8-25C6DF08BE69']">
                    <a href="javascript:void(0)" ng-click='vm.actions.import({
                            Title:"流向数据",
                            ModuleName:"DrugFlowImport",
                            EntityName:"drug_flow",
                            Columns:[
                                {ColumnName:"fromentcode",DisplayName:"上游企业编码",IsRequired:false,IsKey:false},
                                {ColumnName:"fromaccountid",DisplayName:"上游企业名称*",IsRequired:true,IsKey:true},
                                {ColumnName:"business_unit_id",DisplayName:"上游部门",IsRequired:false,IsKey:false},
                                {ColumnName:"from_ownerid",DisplayName:"商务代表*",IsRequired:true,IsKey:false},
                                {ColumnName:"toentcode",DisplayName:"下游企业编码",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_entname",DisplayName:"下游企业名称*",IsRequired:true,IsKey:false},
                                {ColumnName:"saleto_business_unit_id",DisplayName:"下游部门",IsRequired:false,IsKey:false},
                                {ColumnName:"to_ownerid",DisplayName:"下游负责人",IsRequired:false,IsKey:false},
                                {ColumnName:"toenttype",DisplayName:"下游企业类型*",IsRequired:true,IsKey:false},
                                {ColumnName:"toprovinceid",DisplayName:"下游企业省份",IsRequired:false,IsKey:false},
                                {ColumnName:"tocityid",DisplayName:"下游企业城市",IsRequired:false,IsKey:false},
                                {ColumnName:"tocountyid",DisplayName:"下游企业区县",IsRequired:false,IsKey:false},
                                {ColumnName:"drugid",DisplayName:"产品名称*",IsRequired:true,IsKey:false},
                                {ColumnName:"saleto_productsize",DisplayName:"规格*",IsRequired:true,IsKey:false},
                                {ColumnName:"lotno",DisplayName:"批号",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_unit",DisplayName:"单位",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_price",DisplayName:"单价",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_count",DisplayName:"销量*",IsRequired:true,IsKey:false},
                                {ColumnName:"billdate",DisplayName:"交易日期*",IsRequired:true,IsKey:false},
                                {ColumnName:"agent_accountid",DisplayName:"代理商",IsRequired:false,IsKey:false},
                                {ColumnName:"remark",DisplayName:"备注",IsRequired:false,IsKey:false}
                            ]
                        },2)'>
                        <i class="fa fa-upload"></i>导入(按年月+省区/地区)</a>
                </li>
                <li ng-if="vm.operatingPrivilege['btnImportDrugflow_5AFFD8B6-94BF-4F4B-884A-1EAC875020E6']">
                    <a href="javascript:void(0)" ng-click='vm.actions.import({
                            Title:"流向数据",
                            ModuleName:"DrugFlowImport",
                            EntityName:"drug_flow",
                            Columns:[
                                {ColumnName:"fromentcode",DisplayName:"上游企业编码",IsRequired:false,IsKey:false},
                                {ColumnName:"fromaccountid",DisplayName:"上游企业名称*",IsRequired:true,IsKey:true},
                                {ColumnName:"business_unit_id",DisplayName:"上游部门",IsRequired:false,IsKey:false},
                                {ColumnName:"from_ownerid",DisplayName:"商务代表*",IsRequired:true,IsKey:false},
                                {ColumnName:"toentcode",DisplayName:"下游企业编码",IsRequired:false,IsKey:true},
                                {ColumnName:"saleto_entname",DisplayName:"下游企业名称*",IsRequired:true,IsKey:false},
                                {ColumnName:"saleto_business_unit_id",DisplayName:"下游部门",IsRequired:false,IsKey:false},
                                {ColumnName:"to_ownerid",DisplayName:"下游负责人",IsRequired:false,IsKey:false},
                                {ColumnName:"toenttype",DisplayName:"下游企业类型*",IsRequired:true,IsKey:false},
                                {ColumnName:"toprovinceid",DisplayName:"下游企业省份",IsRequired:false,IsKey:false},
                                {ColumnName:"tocityid",DisplayName:"下游企业城市",IsRequired:false,IsKey:false},
                                {ColumnName:"tocountyid",DisplayName:"下游企业区县",IsRequired:false,IsKey:false},
                                {ColumnName:"drugid",DisplayName:"产品名称*",IsRequired:true,IsKey:false},
                                {ColumnName:"saleto_productsize",DisplayName:"规格*",IsRequired:true,IsKey:false},
                                {ColumnName:"lotno",DisplayName:"批号",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_unit",DisplayName:"单位",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_price",DisplayName:"单价",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_count",DisplayName:"销量*",IsRequired:true,IsKey:false},
                                {ColumnName:"billdate",DisplayName:"交易日期*",IsRequired:true,IsKey:false},
                                {ColumnName:"agent_accountid",DisplayName:"代理商",IsRequired:false,IsKey:false},
                                {ColumnName:"remark",DisplayName:"备注",IsRequired:false,IsKey:false}
                            ]
                        },3)'>
                        <i class="fa fa-upload"></i>导入(按年月+省区/地区+商业)</a>
                </li>
            </ul>
            <button class="btn btn-link" ng-show="vm.privilege.IsExport" ng-click='vm.actions.export({},"DrugFlowExport","流向数据")'>
                <i class="fa fa-download"></i> 导出
            </button>
        </div>
    </div>
    <div class="col-sm-4">
        <form class="input-group">
            <input type="search" placeholder="快速查找上游企业名称..." class="form-control" ng-model="vm.view.searchText" />
            <span class="input-group-btn" ng-click="vm.view.search(1)">
                <button type="submit" class="btn btn-default">
                    <i class="fa fa-search"></i>
                </button>
            </span>
        </form>
    </div>
</div>

<div class="box box-primary">
    <div class="box-header with-border" style="cursor: move;">
        <div class="pull-left">
            <div class="btn-group">
                <label class="btn btn-default dropdown-toggle" id="dropdownMenuViewSelect" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    上游
                </label>
            </div>
            <div class="btn-group">
                <button class="btn btn-default dropdown-toggle" id="dropdownMenuBuSelect" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    {{vm.buidSelected==null?"所有事业部":vm.buidSelected.name}}
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" aria-labelledby="dropdownMenuBuSelect">
                    <li ng-click="vm.buidSelected = null;vm.bigDepSelected=null;">
                        <a href="javascript:void(0)">所有事业部</a>
                    </li>
                    <li ng-repeat="item in vm.buidList" ng-click="vm.buidSelected = item;vm.bigDepSelected=null;">
                        <a href="javascript:void(0)">{{item.name}}</a>
                    </li>
                </ul>
            </div>
            <div class="btn-group">
                <button class="btn btn-default dropdown-toggle" id="dropdownMenuBigDepartSelect" data-toggle="dropdown" aria-haspopup="true"
                    aria-expanded="false">
                    {{vm.bigDepSelected==null?"所有业务线/大区":vm.bigDepSelected.name}}
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" aria-labelledby="dropdownMenuBigDepartSelect">
                    <li ng-click="vm.bigDepSelected = null;">
                        <a href="javascript:void(0)">所有业务线/大区</a>
                    </li>
                    <li ng-repeat="item in vm.bigDepList" ng-click="vm.bigDepSelected = item;">
                        <a href="javascript:void(0)">{{item.name}}</a>
                    </li>
                </ul>
            </div>
            <div class="btn-group">
                <label class="btn btn-default dropdown-toggle" id="dropdownMenuViewSelect" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    下游

                </label>
            </div>
            <div class="btn-group">
                <button class="btn btn-default dropdown-toggle" id="dropdowndownMenuBuSelect" data-toggle="dropdown" aria-haspopup="true"
                    aria-expanded="false">
                    {{vm.downbuidSelected==null?"所有事业部":vm.downbuidSelected.name}}
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" aria-labelledby="dropdowndownMenuBuSelect">
                    <li ng-click="vm.downbuidSelected = null;vm.downbigDepSelected=null;">
                        <a href="#">所有事业部</a>
                    </li>
                    <li ng-repeat="item in vm.downbuidList" ng-click="vm.downbuidSelected = item;vm.downbigDepSelected=null;">
                        <a href="javascript:void(0)">{{item.name}}</a>
                    </li>
                </ul>
            </div>
            <div class="btn-group">
                <button class="btn btn-default dropdown-toggle" id="dropdowndownMenuBigDepartSelect" data-toggle="dropdown" aria-haspopup="true"
                    aria-expanded="false">
                    {{vm.downbigDepSelected==null?"所有业务线/大区":vm.downbigDepSelected.name}}
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" aria-labelledby="dropdowndownMenuBigDepartSelect">
                    <li ng-click="vm.downbigDepSelected = null;">
                        <a href="javascript:void(0)">所有业务线/大区</a>
                    </li>
                    <li ng-repeat="item in vm.downbigDepList" ng-click="vm.downbigDepSelected = item;">
                        <a href="javascript:void(0)">{{item.name}}</a>
                    </li>
                </ul>
            </div>

            <button class="btn btn-default" ng-click="vm.view.isShowSearchList = !vm.view.isShowSearchList;overHeightTable();" ng-class="{true:'active',false:'inactive'}[vm.view.isShowSearchList]">
                <i class="fa fa-filter"></i> 更多筛选
                <i class="fa fa-angle-double-down"></i>
            </button>
        </div>
    </div>
    <div ng-if="vm.view.isShowSearchList" class="box box-widget">
        <!-- form start -->
        <form class="form-horizontal">
            <div class="box-body">
                <div class="form-group">
                    <rt-datetime ng-model="vm.startDate" rt-type="month" rt-title="开始年月" rt-required="true" rt-col="3" rt-label-col="2"></rt-datetime>
                    <rt-datetime ng-model="vm.endDate" rt-type="month" rt-title="结束年月" rt-required="true" rt-col="3" rt-label-col="2"></rt-datetime>
                    <div class="col-sm-2">
                        <button class="btn btn-primary" ng-click="vm.view.search(1)">查询</button>
                    </div>
                </div>
                <div class="form-group">
                    <rt-datetime ng-model="vm.billStartDate" rt-type="date" rt-title="交易日期-从" rt-required="false" rt-col="3" rt-label-col="2"></rt-datetime>
                    <rt-datetime ng-model="vm.billEndDate" rt-type="date" rt-title="交易日期-到" rt-required="false" rt-col="3" rt-label-col="2"></rt-datetime>    
                </div>
                <div class="form-group">
                    <rt-lookup2 rt-label-col="2" rt-title="产品名称" ng-model="vm.productSelected" rt-get-data-name="Product.GetProductSize" rt-order-by="name asc"
                        rt-col-list="[{Code:'name',Name:'产品名称'},{Code:'size',Name:'规格'},{Code:'code',Name:'产品编码'}]" rt-multiple="true"
                        rt-col="8"></rt-lookup2>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">上游省区/地区</label>
                    <div class="col-sm-8">
                        <ui-select class="form" multiple allow-clear sortable="true" theme="bootstrap" close-on-select="false" ng-model="vm.businessUnitSelected">
                            <ui-select-match>{{$item.name}}</ui-select-match>
                            <ui-select-choices repeat="item in vm.businessUnitList | filter: {name: $select.search}">
                                <span ng-bind-html="item.name | highlight: $select.search"></span>
                            </ui-select-choices>
                        </ui-select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">上游企业</label>
                    <div class="col-sm-3">
                        <input type="search" placeholder="上游企业名称" class="form-control" ng-model="vm.upCoName" />
                    </div>
                    <label class="col-sm-2 control-label">上游企业类型</label>
                    <div class="col-sm-3">
                        <ui-select class="form" multiple allow-clear sortable="true" theme="bootstrap" close-on-select="false" ng-model="vm.fromAccountclassificationSelected">
                            <ui-select-match>{{$item.Name}}</ui-select-match>
                            <ui-select-choices repeat="item in vm.fromAccountclassificationList | filter: {Name: $select.search}">
                                <span ng-bind-html="item.Name | highlight: $select.search"></span>
                            </ui-select-choices>
                        </ui-select>
                    </div>
                </div>
                <div class="form-group">
                    <rt-lookup2 rt-title="商务代表" ng-model="vm.fromOwnerId" rt-get-data-name="UserInfo.GetAllUser" rt-order-by="name"
                        rt-col-list="[{Code:'name',Name:'姓名'},{Code:'code',Name:'编码'}]" rt-label-col="2" rt-col="3"></rt-lookup2>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">下游省区/地区</label>
                    <div class="col-sm-8">
                        <ui-select class="form" multiple allow-clear sortable="true" theme="bootstrap" close-on-select="false" ng-model="vm.downbusinessUnitSelected">
                            <ui-select-match>{{$item.name}}</ui-select-match>
                            <ui-select-choices repeat="item in vm.downbusinessUnitList | filter: {name: $select.search}">
                                <span ng-bind-html="item.name | highlight: $select.search"></span>
                            </ui-select-choices>
                        </ui-select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">下游企业</label>
                    <div class="col-sm-3">
                        <input type="search" placeholder="下游企业名称" class="form-control" ng-model="vm.downCoName" />
                    </div>
                    <label class="col-sm-2 control-label">下游企业类型</label>
                    <div class="col-sm-3">
                        <ui-select class="form" multiple allow-clear sortable="true" theme="bootstrap" close-on-select="false" ng-model="vm.toAccountclassificationSelected">
                            <ui-select-match>{{$item.Name}}</ui-select-match>
                            <ui-select-choices repeat="item in vm.toAccountclassificationList | filter: {Name: $select.search}">
                                <span ng-bind-html="item.Name | highlight: $select.search"></span>
                            </ui-select-choices>
                        </ui-select>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="nav-tabs-custom">
        <div class="tab-content">
            <rt-data-grid rt-page-record-count="vm.page.recordCount" rt-page-index="vm.page.index" rt-page-size="vm.page.size" rt-get-data="vm.view.search()"
                rt-sort-field="vm.view.sortField" rt-rows="vm.data" rt-selected-ids="vm.view.selectedIds" rt-auto-height="{{vm.view.autoHeight}}">

                <table class="table table-hover ">
                    <thead id="headCode">
                        <tr>
                            <th colspan="3" style="text-align:center;border-right:1px solid #f0f0f0;">基本信息</th>
                            <th colspan="6" style="text-align:center;border-right:1px solid #f0f0f0;">上游企业</th>
                            <th colspan="9" style="text-align:center;border-right:1px solid #f0f0f0;">下游企业</th>
                            <th colspan="8" style="text-align:center;border-right:1px solid #f0f0f0;">产品信息</th>
                        </tr>
                        <tr>
                            <th>
                                <rt-header-checkbox></rt-header-checkbox>
                            </th>
                            <th>统计年月</th>
                            <th style="border-right:1px solid #f0f0f0;">交易日期</th>

                            <th>省市县</th>
                            <th>省区/地区</th>
                            <th>企业编码</th>
                            <th>企业名称</th>
                            <th>商务代表</th>
                            <th style="border-right:1px solid #f0f0f0;">类型</th>
                            <th>省市县</th>
                            <th>省区/地区</th>
                            <th>企业编码</th>
                            <th>企业名称（流向名）</th>
                            <th>企业名称（标准名）</th>
                            <th>医院等级</th>
                            <th>负责人</th>
                            <th>类型</th>
                            <th style="border-right:1px solid #f0f0f0;">代理商名称</th>
                            <th>产品名称</th>
                            <th>规格</th>
                            <th>批号</th>
                            <th>销量</th>
                            <th>计量单位</th>
                            <th>单价</th>
                            <th>金额</th>
                            <th style="border-right:1px solid #f0f0f0;">备注</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="row in vm.data track by $index">
                            <td>
                                <rt-data-checkbox value="{{row.Id}}" />
                            </td>
                            <td>{{ row.year+'-'+row.month }}</td>
                            <td>{{ row.billdate | date:'yyyy-MM-dd'}}</td>

                            <td>{{ row.fromprovinceid.Name}}{{row.fromcityid.Name}}{{row.fromcountyid.Name}}</td>
                            <td>{{ row.business_unit_id.Name}}</td>
                            <td>{{ row.fromentcode}}</td>
                            <td>{{ row.fromaccountid.Name }}</td>
                            <td>{{ row.from_ownerid.Name}}</td>
                            <td>{{ row.accountclassificationcodename}}</td>

                            <td>{{row.toprovinceid.Name}}{{row.tocityid.Name}}{{row.tocountyid.Name}}</td>
                            <td>{{ row.saleto_business_unit_id.Name}}</td>
                            <td>{{ row.toentcode}}</td>
                            <td>{{ row.saleto_entname }}</td>
                            <td>{{ row.toaccountidName == null ? '-' : row.toaccountidName }}</td>
                            <td>{{ row.toenttype.Name == '医院' ? row.account_grade_levelName : ''}}</td>
                            <td>{{ row.to_ownerid.Name}}</td>
                            <td>{{ row.toenttype.Name}}</td>
                            <td>{{ row.agent_accountid.Name }}</td>

                            <td>{{ row.drugid.Name }}</td>
                            <td>{{ row.productsize }}</td>
                            <td>{{ row.lotno }}</td>
                            <td style="text-align:right;">{{ row.saleto_count}}</td>
                            <td>{{ row.regular_unit }}</td>
                            <!--<td>{{ row.saleto_price | currency:"￥" }}</td>
                        <td>{{ row.saleto_total_price | currency:"￥" }}</td>-->
                            <td>{{ row.saleto_price ? '￥':'' }}{{ row.saleto_price | toFixNumber: 4 }}</td>
                            <td>{{ row.saleto_total_price ? '￥':''}}{{ row.saleto_total_price | toFixNumber:4 }}</td>
                            <td>{{ row.remark }}</td>
                        </tr>
                    </tbody>
                </table>
            </rt-data-grid>
            <!-- rt-data-grid  -->
            <div class="row" style="padding-top: 15px;width: 100%;">
                <span style="float: right;">本页合计 金额： {{vm.pagePriceSum | toFixNumber: 4 }} 元、销量： {{vm.pageAmountSum}} ，总计 金额： {{vm.totalPriceSum?vm.totalPriceSum:0}}
                    元、销量： {{vm.totalAmountSum?vm.totalAmountSum:0}}</span>
            </div>
        </div>
    </div>
</div>

<div class="sidebar sidebar-right sidebar-animate rt-shadow-border-left content-wrapper" ng-if="vm.view.type=='default'">
    <div ui-view class="content"></div>
</div>
<!-- div[.editview] -->