<template>
  <div class="container">
    <div class="content content-box flex100">
      <JobContainer :jobGroup="jobGroup" />
      <div class="flex justify-end mt10">
        <button class="darkg-btn small-btn" @click="saveJobGroup()">
          데이터 등록
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import JobContainer from "../../component/connection/jobContainer.vue";
import axios from "axios";

export default {
  openPopup: {
    type: Boolean,
    default: false,
  },
  data() {
    return {
      jobGroup: {},
    };
  },
  methods: {
    saveJobGroup: function () {
      let vm = this;
      axios({
        url: "/job/insertJobGroup.json",
        method: "post",
        headers: {
          "Content-Type": "application/json; charset=UTF-8",
        },
        data: vm.jobGroup,
      })
        .then(function (response) {
          this.$showAlert(
            "에러 발생",
            "에러가 발생했습니다. 관리자에게 문의해 주세요."
          );
        })
        .catch(function (error) {
          this.$showAlert(
            "에러 발생",
            "에러가 발생했습니다. 관리자에게 문의해 주세요."
          );
        });
    },

    selectJobGroup: function () {
      let vm = this;
      axios({
        url: "/job/selectJobGroup.json",
        method: "post",
        headers: {
          "Content-Type": "application/json; charset=UTF-8",
        },
        data: JSON.stringify({ group_id: "JOBGROUP_2024020517352987547982" }),
      })
        .then(function (response) {
          vm.jobGroup = response.data.resultData.jobGroup;
        })
        .catch(function (error) {
          this.$showAlert(
            "에러 발생",
            "에러가 발생했습니다. 관리자에게 문의해 주세요."
          );
        });
    },
  },
  components: {
    JobContainer: JobContainer,
  },
  mounted() {
    this.jobGroup = this.$getDefaultJobGroup().jobGroup;
    this.selectJobGroup();
  },
};
</script>