<script setup>
import {ref} from "vue";
import XSelect from "../XSelect/index.vue";
import Information from "./Information.vue";
import dayjs from "dayjs";
import Api from "../../api/index.js";
import {Message} from "@arco-design/web-vue";
import {useSystemStore} from "../../pinia/SystemStore/index.js";

const SystemStore = useSystemStore();
const InformationRef = ref();
const {task} = defineProps({
    task: {
        type: Object,
        default: null
    }
});
const visible = defineModel('visible');
const emits = defineEmits(['success']);

const getStatus = () => Promise.resolve({
    data: [
        {
            id: 0,
            name: '待回复',
        },
        {
            id: 1,
            name: '已回复',
        },
    ]
});

const changeStatus = async () => {
    const {msg} = await Api.merchant.finshReply({
        id: task.id,
        status: 1,
    });
    Message.success(msg);
    emits('success');
}
</script>

<template>
    <a-modal
        class="Chat"
        width="1200px"
        title="沟通记录"
        :footer="false"
        title-align="start"
        v-model:visible="visible">
        <a-alert>
            平台提示：所有沟通内容均由人工审核，请勿脱离平台交易，请勿发送违规内容，违者永久封禁
        </a-alert>
        <div class="flex">
            <div class="p-[20px] bg-[#F2F3F5] flex-grow min-h-[800px] relative">
                <Information ref="InformationRef" :task="task" v-if="visible && task?.id"
                             @success="emits('success')"></Information>
            </div>
            <div class="w-[280px] h-auto flex flex-col bg-[#F2F3F5] gap-[20px]" v-if="task">
                <div class="bg-white p-[20px]">
                    <template v-if="!SystemStore.isRoot">
                        <div class="mb-[20px] text-[16px]">进度管理</div>
                        <x-select v-model:model-value="task.is_reply" placeholder="待回复" :api="getStatus"
                                  @change="changeStatus" :init="true"></x-select>
                        <a-divider></a-divider>
                    </template>
                    <div class="mb-[20px] text-[16px]">进度管理</div>
                    <div class="grid grid-cols-2 gap-y-[12px]">
                        <div class="text-[#86909C]">创建时间</div>
                        <div class="#1D2129">{{ dayjs(task.createtime * 1000).format('MM-DD HH:mm') }}</div>
                        <div class="text-[#86909C]">任务编号</div>
                        <div class="#1D2129">{{ task?.taskcode || task.m_code }}</div>
                        <div class="text-[#86909C]">子任务编号</div>
                        <div class="#1D2129">{{ task.uid }}</div>
                        <div class="text-[#86909C]">子任务状态</div>
                        <div class="#1D2129">
                            <a-tag v-if="task.status === 0" color="red">待上传素材</a-tag>
                            <a-tag v-if="task.status === 1" color="orangered">素材审核中</a-tag>
                            <a-tag v-if="task.status === 2" color="orangered">重新上传素材</a-tag>
                            <a-tag v-if="task.status === 3" color="gray">待领取</a-tag>
                            <a-tag v-if="task.status === 4" color="green">已领取</a-tag>
                            <a-tag v-if="task.status === 5" color="green">已结算</a-tag>
                            <a-tag v-if="task.status === 6" color="arcoblue">已终止</a-tag>
                        </div>
                        <div class="text-[#86909C]">子任务结算进度</div>
                        <div class="#1D2129">
                            <a-tag v-if="task.is_settlement === 0" color="orangered">{{ task.settlement_text }}</a-tag>
                            <a-tag v-if="task.is_settlement === 1" color="gray">{{ task.settlement_text }}</a-tag>
                            <a-tag v-if="task.is_settlement === 2" color="green">{{ task.settlement_text }}</a-tag>
                            <a-tag v-if="task.is_settlement === -1" color="arcoblue">{{ task.settlement_text }}</a-tag>
                        </div>
                        <div class="text-[#86909C]">结算金额(元)</div>
                        <div class="#1D2129">{{ (task.real_coin / 100).toFixed(2) }}</div>
                        <div class="text-[#86909C]">达人账号</div>
                        <div class="#1D2129">{{ task.account }}</div>
                    </div>
                </div>
                <div class="flex-grow bg-white p-[20px]">
                    <div class="mb-[20px] text-[16px]">达人回填信息</div>
                    /
                </div>
            </div>
        </div>
    </a-modal>
</template>

<style lang="scss">
.Chat {
    .arco-modal-body {
        padding: 0;

        .arco-textarea-wrapper {
            background-color: #fff;
            border: none;
        }
    }
}
</style>

<style scoped lang="scss">

</style>
