<template>
<div class="volume-container">
  <div class="body scroll-view">
    <div class="head">
      <div class="bg"></div>
      <div class="cont">
        <div class="logo">
          <img :src="SvgLogo" />
        </div>
        <h1 v-if="data.topic.name">{{ data.topic.name }}</h1>
        <div class="des" v-if="data.topic.memo" v-html="data.topic.memo"></div>
      </div>
    </div>
    <transition-group name="list" class="volume-content" tag="ul">
      <li
        v-for="(item, index) in data.result"
        :key="index + 1">
        <p>
          <i :class="{cur: !!item.val && !!item.val.length}" />
          <label v-if="item.required">*</label>
          <span>{{index + 1}}. </span>
          <span>{{ item.title }}</span>
          <span v-if="item.type_name">【{{ item.type_name }}】</span>
        </p>
        <div :class="{'align-right': item.layout_align === 'right'}">

          <div class="slider-layout" v-if="item.type === 'slider'">
            <div class="val" v-if="item.val">{{ item.val }}</div>
            <div class="warn" v-else>拨动滑块选择</div>
            <van-slider
              v-model="item.sliderVal"
              :min="-1" 
              :max="item.content.length - 1"
              @input="item.val = (item.content[item.sliderVal] || {}).title || ''" />
            <div class="ruler-layout">
              <div class="ruler-item">
                <span>-</span>
              </div>
              <div class="ruler-item"
                v-for="(it, itIndex) in item.content"
                :key="itIndex">
                <span v-if="!it.sliderHide">{{ it.title }}</span>
              </div>
            </div>
          </div>

          <van-radio-group 
            v-model="item.val" 
            :direction="item.layout_inline === 2 ? 'vertical' : 'horizontal'"
            v-if="item.type === 'radio'">
            <van-radio
              :class="{ vertical: item.layout_inline === 2, horizontal: item.layout_inline === 1 }"
              :name="it.title" 
              v-for="(it, itIndex) in item.content" 
              :key="itIndex">{{ it.title }}</van-radio>
          </van-radio-group>

          <van-checkbox-group 
            v-model="item.val" 
            :direction="item.layout_inline === 2 ? 'vertical' : 'horizontal'"
            :max="item.max" 
            v-if="item.type === 'checkbox'">
            <van-checkbox 
              :class="{ vertical: item.layout_inline === 2, horizontal: item.layout_inline === 1 }"
              :name="it.title" 
              v-for="(it, itIndex) in item.content" 
              :key="itIndex" 
              shape="square">{{ it.title }}</van-checkbox>
          </van-checkbox-group>

          <textarea 
            v-model="item.val" 
            :maxlength="item.max || 200" placeholder="请填写" 
            v-if="item.type === 'textarea'" />

          <input v-model="item.val" 
            :maxlength="item.max || 200" 
            placeholder="请填写" 
            v-if="item.type === 'input'" />
        </div>
      </li>
    </transition-group>
    <slot name="tel" />
  </div>
  
  <div class="footer" v-if="!!data.result.length">
    <button class="btn primary" 
      :disabled="loading.submit || !data.result.length" 
      @click="$emit('submit')">提交</button>
  </div>

  <slot />
</div>
</template>

<script>
import SvgLogo from '~/svg/logo.svg'
export default {
  props: {
    data: {
      required: true,
      type: Object
    },
    loading: {
      required: true,
      type: Object
    }
  },
  data () {
    return {
      SvgLogo
    }
  }
}
</script>

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