return {
  data: function() {
    return {
      info:{
        list: []
      },
      /**提交作业信息*/
      dynamicValidateForm: {
          stuhoemjson: [{
              studenttitle: '',
              studentcontent:'',
              studenturl:{
                list: []
              },
          }],
      },
      limits:1,
      accessoryurl:{},
      previewType:'',
      userpreviewType:'',
      /**加载*/
      loading: true,
      loading2: true,
      /**上传文件类型*/
      fileType:'',
      /**获取班级作业信息*/
      classworkinfo:[],
      /**获取作业详情*/
      workinfo:[],
      /**作业附件类型*/
      accessorytype:'',
      /**学生上传作业类型*/
      useraccessorytype:'',
      /**作业类型*/
      worktype:'1',
      /**作业类型*/
      type:'',
      /**作业资料下载链接*/
      accurl:'',
      state: {},
      actionUrl:'/webapi/School/UploadFile?isadmin=1',
      /**搜索关键字 */
      key: "",
      /**作业tab切换*/
      screentype:'1',
      /**作业完成列表*/
      tableData:[],
      /**考试题库列表*/
      tableExamData:[],
      /**班级列表数据 */
      classList: [],
      /**作业列表 */
      homeworkList: [],
      /**总页数 */
      pageCount: null,
      /**当前页 */
      currentPage: 1,
      /**作业详情 */
      homeworkDetail: {},
      /*作业简介*/
      workcontent:'',
      /*上传位置*/
      indexdat:0
    };
  },
  // watch: {
  //   $route: {
  //     handler: function(val, oldVal){
  //       var that = this
  //       that.getMyWork();
  //     },
  //     deep: true
  //   }
  // },
  activated: function() {
    var that = this;
    that.$store.ready(function(state) {
      that.state = state;
      that.getMyWork();
      that.getUser()
    });
  },
  methods: {
    /**标签页点击回调 */
    handleClick: function(tab, event) {
      var that = this;
    },
    userresetItem:function(item,useraccessorytype){
      var _this = this
      switch (useraccessorytype) {
        case '1' :
            item.type = "图片";
            _this.fileType = ".jpg,.png,.gif";
            _this.userpreviewType = 'image'
            _this.limits = 9
            break;
        case  '2' :
            item.type = "视频";
            _this.fileType = ".mp4";
            _this.userpreviewType = 'video'
            _this.limits = 1
            break;
        case  '3' :
            item.type = "音频";
            _this.fileType = ".mp3";
            _this.userpreviewType = 'audio'
            _this.limits = 1
            break;
        case  '4' :
            item.type = "其他附件";
            _this.fileType = ".doc,.docx,.pdf,.ppt,.pptx,.txt";
            _this.userpreviewType = 'word'
            _this.limits = 1
            break;
      }
      item.urlDialogVisible = false
      item.previewUrl = ''
      item.loadings = false
    },
    resetItem:function(accessorytype){
      var _this = this
      switch (accessorytype) {
        case 1 :
            _this.previewType = 'image'
            break;
        case  2 :
          _this.previewType = 'video'
            break;
        case  3 :
            _this.previewType = 'audio'
            break;
        case  4 :
            _this.previewType = 'word'
            break;
      }
    },
    /** 我的作业*/
    getMyWork:function(){
      var that = this
      var params = {
        // worklistid ,	//	绑定作业ID
        id:this.$route.query.id, //单独学生记录id
      }
      GetHomeworkUserdetails(params).then(function(res){
        if(res.data && res.data[0]){
            that.accessorytype = res.accessorytype
            that.useraccessorytype = res.useraccessorytype
            res.data[0].stuhoemjson.map(function(item){
              that.resetItem(res.accessorytype)
              that.userresetItem(item,res.useraccessorytype)
          })
          that.classworkinfo = res
          that.workinfo = res.data[0]
          that.dynamicValidateForm.stuhoemjson = res.data[0].stuhoemjson
        }
        that.worktype = res.worktype
        that.accessoryurl = res.accessoryurl
        that.loading = false
      })
    },
    //保存作业草稿
    submitForm:function(formName,type) {
      var _this = this
      _this.$refs[formName].validate(function(valid){
        if (valid) {
          _this.UpdatekUserList(type)
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    UpdatekUserList: function(type){ 
      var that = this
      var params = {
        id:that.$route.query.id,
        stuhoemjson:that.dynamicValidateForm.stuhoemjson
      }
      if(type == 1){
        UpdateStudentHomeworkUserList(params).then(function(res){
          if (res.result === true) {
            that.$message.success("操作成功");
          } else {
            that.$message.error(res.msg);
          }
          // that.$router.go(-1)
        })
      }else{
        SaveStudentHomeworkUserList(params).then(function(res){
          if (res.result === true) {
            that.$confirm('提交成功,是否继续作答?', '提示', {
              confirmButtonText: '继续作答',
              cancelButtonText: '返回作业列表',
              type: 'warning'
            }).then(function(){
               
            }).catch(function(){
              that.$router.push({path: `/user/mywork`})
            });
          } else {
            that.$message.error(res.msg);
          }
          // that.$router.go(-1)
        })
      }
    },
    /**下载附件 */
    downloadFile: function(url, id) {
      this.oDownLoad(url, id);
    },
    //获取上传的index
    gelindex:function(index){
      this.indexdat = index
    },
    //上传
    handleRemove:function(file, fileList) {
      // this.accessoryurllist = fileList
    },
    handleAvatarSuccess:function(res, file ,fileList) {
      var _this = this
      console.log(res, file ,fileList,'previewType')
      if(_this.userpreviewType == 'image'){
        if(_this.dynamicValidateForm.stuhoemjson[_this.indexdat].studenturl.list.length >= 9){
          this.$message.warning(`最多只能上传9张图片~`);
        }else{
          _this.dynamicValidateForm.stuhoemjson[_this.indexdat].studenturl.list.push({
            src:res.fileUrl
          })
        }
      }else{
        if(_this.dynamicValidateForm.stuhoemjson[_this.indexdat].studenturl.list.length > 0){
          this.$message.warning(`最多只能上传1个文件~`);
        }else{
          _this.dynamicValidateForm.stuhoemjson[_this.indexdat].studenturl.list.push({
            src:res.fileUrl
          })
        }
      }
    },
    beforeAvatarUpload:function(file,fileList) {
      var that = this
      if(that.fileType != '*'){
          var isJPG = file.type === that.fileType;
          var isLt30M = file.size / 1024 / 1024 < 300;
          if (!isLt30M) {
              that.$message.error('上传文件大小不能超过 300MB!');
              that.imageUrl = ''
          }
          if(isJPG){
              that.$message.error('上传文件只能是' + that.fileType + '格式!');
              return false;
          }
      }
    },
    // handleExceed:function(files, fileList) {
    //   var _this = this
    //   this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    // },
    /**覆盖默认行为*/
    uploadSectionFile:function(){

    },
    /**打开作业 */
    openHomework: function(item) {
      this.homeworkDialogVisible = true;
      this.homeworkDetail = item;
    },
    resetForm:function resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //删除作业
    removeDomain: function(item) {
      var that = this;
      var index = that.dynamicValidateForm.stuhoemjson.indexOf(item)
      if (index !== -1) {
          that.dynamicValidateForm.stuhoemjson.splice(index, 1)
      }
    },
    /**获取学员作业*/
    getUser: function(){
      var that = this;
      that.loading = true
      var _id = this.$route.query.id;
      var params = {
        id:_id, 
        screentype: '-1',
        apptoken:that.state.appToken,
      }
      GetMyUserHomeWork(params).then(function(res){
        that.tableExamData = []
        res.data.map(function(item){
          that.tableExamData.push({
            papername:item.papername,
            papercount:item.papercount,
            score:item.score,
            paperdocount:item.paperdocount,
            worktypeurl:item.worktypeurl,
            workname:item.workname,
            papersumscore:item.papersumscore,
          })
        })
      })
      that.loading = false
    },
    addDomain:function() {
      var obj = {
        studenttitle: '',
        studentcontent:'',
        studenturl:{
          list:[]
        },
        key: Date.now()
      }
      this.resetItem(obj,this.accessorytype)
      this.dynamicValidateForm.stuhoemjson.push(obj);
    },
    getlist:function(val){

    }
  }
};
