<template>
  <n-button
    :loading="loading"
    type="primary"
    size="small"
    @click="showEditModal"
    >编辑</n-button
  >
  <n-modal
    v-model:show="showModal"
    preset="dialog"
    positive-text="确认"
    negative-text="取消"
    :show-icon="false"
    @positive-click="handleEdit"
  >
    <n-form :model="formValue" label-width="auto" show-require-mark>
      <n-form-item label="ID" path="T_id">
        <n-input v-model:value="formValue.T_id" />
      </n-form-item>
      <n-form-item label="SN" path="T_sn">
        <n-input v-model:value="formValue.T_sn" disabled="false" />
      </n-form-item>
    </n-form>
  </n-modal>
</template>

<script setup>
import { editTaskDataClass } from '@/api';

//
const loading = ref(false);

const message = useMessage();

const props = defineProps({
  task: {
    type: Object,
    default: () => ({}),
  },
  taskClass: {
    type: Object,
    default: () => ({}),
  },
  getClassList: {
    type: Function,
    default: () => {},
  },
});

//
const showModal = ref(false);

//
const formValue = reactive({
  T_sn: props.taskClass.T_sn,
  T_id: props.taskClass.T_id,
});

//
const handleEdit = async () => {
  try {
    loading.value = true;
    const { data: res } = await editTaskDataClass({
      T_task_id: props.task.T_task_id,
      T_sn: formValue.T_sn,
      T_id: formValue.T_id,
    });
    if (res.Code === 200) {
      message.success(res.Msg);
      props.getClassList();
    }
    loading.value = false;
  } catch (e) {
    console.log(e);
  }
};

//
const showEditModal = () => {
  showModal.value = true;
};
</script>

<style lang="scss" scoped></style>
