<template>
    <global-popup
        v-model="showPopup"
        mode="bottom"
        :width="580"
        background="#F7F8FA"
        :round="32"
    >
        <view class="list">
            <view class="item" @tap="handleClick">{{ details.failureState == 0 ? '作废' : 'open' }}</view>
            <view class="item" @tap="close">取消</view>
        </view>
    </global-popup>
</template>

<script setup>
import { ref } from 'vue'
import { storeToRefs } from 'pinia'
import { updateOpenAndCloseApi } from 'mocp/api/inforDisclosure'
import useInforDisclosureStore from 'mocp/store/inforDisclosure'
import useUserStore from 'mocp/store/user'

const inforDisclosure = useInforDisclosureStore()
const {details} = storeToRefs(inforDisclosure)
const userStore = useUserStore()

const showPopup = ref(false)
const open = () => {
    showPopup.value = true
}
const close = () => {
    showPopup.value = false
}

const handleClick = async () => {
    console.log(details.value)
    const params = {
        id: details.value.id,
        state: details.value.failureState == 0 ? 1 : 0,//0开户  1作废
        userId: userStore.userInfo.id,
        username: userStore.userInfo.nickname
    }
    console.log(params)
    const res = await updateOpenAndCloseApi(params, {loading: true})
    console.log(res)
    if (res.code == '200') {
        const toast = details.value.failureState == 0 ? '已作废' : '已开启'
        uni.$mocpMessage.success(toast)
        details.value.failureState = details.value.failureState == 0 ? 1 : 0
        showPopup.value = false
        uni.$emit('inforDisclosureReload')
    } else {
        uni.$mocpMessage.error('变更失败！')
    }
}
defineExpose({
    open,
    close
})
</script>
<style lang="scss" scoped>
.list {
    padding: 18rpx 32rpx;

    .item {
        color: $mocp-text-4;
        font-size: 30rpx;
        background: #fff;
        margin-bottom: 24rpx;
        padding: 16rpx 24rpx;
        text-align: center;
    }
}
</style>
