<!--
 * @Author: micky
 * @Date: 2024-08-12 19:51:36
 * @LastEditors: micky
 * @LastEditTime: 2024-09-10 23:28:04
 * @FilePath: \chargingpile-uniapp\src\bundle\pages\client\confirm-scrap.vue
-->
<template>
    <w-page-common
        btnText="确认报废"
        @submit="handleSubmit"
        :needPadding="false"
        :customStyle="{ padding: '20rpx 24rpx' }"
    >
        <TCard>
            <view class="c-form-item-wrapper pt-[12rpx]">
                <view class="item">
                    <view>工单编号</view>
                    <view>
                        {{ detail.orderNo }}
                    </view>
                </view>
                <view class="item">
                    <view>创建人</view>
                    <view>
                        {{ detail.creatorName }}
                    </view>
                </view>
                <view class="item">
                    <view>模块代码</view>
                    <view>{{ detail.moduleCode }}</view>
                </view>
                <view class="item">
                    <view>模块型号</view>
                    <view>{{ detail.moduleNumber }}</view>
                </view>
            </view>
            <!-- <view class="c-input-field-item cell-border">
                <text class="label">是否报废</text>
                <u-switch
                    v-model="formData.scrapOrNot"
                    :activeValue="YesOrNoEnum.YES"
                    :inactiveValue="YesOrNoEnum.NO"
                    :disabled="true"
                ></u-switch>
            </view>
            <view class="c-input-field-item cell-border">
                <text class="label">是否回寄</text>
                <u-switch
                    v-model="formData.returnOrNot"
                    :activeValue="YesOrNoEnum.YES"
                    :inactiveValue="YesOrNoEnum.NO"
                ></u-switch>
            </view>
            <template v-if="formData.returnOrNot == YesOrNoEnum.YES">
                <view class="c-input-field-item cell-border">
                    <text class="label">收件方式</text>
                    <w-dict-select
                        v-model="formData.deliveryMethod"
                        :options="optionsMap.deliveryMethodOpt"
                    ></w-dict-select>
                </view>
                <template v-if="formData.deliveryMethod != DeliveryMethodEnum.VISIT">
                    <view class="c-input-field-item cell-border address">
                        <text class="label required">收件地址</text>
                        <view
                            class="flex flex-1 items-center ml-4 justify-end"
                            @click="handleAddress"
                        >
                            <view v-if="!showInfo.address">请选择收件地址</view>
                            <view v-else>{{ showInfo.address }}</view>
                            <TIcon name="icon-right" :size="24" color="#7C7E82" />
                        </view>
                    </view>
                    <view class="c-input-field-item cell-border" v-if="showInfo.contact">
                        <view class="label">收件人</view>
                        <view class="flex">{{ showInfo.contact }}</view>
                    </view>
                    <view class="c-input-field-item cell-border" v-if="showInfo.mobile">
                        <view class="label">联系电话</view>
                        <view class="flex">{{ showInfo.mobile }}</view>
                    </view>
                </template>
            </template>
            <view class="px-[24rpx] py-[24rpx]">
                <TTextareaField
                    label="备注"
                    v-model="formData.clientScrapRemark"
                    placeholder="请输入备注信息，选填"
                    :remarkStyle="{ padding: 0 }"
                ></TTextareaField>
            </view> -->
        </TCard>
    </w-page-common>
</template>

<script setup lang="ts">
import { ref, unref } from 'vue'
// import { optionsMap } from '@/config/options'
import { DeliveryMethodEnum, YesOrNoEnum } from '@/enums/businessEnums'
import { toast } from '@/utils/util'
import { apiConfirmScrap } from '@/api/client'
import { apiRepairDetail } from '@/api/repair'
import { onLoad } from '@dcloudio/uni-app'

const orderId = ref('')
const detail = ref<any>({})
// const formData = ref({
//     returnOrNot: YesOrNoEnum.NO,
//     deliveryMethod: optionsMap.deliveryMethodOpt[0].value,
//     clientScrapAddressId: '',
//     clientScrapRemark: '',
//     scrapOrNot: YesOrNoEnum.YES,
//     id: '',
//     scrapConfirmation: 0
// })

// const showInfo = ref({
//     address: '',
//     mobile: '',
//     contact: ''
// })

// const handleAddress = () => {
//     uni.navigateTo({
//         url: '/bundle/pages/user_address/index?type=true'
//     })
// }
const handleSubmit = async () => {
    // const form = unref(formData)
    // if (
    //     form.returnOrNot == YesOrNoEnum.YES &&
    //     form.deliveryMethod != DeliveryMethodEnum.VISIT &&
    //     !form.clientScrapAddressId
    // ) {
    //     return toast('请选择收件地址')
    // }
    await apiConfirmScrap({
        id: unref(orderId)
    })
    toast('已确认报废')
    setTimeout(() => {
        uni.navigateBack()
    }, 300)
}

const getDetail = async () => {
    const res = await apiRepairDetail({
        id: unref(orderId)
    })
    detail.value = res
}

onLoad(async (options: any) => {
    orderId.value = options.id as string
    getDetail()
    // formData.value.id = options.id as string
    // uni.$on('address', function (data) {
    //     console.log('data', data)

    //     formData.value.clientScrapAddressId = data.id
    //     showInfo.value.address = `${data.province}${data.city}${data.district}${data.address}`
    //     showInfo.value.mobile = data.mobile
    //     showInfo.value.contact = data.contact
    // })
})
</script>
<style scoped lang="scss">
.cell-border {
    padding: 24rpx;
    border-bottom: 1px solid $gray-3;
}
.address {
    padding: 24rpx;
    height: auto !important;
}
</style>
