<template>
    <div class="orderList distributionOrder">
        <div class="head-title">
            订单列表
            <div style="float:right;">
                <el-button @click="getExport(1)" style="margin: -5px 0 0 20px;" size="small" type="primary">批量导出</el-button>
                <el-button @click="getExport(2)" style="margin-top: -5px;" size="small" type="primary">粉象导出</el-button>
            </div>
        </div>
        <div class="content">
            <div>
                <span>下单时间：</span>
                <el-date-picker
                v-model="dateList"
                @change="msg.pageIndex=1,getList()"
                size="small"
                type="datetimerange"
                range-separator="至"
                value-format="yyyy-MM-dd HH:mm:ss"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
                </el-date-picker>
                <span style="margin-left:15px">所属平台：</span>
                <el-select class="w120" @change="msg.pageIndex=1,getList()" style="margin-right: 10px;" v-model="msg.OrderSource" size="small" placeholder="请选择">
                    <el-option label="全部平台" :value="0"></el-option>
                    <el-option
                    v-for="item in platList"
                    :key="item.Id"
                    :label="item.Name"
                    :value="item.Id">
                    </el-option>
                </el-select>
                <span style="margin-left:15px">配送方式：</span>
                <el-select class="w120" @change="msg.pageIndex=1,getList()" style="margin-right: 10px;" v-model="msg.DeliveryMethod" size="small" placeholder="请选择">
                    <el-option label="全部订单" :value="0"></el-option>
                    <el-option
                    v-for="item in deliveryList"
                    :key="item.Id"
                    :label="item.Name"
                    :value="item.Id">
                    </el-option>
                </el-select>
                <el-input @clear="msg.pageIndex=1,getList()"  @keyup.enter.native="msg.pageIndex=1,getList()" clearable style="margin-left:15px;width:300px" class="input-with-select" placeholder="请输入内容" v-model="msgVal" size="small">
                    <el-select class="pendSelect" @change="ChangeId" v-model="msgId" slot="prepend" placeholder="请选择">
                        <el-option
                        v-for="item in option"
                        :key="item.Id"
                        :label="item.name"
                        :value="item.Id">
                        </el-option>
                    </el-select>
                </el-input>
            </div>
            <div>
                <el-tabs style="margin-top:20px" v-model="activeName" @tab-click="handleClick">
                    <el-tab-pane :dataId="0" label="全部" name="first"></el-tab-pane>
                    <el-tab-pane v-for="item in orderTypeList" :key="item.Id" :dataId="item.Id" :label="item.Name"></el-tab-pane>
                </el-tabs>
                <div class="app-order-title">
                    <div style="width: 55%;">商品信息</div>
                    <div style="width: 20%;">实付金额</div>
                    <div style="width: 20%;">分销状态</div>
                    <div style="width: 20%;">分销情况</div>
                </div>
                <div v-loading="loading" class="app-order-list">
                    <el-card v-for="(item,index) in tableData" :key="index" class="app-order-item" shadow="never">
                        <div slot="header" class="clearfix">
                            <div flex="cross:center" class="app-order-head">
                                <div class="app-order-time">{{item.CreateDate}}</div>
                                <div class="app-order-user">
                                    <span class="app-order-time">订单号：</span>{{item.OrderNo}}({{item.OrderId}})
                                </div>
                                <div flex="cross:center" class="app-order-user">
                                    <img v-if="item.OrderSource==1" src="../../assets/img/userman/wx.png" alt="">
                                    <span>{{item.UserName}}({{item.UserId}})</span>
                                </div>
                                <div flex="dir:left wrap:wrap" class="app-order-offline">
                                    <div v-if="item.DeliveryMethodName && item.DeliveryMethodName!=''" class="express-send-box">
                                        <span class="el-tag el-tag--small el-tag--light">{{item.DeliveryMethodName}}</span>
                                    </div>
                                    <el-tag v-if="item.PaymentTime==''" style="margin-left:5px" size="small" type="warning">未付款</el-tag>
                                    <el-tag v-else style="margin-left:5px" size="small" type="warning">已付款</el-tag>

                                    <el-tag v-if="item.DeliveryTime=='' && item.ReceivingTime==''" style="margin-left:5px" size="small" type="success">未发货</el-tag>
                                    <el-tag v-if="item.DeliveryTime!='' && item.ReceivingTime==''" style="margin-left:5px" size="small" type="success">待发货</el-tag>

                                    <el-tag v-if="item.ReceivingTime!=''" style="margin-left:5px" size="small" type="success">已收货</el-tag>

                                    <el-tag v-if="item.ReceivingTime!=''" style="margin-left:5px" size="small" type="success">已完成</el-tag>

                                    <el-tag v-if="item.OrderStatus==7" style="margin-left:5px" size="small" type="danger">已取消</el-tag>

                                </div>
                            </div>
                        </div>
                        <div class="app-order-body">
                            <div class="goods-item" style="width: 55%;">
                                <div v-for="(list,index2) in item.DetailList" :key="index2" class="goods">
                                    <!-- <img :src="getIconLink(list.CoverImagePath)" class="goods-image"> -->
                                    <el-image :src="getIconLink(list.CoverImagePath)" class="goods-image" :preview-src-list="[getIconLink(list.CoverImagePath)]"></el-image>

                                    <div flex="dir:left">
                                        <div class="goods-info">
                                            <div class="goods-name">
                                                <div class="app-ellipsis">
                                                    <div class="vue-line-clamp" style="word-break: break-all; -webkit-line-clamp: 2;">
                                                        <span class="el-tag el-tag--warning el-tag--mini el-tag--light is-hit" style="margin-right: 5px;">
                                                            {{list.OrderTypeName}}
                                                        </span>
                                                        {{list.GoodsName}}
                                                    </div>
                                                </div>
                                            </div>
                                            <div style="margin-bottom: 24px;">
                                                <span style="margin-right: 10px;">
                                                    规格：
                                                    <el-tag v-for="(item2,index2) in list.SpecificationList" :key="index2" style="top: 5px;position: relative;margin-right: 5px; max-width: 300px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" size="mini">
                                                        {{item2}}
                                                    </el-tag>
                                                </span>
                                            </div>
                                            <div class="app-order-goods-price">
                                                <span>货号：{{list.ProductCode}}</span>
                                            </div>
                                        </div>
                                        <div flex="dir:left box:mean" style="width: 250px;">
                                            <div flex="cross:center main:center">
                                                <span>小计：￥{{list.Final_Price}}
                                                </span>
                                            </div>
                                            <div flex="cross:center main:center">数量：x {{list.Number}}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div flex="cross:center" class="app-order-info" style="width: 15%;">
                                <div flex="dir:top">
                                    <div>
                                        <span style="font-size: 16px;">￥{{item.Income}}</span>
                                        <el-popover
                                            placement="bottom"
                                            title=""
                                            width="200"
                                            trigger="hover"
                                            >
                                            <div>商品小计：{{item.Income}}</div>
                                            <div v-if="item.CouponMoney>0">优惠金额：{{item.CouponMoney}}</div>
                                            <img slot="reference" src="../../assets/img/userman/price.png" alt="">
                                        </el-popover>
                                    </div>
                                    <div class="express-price"><span>
                                        <span style="color: rgb(144, 147, 153);">(含运费￥{{item.FreightMoney}})
                                        </span>
                                    </span></div>
                                    <div><el-tag effect="dark" type="warning" size="mini">{{item.PaymentWayName}}</el-tag></div>
                                  <div style="font-size: 12px;margin-top:3px;" v-if="item.CouponMoney&& item.CouponMoney!=''&& item.CouponMoney>0">
                                    <span>优惠金额:￥{{item.CouponMoney}}</span>
                                  </div>
                                  <div style="font-size: 12px;margin-top:3px;" v-if="item.DepositMoney&& item.DepositMoney!=''&& item.DepositMoney>0">
                                    <span>储蓄卡抵扣:￥{{item.DepositMoney}}</span>
                                  </div>
                                </div>
                            </div>
                            <div flex="main:center cross:center" class="app-box-info" style="width: 10%;border-right: 1px solid #EBEEF5;">
                                <div v-if="item.IsOrderCommission==1">已结算</div>
                                <div v-if="item.IsOrderCommission==2">待结算</div>
                            </div>
                            <div flex="main:center cross:center" class="app-order-info" style="border-right: 0px; width: 20%;">
                                <div style="margin:0 auto;width:90%;margin-left:17%">
                                    <template v-if="item.isShow">
                                        <div v-for="(list,index2) in item.OrderCommissionList" v-if="index2<3" :key="index2" style="margin: 10px;text-align:left">
                                            <div>
                                                <span>{{list.GradeDescription}}</span>
                                                <span class="price">￥{{list.Commission}}</span>
                                            </div>
                                            <div>昵称：{{list.UserName}}</div>
                                            <div v-if="list.Name!=''">姓名：{{list.Name}}</div>
                                            <div v-if="getPanduan(list.Mobile)">手机：{{list.Mobile}}</div>
                                        </div>
                                        <span v-if="item.OrderCommissionList.length>3" @click="showMoreDis(item)" class="distri_more">查看更多↓</span>
                                    </template>
                                    <template v-else>
                                        <div v-for="(list,index2) in item.OrderCommissionList" :key="index2" style="margin: 10px;text-align:left">
                                            <div>
                                                <span>{{list.GradeDescription}}</span>
                                                <span class="price">￥{{list.Commission}}</span>
                                            </div>
                                            <div>昵称：{{list.UserName}}</div>
                                            <div v-if="list.Name!=''">姓名：{{list.Name}}</div>
                                            <div v-if="getPanduan(list.Mobile)">手机：{{list.Mobile}}</div>
                                        </div>
                                        <span v-if="item.OrderCommissionList.length>3" @click="hideMoreDis(item)" class="distri_more">点击收起↑</span>
                                    </template>
                                </div>
                            </div>
                        </div>
                        <div class="card-footer">
                            <div>
                                <div flex="dir:left">
                                    <div class="address-box">收货人: {{item.Consignee}} 电话：{{item.Mobile}} 地址：{{item.ShoppingAddress}}</div>
                                </div>
                            </div>
                            <div v-if="item.ReRemark && item.ReRemark!=''" class="seller-remark">商家备注：{{item.ReRemark}}</div>
                        </div>
                    </el-card>
                    <el-card v-if="tableData.length==0" class="app-order-item" shadow="never">
                        <div style="height:100px;line-height:100px;text-align:center">
                            暂无订单信息
                        </div>
                    </el-card>
                </div>
                <el-pagination style="text-align:right"
                    background
                    @current-change="handleCurrentChange"
                    :page-size="msg.pageSize"
                    :current-page.sync="msg.pageIndex"
                    layout="prev, pager, next"
                    :total="total">
                </el-pagination>
            </div>
        </div>
        <!-- 选择导出信息 -->
        <el-dialog
            title="选择导出信息"
            :visible.sync="dialogVisible"
            width="960px">
            <el-form style="border: 1px solid #F0F2F7;" :model="addMsg" ref="addMsg" label-width="100px">
                <div style="box-sizing: border-box;background-color: #F3F5F6;width: 100%;padding-left: 20px;height: 50px;line-height: 50px;">
                    <el-checkbox v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
                </div>
                <div style="margin: 15px 0;"></div>
                <div style="padding: 10px 25px 20px;">
                    <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
                        <el-checkbox style="margin-bottom:10px;width:135px" v-for="city in cities" :label="city.Id" :key="city.Name">{{city.Name}}</el-checkbox>
                    </el-checkbox-group>
                </div>

            </el-form>
            <div style="text-align:right;margin-top:20px">
                <el-button size="small" v-if="commonNum==1" type="primary" @click="Export">导出</el-button>
                <el-button size="small" v-if="commonNum==2" type="primary" @click="ExportFX">导出</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: "orderList",
    data(){
        return{
            orderStatusList:[],
            checkAll: false,
            checkedCities: [],
            cities: [],
            cityOptions: [],
            addMsg:{},
            dialogVisible:false,

            activeName:'first',
            msgVal:'',
            dateList:[],
            msg:{
                pageIndex:1,
                pageSize:15,
                OrderSource:0,
                OrderType:0,
                DeliveryMethod:0,
                OrderId:0,
                StartTime:'',
                EndTime:'',
                OrderStatus:0,
                OrderNo:'',
                UserName:'',
                UserId:0,
                GoodsName:'',
                DistributionUserId:'',
            },
            platList:[],
            option:[
                {Id:1,name:'订单号'},
                {Id:2,name:'用户名'},
                {Id:3,name:'用户ID'},
                {Id:4,name:'商品名称'},
                {Id:5,name:'返佣用户id'}

            ],
            msgId:1,
            ExpressList:[],
            provinceList:[],
            cityList:[],
            areaList:[],
            tableData:[],
            total:0,
            deliveryList:[],
            orderTypeList:[],
            loading:false,
            checkfhList:[],
            moresendDig:false,
            moresendtips:'',
            hszDig:false,
            hszMsg:{},
            commonNum:0
        }
    },
    created(){
        if (this.$route.query.UserId) {//如果有UserId过来 查询显示用户id
            this.msg.UserId = this.$route.query.UserId;
            this.msgId = 3;
            this.msgVal =  this.msg.UserId
        }
        this.getList();
        this.getplat();
        // this.getDown();
        this.getOrderStatus();
        this.getDelivery();
        this.getOrderType();
    },
    mounted(){},
    methods:{
        ChangeId(val){
            let msgVal=this.msgVal;
            if(val==1){
                this.msg.OrderNo=msgVal;
                this.msg.UserName='';
                this.msg.UserId='';
                this.msg.GoodsName='';
                 this.msg.DistributionUserId = 0
            }
            if(val==2){
                this.msg.OrderNo='';
                this.msg.UserName=msgVal;
                this.msg.UserId='';
                this.msg.GoodsName='';
                 this.msg.DistributionUserId = 0
            }
            if(val==3){
                this.msg.OrderNo='';
                this.msg.UserName='';
                this.msg.UserId=msgVal;
                this.msg.GoodsName='';
                 this.msg.DistributionUserId = 0
            }
            if(val==4){
                this.msg.OrderNo='';
                this.msg.UserName='';
                this.msg.UserId='';
                this.msg.GoodsName=msgVal;
                 this.msg.DistributionUserId = 0
            }
               if(val==5){
                this.msg.OrderNo='';
                this.msg.UserName='';
                this.msg.UserId='';
                this.msg.GoodsName='';
                 this.msg.DistributionUserId = msgVal
            }
        },
        //点击批量导出或粉象导出
        getExport(num){
           this.dialogVisible=true;
           this.commonNum=num;
           if(num==1){
              this.getDown();
           }else{
              this.getFxList();
           }
        },
        Export(){
            this.msg.ExcelEnumIds=this.checkedCities;
            let msg = JSON.parse(JSON.stringify(this.msg));
            this.GetLocalFile(
            "/api/order/GetDistributionOrdersToExcel",
            msg,
            "分销订单列表.xls"
            );
        },
        getDown(){
            this.cityOptions=[];
            this.apipost("/api/order/GetDistributionOrdersExportEnumList",{}, res => {
                this.cities=res.data.data;
                let data=res.data.data;
                data.forEach(item=>{
                    this.cityOptions.push(item.Id)
                })

            })
        },
        //粉象弹窗数据
        getFxList(){
            this.cityOptions=[];
            this.apipost("/api/order/GetDistributionOrdersExportEnumListForFX",{}, res => {
                this.cities=res.data.data;
                let data=res.data.data;
                data.forEach(item=>{
                    this.cityOptions.push(item.Id)
                })

            })
        },
        //导出粉象
        ExportFX(){
            this.msg.ExcelEnumIds=this.checkedCities;
            let msg = JSON.parse(JSON.stringify(this.msg));
            this.GetLocalFile(
            "/api/order/GetDistributionOrdersToExcelForFX",
            msg,
            "分销订单列表.xls"
            );
        },
        //显示更多
        showMoreDis(item){
            item.isShow=false;
            this.$forceUpdate();
        },
        //点击收起
        hideMoreDis(item){
            item.isShow=true;
            this.$forceUpdate();
        },
        handleCheckAllChange(val) {
            this.checkedCities = val ? this.cityOptions : [];
        },
        handleCheckedCitiesChange(value) {
            let checkedCount = value.length;
            this.checkAll = checkedCount === this.cities.length;
        },
        handleClick(val){
            let dataId=val.$attrs.dataId;
            this.msg.OrderType=dataId;
            this.msg.pageIndex=1
            this.getList();
        },

        //判断字段是否全为空格
        getPanduan(val){
            if(val.trim().length === 0){
                return false;
            }else{
                return true;
            }
        },

        getList(){
            this.ChangeId(this.msgId);
            if(!this.msgVal || this.msgVal==''){
                this.msg.OrderNo='';
                this.msg.UserName='';
                this.msg.UserId=0;
                this.msg.GoodsName='';
                this.msg.DistributionUserId = 0
            }
            if(this.dateList && this.dateList.length>0){
                this.msg.StartTime=this.dateList[0];
                this.msg.EndTime=this.dateList[1];
            }else{
                this.msg.StartTime='';
                this.msg.EndTime='';
            }
            this.loading=true;
            this.apipost("/api/order/GetDistributionOrdersPageList", this.msg, res => {
                this.loading=false;
                if(res.data.resultCode==1){
                    this.total=res.data.data.count;
                    let pageData=res.data.data.pageData;
                    this.tableData=pageData;
                    if(this.tableData){
                        this.tableData.forEach(x=>{
                            x.isShow=true;
                        })
                    }
                }

            })
        },
        handleCurrentChange(val) {
            this.msg.pageIndex = val;
            this.getList();
        },
        getOrderStatus(){
            this.apipost("/api/order/GetOrderStatusEnumList",{}, res => {
                this.orderStatusList=res.data.data;
            })
        },
        getDelivery(){
            this.apipost("/api/order/GetOrderDeliveryMethodEnumList",{}, res => {
                this.deliveryList=res.data.data;
            })
        },
        getOrderType(){
            this.apipost("/api/order/GetOrderTypeEnumList",{}, res => {
                this.orderTypeList=res.data.data;
            })
        },

        getplat(){
            this.apipost("/api/user/GetMemberUserSourceEnumList",{}, res => {
                this.platList=res.data.data;
            })
        },

    },
};
</script>

