|
@@ -1,400 +1,566 @@
|
|
|
<template>
|
|
|
- <div class="component-hw-form">
|
|
|
- <Form ref="hwForm" :model="hwForm" label-position="top" :rules="ruleValidate" :disabled="!hwFormEdit">
|
|
|
- <FormItem label="作业名称" prop="name">
|
|
|
- <Input :class="!hwFormEdit ? 'hw-form-disabled':''" v-model="hwForm.name" placeholder="请输入作业名称"></Input>
|
|
|
- </FormItem>
|
|
|
- <FormItem label="" prop="other">
|
|
|
- <CheckboxGroup v-model="hwForm.other">
|
|
|
- <Checkbox label="view">开放观摩</Checkbox>
|
|
|
- <Checkbox label="comment">开放互评</Checkbox>
|
|
|
- </CheckboxGroup>
|
|
|
- </FormItem>
|
|
|
- <FormItem label="作业对象" prop="target">
|
|
|
- <Select multiple v-model="hwForm.target" :class="!hwFormEdit ? 'hw-form-disabled':''" placeholder="请选择作业发布对象">
|
|
|
- <OptionGroup label="个人班级">
|
|
|
- <Option v-for="item in classRooms.filter(i=>i.scope === 'private')" :value="item.id" :key="item.id">{{ item.name }}</Option>
|
|
|
- </OptionGroup>
|
|
|
- <OptionGroup label="校本班级">
|
|
|
- <Option v-for="item in classRooms.filter(i=>i.scope === 'school')" :value="item.id" :key="item.id">{{ item.name }}</Option>
|
|
|
- </OptionGroup>
|
|
|
- </Select>
|
|
|
- </FormItem>
|
|
|
- <FormItem label="发布时间" prop="publishModel">
|
|
|
- <RadioGroup v-model="hwForm.publishModel" v-show="hwFormEdit">
|
|
|
- <Radio label="0" :disabled="currentState !== 100 && !isAdd">立即发布</Radio>
|
|
|
- <Radio label="1" :disabled="currentState !== 100 && !isAdd">定时发布</Radio>
|
|
|
- </RadioGroup>
|
|
|
-
|
|
|
- <DatePicker type="datetime"
|
|
|
- :class="!hwFormEdit ? 'hw-form-disabled':''"
|
|
|
- :editable="isDateEdit"
|
|
|
- :disabled="(currentState !== 100 && !isAdd) || hwForm.publishModel === '0'"
|
|
|
- placeholder="请选择发布时间"
|
|
|
- v-model="hwForm.startTime"
|
|
|
- style="margin-top:10px"></DatePicker>
|
|
|
-
|
|
|
- </FormItem>
|
|
|
-
|
|
|
- <FormItem label="结束时间" prop="endTime">
|
|
|
- <DatePicker :class="!hwFormEdit ? 'hw-form-disabled':''" type="datetime" :editable="isDateEdit && hwForm.startTime" placeholder="请选择作业结束时间" v-model="hwForm.endTime" :options="endTimeOptions"></DatePicker>
|
|
|
- </FormItem>
|
|
|
-
|
|
|
- <!-- <FormItem label="起止时间" prop="endTime">
|
|
|
- <DatePicker type="datetimerange" @on-change="onDateRangeChange" placeholder="Select date and time" style="width: 300px"></DatePicker>
|
|
|
- </FormItem> -->
|
|
|
-
|
|
|
- <FormItem label="作业描述" prop="description">
|
|
|
- <!-- <div ref="descriptionEditor" style="text-align:left" v-show="hwFormEdit"></div> -->
|
|
|
- <Input v-model="hwForm.description" type="textarea" placeholder="" :class="!hwFormEdit ? 'hw-form-disabled':''" v-show="hwFormEdit"/>
|
|
|
- <div v-html="hwForm.description" v-show="!hwFormEdit" style="margin:10px;font-size:16px;font-weight:bold;color:#fff"></div>
|
|
|
- <!--<Input v-model="hwForm.description" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入作业内容描述">--></Input>
|
|
|
- </FormItem>
|
|
|
-
|
|
|
- <FormItem label="作业附件" prop="attachment" v-show="hwFormEdit" style="position:relative">
|
|
|
- <span class="btn-choose-content" @click="onRelateContent">关联内容</span>
|
|
|
- <UploadFile ref="uploadRef"
|
|
|
- @successData="getFileUrl"
|
|
|
- :uploadUrl="uploadUrl"
|
|
|
- :defaultFileList="defaultFileList"
|
|
|
- :pathName="userInfo.TEAMModelId.replace('#','')"
|
|
|
- :quality="1"></UploadFile>
|
|
|
- </FormItem>
|
|
|
-
|
|
|
- <FormItem label="作业附件" v-show="!hwFormEdit">
|
|
|
- <div v-for="item in defaultFileList" :key="item.id" style="margin:10px 0">
|
|
|
- <span><Icon type="md-checkmark" color="#1BC6B0" size="20" /></span>
|
|
|
- <span style="margin-left:10px">{{ item.fileName }}</span>
|
|
|
- </div>
|
|
|
- <span v-show="!defaultFileList.length" style="margin-left:10px">暂无数据</span>
|
|
|
- </FormItem>
|
|
|
-
|
|
|
- <FormItem label="作业记录" prop="isReset" v-show="editable && isEdit">
|
|
|
- <CheckboxGroup v-model="hwForm.isReset">
|
|
|
- <Checkbox label="reset">清空作业提交记录</Checkbox>
|
|
|
- </CheckboxGroup>
|
|
|
- </FormItem>
|
|
|
-
|
|
|
- <FormItem v-show="hwFormEdit">
|
|
|
- <Button type="primary" class="btn-save" @click="handleSubmit('hwForm')" :loading="isBtnLoading">保存</Button>
|
|
|
- <Button @click="handleCancel('hwForm')" class="btn-reset" style="margin-left: 8px">取消</Button>
|
|
|
- </FormItem>
|
|
|
- </Form>
|
|
|
-
|
|
|
- <!-- 关联内容弹窗 -->
|
|
|
- <Modal v-model="isRelatedContent" width="880" footer-hide class="relate-modal related-modal">
|
|
|
- <div class="modal-header" slot="header">内容关联</div>
|
|
|
- <ChooseContent :showSyllabus="isFalse"
|
|
|
- :showOther="isFalse"
|
|
|
- :showQuestion="isFalse"
|
|
|
- @on-file-change="onSelectFile"></ChooseContent>
|
|
|
-
|
|
|
- <Button class="modal-btn" :loading="isLoading" @click="onConfirmRelate">确认</Button>
|
|
|
- </Modal>
|
|
|
- </div>
|
|
|
+ <div class="component-vote-form light-iview-form light-el-input">
|
|
|
+ <Form ref="voteForm" :model="voteForm" label-position="top" :rules="ruleValidate" :disabled="!voteFormEdit"
|
|
|
+ hide-required-mark>
|
|
|
+ <FormItem :label="$t('homework.form.name')" prop="name">
|
|
|
+ <Input :class="!voteFormEdit ? 'vote-form-disabled':''" v-model="voteForm.name"
|
|
|
+ :placeholder="$t('homework.form.namePlace')"></Input>
|
|
|
+ </FormItem>
|
|
|
+ <FormItem :label="$t('homework.form.target')" prop="classes">
|
|
|
+ <!-- 预览状态 -->
|
|
|
+ <div v-if="!voteFormEdit && curVoteItem" class="vote-class">
|
|
|
+ <span v-for="item in classNameArr" class="vote-class-item">{{ item.name }}</span>
|
|
|
+ </div>
|
|
|
+ <!-- 编辑状态 -->
|
|
|
+ <div v-else>
|
|
|
+ <BaseClassSelectPri :classes="classTargets" :scope="classType" @onChange="onTargetChange"
|
|
|
+ ref="classSelectRef" v-if="getCurScope === 'private' && curVoteItem"></BaseClassSelectPri>
|
|
|
+ </div>
|
|
|
+ </FormItem>
|
|
|
+ <FormItem :label="$t('learnActivity.createEv.startTime')" v-if="!isImmediate || !voteFormEdit"
|
|
|
+ prop="startTime">
|
|
|
+ <DatePicker v-show="voteFormEdit" type="datetime" :options="startOption" format="yyyy/MM/dd HH:mm"
|
|
|
+ v-model="voteForm.startTime" split-panels :placeholder="$t('learnActivity.createEv.sTimeHolder')"
|
|
|
+ style="width:100%" @on-change="onChangeSTime"></DatePicker>
|
|
|
+ <div v-show="!voteFormEdit" style="margin:10px;font-size:16px;font-weight:bold;">
|
|
|
+ {{ $tools.formatTime(voteForm.startTime,'yyyy-MM-dd hh:mm') }}
|
|
|
+ </div>
|
|
|
+ </FormItem>
|
|
|
+ <FormItem :label="$t('learnActivity.createEv.endTime')" prop="endTime">
|
|
|
+ <DatePicker v-show="voteFormEdit" type="datetime" :options="endOption" format="yyyy/MM/dd HH:mm"
|
|
|
+ v-model="voteForm.endTime" split-panels @on-change="onChangeEndTime"
|
|
|
+ :placeholder="$t('learnActivity.createEv.eTimeHolder')" style="width:100%"></DatePicker>
|
|
|
+ <div v-show="!voteFormEdit" style="margin:10px;font-size:16px;font-weight:bold;">
|
|
|
+ {{ $tools.formatTime(voteForm.endTime,'yyyy-MM-dd hh:mm') }}
|
|
|
+ </div>
|
|
|
+ </FormItem>
|
|
|
+
|
|
|
+ <FormItem :label="$t('homework.form.description')" prop="description">
|
|
|
+ <div ref="descriptionEditor" style="text-align:left" v-show="voteFormEdit"></div>
|
|
|
+ <div v-html="voteForm.description" v-show="!voteFormEdit"
|
|
|
+ style="margin:10px;font-size:16px;font-weight:bold;"></div>
|
|
|
+ </FormItem>
|
|
|
+
|
|
|
+
|
|
|
+ <FormItem :label="$t('homework.form.attachments')">
|
|
|
+ <BaseUpload simpleUpload v-show="voteFormEdit"></BaseUpload>
|
|
|
+ <div class="attachments-list">
|
|
|
+ <div class="attachments-item" v-for="(item,index) in attachmentsArr" :key="index">
|
|
|
+ <span class="name">{{ item.name }}</span>
|
|
|
+ <span class="name">{{ getSizeByBytes(item.size) }}</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </FormItem>
|
|
|
+
|
|
|
+ <FormItem :label="$t('homework.form.other')">
|
|
|
+ <!-- <CheckboxGroup v-model="voteForm.allowSupply">
|
|
|
+ <Checkbox label="allowSupply">{{ $t('homework.form.allowFix') }}</Checkbox>
|
|
|
+ </CheckboxGroup>
|
|
|
+ <CheckboxGroup v-model="voteForm.typeLimit">
|
|
|
+ <Checkbox label="typeLimit">{{ $t('homework.form.allowFileType') }}</Checkbox>
|
|
|
+ </CheckboxGroup> -->
|
|
|
+ </FormItem>
|
|
|
+
|
|
|
+ <FormItem v-show="voteFormEdit">
|
|
|
+ <Button type="primary" class="btn-save" @click="handleSubmit('voteForm')"
|
|
|
+ :loading="isBtnLoading">{{ $t('homework.form.save') }}</Button>
|
|
|
+ <Button @click="handleCancel('voteForm')" class="btn-reset"
|
|
|
+ style="margin-left: 8px">{{ $t('homework.form.cancel') }}</Button>
|
|
|
+ </FormItem>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
<script>
|
|
|
- import E from '@/utils/wangEditor.js'
|
|
|
- import UploadFile from '@/common/UploadFile.vue'
|
|
|
- import ChooseContent from '@/components/selflearn/NewChooseContent'
|
|
|
- export default {
|
|
|
- props: {
|
|
|
- editItem: {
|
|
|
- default: null,
|
|
|
- type: Object
|
|
|
- },
|
|
|
- editable: {
|
|
|
- default: false,
|
|
|
- type: Boolean
|
|
|
- }
|
|
|
- },
|
|
|
- components: { UploadFile, ChooseContent },
|
|
|
- data() {
|
|
|
- return {
|
|
|
- isFalse:false,
|
|
|
- isLoading:false,
|
|
|
- isRelatedContent:false,
|
|
|
- isAdd:true,
|
|
|
- isEdit: false,
|
|
|
- isBtnLoading: false,
|
|
|
- isDateEdit: false,
|
|
|
- hwFormEdit:false,
|
|
|
- currentState:0,
|
|
|
- editInfo: null,
|
|
|
- userInfo:this.$store.state.userInfo,
|
|
|
- descriptionEditor: null,
|
|
|
- classRooms: [],
|
|
|
- uploadFileList: [],
|
|
|
- defaultFileList: [],
|
|
|
- relateFileList:[],
|
|
|
- uploadUrl:'',
|
|
|
- defaultConfig: {
|
|
|
- showLinkImg: false, // 是否展示网络图片链接上传
|
|
|
- uploadFileName: 'files', // 上传图片后台获取的文件名
|
|
|
- menus:this.$tools.wangEditorMenuSimple
|
|
|
-
|
|
|
- },
|
|
|
- hwForm: {
|
|
|
- name: '',
|
|
|
- target: [],
|
|
|
- endTime: '',
|
|
|
- publishModel:'0',
|
|
|
- startTime:'',
|
|
|
- description: '',
|
|
|
- isReset:[],
|
|
|
- other: []
|
|
|
- },
|
|
|
- defaultParams: {
|
|
|
- code: "",
|
|
|
- name: "",
|
|
|
- target: [],
|
|
|
- publishModel: "0",
|
|
|
- startTime: 0,
|
|
|
- endTime: 0,
|
|
|
- resource: []
|
|
|
- },
|
|
|
- uploadList:[],
|
|
|
- endTimeOptions: {
|
|
|
- disabledDate : date => {
|
|
|
- return date && date.valueOf() < this.getDisableDays;
|
|
|
+ import E from 'wangeditor'
|
|
|
+ export default {
|
|
|
+ props: {
|
|
|
+ editItem: {
|
|
|
+ type: Object,
|
|
|
+ default: null
|
|
|
+ },
|
|
|
+ editable: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data(vm) {
|
|
|
+ const _this = this
|
|
|
+ return {
|
|
|
+ props: {
|
|
|
+ multiple: true,
|
|
|
+ value: 'id',
|
|
|
+ label: 'name',
|
|
|
+ },
|
|
|
+ attachmentsArr:[],
|
|
|
+ schoolTarget: [],
|
|
|
+ classTargets: [],
|
|
|
+ classNameArr: [],
|
|
|
+ classType: 'private',
|
|
|
+ curVoteItem: null,
|
|
|
+ isAdd: true,
|
|
|
+ isEdit: false,
|
|
|
+ isBtnLoading: false,
|
|
|
+ isDateEdit: false,
|
|
|
+ voteFormEdit: true,
|
|
|
+ currentState: 0,
|
|
|
+ editInfo: null,
|
|
|
+ userInfo: this.$store.state.userInfo,
|
|
|
+ descriptionEditor: null,
|
|
|
+ classRooms: [],
|
|
|
+ uploadFileList: [],
|
|
|
+ uploadUrl: '',
|
|
|
+ defaultConfig: {
|
|
|
+ uploadImgShowBase64: true,
|
|
|
+ menus: this.$tools.wangEditorMenuSimple,
|
|
|
+ },
|
|
|
+ voteOptions: [...new Array(2).keys()], // 默认四个选项,
|
|
|
+ voteOptionsContent: [],
|
|
|
+ isImmediate: true,
|
|
|
+ voteForm: {
|
|
|
+ name: '',
|
|
|
+ classes: [],
|
|
|
+ startTime: '',
|
|
|
+ endTime: '',
|
|
|
+ description: '',
|
|
|
+ allowSupply:false,
|
|
|
+ typeLimit:false,
|
|
|
+ },
|
|
|
+ defaultParams: {
|
|
|
+ code: "",
|
|
|
+ name: "",
|
|
|
+ classes: [],
|
|
|
+ publishModel: "0",
|
|
|
+ status: 0,
|
|
|
+ startTime: 0,
|
|
|
+ endTime: 0,
|
|
|
+ },
|
|
|
+ uploadList: [],
|
|
|
+ options3: {
|
|
|
+ disabledDate: (date) => {
|
|
|
+ //这里写上自己的逻辑,返回true,表示当前日期需要设置为不可选
|
|
|
+ return date && date.valueOf() < Date.now() - 86400000;
|
|
|
}
|
|
|
},
|
|
|
- ruleValidate: {
|
|
|
- name: [
|
|
|
- { required: true, message: '作业名称不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- publishModel: [
|
|
|
- { required: true, trigger: 'change' }
|
|
|
- ],
|
|
|
- description: [
|
|
|
- { required: true, message: '作业描述不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- target: [
|
|
|
- { required: true, message: '作业对象不能为空' }
|
|
|
- ],
|
|
|
- endTime: [
|
|
|
- { required: true, type: 'date', message: '请设置结束时间', trigger: 'change' }
|
|
|
- ]
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- methods: {
|
|
|
- /**
|
|
|
- * 提交新增作业表单
|
|
|
- * @param name FormName
|
|
|
- */
|
|
|
- handleSubmit(name) {
|
|
|
- this.$refs[name].validate((valid) => {
|
|
|
- if (valid && this.getSimpleText(this.hwForm.description)) {
|
|
|
- let params = Object.assign({}, this.defaultParams)
|
|
|
- let target = []
|
|
|
- let isReset = this.hwForm.isReset.length > 0
|
|
|
- params.code = this.userInfo.TEAMModelId
|
|
|
- params.name = this.hwForm.name
|
|
|
- params.publishModel = this.hwForm.publishModel
|
|
|
- params.startTime = this.hwForm.publishModel === '1' ? Math.round(this.hwForm.startTime.getTime()) : new Date().getTime()
|
|
|
- params.endTime = Math.round(this.hwForm.endTime.getTime())
|
|
|
- params.description = this.hwForm.description
|
|
|
- params.other = this.hwForm.other
|
|
|
- params.resource = this.defaultFileList
|
|
|
- if (this.isEdit && this.editInfo.id) {
|
|
|
- params.id = this.editInfo.id
|
|
|
- params.createTime = this.editInfo.createTime
|
|
|
- }
|
|
|
-
|
|
|
- /** 替换作业对象格式 */
|
|
|
- this.hwForm.target.forEach(item => {
|
|
|
- target.push({
|
|
|
- classroomCode: item,
|
|
|
- classroomName: this.classRooms.filter(i => i.classroomCode === item)[0].classroomName,
|
|
|
- code: this.classRooms.filter(i => i.classroomCode === item)[0].scopeCode
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- params.target = target
|
|
|
- this.isBtnLoading = true
|
|
|
- this.saveorUpdataHw({ homeWork: params, reset: isReset }).then(res => {
|
|
|
- this.$Message.success((this.isEdit && this.editInfo.id) ? '修改成功!' : '添加成功!')
|
|
|
- this.hwFormEdit = false
|
|
|
- this.$emit('onAddSuccess')
|
|
|
- this.isBtnLoading = false
|
|
|
- }).catch(error => {
|
|
|
- console.log(error)
|
|
|
- this.isBtnLoading = false
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.$Message.error('请将信息填写完整')
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- onRelateContent() {
|
|
|
- this.isRelatedContent = true
|
|
|
- },
|
|
|
-
|
|
|
- onConfirmRelate() {
|
|
|
- this.isRelatedContent = false
|
|
|
- console.log(this.relateFileList)
|
|
|
- console.log(this.defaultFileList)
|
|
|
- this.defaultFileList = this.defaultFileList.concat(this.relateFileList)
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- onSelectFile(val) {
|
|
|
- this.relateFileList = val.files
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取当前教师的所有班级数据
|
|
|
- * @param teacherId 老师的醍摩豆ID
|
|
|
- */
|
|
|
- getClassrooms(teacherId) {
|
|
|
- return new Promise((r, j) => {
|
|
|
- this.$api.learnActivity.FindClassroomByTeacherId({ code:teacherId }).then(res => {
|
|
|
- if (!res.error && res.result.data) {
|
|
|
- r(res.result.data)
|
|
|
- } else {
|
|
|
- j(500)
|
|
|
- this.$Message.error('获取数据失败')
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- // 提取富文本内容中的文本
|
|
|
- getSimpleText(html) {
|
|
|
- var r = /<(?!img|video|audio).*?>/g;
|
|
|
- return html.replace(r, "");
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 重置表单
|
|
|
- * @param name
|
|
|
- */
|
|
|
- handleCancel() {
|
|
|
- this.hwFormEdit = false
|
|
|
- this.doRender(this.editInfo)
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 重置表单
|
|
|
- * @param name
|
|
|
- */
|
|
|
- handleReset(name) {
|
|
|
- this.$refs[name].resetFields();
|
|
|
- this.descriptionEditor.txt.clear()
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /** 附件上传之前钩子 限制附件上传个数 */
|
|
|
- handleBeforeUpload () {
|
|
|
- const check = this.uploadList.length < 5;
|
|
|
- if (!check) {
|
|
|
- this.$Notice.warning({
|
|
|
- title: '最多只能上传5个附件'
|
|
|
- });
|
|
|
- }
|
|
|
- return check;
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增作业或者编辑作业
|
|
|
- * @param data
|
|
|
- */
|
|
|
- saveorUpdataHw(data) {
|
|
|
- return new Promise((r, j) => {
|
|
|
- this.$api.learnActivity.SaveorUpdataHomeWork(data).then(res => {
|
|
|
- if (!res.error) {
|
|
|
- r(res.result.data)
|
|
|
- } else {
|
|
|
- j(res.error)
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 回显作业详情
|
|
|
- * @param item
|
|
|
- */
|
|
|
- doRender(item) {
|
|
|
- console.log(item)
|
|
|
-
|
|
|
- this.hwForm = {
|
|
|
- name: item.name,
|
|
|
- target: item.target.map(item => item.classroomCode),
|
|
|
- publishModel: item.publishModel,
|
|
|
- startTime: item.publishModel === '0' ? new Date(new Date().getTime()) : new Date(item.startTime),
|
|
|
- endTime: item.endTime ? new Date(item.endTime) : '',
|
|
|
- description: item.description,
|
|
|
- other: item.other,
|
|
|
- isReset:[]
|
|
|
- }
|
|
|
- this.currentState = item.state
|
|
|
- this.defaultFileList = item.resource
|
|
|
- this.defaultFileList = JSON.parse(JSON.stringify(item.resource))
|
|
|
- // this.descriptionEditor.txt.html(item.description)
|
|
|
- //this.uploadFileList = item.resource.length ? item.resource : []
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- getFileUrl(file) { // 获取文件地址
|
|
|
- //if (this.isEdit && this.uploadFileList.length) return
|
|
|
- //this.uploadFileList.push({
|
|
|
- // fileName: file.fileName,
|
|
|
- // type: file.type,
|
|
|
- // size: file.size,
|
|
|
- // blobUrl: file.blobUrl,
|
|
|
- // sha1Code: file.sha1Code,
|
|
|
- // compressUrl: file.compressUrl
|
|
|
- //})
|
|
|
- //console.log(this.uploadFileList)
|
|
|
- },
|
|
|
- },
|
|
|
- mounted() {
|
|
|
-
|
|
|
- /** 获取可选班级列表 */
|
|
|
- this.getClassrooms(this.userInfo.TEAMModelId).then(res => this.classRooms = res)
|
|
|
+ ruleValidate: {
|
|
|
+ name: [{
|
|
|
+ required: true,
|
|
|
+ message: vm.$t('homework.form.ruleName'),
|
|
|
+ trigger: 'blur'
|
|
|
+ }],
|
|
|
+ // description: [{
|
|
|
+ // // required: true,
|
|
|
+ // message: vm.$t('homework.form.ruleDescription'),
|
|
|
+ // trigger: 'blur'
|
|
|
+ // }],
|
|
|
+ startTime: [{
|
|
|
+ required: true,
|
|
|
+ type: 'date',
|
|
|
+ message: this.$t('learnActivity.createEv.errTips8'),
|
|
|
+ trigger: 'change'
|
|
|
+ }],
|
|
|
+ endTime: [{
|
|
|
+ required: true,
|
|
|
+ type: 'date',
|
|
|
+ message: this.$t('learnActivity.createEv.errTips9'),
|
|
|
+ trigger: 'change'
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ startOption: {
|
|
|
+ disabledDate(date) {
|
|
|
+ return date && date.valueOf() < Date.now() - 86400000
|
|
|
+ }
|
|
|
+ },
|
|
|
+ endOption: {
|
|
|
+ disabledDate(date) {
|
|
|
+ let data = _this.voteForm.startTime ? _this.voteForm.startTime : Date.now()
|
|
|
+ return data && data > date.valueOf() + 86400000
|
|
|
+ }
|
|
|
+ },
|
|
|
+ classIds: [],
|
|
|
+ groupList: [],
|
|
|
+ targetType: '',
|
|
|
+ schList: [],
|
|
|
+ csOptions: [],
|
|
|
+ areaId: sessionStorage.getItem('areaId'),
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ /** 获取可选班级列表 */
|
|
|
+ this.getClassrooms(this.userInfo.TEAMModelId).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ this.classRooms = res
|
|
|
+ })
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ treeChange(data) {
|
|
|
+ console.log('选择数据', this.schoolTarget)
|
|
|
+ },
|
|
|
+ getAreaTargets() {
|
|
|
+ this.$api.ability.findAreaGroup({
|
|
|
+ id: this.areaId
|
|
|
+ }).then(
|
|
|
+ res => {
|
|
|
+ if (res.gr && res.gr.length) {
|
|
|
+ this.schList = res.gr
|
|
|
+ this.csOptions = []
|
|
|
+ res.gr.forEach(sItem => {
|
|
|
+ let i = {
|
|
|
+ id: sItem.id,
|
|
|
+ name: sItem.sname,
|
|
|
+ children: []
|
|
|
+ }
|
|
|
+ sItem.name.forEach((gItem, gIndex) => {
|
|
|
+ i.children.push({
|
|
|
+ id: sItem.sname + '-' + gItem,
|
|
|
+ name: sItem.sname + '-' + gItem,
|
|
|
+ })
|
|
|
+ })
|
|
|
+ if (!i.children.length) {
|
|
|
+ i.children.push({
|
|
|
+ id: sItem.sname + '-' + '所有老师(未分组)',
|
|
|
+ name: sItem.sname + '-' + '所有老师(未分组)'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.csOptions.push(i)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ console.log(this.schList)
|
|
|
+
|
|
|
+ },
|
|
|
+ err => {
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ },
|
|
|
+ onClassTypeChange(val) {
|
|
|
+ this.voteForm.classes = []
|
|
|
+ },
|
|
|
+
|
|
|
+ onTargetChange(data) {
|
|
|
+ this.voteForm.classes = this.getCurScope === 'school' ? data : data.map(i => i.split('/')[1])
|
|
|
+ this.voteForm.targets = this.getCurScope === 'school' ? [] : data
|
|
|
+ },
|
|
|
+
|
|
|
+ onChangeSTime(val) {
|
|
|
+ let endTime = this.voteForm.endTime || Date.now()
|
|
|
+ if (new Date(val).getTime() >= new Date(endTime).getTime()) {
|
|
|
+ this.voteForm.endTime = null
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ onChangeEndTime(val) {
|
|
|
+ if (val.indexOf('00:00') > 0) {
|
|
|
+ val = val.replace('00:00', '23:59')
|
|
|
+ this.voteForm.endTime = val
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 提交新增投票表单
|
|
|
+ * @param name FormName
|
|
|
+ */
|
|
|
+ async handleSubmit(name) {
|
|
|
+ this.isBtnLoading = true
|
|
|
+ let hasTargets = this.voteForm.classes.length
|
|
|
+ this.$refs[name].validate(async (valid) => {
|
|
|
+ if (valid && this.getSimpleText(this.voteForm.description) && hasTargets) {
|
|
|
+ console.log(this.voteForm)
|
|
|
+ let classSelectScope = this.$refs.classSelectRef
|
|
|
+ .evaluationInfo.scope
|
|
|
+ let isSchoolClass = this.$refs.classSelectRef.evaluationInfo.scope === 'school' &&
|
|
|
+ this.$refs.classSelectRef.privateClassType === 'school'
|
|
|
+ let params = Object.assign({}, this.defaultParams)
|
|
|
+ let areaParams = null
|
|
|
+ let target = []
|
|
|
+ let fileName = this.$tools.guid()
|
|
|
+ let isReset = this.voteForm.isReset.length > 0
|
|
|
+ let isPersonal = this.$route.name === 'personalVote' && classSelectScope ===
|
|
|
+ 'private'
|
|
|
+ let isSchool = this.$route.name === 'manageVote'
|
|
|
+
|
|
|
+ params.code = this.getCurCode
|
|
|
+ params.scope = isPersonal ? 'private' : 'school'
|
|
|
+ params.name = this.voteForm.name
|
|
|
+ params.startTime = !this.isImmediate ? new Date(this.voteForm.startTime)
|
|
|
+ .getTime() : -1
|
|
|
+ params.endTime = new Date(this.voteForm.endTime).getTime()
|
|
|
+ params.description = this.voteForm.description
|
|
|
+ params.targets = this.voteForm.targets
|
|
|
+ params.selectMax = this.voteForm.selectMax || 1
|
|
|
+ params.secret = this.voteForm.secret.indexOf('secret') > -1
|
|
|
+ params.repeat = this.voteForm.repeat.indexOf('repeat') > -1
|
|
|
+ params.options = this.voteOptionsContent
|
|
|
+ // 新增参数
|
|
|
+ params.owner = isSchool ? 'school' : 'teacher'
|
|
|
+ params.creatorId = this.$store.state.userInfo.TEAMModelId
|
|
|
+ params.voteNum = this.voteForm.selectMax
|
|
|
+ params.times = this.voteForm.times
|
|
|
+ params.school = params.scope === 'school' ? this.$store.state.userInfo.schoolCode :
|
|
|
+ null
|
|
|
+ params.tchLists = []
|
|
|
+ params.classes = []
|
|
|
+ params.stuLists = []
|
|
|
+ if (this.isEdit && this.editInfo.id && this.editInfo.code) {
|
|
|
+ params.id = this.editInfo.id
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isSchoolClass) {
|
|
|
+ params.classes = this.voteForm.classes
|
|
|
+ params.targetType = 'student'
|
|
|
+ } else {
|
|
|
+ params.stuLists = this.voteForm.classes
|
|
|
+ params.targetType = 'student'
|
|
|
+ }
|
|
|
+ /* 保存BLOB以及COSMOS */
|
|
|
+ this.saveorUpdateVote(params).then(res => {
|
|
|
+ this.$Message.success((this.isEdit && this.editInfo.id) ? this.$t(
|
|
|
+ 'vote.form.editSuc') : this.$t(
|
|
|
+ 'vote.form.addSuc'))
|
|
|
+ this.$emit('onAddSuccess')
|
|
|
+ this.isBtnLoading = false
|
|
|
+ }).catch(error => {
|
|
|
+ this.isBtnLoading = false
|
|
|
+ console.log(error)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.isBtnLoading = false
|
|
|
+ if (!optionComplete) {
|
|
|
+ this.$Message.error(this.$t('homework.form.noOptionTip'))
|
|
|
+ } else if (!hasTargets) {
|
|
|
+ this.$Message.error(this.$t('homework.form.ruleClasses'))
|
|
|
+ } else if (!this.getSimpleText(this.voteForm.description)) {
|
|
|
+ this.$Message.error('投票详情不能为空!')
|
|
|
+ } else {
|
|
|
+ this.$Message.error(this.$t('homework.form.noCompleteTip'))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前教师的所有班级数据
|
|
|
+ * @param teacherId 老师的醍摩豆ID
|
|
|
+ */
|
|
|
+ getClassrooms(teacherId) {
|
|
|
+ return new Promise((r, j) => {
|
|
|
+ this.$api.learnActivity.FindClassroomByTeacherId({
|
|
|
+ id: teacherId,
|
|
|
+ code: this.$store.state.userInfo.schoolCode
|
|
|
+ }).then(res => {
|
|
|
+ if (!res.error && res.courses) {
|
|
|
+ this.$store.dispatch('user/getSchoolProfile').then(schoolProfile => {
|
|
|
+ // let schoolClasses = schoolProfile.school_classes
|
|
|
+ // console.log(schoolClasses)
|
|
|
+ r(res.courses)
|
|
|
+ }).catch(err => {
|
|
|
+ r([])
|
|
|
+ })
|
|
|
+
|
|
|
+ } else {
|
|
|
+ j(500)
|
|
|
+ this.$Message.error(this.$t('homework.form.getDataFailTip'))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 提取富文本内容中的文本
|
|
|
+ getSimpleText(html) {
|
|
|
+ var r = /<(?!img|video|audio).*?>/g;
|
|
|
+ return html.replace(r, "");
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重置表单
|
|
|
+ * @param name
|
|
|
+ */
|
|
|
+ handleReset(name) {
|
|
|
+ this.$refs[name].resetFields();
|
|
|
+ this.descriptionEditor.txt.clear()
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重置表单
|
|
|
+ * @param name
|
|
|
+ */
|
|
|
+ handleCancel() {
|
|
|
+ // 如果是新增的问卷点击取消编辑 则需要进行特殊处理
|
|
|
+ if (!this.curVoteItem.id) {
|
|
|
+ this.$emit('onCancelVote')
|
|
|
+ }
|
|
|
+ this.voteFormEdit = false
|
|
|
+ this.doRender(this.editInfo)
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 附件上传之前钩子 限制附件上传个数 */
|
|
|
+ handleBeforeUpload() {
|
|
|
+ const check = this.uploadList.length < 5;
|
|
|
+ if (!check) {
|
|
|
+ this.$Notice.warning({
|
|
|
+ title: this.$t('homework.form.attachmentMaxTip')
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return check;
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增投票或者编辑投票
|
|
|
+ * @param data
|
|
|
+ */
|
|
|
+ saveorUpdateVote(data) {
|
|
|
+ return new Promise((r, j) => {
|
|
|
+ if (this.curVoteItem.owner === 'school') {
|
|
|
+ this.$api.learnActivity.SaveorUpdataVote(data).then(res => {
|
|
|
+ if (!res.error) {
|
|
|
+ r(res)
|
|
|
+ } else {
|
|
|
+ j(res.error)
|
|
|
+ }
|
|
|
+ }).catch(e => j(e))
|
|
|
+ } else {
|
|
|
+ this.$api.ability.saveAreaVote(data).then(res => {
|
|
|
+ if (!res.error) {
|
|
|
+ r(res)
|
|
|
+ } else {
|
|
|
+ j(res.error)
|
|
|
+ }
|
|
|
+ }).catch(e => j(e))
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 回显投票详情
|
|
|
+ * @param item
|
|
|
+ */
|
|
|
+ async doRender(item) {
|
|
|
+ console.log('需要渲染的投票对象', item)
|
|
|
+ if (item.targetType === 'research') {
|
|
|
+ console.log(this.groupList);
|
|
|
+ let groupNameArr = []
|
|
|
+ item.tchLists.forEach(i => {
|
|
|
+ let findObj = this.groupList.find(j => j.id === i)
|
|
|
+ if (findObj) {
|
|
|
+ groupNameArr.push(findObj)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.classNameArr = groupNameArr
|
|
|
+ } else {
|
|
|
+ this.classNameArr = item.classes.length ? await this.getClassNameByIds(item.classes) : item
|
|
|
+ .stuLists.length ? await this.getClassNameByIds(item.stuLists) : []
|
|
|
+ }
|
|
|
+ console.log(this.classNameArr);
|
|
|
+
|
|
|
+ this.classType = item.classes.length ? 'school' : 'private'
|
|
|
+ this.classTargets = this.getCurScope === 'school' ? item.classes : item.targets
|
|
|
+ this.targetType = item.targetType
|
|
|
+ console.log(this.classNameArr)
|
|
|
+ this.voteForm = null
|
|
|
+ this.voteForm = {
|
|
|
+ name: item.name,
|
|
|
+ code: item.code,
|
|
|
+ targets: item.targets,
|
|
|
+ classes: item.classes.length ? item.classes : item.stuLists,
|
|
|
+ startTime: item.startTime ? new Date(item.startTime) : '',
|
|
|
+ endTime: item.endTime ? new Date(item.endTime) : '',
|
|
|
+ description: item.description,
|
|
|
+ allowSupply:item.allowSupply,
|
|
|
+ typeLimit:false,
|
|
|
+ attachments:item.attachments || []
|
|
|
+ }
|
|
|
+ this.isImmediate = true
|
|
|
+ this.descriptionEditor.txt.html(item.description)
|
|
|
+
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.curVoteItem = JSON.parse(JSON.stringify(item))
|
|
|
+ this.$refs.voteForm.validateField('name')
|
|
|
+ this.$refs.voteForm.validateField('classes')
|
|
|
+ this.$refs.voteForm.validateField('description')
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 根据班级ID集合换取班级名称 */
|
|
|
+ getClassNameByIds(ids) {
|
|
|
+ return new Promise((r, j) => {
|
|
|
+ this.$api.learnActivity.getClassNameByIds({
|
|
|
+ classes: ids,
|
|
|
+ school: this.$store.state.userInfo.schoolCode
|
|
|
+ }).then(res => {
|
|
|
+ if (!res.error) {
|
|
|
+ r(res.classInfos)
|
|
|
+ }
|
|
|
+ }).catch(e => {
|
|
|
+ j(e)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 根据班级ID获取班级名称 */
|
|
|
+ getTargetName(classId) {
|
|
|
+ return this.classNameArr.find(i => i.id === classId) ? this.classNameArr.find(i => i.id === classId).name :
|
|
|
+ this.$t('homework.form.noMatchDataTip')
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 根据字节数转换为大小 */
|
|
|
+ getSizeByBytes(bytes) {
|
|
|
+ return bytes / 1024 < 1024 ? (bytes / 1024).toFixed(1) + 'KB' : bytes / 1024 / 1024 < 1024 ? (bytes / 1024 / 1024).toFixed(1) + 'M' : (bytes / 1024 / 1024 / 1024).toFixed(1) + 'G'
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ let descriptionEditor = new E(this.$refs.descriptionEditor)
|
|
|
+ descriptionEditor.config.onchange = (html) => {
|
|
|
+ this.voteForm.description = html
|
|
|
+ }
|
|
|
+ descriptionEditor.config.height = 200
|
|
|
+ this.$editorTools.initSimpleEditor(descriptionEditor, this)
|
|
|
+ descriptionEditor.create()
|
|
|
+ this.descriptionEditor = descriptionEditor
|
|
|
|
|
|
|
|
|
- /** 初始化作业详情的富文本编辑器 */
|
|
|
- // let descriptionEditor = new E(this.$refs.descriptionEditor)
|
|
|
- // descriptionEditor.customConfig = this.defaultConfig
|
|
|
- // descriptionEditor.customConfig.onchange = (html) => { this.hwForm.description = html }
|
|
|
- // descriptionEditor.create()
|
|
|
- // this.descriptionEditor = descriptionEditor
|
|
|
- },
|
|
|
- computed:{
|
|
|
- getDisableDays(){
|
|
|
- return this.hwForm.startTime
|
|
|
+ if (this.editItem && this.editItem.name) {
|
|
|
+ console.log(this.editItem)
|
|
|
+ this.editInfo = JSON.parse(JSON.stringify(this.editItem))
|
|
|
+ this.doRender(this.editInfo)
|
|
|
}
|
|
|
+
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ getDisableDays() {
|
|
|
+ return this.voteForm.startTime
|
|
|
+ },
|
|
|
+ getCurCode() {
|
|
|
+ return this.$store.state.userInfo.TEAMModelId
|
|
|
+ },
|
|
|
+ getCurScope() {
|
|
|
+ return this.$route.name === 'manageHomeWork' ? 'private' : 'school'
|
|
|
+ },
|
|
|
+
|
|
|
},
|
|
|
watch: {
|
|
|
- editItem: {
|
|
|
- handler(newValue) {
|
|
|
- /** 编辑回显 */
|
|
|
- if (newValue) {
|
|
|
- this.doRender(JSON.parse(JSON.stringify(newValue)))
|
|
|
- this.isEdit = true
|
|
|
- this.editInfo = newValue
|
|
|
- } else {
|
|
|
- /** 新增 */
|
|
|
- this.handleReset('hwForm')
|
|
|
- this.isEdit = false
|
|
|
- this.editInfo = null
|
|
|
- }
|
|
|
- },
|
|
|
- deep: true
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ editItem: {
|
|
|
+ handler(newValue) {
|
|
|
+ /** 编辑回显 */
|
|
|
+ if (newValue) {
|
|
|
+ console.log(newValue)
|
|
|
+ this.doRender(JSON.parse(JSON.stringify(newValue)))
|
|
|
+ this.isEdit = true
|
|
|
+ this.editInfo = JSON.parse(JSON.stringify(newValue))
|
|
|
+
|
|
|
+ } else {
|
|
|
+ /** 新增 */
|
|
|
+ console.log(newValue)
|
|
|
+ this.handleReset('voteForm')
|
|
|
+ this.isEdit = false
|
|
|
+ this.editInfo = null
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
</script>
|
|
|
|
|
|
<style lang="less">
|
|
|
-@import "./BaseHwForm.less";
|
|
|
+ @import "../vote/BaseVoteForm.less";
|
|
|
</style>
|