<template>
  <el-form :model="formCallback" label-width="120px" ref="form" v-loading="loading" class="pr-4">
    <el-form-item label="列表名称" prop="ids" :rules="[{ required: false, message: '巨量账户ID必须填写' }]" label-width="120px">
      <el-input v-model="props.primary.type_str" disabled size="default" clearable></el-input>
    </el-form-item>
    <el-form-item label="短剧" prop="duanjus" :rules="[{ required: true, message: '选择短剧' }]">
      <div>
        <div class="flex flex-wrap mb-5" v-if="formCallback.duanjus.length > 0">
          <div v-for="item in formCallback.duanjus" :key="item.id" class="mt-3 mr-3">
            <el-input v-model="item.name" disabled placeholder="短剧名称" style="width:300px;" class="input-with-select">
              <template #prepend>
                <el-input type="number" min="1" disabled v-model.number="item.sort" placeholder="排序" size="default"
                  clearable style="width: 115px"></el-input>
              </template>
            </el-input>
          </div>
        </div>
        <div>
          <el-button type="primary" size="default" @click="chooseShort">选择短剧</el-button>
        </div>
      </div>
    </el-form-item>
    <div class="flex justify-end">
      <el-button type="primary" @click="submitForm(form)">{{
        $t('system.confirm')
      }}</el-button>
    </div>
  </el-form>
  <Dialog v-model="videoVisible" title="选择短剧" width="90%" :alignCenter="true" destroy-on-close>
    <videoList @confirm="confirm" :primary="formCallback.duanjus"></videoList>
  </Dialog>
</template>

<script lang="ts" setup>
import videoList from './videoList.vue';
import { Close } from '@element-plus/icons-vue';
import { FormInstance } from 'element-plus';
import { operationManageFirstPageSetConfig } from '@/api/pageLayout/homePage/index';
import { useRouter, useRoute } from 'vue-router'
const props = defineProps({
  primary: Object,
});
const router = useRouter()
const route = useRoute()
const emit = defineEmits(['close']);
const loading = ref(false)
const videoVisible = ref(false)
const promotion = ref('')
const form = ref()
const formCallback = ref({
  duanjus: []
})


const chooseShort = () => {
  videoVisible.value = true
}

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

if (props.primary) {
  console.log(props.primary, 'props.primaryprops.primary');
  formCallback.value.id = props.primary.id
  formCallback.value.duanjus = props.primary.duanjus
}
onMounted(() => {
});
</script>

<style lang="scss" scoped>
:deep(.input-with-select .el-input-group__prepend) {
  background-color: #FFFFFF;
  padding: 0;
  border: 1px solid #dcdfe6;
}
</style>
