<style scoped lang="scss">

</style>
<template>
  <div class="system-dialog-container">
    <el-dialog
        :title="state.dialog.title"
        v-model="state.dialog.visible"
        width="380px"
        draggable
        destroy-on-close
        :close-on-click-modal="false"
        align-center>
      <el-form
          inline
          :model="state.ruleForm"
          :rules="state.rules"
          label-position="top"
          ref="formRef"
          size="default"
          label-width="100px"
          class="mt5">
        <!--        <el-form-item label="充电桩序列号" prop="equipmentId" class="wd300">
                  <el-input
                      v-model="state.ruleForm.equipmentId"
                      placeholder="充电桩序列号"
                      clearable
                      readonly
                      class="w100">
                  </el-input>
                </el-form-item>-->
        <el-form-item label="" prop="platformName" class="wd300">

          <ext-select
              v-model="state.ruleForm.platformName"
              placeholder="请选择平台"
              clearable
              url="platform/list"
              urlMethod="get"
              data-key="list"
              label-key="platformName"
              value-key="platformName"
              class="w100 mr10">
          </ext-select>
        </el-form-item>

      </el-form>

      <template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="default">取 消</el-button>
					<el-button :loading="state.btnLoading" type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
				</span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts" name="EquipmentInfoDialog">
import {defineAsyncComponent, reactive, onMounted, ref} from 'vue';
import {Msg} from "/@/utils/message";
import {$body, $get} from "/@/utils/request";
import u from '/@/utils/u'
import ExtSelect from "/@/components/form/ExtSelect.vue";

// 引入组件

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);
const formRef = ref();
//定义初始变量，重置使用
const initState = () => ({
  ruleForm: {
    connectorIds: [],
    platformName: '',
  },
  btnLoading: false,
  dialog: {
    visible: false,
    type: '',
    title: '',
    submitTxt: '',
  },
  rules: {},
  relation: {}
})

// 定义变量内容
const state = reactive(initState());


// 打开弹窗
const open = ( connectorIds: any) => {
  state.dialog.title = "批量绑定平台"
  state.dialog.submitTxt = "确定"
  state.dialog.visible = true;
  state.ruleForm.connectorIds = connectorIds;
};
// 关闭弹窗
const onClose = () => {
  state.dialog.visible = false;
  Object.assign(state, initState())
};
// 取消
const onCancel = () => {
  onClose();
};
// 提交
const onSubmit = () => {
  formRef.value.validate((v: boolean) => {
    if (v) {
      state.btnLoading = true;
      $body(`equipment-relation/batchBind`, state.ruleForm).then(() => {
        state.btnLoading = false;
        Msg.message('操作成功');
        onClose();
        emit('refresh');
      })
    } else {
      state.btnLoading = false;
      Msg.message('请先完整填写表单', 'error');
    }
  })
};

const handleFormChange = (formData: any) => {
  console.log(formData)
}


// 暴露变量
defineExpose({
  open
});


</script>
