<template>
  <div>
    <div ref="lxHeader">
      <lx-header
        icon="md-apps"
        style="margin-bottom: 10px; border: 0px; margin-top: 15px"
        text="统招模版"
      >
        <div slot="content"></div>
        <slot>
          <header-content :auths="auths_auth_mixin">
            <template v-slot:search>
              <el-date-picker
                size="small"
                type="year"
                placement="bottom"
                placeholder="年份选择"
                style="width: 160px"
                value-format="yyyy"
                v-model="select.year"
                @change="$refs['xyTable'].getTableData()"
              ></el-date-picker>
            </template>
            <template v-slot:create>
              <Button
                type="primary"
                @click="
                  ($refs['addTemplate'].type = 'add'),
                    ($refs['addTemplate'].isShow = true)
                "
                >新建</Button
              >
            </template>
          </header-content>
        </slot>
      </lx-header>
    </div>

    <xy-table
      ref="xyTable"
      :req-opt="select"
      :action="index"
      :destroy-action="destroy"
      :table-item="table"
      :auths="auths_auth_mixin"
      @editor=""
    >
      <template v-slot:setting="scope">
        <Button
            size="small"
            type="primary"
            ghost
            @click="e => {
              $refs['setting'].id = scope.row.id
              isShowSetting = true
            }"
          >模版设置</Button
        >
      </template>
    </xy-table>

    <addTemplate
      ref="addTemplate"
      @refresh="$refs['xyTable'].getTableData()"
    ></addTemplate>

    <setting ref="setting" :is-show.sync="isShowSetting"></setting>
  </div>
</template>

<script>
import { index, destroy, save } from "@/api/unifiedRecruitment/template";
import { authMixin } from "@/mixin/authMixin";

import addTemplate from "./component/addTemplate.vue";
import setting from "./component/setting.vue";
export default {
  mixins: [authMixin],
  components: {
    addTemplate,
    setting,
  },
  data() {
    return {
      isShowSetting: false,
      select: {
        year: "",
      },

      table: [
        {
          prop: "year",
          label: "年份",
          width: 140,
          sortable: "custom",
        },
        {
          prop: "remark",
          label: "录取查询说明",
          align: "left",
          minWidth: 300,
        },
        {
          label: "是否开放查询",
          width: 190,
          customFn: (row) => {
            return (
              <el-switch
                v-model={row.is_open}
                inactive-text="否"
                active-text="是"
                inactive-value={0}
                active-value={1}
                on={{
                  ["change"]: (e) => {
                    save(row).then((res) => {
                      this.$refs["xyTable"].getTableData();
                    });
                  },
                }}
              ></el-switch>
            );
          },
        },
      ],
    };
  },
  methods: {
    index,
    destroy,
  },
  computed: {},
};
</script>

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