<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="style">
        <el-form ref="form" :model="form">
          <el-col :span="24" class="topTitle">
            {{ task.name }}
          </el-col>
          <el-col :span="24" v-for="(item, index) in task.question" :key="index">
            <el-form-item>
              <span slot="label">{{ index + 1 }} . {{ item.topic }}</span>
            </el-form-item>
            <template v-if="item.type === '0'">
              <el-col :span="24" v-for="(items, index) in item.option" :key="index">
                <el-radio v-model="item.answer" :label="items.opname">{{ items.opname }}</el-radio>
              </el-col>
            </template>
            <template v-else-if="item.type === '1'">
              <el-checkbox-group v-model="item.answer">
                <el-col :span="24" v-for="(items, index) in item.option" :key="index">
                  <el-checkbox :label="items.opname">{{ items.opname }}</el-checkbox>
                </el-col>
              </el-checkbox-group>
            </template>
            <span v-else>
              <el-input
                type="textarea"
                placeholder="请输入内容"
                v-model="item.answer"
                :autosize="{ minRows: 4, maxRows: 6 }"
                maxlength="300"
                show-word-limit
              ></el-input>
            </span>
          </el-col>
          <el-col :span="24" class="btn">
            <el-button type="primary" @click="onSubmit">提交</el-button>
          </el-col>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import _ from 'lodash';
export default {
  name: 'index',
  props: {
    info: { type: Object, required: true },
    form: null,
  },
  components: {},
  data: () => ({
    task: {},
  }),
  created() {},
  computed: {},
  methods: {
    onSubmit() {
      this.$emit('submit', this.task);
    },
  },
  watch: {
    info: {
      handler(val) {
        if (_.get(val, `id`)) this.$set(this, `task`, val);
      },
      immediate: true,
      deep: true,
    },
  },
};
</script>
<style lang="less" scoped>
.style {
  min-height: 300px;
  padding: 0 40px;
}
.topTitle {
  text-align: center;
  height: 50px;
  line-height: 50px;
  border-bottom: 1px dashed #333;
}
/deep/.el-form-item {
  margin: 0;
}
/deep/.el-form-item__label {
  color: #389ff0;
}
.btn {
  text-align: center;
  padding: 30px 0;
  margin: 0 0 20px 0;
}
</style>
