<!--订单列表-->
<template>
  <div class="classorder">
    <div class="table-head">
      <table class="enrollTotalSearchTable" border="0" cellspacing="0" cellpadding="0">
        <colgroup>
          <col width="12%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />          
          <col width="100px"/>
        </colgroup>
        <thead>
          <tr class="fix_th">
            <th width="12%">单号</th>
            <th width="6.5%">客人</th>
            <th width="6.5%">人数</th>
            <th width="6.5%">起始城市</th>
            <th width="6.5%">应收</th>
            <th width="6.5%">实收</th>
            <th width="6.5%">退款</th>
            <th width="6.5%">成本</th>
            <th width="6.5%">手续费</th>
            <th width="6.5%">待收</th>
            <th width="6.5%">出票状态</th>
            <th width="6.5%">订单状态</th>
            <th width="100px">操作</th>
          </tr>
        </thead>
      </table>
    </div>
    <div class="table-body" v-loading="loading">
      <table class="enrollTotalSearchTable" border="0" cellspacing="0" cellpadding="0">
        <colgroup>
          <col width="12%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="6.5%" />
          <col width="100px"/>
        </colgroup>
        <template>
          <tbody v-for="(item, index) in dataList" :key="index">
            <tr>
              <td :rowspan="3">
               <p class="OrderId-text">{{item.OrderId}}</p>
               <p class="CreateByName-text">{{item.CreateByName}}</p>
               <p class="CreateByName-text">业务员：<span class="colorblue">{{item.EnterName}}</span></p>
               <p>{{item.CreateTime}}</p>
              </td>
              <td style="border:none" min-width="6.5%">{{item.GuestName}}
                  <p>{{item.MobilePhone}}</p>
              </td>
              <td style="border:none">{{item.GuestCount}}人</td>
              <td style="border:none">
                  {{item.StartCityName}}->
                  {{item.EndCityName}}
              </td>
              <td style="border:none">
                  <p @click="editOrderAmount(item)" class="cp"
              :class="item.TicketStatus==1&&item.OrderStatus==1?'font-color-link':''">{{item.Money}}</p>
              </td>
              <td style="border:none">
                  {{item.IncomeMoney}}
              </td>
              <td style="border:none">
                  {{item.BackMoney}}
              </td>
              <td style="border:none">
                  {{item.BackMoney}}
              </td>
              <td style="border:none">
                  {{item.PayMoney}}
              </td>
              <td style="border:none">
                  {{item.DueinMoney}}
              </td>
              <td style="border:none">
                  <p  @click="modifyStatus(item)" 
                class="cp tatusText"
                :class="item.TicketStatus==1?'grey':
                (item.TicketStatus==2?'success':
                (item.TicketStatus==3?'error':
                (item.TicketStatus==4?'Black':'')))">
                    {{item.TicketStatusName}}
                </p>
              </td>
              <td style="border:none">
                  <div style="background: rgba(2, 196, 153, 0.2);width: 80px;border-radius: 2px;text-align: center"
                  :style="{background:item.OrderStatus==1?'rgba(2, 196, 153, 0.2)':'rgba(0, 0, 0, 0.2)'}">
                    <span :style="{color: item.OrderStatus==1?'#02C499':''}">{{item.OrderStatus==1?"正常":"取消"}}</span>
                </div>
              </td>
              <td style="border:none;width:150px">
                  <div class="enedit-box">
                    <el-tooltip
                    class="item-but" effect="dark" content="编辑订单" placement="top">
                        <i class="iconfont iconwenbenbianji cp" @click="editOrder(item)"></i>
                    </el-tooltip>
                    <div>
                        <el-select style="width:80px;"  class="select-right" 
                        clearable
                        size="mini" 
                        v-model="item.More" placeholder="更多"
                        @change="chooseMore(item)">
                            <el-option
                            v-for="item in MoreList"
                            :key="item.Id"
                            :label="item.Name"
                            :value="item.Id">
                            </el-option>
                        </el-select>
                    </div>
                    
                </div>
              </td>
            </tr>
            <tr>
              <td :colspan="8" style="height: 108px;text-align: left">
                <div>备注：</div>
                <div class="remarks-b">
                    <div v-if="item.Remark != null || item.Remark != ''">
                        <div>{{ item.Remark }}</div>
                    </div>
                    <span v-if="item.Remark == null || item.Remark == ''">暂无</span>
                </div>
              </td>
              <td :colspan="4" style="height: 108px;text-align: left">
                <div class="documents-text">
                    <div class="documents-left">
                        <div>收入单据：</div>
                        <span 
                        v-for="(item,index) in item.IncomeFinance" :key="index" >{{item.FrID}}</span>
                    </div>
                    <div class="documents-right">
                        <el-tooltip
                        class="item-but" effect="dark" content="制单" placement="top">
                            <i class="iconfont iconwenbenbianji cp blue" @click="makeAdocument(item)"></i>
                        </el-tooltip>
                    </div>
                </div>
                <div class="documents-text">
                    <div class="documents-left">
                        <div>退款单据：</div>
                        <span 
                        v-for="(item,index) in item.BackFinance" :key="index" >{{item.FrID}}</span>
                    </div>
                    <div class="documents-right">
                        <el-tooltip
                        class="item-but" effect="dark" content="制单" placement="top">
                            <i class="iconfont iconwenbenbianji cp blue" @click="makeAdocument(item)"></i>
                        </el-tooltip>
                    </div>
                </div>
                <div class="documents-text">
                    <div class="documents-left">
                        <div>成本单据：</div>
                        <span 
                        v-for="(item,index) in item.PayFinance" :key="index">{{item.FrID}}</span>
                    </div>
                    <div class="documents-right">
                        <el-tooltip
                        class="item-but" effect="dark" content="制单" placement="top">
                            <i class="iconfont iconwenbenbianji cp blue" @click="makeAdocument(item)"></i>
                        </el-tooltip>
                    </div>
                </div>
              </td>
              <!-- <td :colspan="3" style="height: 168px;text-align: left">
                <div class="documents-text num">
                    <div>实收：</div>
                    <el-tooltip class="item" effect="dark" content="实收制单" placement="top-start">
                        <span @click="makeAdocument(item,1)">{{item.IncomeMoney}}</span>
                    </el-tooltip>
                    
                </div>
                <div class="documents-text num">
                    <div>退款：</div>
                    <el-tooltip class="item" effect="dark" content="退款制单" placement="top-start">
                        <span @click="makeAdocument(item,2)">{{item.BackMoney}}</span>
                    </el-tooltip>
                </div>
                <div class="documents-text num">
                    <div>成本：</div>
                    <el-tooltip class="item" effect="dark" content="成本制单" placement="top-start">
                        <span @click="makeAdocument(item,3)">{{item.PayMoney}}</span>
                    </el-tooltip>
                </div>
              </td> -->
            </tr>
          </tbody>
        </template>
        <!--取消订单-->
      </table>
    </div>

  </div>