<style>

.orderList .pendSelect .el-input {
    width: 100px;
}
.hszDigClass .el-dialog__body{
    padding: 0 10px 20px 0;
}
.sendDigClass .el-dialog__body{
    padding: 0 10px 10px 0;
}
.app-order-list .card-footer .seller-remark {
    margin-top: 10px;
    color: #E6A23C;
}
.app-send .el-table__header-wrapper th {
    background-color: #f5f7fa;
}
.app-send .title-box .text {
    background-color: #FEFAEF;
    color: #E6A23C;
    padding: 6px;
}
.app-send .title-box {
    margin: 15px 0;
}
.app-order-list .app-order-item .el-button {
    padding: 0;
}
.app-order-list .card-footer .address-box {
    margin-right: 10px;
}
.app-order-list .card-footer {
    background: #F3F5F6;
    padding: 10px 20px;
}
.app-order-list .app-order-info > div {
    width: 100%;
}
.app-order-icon {
    margin-right: 5%;
    margin-bottom: 10px;
    cursor: pointer;
}
.app-order-body {
    display: flex;
    flex-wrap: nowrap;
}
.app-order-list .app-order-info {
    display: flex;
    align-items: center;
    width: 15%;
    text-align: center;
    border-right: 1px solid #EBEEF5;
    justify-content: center;
}
.app-order-list .el-card__body {
    padding: 0;
}
.app-order-list .express-price {
    height: 30px;
    line-height: 30px;
}
.app-order-list .goods-item {
    border-right: 1px solid #EBEEF5;
}
.app-order-list .app-order-info {
    display: flex;
    align-items: center;
    width: 15%;
    text-align: center;
    border-right: 1px solid #EBEEF5;

}
.app-order-list .goods-item .goods .app-order-goods-price {
    height: 24px;
    margin-top: 10px;
    position: absolute;
    bottom: 20px;
    left: 125px;
}
.app-order-list .goods-item .goods-info .goods-name {
    margin-bottom: 5px;
    word-break: break-all;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}
