<template>
  <view class="page__view">
		<navbar title="问卷测评" leftClick @leftClick="$utils.navigateBack" color="#191919" bgColor="transparent" />

    <view class="main">
      <view class="title">
        <view class="title-zh">{{ detail.title }}</view>
        <view class="title-en">{{ detail.enTitle }}</view>
      </view>
      <view class="flex desc">
        <view class="dot"></view>{{ detail.tips }}
      </view>
    </view>

    <view class="footer">
      <view class="agreement">
				<uv-checkbox-group
					v-model="checkboxValue"
					shape="circle"
				>
					<uv-checkbox
						size="40rpx"
						icon-size="40rpx"
						activeColor="#7451DE"
						:name="1"
					></uv-checkbox>
				</uv-checkbox-group>
				<view class="desc">
          我已阅读并同意
					<text class="highlight" @click="$refs.modal.open('user_agreement', '用户协议')">《用户协议》</text>
					<text class="highlight" @click="$refs.modal.open('privacy_policy', '隐私协议')">《隐私协议》</text>
				</view>
			</view>
      <view class="bar">
        <button class="btn" @click="onStart">开始答题</button>
      </view>
    </view>

		<agreementModal ref="modal" @confirm="onConfirmAgreement"></agreementModal>

  </view>
</template>

<script>
	import { mapState } from 'vuex'
	import agreementModal from '@/pages_order/components/agreementModal.vue'

  export default {
    components: {
      agreementModal,
    },
    data() {
      return {
        id: null,
        detail: {},
        checkboxValue : []
      }
    },
		computed: {
			...mapState(['paperInfo']),
    },
    onLoad(arg) {
      const { id } = arg

      this.id = id

      this.getData(id)
    },
    methods: {
      async getData(id) {
        try {
          this.detail = await this.$fetch('getPaperDetail', { id })
        } catch (err) {

        }
      },
      async onStart(){
        if(!this.checkboxValue.length){
          return uni.showToast({
            title: '请先同意《用户协议》《隐私协议》',
            icon:'none'
          })
        }

        try {

          const reportId = await this.$fetch('startPaper', { id: this.id })
          this.detail.reportId = reportId
          this.$store.commit('setPaperInfo', this.detail)
          const defaultPaperTags = this.detail.category.map(category => {
            return category.questionsList.map(() => [])
          })
          this.$store.commit('setPaperTags', defaultPaperTags)

          this.$utils.navigateTo('/pages_order/report/test/step?step=0')
        } catch (err) {

        }
        
      },
      onConfirmAgreement(confirm) {
        if (confirm) {
          this.checkboxValue = [1]
        } else {
          this.checkboxValue = []
        }
      },
    },
  }
</script>

<style scoped lang="scss">
	.page__view {
		width: 100vw;
		min-height: 100vh;
		background-color: $uni-bg-color;
		position: relative;
	}

  .main {
    margin-top: 448rpx;

    .title {
      text-align: center;
      font-family: PingFang SC;
      line-height: 1.4;
      color: #252545;

      &-zh {
        font-size: 48rpx;
        font-weight: 600;
      }

      &-en {
        font-size: 26rpx;
        font-weight: 400;
      }
    }

    .desc {
      margin-top: 48rpx;
      text-align: center;
      font-size: 28rpx;
      font-weight: 400;
      font-family: PingFang SC;
      line-height: 1.4;
      color: #989898;

      .dot {
        display: inline-block;
        width: 10rpx;
        height: 10rpx;
        border-radius: 50%;
        background: #989898;
        margin-right: 20rpx;
      }
    }
  }

  .footer {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;

    .agreement {
      display: flex;
      padding: 16rpx 40rpx;
      background: #EFEAFF;

      /deep/ .uv-checkbox-group {
        flex: none;
      }

      .desc {
        flex: 1;
        font-family: PingFang SC;
        font-size: 24rpx;
        font-weight: 400;
        line-height: 40rpx;
        color: #8B8B8B;
      }

      .highlight {
        color: $uni-color;
      }
    }

    .bar {
      padding: 24rpx 40rpx;
		  padding-bottom: calc(env(safe-area-inset-bottom) + 24rpx);
      box-sizing: border-box;
      // height: 200rpx;
      background: #FFFFFF;

      .btn {
        padding: 16rpx 0;
        font-family: PingFang SC;
        font-weight: 600;
        font-size: 36rpx;
        line-height: 1.2;
        color: #FFFFFF;
        background-image: linear-gradient(to right, #4B348F, #845CFA);
        border-radius: 42rpx;
      }
    }
  }
</style>