<template>
  <div class="content_t">
    <div class="content_item">
      <span>免费发布岗位数量</span>
      <el-input v-model="options.free_num" type="number" class="input_t"></el-input>
      <spqn>个</spqn>
    </div>
    <div class="content_item">
      <span>刷新岗位单次价格</span>
      <el-input v-model="package[1].price" type="number" class="input_t"></el-input>
      <spqn>元</spqn>
    </div>
    <div class="content_item">
      <span>单次发布岗位价格</span>
      <el-input v-model="package[0].price" type="number" class="input_t"></el-input>
      <spqn>元</spqn>
    </div>
    <template v-for="(item, key) in package">
      <div v-if="item.type == '2'">
        <div class="conf_title">{{ item.name }}:</div>
        <div class="conf_content">
          <span>套餐次数</span>
          <el-input v-model="item.num" type="number" class="input_t"></el-input>
          <spqn>次</spqn>
          <span>原价</span>
          <el-input v-model="item.original_price" type="number" class="input_t"></el-input>
          <spqn>元</spqn>
          <spqn>现价</spqn>
          <el-input v-model="item.price" type="number" class="input_t"></el-input>
          <spqn>元</spqn>
        </div>
      </div>
    </template>
    <div class="save-btn">
      <el-button @click="onSave" :loading="loading">保存配置</el-button>
    </div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      loading: false,
      options: [],
      package: [{price:0}, {price:0}]
    };
  },
  mounted() {
    this.getData()
  },
  methods: {
    async getData() {
      const res = await this.$post("/api/admin/recruit/getConf");
      if (res && res.status === 1) {
        this.options = res.data.options;
        this.package = res.data.package;
      }
    },
    async onSave() {
      this.loading = true;
      let data = {
        content: JSON.stringify({
          options: this.options,
          package: this.package
        })
      };
      const res = await this.$post("/api/admin/recruit/saveConf", data);
      if (res && res.status === 1) {
        this.$message({
          message: '修改成功',
          type: 'success'
        })
        this.getData()
      }
      this.loading = false;

    }
  }
};
</script>

<style scoped>
.content_t {
  padding: 20px;
}

.conf_title {
  font-weight: 500;
  margin: 10px 0 10px 0;
}

.conf_content {
  margin-left: 30px;
}

.input_t {
  width: 120px;
}
.save-btn{
  margin-top: 30px;
}
.content_item{
  margin-bottom: 10px;
}
</style>
