<template>
    <el-drawer v-model="visible" direction="rtl" :before-close="closeDialog">
        <div class="count-status">
            <el-input-number v-model="writeV" style="width: 240px" placeholder="请输入点位值" size="large"/>
        </div>
        <div class="btns">
            <el-button type="primary" size="large" @click="writeValue">写值</el-button>
        </div>
    </el-drawer>
</template>
<script>
import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue";
import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
export default {
  props: ["dialogVisible", "formData"],
  emits: ["dialogClose", "dialogSuccess"],
  setup(props, ctx) {
    const state = reactive({
        writeV: '',
    }) 
    const visible = computed(() => {
      return props.dialogVisible;
    });

    onMounted(() => {
       
    });
 
    const writeValue = async () => {
        const parm = {
            driver_name: props.formData.driver_name, 
            device_name: props.formData.device_name, 
            point_name: props.formData.point_name,
            point_in_value: state.writeV
        }
        const res = await infoApi.writeValue(parm);
        if (res.code == 0) { 
            ElMessage.success(res.data || "请求成功");
            ctx.emit("dialogClose");
        }
    }
    const closeDialog = () => {
      ctx.emit("dialogClose");
    };


    return {
      ...toRefs(state),
      visible,
      closeDialog,
      writeValue
    };
  },
};
</script>
<style lang="scss" scoped>
    ::v-deep .el-form-item__content {
        display: flex;
        flex-wrap: nowrap;

        >span {
            margin-left: 10px;
        }
    }
    .count-status {
        display: flex;
        justify-content: space-around;
    }
</style>