.app-order-list .goods-item .goods-info {
    width: 50%;
    margin-top: 5px;
}
.app-order-list .goods-image {
    height: 90px;
    width: 90px;
    margin-right: 15px;
    float: left;
}
.app-order-list .goods-item .goods {
    position: relative;
    padding: 20px;
    min-height: 130px;
    border-top: 1px solid #EBEEF5;
}
.app-order-list .goods-item .goods:first-of-type {
    border-top: 0;
}
.orderList .app-order-list .app-order-item:hover .app-order-btnimg{
    display: block;
}
.orderList .app-order-list .app-order-item:hover{
    border: 1px solid #3399FF;
}
.orderList .app-order-btnimg {
    position: absolute;
    top: 20px;
    right:25px;
    color: #7C868D;
    font-size: 18px;
    padding: 0;
    display: none;
}
.orderList .app-order-offline {
    margin-left: 30px;
    margin-top: -2px;
}
.orderList .app-order-user img {
    height: 20px;
    width: 20px;
    display: block;
    float: left;
    border-radius: 50%;
    margin-right: 10px;
}
.orderList .app-order-list .app-order-time {
    color: #909399;
}
.orderList .app-order-user {
    margin-left: 30px;
}
.orderList  .app-order-list .app-order-time {
    color: #909399;
}
.orderList .app-order-list .app-order-item .el-card__header {
    padding: 0;
}
.orderList .app-order-list .app-order-item {
    margin-top: 20px;
    min-width: 750px;
}
.orderList .app-order-list .app-order-head {
    padding: 20px;
    background-color: #F3F5F6;
    color: #303133;
    min-width: 750px;
    display: flex;
    position: relative;
}
.orderList .app-order-title div {
    text-align: center;
}
.orderList .app-order-title {
    background-color: #F3F5F6;
    height: 40px;
    line-height: 40px;
    display: flex;
    min-width: 750px;
}
.orderList .content{
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    box-sizing: border-box;
}
.distri_more{
    color:#409EFF;
    margin-bottom:20px;
    cursor: pointer;
    display:block;
}
</style>