</template>

<script>
  export default {
    components: {
      
    },
    props: {
      //订单
      dataList: {
        type: Array,
        default: null
      },
      loading: {
        type: Boolean,
        default: false,
      }
    },
    data() {
      return {
        userInfo:{},
        MoreList:[
            {Name:'取消订单',Id:'1'},
            {Name:'订单转交',Id:'2'},
            {Name:'修改出票状态',Id:'4'},
            {Name:'操作日志',Id:'3'},
        ],
        clickMore:''
      };
    },
    created() {
      
    },
    watch: {
      loading:{
        handler(val, oldVal){
            this.loading = val
        },
        deep:true
      }
    },
    mounted() {
        this.userInfo = this.getLocalStorage();
    },
    methods: {
      chooseMore(row){
        //   取消订单
          if(row.More=='1'){
              this.cancelOrder(row)
          }
        //   订单转换
          if(row.More=='2'){
              this.convertOrder(row)
          }
        //   操作日志
          if(row.More=='3'){
              this.operationLog(row)
          }
        //   修改出票状态
          if(row.More=='4'){
              this.modifyStatus(row)
          }
        //   编辑订单金额
          if(row.More=='5'){
              this.editOrderAmount(row)
          }
      },
      // 转换订单  
      convertOrder(row){
        this.MsgBus.$emit("convertOrderTicketOrderBoxOpen", row.GuestId, row, true);
      },
      // 验证操作员
        ValidateOperator(){
            let tips = '您没有操作权限'
            this.$confirm('此订单'+tips+'!', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$emit('emptyMore')
            }).catch(() => {
                this.$emit('emptyMore')           
            });
            

        },
        // 制作单据
        makeAdocument(row,num){
            if(this.userInfo.EmName!=row.EnterName){
                this.ValidateOperator()
            }else{
                let type
                type = num==1? 1:2 // 1收款 2退款 3成本
                let href
                let url
                if(this.isOnline()){
                url = 'http://yx.oytour.com/#/'
                }else{
                url = 'http://www.test.com:8080/#/'
                }
                let data = [
                    {   
                    path:'ChoiceAddFinancialDocuments',
                    type: type,
                    OtherType: 55,
                    ReFinanceId: row.OrderId,
                    ReFinanceId2: num,
                    GuestId: row.GuestId
                    }
                ]
                href = url+'automaticLogin?token='+this.getLocalStorage().token+'&data=' + JSON.stringify(data)
                window.open(href);
            }
        },
        // 操作日志
        operationLog(row){
            this.MsgBus.$emit("logTicketOrderBoxOpen", row.GuestId, row, true);
        },
        // 修改出票状态
        modifyStatus(row){
        if(this.userInfo.EmName!=row.EnterName){
            this.ValidateOperator()
        }else{
            if(row.OrderStatus==2){
                let tips = '该订单已取消，不能修改出票状态'
                this.$confirm(tips, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$emit('emptyMore')
                }).catch(() => {
                    this.$emit('emptyMore')         
                });
            }else{
            if(row.TicketStatus==3){
                return
            }else if(row.TicketStatus==4){
                return
            }else{
                this.MsgBus.$emit("reviseTicketOrderBoxOpen", row.GuestId, row, true);
            }
            }
        }
        
        
        },
        // 取消订单
        cancelOrder(row){
        if(this.userInfo.EmName!=row.EnterName){
            this.ValidateOperator()
        }else{
            let tips = '此操作将取消该订单，是否继续取消?'
            this.$confirm(tips, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.apipost('/api/Order/SetGuestOrderState', {
                    OrderId: row.OrderId,
                    Type: '1',
                }, res=>{
                    if (res.data.resultCode == 1) {
                        this.$message.success(res.data.message);
                        this.getList()
                    }
                })
            }).catch(() => {
                this.$emit('emptyMore')
                this.$message({
                    type: 'info',
                    message: '已取消'
                });          
            });
        }
        
        },
        // 编辑订单
        editOrder(row){
            if(this.userInfo.EmName!=row.EnterName){
                this.ValidateOperator()
            }else{
                if(row.TicketStatus==1&&row.OrderStatus==1){
                    this.MsgBus.$emit("editOrderTicketOrderBoxOpen", row.GuestId, row, true);
                }else{
                let tips = ''
                if(row.TicketStatus==2&&row.OrderStatus==1){
                    tips = '已出票'
                }
                if(row.TicketStatus==3&&row.OrderStatus==1){
                    tips = '航班熔断'
                }
                if(row.TicketStatus==4&&row.OrderStatus==1){
                    tips = '用户取消航班'
                }
                if(row.OrderStatus==2){
                    tips = '已取消'
                }
                this.$confirm('此订单'+tips+'，无法编辑订单金额?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$emit('emptyMore')
                }).catch(() => {
                    this.$emit('emptyMore')         
                });
            }
        }
        },
        // 编辑订单金额
        editOrderAmount(row){
        if(this.userInfo.EmName!=row.EnterName){
            this.ValidateOperator()
        }else{
            if(row.TicketStatus==1&&row.OrderStatus==1){
                this.MsgBus.$emit("editTicketOrderBoxOpen", row.GuestId, row, true);
            }else{
                let tips = ''
                if(row.TicketStatus==2&&row.OrderStatus==1){
                    tips = '已出票'
                }
                if(row.TicketStatus==3&&row.OrderStatus==1){
                    tips = '航班熔断'
                }
                if(row.TicketStatus==4&&row.OrderStatus==1){
                    tips = '用户取消航班'
                }
                if(row.OrderStatus==2){
                    tips = '已取消'
                }
                this.$confirm('此订单'+tips+'，无法编辑订单金额?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$emit('emptyMore')
                }).catch(() => {
                    this.$emit('emptyMore')          
                });
            }
        }
        
        
        },
        openDetails(item) {
            console.log(item.ID);
            this.MsgBus.$emit("busnessDrawerShow", item.ID, 1);
        },
        // 获取出票状态枚举
        GetTicketStatusEnumList(){
        this.msg.GuestId = row.GuestId
        this.apipost(
            "/api/Order/GetTicketStatusEnumList",
            {},
            (res) => {
            if (res.data.resultCode == 1) {
                this.ticketingStatusList = res.data.data;
                let data = {
                Name:'全部',
                Id:'0'
                }
                this.ticketingStatusList.unshift(data)
            } else {
                this.$message.error(res.data.message);
            }
            }
        );
        },
    }
  };
