<template>
    <div v-if="dgstfnExmnUseYn == 'Y'">
        <label class="form-title">{{pgNm}} 만족도 조사</label>
        <div class="check-area">
            <div class="form-check">
                <input type="radio" name="rspns" id="rspnsFive" class="mr5" v-model="menuDgstfn.rspnsFive"
                    value="Y" />
                <label for="rspnsFive">매우 만족</label>
            </div>
            <div class="form-check">
                <input type="radio" name="rspns" id="rspnsFour" class="mr5" v-model="menuDgstfn.rspnsFour"
                    value="Y" />
                <label for="rspnsFour">만족</label>
            </div>
        </div>
        <div class="layout">
            <label class="form-title">의견</label>
            <input
            type="text"
            class="form-control sm"
            v-model="menuDgstfn.opnn"
            placeholder="의견을 남겨주세요"
            />
        </div>
    </div>
    <div v-else>
        <label class="form-title">[만족도 조사 비활성화 상태]</label>
    </div>
</template>

<script>
import store from "../pages/AppStore";
import { menuFindByMenu } from '../../resources/api/menu.js';
import { save } from '../../resources/api/menuDgstfn.js';

export default {
    data() {
        return {
            mbrNm: store.state.mbrNm,
            pgNm: store.state.menu && store.state.menu.menuNm ? store.state.menu.menuNm : "홈",
            menuId: null,

            dgstfnExmnUseYn: "N", // 메뉴 사용 여부
            // satisfaction: {}, // 만족도
            menuDgstfn: {}, // 메뉴 만족도
        }
    },
    created() {
        this.fnView(store.state.menu.menuId);
    },
    methods: {
        // 상세 조회
        async fnView(menuId) {
            try {
                const params = { menuId: menuId };
                const res = await menuFindByMenu(params);
                if (res.status == 200) {
                    console.log("메뉴상태: ", res.data.data);
                    this.dgstfnExmnUseYn = res.data.data.dgstfnExmnUseYn;
                }
            } catch (error) {
                alert(error.response.data.message);
            }
        },

        // 저장
        async save() {
            try {
                const res = await save(this.menuDgstfn);
                alert(res.data.message);
                if (res.status == 200) {
                }
            } catch (error) {
                alert(error.response.data.message);
            }
        },

    },
    watch: {
        'pgNm'(newValue, oldValue) {
            console.log(oldValue)
        },
        '$store.state.menu'(newValue) {
            console.log("newValue : ", newValue);
            this.pgNm = newValue.menuNm
            this.menuId = newValue.menuId
            this.fnView(this.menuId);
        },

    },
    computed: {

        pgNm() {
            return store.state.menu && store.state.menu.menuNm ? store.state.menu.menuNm : "홈";
        }

    },
    mounted() {

    }
}
</script>