return {
  data: function() {
    return {
      /**提交作业信息*/
      dynamicValidateForm: {
          stuhoemjson: [{
              studenttitle: '',
              studentcontent:'',
              studenturl:'',
          }],
      },
      /**加载*/
      loading: true,
      loading2:true,
      /**上传文件类型*/
      fileType:'',
      /**获取班级作业信息*/
      classworkinfo:[],
      /**获取作业详情*/
      workinfo:[],
      /**作业附件类型*/
      accessorytype:'',
      /**作业类型*/
      worktype:'1',
      /**作业类型*/
      type:'',
      /**作业资料下载链接*/
      accurl:'',
      state: {},
      actionUrl:'',
      /**列表页详情页切换开关 */
      listFalg: true,
      /**搜索关键字 */
      key: "",
      /**作业tab切换*/
      screentype:'1',
      /**作业完成列表*/
      tableData:[],
      /**考试题库列表*/
      tableExamData: [],
      /**选择器默认值 */
      sort: "b.LastDate Desc",
      /**班级列表数据 */
      classList: [],
      /**详情数据 */
      /**作业列表 */
      homeworkList: [],
      /**课程列表 */
      courseList: [],
      coursefacelist: [],
      /**训练营列表 */
      trainList: [],
      /**问答列表 */
      askList: [],
      /**公告列表 */
      noticeList: [],
      /**班级详情 */
      classInfo: {},
      /**当前选中项 */
      activeName: "first",
      activeName1: 0,
      activeCourse: 0,
      /**总页数 */
      pageCount: null,
      /**当前页 */
      currentPage: 1,
      /**公告详情显示开关 */
      noticeDialogVisible: false,
      /**公告详情 */
      noticeDetail: {},
      /**作业详情开关 */
      homeworkDialogVisible: false,
      /**作业详情 */
      homeworkDetail: {},
      /*作业简介*/
      workcontent:''
    };
  },
  watch: {
    $route: {
      handler: function(val, oldVal){
        var that = this
        that.getMyWork();
      },
      deep: true
    }
  },
  methods: {
    // 上传
    uploaded:function(domain){
      this.viewFil(domain,domain.studenturl)
    },

    /**标签页点击回调 */
    handleClick: function(tab, event) {
      var that = this;
    },
    viewFil:function(domain,url) {
      var that = this;
      var onlineViewType = ['doc', 'docx', 'xls', 'xlsx', 'xlsm', 'ppt', 'pptx','txt','pdf']
      var fileTypeName = url.substring(url.lastIndexOf('.') + 1, url.length).split('?')[0]
      var isWord = onlineViewType.find((type) => type === fileTypeName)
     
      var ksType = ['jpg', 'png', 'mp3', 'mp4']
      var ksTypeName = url.substring(url.lastIndexOf('.') + 1, url.length).split('?')[0]
      var ksisWord = ksType.find((type) => type === ksTypeName)

      if (isWord) {
        if(url.indexOf('//') != 0 && url.indexOf('http') != 0){
          url = window.location.origin + url
        }
        url = 'http://ow365.cn/?i=22247&furl=' + url
        // url = 'https://api.idocv.com/view/url?url=http%3A%2F%2Fapi.idocv.com%2Fdata%2Fdoc%2Fmanual.docx'
        domain.previewUrl = url
        domain.urlDialogVisible = true
        // that.loading2 = false
      }else{
        switch (ksisWord) {
          case 'mp3' :
              domain.type2 = "音频";
              break;
          case 'mp4' :
              domain.type2 = "视频";
              break;
          case 'jpg' :
          case 'png' :
              domain.type2 = "图片";
              break;
        }
        domain.loadings = true
      }
    },
    resetItem:function(item,accessorytype){
      switch (accessorytype) {
        case 0 :
            item.type = "无类型";
            this.fileType = true
            break;
        case 1 :
            item.type = "图片";
            this.fileType = ".jpeg,.jpg";
            break;
        case  2 :
            item.type = "视频";
            this.fileType = ".mp4";
            break;
        case  3 :
            item.type = "音频";
            this.fileType = ".mp3";
            break;
        case  4 :
            item.type = "其他附件";
            this.fileType = ".doc,.docx,.pdf,.ppt,.pptx,.txt";
            break;
      }
      item.urlDialogVisible = false
      item.previewUrl = ''
      item.loadings = false
    },
    /** 我的作业*/
    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
            res.data[0].stuhoemjson.map(function(item){
              that.resetItem(item,res.accessorytype)
          })
          that.classworkinfo = res
          that.workinfo = res.data[0]
          that.dynamicValidateForm.stuhoemjson = res.data[0].stuhoemjson
          if(that.dynamicValidateForm.stuhoemjson != ''){
            if(that.dynamicValidateForm.stuhoemjson[0].studenturl != ''){
              var url = that.dynamicValidateForm.stuhoemjson[0].studenturl 
              that.viewFil(that.dynamicValidateForm.stuhoemjson[0],url)
            }
          }
        }
        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.$message.success("操作成功");
          } else {
            that.$message.error(res.msg);
          }
          // that.$router.go(-1)
        })
      }
    },
    // matchReg: function(str){
    //   var that = this
    //   let reg=/<\/?.+?\/?>/g;
    //   that.workcontent = str.replace(reg,'')
    //   // console.log(str.replace(reg,''))
    // },
    /**下载附件 */
    downloadFile: function(url, id) {
      this.oDownLoad(url, id);
    },
 
    /**打开作业 */
    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)
      }
    },
    /**获取学员作业*/
    getUserWork: function(){
      var that = this;
      var params = {
        studenttype: that.studenttype,
        apptoken: that.state.appToken,
        id:that.$route.query.id, //单独学生记录id
      }
      GetMyUserHomeWork(params).then(function(res){
        that.tableExamData = res.data[0]
        that.worktype = res.worktype
        console.log(that.worktype,111)
      })
    },
    addDomain:function() {
      var obj = {
        studenttitle: '',
        studentcontent:'',
        studenturl:'',
        key: Date.now()
      }
      this.resetItem(obj,this.accessorytype)
      this.dynamicValidateForm.stuhoemjson.push(obj);
    },
  },
  mounted: function() {
    var that = this;
    that.$store.ready(function(state) {
      that.state = state;
      that.actionUrl = '/webapi/School/UploadFile?userid='+ state.userId+'&apptoken='+ state.appToken
    });
    that.getMyWork();
    that.getUserWork()
  }
};