</script>
<style>
  li {
    list-style-type: none;
  }

  .classorder ul {
    padding: 0px;
  }

  .classorder .price-popup {
    border-radius: 4px;
  }

  .classorder .el-range-editor .el-range-input {
    background: none;
  }

  .classorder .el-range-editor.el-input__inner {
    background-color: transparent;
  }

  .classorder .q-mb-md {
    margin-bottom: 0;
  }

  .classorder .stics {
    padding: 10px 20px;
    background: #dddee0;
    border-radius: 4px;
    font-size: 14px;
    color: #000000;
    font-weight: bold;
  }

  .classorder .stics .stics-name {
    color: #2d2d2d;
    font-weight: 600;
    margin-right: 10px;
  }

  .classorder .tis {
    margin: 10px 0;
    align-items: center;
  }

  .classorder .tis .tis-k {
    width: 10px;
    height: 10px;
    margin-right: 8px;
  }

  .classorder .tis span {
    font-size: 14px;
    color: #2d2d2d;
    font-weight: 600;
    margin-right: 20px;
  }

  .classorder table {
    padding: 10px 0;
    width: 100%;
    background-color: #ededed;
    border-collapse: collapse;
    border: 1px solid #d2d2d2;
    font-size: 12px;
  }

  .classorder table th {
    background-color: #ededed;
    height: 34px;
    text-indent: 15px;
  }

  .classorder table td {
    background-color: #ffffff;
    padding: 9px 15px;
    color: #333333;
    border: 1px solid rgba(138, 138, 138, 0.09);
    text-align: left;
  }

  .classorder table ._color_666 {
    color: #666666;
  }

  .classorder table tr._color_666 th {
    padding: 9px 15px;
  }

  .classorder table th {
    background-color: #ededed;
    height: 34px;
    text-indent: 15px;
  }

  .classorder table td {
    background-color: #ffffff;
    padding: 9px 15px;
    color: #333333;
  }

  .classorder table ._color_666 {
    color: #666666;
  }

  .classorder table tr._color_666 th {
    padding: 9px 15px;
  }

  .classorder .enrollTotalSearchTable {
    width: 100%;
    font-size: 14px;
    color: #333;
    border-bottom: 1px solid #cccccc;
    border-right: 1px solid #cccccc;
    border-collapse: collapse;
  }

  .classorder .enrollTotalSearchTable tr {}

  .classorder .enrollTotalSearchTable tr th {
    background: #dddee0;
    height: 30px;
    font-size: 12px;
    text-align: left;
  }

  .classorder .enrollTotalSearchTable tr {
    background: #fff;
    text-align: left;
  }

  .classorder .enrollTotalSearchTable tbody tr:last-child {
    border-bottom: 2px solid #ddd;
  }

  .classorder .enrollTotalSearchTable tr:first-child td:first-child {
    border-bottom: 2px solid #ddd;
  }

  .classorder .enrollTotalSearchTable tr td {
    height: 66px;
    padding: 10px;
  }

  .classorder .enrollTotalSearchTable tr td>img {
    width: 32px;
    height: 32px;
    border-radius: 16px;
    vertical-align: middle;
    margin-right: 5px;
  }

  .classorder .enrollTotalSearchTable tr td p {
    line-height: 20px;
  }

  .classorder .remarks {
    font-size: 14px;
    color: #2d2d2d;
  }

  .classorder .remarks-b {
    height: 34px;
    background: #f0f5fb;
    margin-top: 10px;
    padding: 15px;
    font-size: 12px;
    color: #999999;
    position: relative;
    overflow: hidden;
    display: -webkit-box;
    line-height: 20px;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
  }

  .classorder .remarks-b-b {
    text-align: right;
    position: absolute;
    right: 0px;
    bottom: 0px;
  }

  .classorder .on-left {
    margin-right: 5px;
  }

  .classorder .finance {
    padding: 1px 10px;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    margin: 5px 3px 3px 0;
  }

  .classorder .order_OfferId {
    font-size: 18px;
    color: #2961fe;
    margin-bottom: 10px;
    font-weight: bold;
    text-decoration: underline;
    cursor: pointer;
  }

  .takeContract {
    cursor: pointer;
    color: rgb(41, 97, 254);
  }

  .Contract_Table {
    width: 100%;
    border-collapse: collapse;
  }

  .Contract_Table th,
  .Contract_Table td {
    padding: 5px;
    color: #000;
    text-align: center;
  }

  .table-body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .classorder .redstyle {
    color: var(--q-color-negative);
  }

  .order_OferTitle {
    font-size: 14px;
    color: #333333;
    margin-bottom: 10px;
  }
  .tatusText.grey{
  color: grey;
}
.tatusText.success{
  color: #21BA45;
}
.tatusText.error{
  color: #F2C037;
}
.tatusText.Black{
  color: Black;
}
.ToBeReceived.red{
  color: #fd397a;
}
.ToBeReceived.blue{
  color: #409eff;
}
.documents-text{
    display: flex;
    justify-content: space-between;
}
.documents-left{
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    margin: 5px 0;
}
.documents-left span{
    margin-right: 10px;
    background-color: rgba(41, 97, 254, 0.2);
    color: rgb(41, 97, 254);
    border-radius: 3px;
    padding:2px 6px;
}
.documents-left.num span{
    background-color: rgba(41, 97, 254, 0);
    color: rgb(41, 97, 254);
    padding: 0;
}
.documents-right {
  margin-right: 20px;
}
.OrderId-text{
    font-weight: bold;
    color: #2961fe;
    margin-bottom: 10px;
}
.CreateByName-text{
    margin-bottom: 10px;
}
.colorblue{
    color: #2961fe;
}
.enedit-box{
    display: flex;
    align-items: center;
}
.select-right{
    margin-left: 5px;
}
</style>