<script setup>
import { ArrowLeftBold } from "@element-plus/icons-vue";

import { user } from "~/store/index";
const router = useRouter();
const route = useRoute();
let detailInfo = $ref({});
function handleBack() {
  router.back();
}
//初始化
if (route.query.as_id) {
  let as_id = route.query.as_id;
  initData("1");
}
async function initData(init) {
  const { code, data } = await request({
    url: "/aimooc/spjj/detail",
    data: { as_id: route.query.as_id },
  });
  if (code === "1") {
    detailInfo = data.one_info;
    if (init == "1") {
    const player = new Aliplayer(
      {
        id: "player-con",
        source: detailInfo.as_file,
        width: "100%",
        height: "calc(100vh - 120px)",
        autoplay: false,
        cover: detailInfo.as_img,
        isLive: false,
        rePlay: false,
        playsinline: true,
        preload: true,
        controlBarVisibility: "hover",
        useH5Prism: true,
        skinLayout: [
          {
            name: "bigPlayButton",
            align: "blabs",
            x: 30,
            y: 80,
          },
          {
            name: "H5Loading",
            align: "cc",
          },
          {
            name: "errorDisplay",
            align: "tlabs",
            x: 0,
            y: 0,
          },
          {
            name: "infoDisplay",
          },
          {
            name: "tooltip",
            align: "blabs",
            x: 0,
            y: 56,
          },
          {
            name: "thumbnail",
          },
          {
            name: "controlBar",
            align: "blabs",
            x: 0,
            y: 0,
            children: [
              {
                name: "progress",
                align: "blabs",
                x: 0,
                y: 44,
              },
              {
                name: "playButton",
                align: "tl",
                x: 15,
                y: 12,
              },
              {
                name: "timeDisplay",
                align: "tl",
                x: 10,
                y: 7,
              },
              {
                name: "fullScreenButton",
                align: "tr",
                x: 10,
                y: 12,
              },
              {
                name: "setting",
                align: "tr",
                x: 15,
                y: 12,
              },
              {
                name: "volume",
                align: "tr",
                x: 5,
                y: 10,
              },
            ],
          },
        ],
      },
      (player) => {
        console.log("The player is created");
      }
    );
   }
  }
}

/**打开审核dialog*/
const checkDialog = () => {
  checkForm.value = {
    result: "",
    reason: "",
  };
  dialogFormVisible_check.value = true;
};

const dialogFormVisible_check = ref(false);
const formLabelWidth = "100px";
const ruleFormRef = ref();

const checkForm = ref({
  result: "",
  reason: "",
});
const rules = ref({
  result: [
    {
      required: true,
      message: "请选择一项",
      trigger: "change",
    },
  ],
  reason: [{ required: true, message: "请输入理由", trigger: "blur" }],
});

//审核按钮
const checkSubmit = (formEl) => {
  if (!formEl) return;
  formEl.validate((valid, fields) => {
    if (valid) {
      request({
        url: "/aimooc/spjj/edit",
        data: {
          as_id: route.query.as_id,
          aimooc_spjj: {
            as_zy_shr_v2:user.value.user_realname,
            as_zy_shzt_v2: checkForm.value.result, //审核状态 ;radio;1|已通过,2|未通过,3|待审核
            as_zy_shbz_v2: checkForm.value.reason, //审核原因
          },
        },
      })
        .then((res) => {
          if (res.code == "1") {
            ElMessage({
              message: res.msg,
              type: "success",
            });
            dialogFormVisible_check.value = false;
            initData();
          }
        })
        .catch((err) => console.log(err));
    } else {
      console.log("error submit!", fields);
    }
  });
};
</script>

<template>
  <div>
    <div class="h-77px flex items-center justify-between bg-white px-20px">
      <div class="w-1/2 flex items-center justify-between">
        <div class="flex items-end">
          <el-icon class="mr-30px cursor-pointer" size="29" @click="handleBack">
            <ArrowLeftBold />
          </el-icon>
          <span class="text-24px mr-33px"> {{ detailInfo.as_title }}</span>
           <div class="text-16px">
            {{ detailInfo.as_zy_syxm_v2}}
          </div>
        </div>
      </div>

      <div>
        <el-button
          @click="checkDialog"
          v-if="detailInfo.as_zy_shzt_v2_option_k == '3'"
          type="primary"
          class="h-48px w-118px"
        >
          审核
        </el-button>
        <el-button v-else type="info" class="h-48px w-118px" disabled>
          已审核
        </el-button>
      </div>
    </div>
    <div class="h-full">
      <div class="mx-65px mt-28px rounded-24px">
        <div id="player-con" class="rounded-24px" />
      </div>
    </div>
    <el-dialog v-model="dialogFormVisible_check" title="审核" width="360px">
      <el-form
        :model="checkForm"
        ref="ruleFormRef"
        :rules="rules"
        label-position="top"
      >
        <el-form-item label="" :label-width="formLabelWidth" prop="result">
          <el-radio-group v-model="checkForm.result">
            <el-radio label="1">通过</el-radio>
            <el-radio label="2">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
        v-if="checkForm.result=='2'"
          label="备注描述："
          :label-width="formLabelWidth"
          prop="reason"
        >
          <el-input
            v-model="checkForm.reason"
            :autosize="{ minRows: 3 }"
            type="textarea"
          />
        </el-form-item>
      </el-form>
      <template #footer>      
          <el-button type="primary" class="w-full" size="large" @click="checkSubmit(ruleFormRef)"
            >确认</el-button
          >
      
      </template>
    </el-dialog>
  </div>
</template>

<route lang="json">
  {
    "meta":{
      "hidden": true,
      "hideLayout": true
    }
  }
</route>

<style lang="scss" scoped>
@use "~/styles/page.scss";
:deep {
  .is-checked .el-radio__inner {
    background: #fdcb9e;
    border-color: #fdcb9e;
  }
  .is-checked .el-radio__label {
    color: #fdcb9e;
  }
}
</style>
