<template>
  <el-form :model="formCallback" label-width="120px" ref="form" v-loading="loading" class="pr-4">
    <el-form-item label="小程序类型" prop="miniprogram_type" :rules="[{ required: true, message: '选择小程序类型' }]"
      label-width="120px">
      <el-select v-model="formCallback.miniprogram_type" clearable filterable placeholder="请选择小程序类型">
        <el-option v-for="(item, index) in miniprogramTypelist" :key="index" :label="item.label" :value="item.value" />
      </el-select>
    </el-form-item>
    <el-form-item label="列表名称" prop="type" :rules="[{ required: true, message: '选择列表名称' }]" label-width="120px">
      <el-select v-model="formCallback.type" clearable filterable placeholder="请选择列表名称">
        <el-option v-for="(item, index) in typeList" :key="index" :label="item.name" :value="item.value" />
      </el-select>
    </el-form-item>
    <el-form-item label="状态" prop="status" label-width="120px" :rules="[{ required: true, message: '选择状态' }]">
      <el-switch v-model="formCallback.status" :active-value="1" :inactive-value="0"></el-switch>
    </el-form-item>
    <div class="flex justify-end">
      <el-button type="primary" @click="submitForm(form)">{{
        $t('system.confirm')
      }}</el-button>
    </div>
  </el-form>
</template>

<script lang="ts" setup>
import { Close } from '@element-plus/icons-vue';
import { FormInstance } from 'element-plus';
import { optionsCommonParams } from '@/api/common/index'
import { operationManageFirstPageAdd } from '@/api/pageLayout/homePage/index'
const emit = defineEmits(['close']);
const loading = ref(false)
const form = ref()
const promotion = ref('')
const formCallback = ref({
  status: 0,
})
const miniprogramTypelist = ref([])

const typeList = ref([{ name: '本周精选', value: 1 }, { name: '优选好剧', value: 2 }])
const init = () => {
  optionsCommonParams().then(res => {
    console.log(res, 'optionsCommonParams');
    miniprogramTypelist.value = res.data.miniprogramType
  })
}

// 提交回传配置
const submitForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  loading.value = true;
  if (!formEl) return;
  formEl
    .validate(valid => {
      if (valid) {
        operationManageFirstPageAdd(formCallback.value).then(res => {
          ElMessage.success(res.message)
          emit('close')
        })
        loading.value = false;
      } else {
        loading.value = false;
      }
    })
    .then(() => { });
}


onMounted(() => {
  init()
});
</script>

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