"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_http = require("../../utils/http.js");
const apis_videos = require("../../apis/videos.js");
require("../../utils/Auth.js");
if (!Array) {
  const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload");
  const _easycom_up_notify2 = common_vendor.resolveComponent("up-notify");
  (_easycom_up_upload2 + _easycom_up_notify2)();
}
const _easycom_up_upload = () => "../../node-modules/uview-plus/components/u-upload/u-upload.js";
const _easycom_up_notify = () => "../../node-modules/uview-plus/components/u-notify/u-notify.js";
if (!Math) {
  (_easycom_up_upload + _easycom_up_notify)();
}
const _sfc_main = {
  __name: "uploadVideo",
  setup(__props) {
    const fileList1 = common_vendor.reactive([]);
    const uNotifyRef = common_vendor.ref(null);
    const deletePic = (event) => {
      fileList1.splice(event.index, 1);
    };
    const afterRead = async (event) => {
      let lists = [].concat(event.file);
      for (let item of lists) {
        fileList1.push({
          ...item,
          status: "uploading",
          message: "上传中"
        });
        console.log("开始上传");
        try {
          console.log(item);
          let res = await utils_http.uploadFile(item.url);
          res = JSON.parse(res);
          console.log("上传图片结果", res);
          fileList1[fileList1.length - 1].status = "done";
          fileList1[fileList1.length - 1].url = res.url;
          state.imageUrl = res.url;
        } catch (error) {
          console.error("上传图片失败", error);
          fileList1[fileList1.length - 1].status = "failed";
          fileList1[fileList1.length - 1].message = "上传失败";
        }
      }
    };
    const state = common_vendor.reactive({
      title: "",
      description: "",
      content: "",
      imageUrl: ""
    });
    const publish = async () => {
      const data = {
        title: state.title,
        description: state.description,
        // content: state.content,
        videoUrl: state.imageUrl
      };
      console.log("发布内容:", data);
      let res = await apis_videos.saveVideosInfo(data);
      if (res.code == 200) {
        uNotifyRef.value.show({
          top: 10,
          type: "error",
          color: "#000",
          bgColor: "#e8e8e8",
          message: "Hi uview-plus",
          duration: 1e3 * 3,
          fontSize: 20,
          safeAreaInsetTop: true
        });
      }
      resetForm();
    };
    const resetForm = () => {
      fileList1.splice(0, fileList1.length);
      state.title = "";
      state.description = "";
      state.content = "";
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.o(afterRead),
        b: common_vendor.o(deletePic),
        c: common_vendor.p({
          fileList: fileList1,
          name: "1",
          multiple: true,
          maxCount: 1,
          previewFullImage: true,
          width: "400rpx",
          height: "300rpx",
          accept: "video"
        }),
        d: state.title,
        e: common_vendor.o(($event) => state.title = $event.detail.value),
        f: state.content,
        g: common_vendor.o(($event) => state.content = $event.detail.value),
        h: common_vendor.o(publish),
        i: common_vendor.sr(uNotifyRef, "4f3ecb6a-1", {
          "k": "uNotifyRef"
        }),
        j: common_vendor.p({
          message: "Hi uview-plus"
        })
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4f3ecb6a"], ["__file", "D:/uniapp1/gree_leran/pages/uploadVideo/uploadVideo.vue"]]);
wx.createPage(MiniProgramPage);