<template>
  <div id="homework">
    <el-row>
      <el-col :span="24" class="list">
        <van-collapse v-model="openCollapse" accordion>
          <van-collapse-item :name="index" v-for="(item, index) in list" :key="index">
            <div slot="title" class="title">
              <span class="name">{{ item.name }}</span>
            </div>
            <van-row v-for="(tag, index) in item.lesson" :key="index">
              <el-col :span="18">
                <van-col :span="24" class="score"> 名称：{{ tag.lessonname }} </van-col>
                <van-col :span="24" class="score"> 作业分： {{ tag.score }}分</van-col>
              </el-col>
              <el-col :span="6" class="anniu">
                <van-button v-if="user.job == '学委'" type="primary" size="mini" @click="clickBtn(tag.id, tag.lessonname, tag.score)">上成绩</van-button>
              </el-col>
            </van-row>
          </van-collapse-item>
        </van-collapse>
      </el-col>
    </el-row>
    <van-dialog v-model="show" @before-close="closeDialog" title="学生成绩上传" :showConfirmButton="false" show-cancel-button>
      <van-form @submit="onSubmit">
        <span class="lesson">课程名称</span><span class="lesson">{{ form.name }}</span>
        <van-field v-model="form.score" name="作业分数" label="作业分数" placeholder="请输入作业分数" />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">
            提交
          </van-button>
        </div>
      </van-form>
    </van-dialog>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
export default {
  name: 'homework',
  props: {
    list: null,
  },
  components: {},
  data: () => ({
    ruleForm: {
      region: '',
      lesson: [],
    },
    show: false,
    dscore: 0,
    form: {},
    value: '',
    openCollapse: [],
  }),
  created() {},
  computed: { ...mapState(['user']) },
  methods: {
    clickcds(index) {
      this.openCollapse = index;
    },
    clickBtn(id, name, score) {
      this.form = { id, name, score };
      this.dscore = score;
      this.show = true;
    },
    onSubmit() {
      this.$emit('submit', { data: this.form });
      this.closeDialog();
    },
    closeDialog() {
      this.form = {};
      this.show = false;
      this.dscore = 0;
    },
  },
};
</script>

<style lang="less" scoped>
p {
  padding: 0;
  margin: 0;
}
.list {
  margin: 5px;
  width: 97%;
  padding: 0 10px;
  border-radius: 15px;
}
.list .title {
  float: left;
  width: 100%;
}
.list .name {
  float: left;
  width: 80%;
  font-size: 20px;
}
/deep/.van-cell {
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}
/deep/.van-collapse-item__content {
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  padding: 5px 10px;
}
/deep/.van-collapse-item {
  margin: 0 0 10px 0;
}
/deep/.el-collapse-item__content {
  padding: 10px 0 10px 0;
}
.list .score {
  padding: 5px 0;
  font-size: 18px;
}
.anniu {
  padding: 20px 0 0 0;
}
.lesson {
  font-size: 14px;
  padding: 0 21px 0 16px;
  color: #323233;
}
</style>
