<template>
    <!-- 广告服务 -->
    <div>
        <!-- 广告页面头部 -->
        <HomePageHead></HomePageHead>
        <HomePageNavigation1></HomePageNavigation1>

        <div class="adDetail">
            <div class="inner">
                <!-- 标题 -->
                <h3>广告基本信息</h3>
                <!-- 工单头部 -->
                <div class="order">
                    <div class="title">
                        <span class="statusGreen left" v-if="order.status == 1">{{ orderstate[order.status] }}</span>
                        <span class="statusOrange left" v-else-if="order.status == 6">{{ orderstate[order.status]
                            }}</span>
                        <span class="statusGray left" v-else>{{ orderstate[order.status] }}</span>
                        <span class="code left">
                            工单编号:
                            <span>{{ order.order_num }}</span>
                        </span>
                        <span class="createTime right">{{ order.created_at }}</span>
                    </div>
                    <!-- 工单内容 -->
                    <div class="text">
                        <span>开始时间:{{ order.sttime }}</span>
                        <span>结束时间:{{ order.edtime }}</span>
                        <span>
                            <!-- <span class="money">{{ order.price ? order.price : 260 }}</span> -->
                            <span class="money">{{ order.price }}</span>
                            元
                        </span>
                        <!-- <NuxtLink :to="`/advertising?activeName=${'1'}&ad=${1}`">
                            <button>再次申请</button>
                        </NuxtLink> -->
                        <button @click="goReapply">再次申请</button>
                    </div>
                </div>

                <div class="detail">
                    <el-table :data="orderDetail" style="width: 100%">
                        <el-table-column prop="" label="图片信息" align="center">
                            <template #default="scope">
                                <div class="content">
                                    <img :src="scope.row.image_src" alt="" class="left">
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="" label="">
                            <template #default="scope">
                                <div class="content">
                                    <h5>{{ scope.row.apname }}</h5>
                                    <p>{{ scope.row.adname }}</p>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="website_name" label="网站" width="200px" align="center" />
                        <el-table-column prop="days" label="天数" width="200px" align="center">
                            <template #default="scope">
                                {{ order.days }}
                                <!-- {{ orderstate[scope.row.status] }} -->
                            </template>
                        </el-table-column>
                        <el-table-column prop="" label="审核状态" width="200px" align="center">
                            <template #default="scope">
                                {{ orderstate[order.status] }}
                                <!-- {{ orderstate[scope.row.status] }} -->
                            </template>
                        </el-table-column>
                        <el-table-column label="广告状态" width="200px" align="center">
                            <template #default="scope">
                                {{ order_adstate[order.ad_status] }}
                            </template>
                        </el-table-column>
                    </el-table>
                </div>

                <div class="pagination">
                    <HomePagination></HomePagination>
                </div>
            </div>

        </div>
        <!-- 广告页面底部 -->
        <HomeFoot1></HomeFoot1>
    </div>
</template>

<script setup>
import { onMounted } from 'vue';
import { ElTable, ElTableColumn } from 'element-plus'
import { useStatusStore } from "@/store/status.js"

const statusStore = useStatusStore()
const { $webUrl, $CwebUrl, $BwebUrl } = useNuxtApp()

// axios请求
const nuxtApp = useNuxtApp();
const axios = nuxtApp.$axios;

//工单列表页面跳转传递到的参数
let route = useRoute()
let order_id = route.query.id
let days = route.query.days
let state = route.query.status
let ad_status = route.query.status
console.log(order_id);

let pageSize = useState("pageSize", () => 10)
let page = useState("page", () => 1)
let orderstate = useState("orderstate", () => 1) //审核状态
let order_adstate = useState("order_adstate", () => 1) //广告状态


let order = useState("order", () => "")
let orderDetail = useState("orderDetail", () => "")
let newArr = useState("newArr", () => "")

// 定义响应式数据
const seoData = ref({
    title: '广告服务',
    description: '默认描述',
    keywords: '默认关键词',
    image: 'https://example.com/default-image.jpg'
});

// 在 onMounted 钩子中获取数据
onMounted(()=>{
    seoData.value.title = '广告服务';
    seoData.value.description = '默认描述';
    seoData.value.keywords = '默认关键词';
})

//获取订单状态
const getOrderstatus = async () => {
    try {
        const response = await axios.get(`/order/getStatus`);
        console.log(response);
        orderstate.value = response.data.order
        order_adstate.value = response.data.order_ad

    } catch (error) {
        console.error(error);
    }
}

