<template>
  <view class="page">
		<navbar title="视频分享" leftClick @leftClick="$utils.navigateBack" />

    <view class="content">
      <uv-form 
        ref="form"
        :model="form"
        :rules="rules"
        labelPosition="left" 
        labelWidth="340rpx"
        :labelStyle="{
          color: '#1B1B1B',
          fontSize: '32rpx',
          fontWeight: 'bold',
        }"
      >
        <view class="flex upload__view">
          <view class="upload upload-cover">
            <uv-form-item labelWidth="0" prop="coverImageUrl">
              <formUpload  v-model="form.coverImageUrl">
                <template v-slot="{ value }">
                  <!-- todo: 默认 -->
                  <image 
                    :src="value" 
                    mode="aspectFill" 
                    style="width: 344rpx; height: 344rpx;"
                    radius="14rpx"
                  />
                </template>
              </formUpload>
              <view class="upload-cover-text flex">设置封面</view>
            </uv-form-item>
          </view>
          <view class="upload upload-video">
            <uv-form-item labelWidth="0" prop="videoUrl">
              <formUpload v-model="form.videoUrl">
                <template v-slot="{ value }">
                  <image v-if="value"
                    :src="form.videoUrl" 
                    mode="aspectFill" 
                    style="width: 344rpx; height: 344rpx;"
                    radius="14rpx"
                  />
                  <view v-else class="flex flex-column" style="width: 344rpx; height: 344rpx;">
                    <uv-icon name="camera" color="#000000" size="129rpx"></uv-icon>
                    <text class="upload-video-text">上传视频</text>
                  </view>
                </template>
              </formUpload>
            </uv-form-item>
          </view>
        </view>
        <view class="form-item">
          <uv-form-item label="标题" labelWidth="84rpx" prop="title">
            <view class="form-item-content">
              <formInput v-model="form.title" placeholder="请输入你的视频名称" width="584rpx"></formInput>
            </view>
          </uv-form-item>
        </view>
        <view class="form-item">
          <uv-form-item label="设置广告弹出时间（s）" prop="mins">
            <view class="form-item-content">
              <formNumberBox v-model="form.mins" ></formNumberBox>
            </view>
          </uv-form-item>
        </view>
        <view class="form-item">
          <uv-form-item label="设置转发次数（次）" prop="times">
            <view class="form-item-content">
              <formNumberBox v-model="form.times" ></formNumberBox>
            </view>
          </uv-form-item>
        </view>
        <view class="form-item">
          <uv-form-item label="选择二维码" prop="qrCode">
            <view class="form-item-content">
              <formUpload v-model="form.qrCode">
                <template v-slot="{ value }">
                  <view class="flex" style="min-width: 93rpx; height: 45rpx;">
                    <image 
                      :src="value" 
                      mode="aspectFill" 
                      style="width: 45rpx; height: 45rpx;"
                      radius="14rpx"
                    />
                    <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000" size="28rpx"></uv-icon>
                  </view>
                </template>
              </formUpload>
            </view>
          </uv-form-item>
        </view>
        <view class="form-item">
          <uv-form-item label="视频描述" prop="description" labelPosition="top">
            <view style="margin-top: 32rpx;">
              <formTextarea
                v-model="form.description" 
                placeholder="请描述你的视频"
              ></formTextarea>
            </view>
          </uv-form-item>
        </view>

      </uv-form>
    </view>

    <!-- 审核通过 -->
    <button v-if="auditStatus === 1" class="button-submit" @click="onPublish">
      发布
    </button>
    <!-- 不是 审核中 或 已发布 -> 即 创建分享 或 审核不通过 -->
    <button v-else-if="![0,2].includes(auditStatus)" class="button-submit" @click="onSubmit">
      提交审核
    </button>
  </view>
</template>

<script>
  import formUpload from '../components/formUpload.vue'
  import formInput from '../components/formInput.vue'
  import formNumberBox from '../components/formNumberBox.vue'
  import formTextarea from '../components/formTextarea.vue'

	export default {
    components: {
      formUpload,
      formInput,
      formNumberBox,
      formTextarea,
    },
		data() {
      return {
        id: null,
        auditStatus: null,
        form: {
          title: null,
          coverImageUrl: null,
          videoUrl: null,
          mins: 2,
          times: 10,
          qrCode: null,
          description: null,
        },
        rules: {
          // todo
        },
      }
    },
		onLoad(option) {
      const { id } = option

      this.id = id
      // todo: init data by id
		},
    methods: {
      onSubmit() {
        // todo

        const params = { ...this.form }
        
				this.$api('submitPersonalSharing', params)
      },
      onPublish() {
        // todo
      },
    }
  }

</script>

<style scoped lang="scss">
@import '../styles/pageForm.scss';

.upload__view {
  justify-content: space-between;
  margin-bottom: 20rpx;
}

.upload {
  background-color: $uni-fg-color;
  border-radius: 12rpx;
  overflow: hidden;
}

.upload-video {
  &-text {
    color: #1B1B1B;
    font-size: 32rpx;
  }
}

.upload-cover {
  position: relative;

  &-text {
    position: absolute;
    bottom: 0;
    width: 100%;
    background-color: rgba($color: #000000, $alpha: 0.6);
    color: #FFFFFF;
    padding: 21rpx 0;
  }
}

</style>