<div class="row rt-margin-bottom-before-box">
    <div class="col-sm-8">
        <div class="btn-group" ng-if="vm.isShowBack" >
            <button class="btn btn-link"  ng-click="goBack()" >
                <i class="fa fa-step-backward"></i> 返回上一页
            </button>
        </div>
    </div>
    <div class="col-sm-4">
    </div>
</div>

<div class="box box-primary">
    <div class="box-header" style="cursor: move;">
        <label style="padding-left: 20px;margin-top:20px;">一共{{vm.recordCount}}条流向数据，{{vm.unAssignCount}}条未匹配代表，数据如下：</label>
    </div>
    <div  class="box box-widget">
        <!-- /.box-header -->
        <!-- form start -->
        <form class="form-horizontal">
            <div class="box-body">
                <div class="form-group">
                    <rt-datetime ng-model="vm.yM" rt-type="month" rt-title="年月" rt-required="true" rt-col="3" rt-label-col="2">
                    </rt-datetime>
                    <div class="col-sm-5"></div>
                    <div class="btn-group" class="col-sm-2">
                        <button class="btn btn-primary" ng-click="vm.importType = 'query';vm.actions.getDataList()">查询</button>
                    </div>
                </div>
                <div class="form-group">
                    <rt-lookup2 rt-title="部门" ng-model="vm.businessunitId" rt-get-data-name="TblBusinessUnit.BusinessUnitId" rt-order-by="code"
                        rt-col-list="[{Code:'name',Name:'业务部门名称'},{Code:'code',Name:'业务部门编码'}]" rt-label-col="2" rt-col="3"></rt-lookup2>
                    <rt-lookup2 rt-title="商业" ng-model="vm.accountId" rt-get-data-name="Account.GetAccount" rt-order-by="accountnumber" rt-col-list="[{Code:'name',Name:'企业名称'},{Code:'accountnumber',Name:'企业编码'}]"
                        rt-label-col="2" rt-col="3"></rt-lookup2>
                </div>
                <div class="form-group">
                    <div class="col-sm-5">
                        <input type="radio" name="flowType" value="unAssign" ng-checked="true" ng-click="vm.actions.chooseFlowType()" />未归属代表的流向
                        <input type="radio" name="flowType" value="all" ng-click="vm.actions.chooseFlowType()" />所有的流向
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="nav-tabs-custom">
        <div class="tab-content">
            <rt-data-grid rt-page-record-count="vm.recordCount"  rt-page-index="vm.page.index" rt-page-size="vm.page.size" rt-get-data="vm.actions.getDataList()"
            rt-rows="vm.data" rt-auto-height="{{vm.view.autoHeight}}">
            <table class="table table-hover ">
                <thead id="headCode">
                    <tr>
                        <th class="rt-text-align">导入部门</th>
                        <th class="rt-text-align">上游企业名称</th>
                        <th class="rt-text-align">上游部门</th>
                        <th class="rt-text-align">上游代表</th>
                        <th class="rt-text-align">下游企业名称</th>
                        <th class="rt-text-align">下游企业标准名</th>
                        <th class="rt-text-align">下游企业类型</th>
                        <th class="rt-text-align">下游部门</th>
                        <th class="rt-text-align">下游代表</th>
                        <th class="rt-text-align">药品名称</th>
                        <th class="rt-text-align">药品规格</th>
                        <th class="rt-text-align">药品标准名</th>
                        <th class="rt-text-align">计量单位</th>
                        <th class="rt-text-align">药品批号</th>
                        <th class="rt-datetime-align">销售日期</th>
                        <th class="rt-number-align">销售价格</th>
                        <th class="rt-number-align">销售数量</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="row in vm.data track by $index">
                        <td class="rt-text-align">
                            {{row.import_businessunitidName}}
                        </td>
                        <td class="rt-text-align">
                            {{row.from_accountidName}}
                        </td>
                        <td class="rt-text-align">
                            <rt-lookup2-no-label ng-model="row.from_businessunitid" rt-get-data-name="TblBusinessUnit.BusinessUnitId" rt-col-list="[{Code:'name',Name:'业务部门名称'},{Code:'code',Name:'业务部门编码'}]"
                                rt-col="18" style="width: 300px;"></rt-lookup2-no-label>
                        </td>
                        <!-- <td class="rt-text-align">
                            {{row.from_businessunitidName}}
                        </td> -->
                        <td class="rt-text-align">
                            <rt-lookup2-no-label ng-model="row.from_ownerid" rt-disabled="row.from_businessunitid==null" rt-get-data-name="UserInfo.GetUserByBu"
                                rt-col-list="[{Code:'name',Name:'业务代表名称'},{Code:'code',Name:'业务代表编码'}]" rt-params="{'@businessunitid':row.from_businessunitid ? row.from_businessunitid.Id :''}"
                                rt-col="18" style="width: 300px;"></rt-lookup2-no-label>
                        </td>
                        <td class="rt-text-align">
                            {{row.to_account_alias_name}}
                        </td>
                        <td class="rt-text-align">
                            {{row.to_accountidName}}
                        </td>
                        <td class="rt-text-align">
                            {{row.to_account_classificationcodeName}}
                        </td>
                        <td class="rt-text-align">
                            <rt-lookup2-no-label ng-model="row.to_businessunitid" rt-get-data-name="TblBusinessUnit.BusinessUnitId" rt-col-list="[{Code:'name',Name:'业务部门名称'},{Code:'code',Name:'业务部门编码'}]"
                                rt-col="18" style="width: 300px;"></rt-lookup2-no-label>
                        </td>
                        <td class="rt-text-align">
                            <rt-lookup2-no-label ng-model="row.to_ownerid" rt-disabled="row.to_businessunitid==null" rt-get-data-name="UserInfo.GetUserByBu"
                                rt-col-list="[{Code:'name',Name:'业务代表名称'},{Code:'code',Name:'业务代表编码'}]" rt-params="{'@businessunitid':row.to_businessunitid ? row.to_businessunitid.Id :''}"
                                rt-col="18" style="width: 300px;"></rt-lookup2-no-label>
                        </td>
                        <td class="rt-text-align">
                            {{row.product_alias_name}}
                        </td>
                        <td class="rt-text-align">
                            {{row.product_alias_size}}
                        </td>
                        <td class="rt-text-align">
                            {{row.productidName}}
                        </td>
                        <td class="rt-text-align">
                            {{row.product_alias_uom}}
                        </td>
                        <td class="rt-text-align">
                            {{row.product_lotno}}
                        </td>
                        <td class="rt-datetime-align">
                            {{row.saleto_date|date:'yyyy-MM-dd'}}
                        </td>
                        <td class="rt-number-align">
                            {{row.saleto_price}}
                        </td>
                        <td class="rt-number-align">
                            {{row.saleto_qty}}
                        </td>
                    </tr>
                </tbody>
            </table>
        </rt-data-grid>
        </div>
    </div>
     <button class="btn btn-primary" ng-click="vm.importType = 'cal';vm.actions.calDrugFlowAssignment()" style="margin-top: 10px;margin-left: 3%;">开始进行流向归属计算</button>
        <div style="margin-left: 3%;margin-top: 20px;">
            <p>完成别名匹配，还有 {{vm.unAssignCount}} 条产品未归属代表，可以选择：</p>
            <p>1：导出数据，进行匹配并导入 <button class="btn btn-primary" 
            ng-click='vm.actions.export({
                        "$ddm_clean_dataId":"主键*",
                        "from_accountidName":"上游企业名称",
                        "from_businessunitidName":"上游部门",
                        "from_owneridName":"上游代表",
                        "to_account_alias_name":"下游企业名称",
                        "to_accountidName":"下游企业标准名",
                        "to_account_classificationcodeName":"下游企业类型",
                        "to_businessunitidName":"下游部门",
                        "to_owneridName":"下游代表",
                        "product_alias_name":"药品名称",
                        "product_alias_size":"药品规格",
                        "productidName":"药品标准名",
                        "product_alias_uom":"计量单位",
                        "product_lotno":"药品批号",
                        "saleto_date":"销售日期",
                        "saleto_price":"销售价格",
                        "saleto_qty":"销售数量"
                        },"CalDrugFlowAssignmentExport","流向数据归属")'>导出</button> <button class="btn btn-primary"
                        ng-click='vm.actions.import({
                            Title:"流向数据归属",
                            ModuleName:"CalDrugFlowAssignmentImport",
                            EntityName:"ddm_clean_data",
                            Columns:[
                                {ColumnName:"ddm_clean_dataId",DisplayName:"主键*",IsRequired:true,IsKey:true},
                                {ColumnName:"from_accountidName",DisplayName:"上游企业名称",IsRequired:false,IsKey:false},
                                {ColumnName:"from_businessunitidName",DisplayName:"上游部门",IsRequired:false,IsKey:false},
                                {ColumnName:"from_owneridName",DisplayName:"上游代表",IsRequired:false,IsKey:false},
                                {ColumnName:"to_account_alias_name",DisplayName:"下游企业名称",IsRequired:false,IsKey:false},
                                {ColumnName:"to_accountidName",DisplayName:"下游企业标准名",IsRequired:false,IsKey:false},
                                {ColumnName:"to_account_classificationcodeName",DisplayName:"下游企业类型",IsRequired:false,IsKey:false},
                                {ColumnName:"to_businessunitidName",DisplayName:"下游部门",IsRequired:false,IsKey:false},
                                {ColumnName:"to_owneridName",DisplayName:"下游代表",IsRequired:false,IsKey:false},
                                {ColumnName:"product_alias_name",DisplayName:"药品名称",IsRequired:false,IsKey:false},
                                {ColumnName:"product_alias_size",DisplayName:"药品规格",IsRequired:false,IsKey:false},
                                {ColumnName:"productidName",DisplayName:"药品标准名",IsRequired:false,IsKey:false},
                                {ColumnName:"product_alias_uom",DisplayName:"计量单位",IsRequired:false,IsKey:false},
                                {ColumnName:"product_lotno",DisplayName:"药品批号",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_date",DisplayName:"销售日期",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_price",DisplayName:"销售价格",IsRequired:false,IsKey:false},
                                {ColumnName:"saleto_qty",DisplayName:"销售数量",IsRequired:false,IsKey:false}]})'>导入</button></p>
            <p>2：在本界面上手工进行流向归属</p>
            <p>3：在《销售区域》功能里设定客户归属，然后重新匹配</p>
        </div>
        <button class="btn btn-primary" ng-click="vm.actions.saveData()" style="margin-top: 10px;margin-left: 3%;margin-bottom: 20px;"
            ng-show="vm.isSaveShow">下一步，保存流向归属</button>
</div>