// 获取订单详情
const getOrderDetail = async () => {
    try {
        const response = await axios.get(`/order/getOrderDetail?order_id=${order_id}&pageSize=${pageSize.value}&page=${page.value}`);
        console.log("response", response.data);
        order.value = response.data.order
        orderDetail.value = response.data.orderads

        // 将state和days添加到orderDetail里面
        newArr.value = orderDetail.value.map((item) => {
            item.state = statusStore.orderStatus[state]  //审核状态
            // item.state = state  //审核状态
            // item.ad_status =ad_status //广告状态
            item.ad_status = statusStore.adStatus[ad_status]  //广告状态
            item.days = days + '天' // 过期时间
            return item
        })

    } catch (error) {
        console.error(error);
    }
}

let goReapply = () => {
    // ad.value = 1
    // window.location.href = (`http://localhost:3000/advertising?activeName=${'1'}`)
    let url = $CwebUrl + '/advertising?activeName=1';
    window.location.href = url;
}

onMounted(() => {

    // 获取订单详情
    getOrderDetail()
    //获取订单状态
    getOrderstatus()
})





</script>

<style lang="less" scoped>
.adDetail {
    width: 100%;
    overflow: hidden;

    .inner {
        width: 1200px;
        overflow: hidden;

        h3 {
            font-family: Microsoft YaHei, Microsoft YaHei;
            font-weight: 400;
            font-size: 20px;
            color: #333333;
            margin: 40px 0;
        }

        .order {
            width: 1198px;
            height: 160px;
            border: 1px solid #e1e1e1;

            .title {
                height: 60px;
                line-height: 30px;
                border-bottom: 1px solid #e1e1e1;
                padding: 15px 24px 15px 50px;
                box-sizing: border-box;
                background-color: #fafafa;

                >span {
                    display: inline-block;
                    text-align: center;
                    font-family: Microsoft YaHei, Microsoft YaHei;
                }

                .statusGreen {
                    width: 70px;
                    height: 32px;
                    line-height: 32px;
                    margin-right: 50px;
                    background: #d5ecd2;
                    color: #33B023;
                    font-weight: 400;
                    font-size: 16px;
                }

                .statusOrange {
                    width: 70px;
                    height: 32px;
                    line-height: 32px;
                    margin-right: 50px;
                    background: #fbebd5;
                    color: #FFAA33;
                    font-weight: 400;
                    font-size: 16px;
                }

                .statusGray {
                    width: 70px;
                    height: 32px;
                    line-height: 32px;
                    margin-right: 50px;
                    background: #e8e8e8;
                    color: #999999;
                    font-weight: 400;
                    font-size: 16px;
                }

                .code {
                    font-weight: 400;
                    font-size: 16px;
                    color: #333333;
                }

                .createTime {
                    font-weight: bold;
                    font-size: 16px;
                    color: #333333;
                }
            }

            .text {
                padding: 33px 70px 33px 50px;
                position: relative;

                span {
                    font-weight: 400;
                    font-size: 16px;
                    color: #333333;

                    .money {
                        font-weight: bold;
                        font-size: 24px;
                        color: #028E21;
                        padding-right: 10px;
                    }
                }

                >span:first-child {
                    padding-right: 80px;
                }

                >span:nth-child(2) {
                    padding-right: 200px;
                }

                >span:nth-child(3) {
                    padding-right: 183px;
                }

                button {
                    width: 82px;
                    height: 34px;
                    font-size: 13px;
                    background: #33B023;
                    color: #fff;
                    border: none;
                    border-radius: 4px;
                    position: absolute;
                    right: 70px;
                    top: 32px;
                }
            }

        }

        .detail {
            width: 1198px;
            overflow: hidden;
            border-right: 1px solid #e1e1e1;
            border-left: 1px solid #e1e1e1;

            /deep/.el-table .cell {
                box-sizing: border-box;
                line-height: 23px;
                overflow: hidden;
                overflow-wrap: break-word;
                padding: 12px 12px;
                text-overflow: ellipsis;
                white-space: normal;
                font-size: 16px;
                font-weight: 400;
            }

            /deep/.el-table__header th {
                color: #999999;
                /* 设置表头颜色 */
            }

            /deep/.el-table__body td {
                color: #333333;
                /* 设置表格内容字体颜色 */
            }

            .content {
                height: 95px;

                >img {
                    width: 150px;
                    height: 95px;
                    margin: 20px;
                }

                >h5 {
                    // margin-top: 20px;
                    width: 170px;
                    font-family: Microsoft YaHei, Microsoft YaHei;
                    color: #333333;
                    margin-bottom: 20px;
                    font-weight: 400;
                    font-size: 16px;
                }

                >p {
                    // margin-top: 40px;
                    width: 170px;
                    font-family: Microsoft YaHei, Microsoft YaHei;
                    font-weight: 400;
                    font-size: 16px;
                    color: #333333;
                }

            }

        }

        .pagination {
            margin-top: 60px;
            margin-bottom: 90px;
        }




    }

}
</style>