<template>
<el-dialog v-model="dialogVisible" width="637" class="dialog-box" v-if="data"
    align-center
    destroy-on-close
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :show-close="false">
    <template #header="{ close, titleId, titleClass }">
        <div class="msg-header" >
            <!-- <svg-icon icon-class="leverage" class="header-icon" /> -->
            <div class="header-title">{{ t('activity.cancelOrder') }}</div>
            <div class="header-close" >
            <el-icon color="rgba(196, 196, 196, 1)" @click="close" ><Close /></el-icon>
            </div>
        </div>
    </template>
    <div class="msg-body" >
        <el-form ref="postRef" :model="form" autocapitalize="off" size="large" label-position="top" style="user-select: none;" >
            <el-descriptions :column="1" >
                <el-descriptions-item :label="t('activity.goodsName')">{{ data.goods_name }}</el-descriptions-item>
                <el-descriptions-item :label="t('activity.point')">{{ data.integral }}</el-descriptions-item>
                <el-descriptions-item :label="t('activity.addr')">{{ data.delivery_address }}</el-descriptions-item>
                <el-descriptions-item :label="t('activity.phone')">{{ data.delivery_phone }}</el-descriptions-item>
                <el-descriptions-item :label="t('activity.recipients')">{{ data.delivery_recipients }}</el-descriptions-item>
            </el-descriptions>
            <el-form-item :label="t('home.remark')" >
                <el-input v-model="form.remark" />
            </el-form-item>
            <el-form-item>
                <div style="display: flex;width: 100%;justify-content: center;">
                    <el-button @click="save" class="dark-btn" style="width: 264px;" type="primary">{{ t('activity.cancelOrder') }}</el-button>
                    <el-button @click="dialogVisible = false" style="width: 264px;" type="primary">{{ t('activity.cancel22') }}</el-button>
                </div>
            </el-form-item>
        </el-form>
    </div>
</el-dialog>

</template>

<script setup>
import { useLocale } from 'element-plus'
import { ref, defineModel, watch } from 'vue';
import { serverLang } from '@/utils/i18n'
import { doQX } from '@/api/shop'

const { proxy } = getCurrentInstance();
const { t } = useLocale()
const dialogVisible = defineModel("show")
const emit = defineEmits(['cancel'])
const props = defineProps({
    data: {
        type: Object,
        default: null
    }
})

const d = reactive({
  form: {
    remark: undefined,
    id: undefined
  }
});

const { form } = toRefs(d);

function save() {
    const { id } = props.data
    const { remark } = form.value
    doQX({
        id, remark, qcc_language: serverLang()
    }).then(resp => {
        dialogVisible.value = false
        window.showTip({
            title: t('common.success.action'),
            status: 'success'
        })
        emit('cancel')
    })
}

watch(dialogVisible, (n, o) => {
    if(!n) {
        proxy.resetForm("postRef");
    }
})
</script>

<style lang="scss">
.dialog-box {
    border-radius: 16px;
    padding: 0;
    
    .el-dialog__header {
        margin-right: 0;
        padding: 0;
        overflow: hidden;
    }

    .el-dialog__body {
        box-sizing: border-box;
        padding: 16px 22px;
        min-height: 250px;
    }

    .msg-header {
        border-radius: 16px 16px 0 0;
        width: 100%;
        height: 50px;
        position: relative;
        overflow: hidden;
        background-color: #0F3675;
        display: flex;
        align-items: center;
        color: #fff;

        .header-icon {
            width: 25px;
            height: 28px;
            margin-left: 22px;
            margin-right: 14px;
        }

        .header-title {
            margin-left: 22px;
            font-size: 26px;
            font-weight: 700;
        }

        .header-close {
            cursor: pointer;
            position: absolute;
            bottom: 0;
            right: 20px;
            font-size: 32px;
        }
    }

    .msg-body {
        background-color: #ffffff;

        .account {
            font-size: 18px;
            font-weight: 700;
            color: rgba(51, 51, 51, 1);
            margin-bottom: 14px;
            width: 50%;
        }
    }
}
</style>