<!--订单列表-->
<template>
  <div class="classorder classorder-bottom">
    <div class="table-head">
      <table class="enrollTotalSearchTable" border="0" cellspacing="0" cellpadding="0">
        <colgroup>
          <col width="12%" />
          <col width="8.5%" />
          <col width="6.5%" />
          <col width="8.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="8.5%">客人</th>
            <th width="6.5%">人数</th>
            <th width="8.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="8.5%" />
          <col width="6.5%" />
          <col width="8.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%">
                  <p class="colorblue font-color-link" 
                  @click="openNameDetails(item)">{{item.GuestName}}</p>
                  <p>{{item.MobilePhone}}</p>
              </td>
              <td style="border:none">{{item.GuestCount}}人</td>
              <td style="border:none">
                  {{item.StartCityName}}
              </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.PayMoney}}
              </td>
              <td style="border:none">
                  {{item.TaxMoney}}
              </td>
              <td style="border:none">
                  {{item.DueinMoney}}
              </td>
              <td style="border:none">
                <p class="TicketVoucher-box">
                    <span  @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}}
                  </span>
                  <i v-if="item.TicketStatus!=1&&item.TicketVoucherList!=[]&&item.CancelVoucherList!=[]" class="iconfont iconpingzhengchaxun Credentials" @click="viewCredentials(item)"></i>
                </p>
                
              </td>
              <td style="border:none">
                  <div style="background: rgba(2, 196, 153, 0.2);width: 70px;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
                        :class="item.Status===1&&item.Is_Cashier===0?'one':(item.Status===1&&item.Is_Cashier===1?'two':(item.Status===2?'three':''))"
                        v-for="(item,index) in item.IncomeFinance" :key="index"
                        @click="openDetails(item)">{{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,1)"></i>
                        </el-tooltip>
                    </div> 
                </div>
                <div class="documents-text">
                    <div class="documents-left">
                        <div>退款单据：</div>
                        <span
                        :class="item.Status===1&&item.Is_Cashier===0?'one':(item.Status===1&&item.Is_Cashier===1?'two':(item.Status===2&&item.Is_Cashier===1?'three':''))"
                        v-for="(item,index) in item.BackFinance" :key="index"
                        @click="openDetails(item)">{{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,2)"></i>
                        </el-tooltip>
                    </div>
                </div>
                <div class="documents-text">
                    <div class="documents-left">
                        <div>成本单据：</div>
                        <span
                        :class="item.Status==1&&item.Is_Cashier==0?'one':(item.Status==1&&item.Is_Cashier==1?'two':(item.Status==2?'three':''))"
                        v-for="(item,index) in item.PayFinance" :key="index"
                        @click="openDetails(item)">{{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,3)"></i>
                        </el-tooltip>
                    </div>
                </div>
              </td>
            </tr>
          </tbody>
        </template>
<!--取消订单-->
</table>
</div>
<el-drawer :with-header="false" size='70%' :visible.sync="drawer" direction="rtl" :before-close="handleClose">
    <customerInfoBox :CustomerId="CustomerId" />
</el-drawer>

</div>
</template>

<script>
    import customerInfoBox from "../guestManagement/customerInfoBox";
    export default {
        components: {
            customerInfoBox
        },
        props: {
            //订单
            dataList: {
                type: Array,
                default: null
            },
            loading: {
                type: Boolean,
                default: false,
            },
            superManage: {
                type: String,
                default: ""
            }
        },
        data() {
            return {
                userInfo: {},
                MoreList: [{
                    Name: '取消订单',
                    Id: '1'
                }, {
                    Name: '订单转交',
                    Id: '2'
                }, {
                    Name: '修改出票状态',
                    Id: '4'
                }, {
                    Name: '操作日志',
                    Id: '3'
                }, ],
                clickMore: '',
                drawer: false,
                CustomerId: '',
                CustomerName: ''
            };
        },
        created() {

        },
        watch: {
            loading: {
                handler(val, oldVal) {
                    this.loading = val
                },
                deep: true
            }
        },
        mounted() {
            this.userInfo = this.getLocalStorage();
        },
        methods: {
            handleClose(done) {
                done();
            },
            openNameDetails(item) {
                this.drawer = true;
                this.CustomerId = item.GuestId;
                this.CustomerName = item.GuestName;
            },
            // 查看出票凭据
            viewCredentials(row) {
                let $this = this;
                this.MsgBus.$emit("CredentialsOrderTicketOrderBoxOpen", $this.ID, row, true);
            },
            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() {
                this.$message({
                    type: 'warning',
                    message: '抱歉,该订单您没有操作权限!'
                });
                this.$emit('emptyMore')
            },
            // 制作单据
            makeAdocument(row, num) {
                if (this.superManage) {
                    this.makeAdocumentfun(row, num)
                } else {
                    if (this.userInfo.EmName != row.EnterName) {
                        this.ValidateOperator()
                    } else {
                        this.makeAdocumentfun(row, num)
                    }
                }

            },
            makeAdocumentfun(row, num) {
                if (row.OrderStatus != '2') {
                    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.superManage) {
                    this.ModifyStatusfun(row)
                } else {
                    if (this.userInfo.EmName != row.EnterName) {
                        this.ValidateOperator()
                    } else {
                        this.ModifyStatusfun(row)
                    }
                }
            },
            ModifyStatusfun(row) {
                if (row.TicketStatus == 3 || row.TicketStatus == 4 || row.OrderStatus == '2') {
                    return
                } else {
                    this.MsgBus.$emit("reviseTicketOrderBoxOpen", row.GuestId, row, true);
                }
            },
            // 取消订单
            cancelOrder(row) {
                if (this.superManage) {
                    this.cancelOrderfun(row)
                } else {
                    if (this.userInfo.EmName != row.EnterName) {
                        this.ValidateOperator()
                    } else {
                        this.cancelOrderfun(row)
                    }
                }
            },
            cancelOrderfun(row) {
                if (row.OrderStatus != '2' && row.IncomeFinance == [] && row.BackFinance == [] && row.PayFinance == []) {
                    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: '已取消'
                        });
                    });
                } else {
                    this.$emit('emptyMore')
                }
            },
            // 编辑订单
            editOrder(row) {
                if (this.superManage) {
                    this.editOrderfun(row)
                } else {
                    if (this.userInfo.EmName != row.EnterName) {
                        this.ValidateOperator()
                    } else {
                        this.editOrderfun(row)
                    }
                }
            },
            editOrderfun(row) {
                if (row.TicketStatus == 1 && row.OrderStatus == 1) {
                    this.MsgBus.$emit("editOrderTicketOrderBoxOpen", row.GuestId, row, true);
                } else {
                    this.$emit('emptyMore')
                }
            },
            // 编辑订单金额
            editOrderAmount(row) {
                if (this.superManage) {
                    this.editOrderAmountfun(row)
                } else {
                    if (this.userInfo.EmName != row.EnterName) {
                        this.ValidateOperator()
                    } else {
                        this.editOrderAmountfun(row)
                    }
                }
            },
            editOrderAmountfun(row) {
                if (row.TicketStatus == 1 && row.OrderStatus == 1) {
                    this.MsgBus.$emit("editTicketOrderBoxOpen", row.GuestId, row, true);
                } else {
                    this.$emit('emptyMore')
                }
            },
            openDetails(item) {
                let href
                let url
                if (this.isOnline()) {
                    url = 'http://yx.oytour.com/#/'
                } else {
                    url = 'http://www.test.com:8080/#/'
                }
                let data = [{
                    path: 'FinancialDocumentsDetail',
                    id: item.FrID
                }]
                href = url + 'automaticLogin?token=' + this.getLocalStorage().token + '&data=' + JSON.stringify(data)
                window.open(href);
            },
            // 获取出票状态枚举
            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;
    }
    
    .enrollTotalSearchTable 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: 46px;
        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: 2px 0;
    }
    
    .documents-left span {
        margin-right: 10px;
        border-radius: 3px;
        padding: 2px 6px;
    }
    
    .documents-left span:hover {
        cursor: pointer;
    }
    
    .documents-left span.one {
        background-color: rgba(41, 97, 254, 0.2);
        color: rgb(41, 97, 254);
    }
    
    .documents-left span.two {
        background-color: rgba(242, 140, 29, 0.2);
        color: rgb(242, 140, 29);
    }
    
    .documents-left span.three {
        background-color: rgba(63, 196, 255, 0.2);
        color: rgb(63, 196, 255);
    }
    
    .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-size: 19px;
        /* text-decoration:underline; */
        font-weight: bold;
        color: #2961fe;
        margin-bottom: 10px;
    }
    
    .CreateByName-text {
        margin-bottom: 10px;
    }
    
    .colorblue {
        color: #2961fe;
    }
    
    .colorblue:hover {
        cursor: pointer;
    }
    
    .enedit-box {
        display: flex;
        align-items: center;
    }
    
    .select-right {
        margin-left: 5px;
    }
    
    .Credentials {
        color: #2961FE;
    }
    
    .TicketVoucher-box {
        display: flex;
    }
    
    .TicketVoucher-box span {
        flex-shrink: 0;
    }
    
    .TicketVoucher-box i {
        margin-left: 5px;
    }
</style>