123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <template>
- <div class="subPage">
- <form class="mainForm">
- <ul>
- <li class="flex-h">
- <span>跳转类型:<em>*</em></span>
- <div class="flex-item">
- <div style="width:50%" class="radio">
- <el-radio v-model="postData.ForwardType" label='url' >链接</el-radio>
- <el-radio v-model="postData.ForwardType" label='course' >课程</el-radio>
- </div>
- </div>
- </li>
- <li class="flex-h" v-if="postData.ForwardType==='url'">
- <span>链接:<em>*</em></span>
- <div class="flex-item">
- <div style="width:50%">
- <el-input
- placeholder="请输入链接"
- v-model="postData.ForwardUrl"
- clearable>
- </el-input>
- </div>
- </div>
- </li>
- <li class="flex-h" v-else>
- <span>课程:<em>*</em></span>
- <div class="flex-item">
- <div style="width:50%">
- <el-select v-model="postData.ForwardCourseId" placeholder="请选择课程">
- <el-option
- v-for="item in courses.list"
- :key="item.CourseId"
- :label="item.CourseName"
- :value="item.CourseId">
- </el-option>
- </el-select>
- </div>
- </div>
- </li>
- <li class="flex-h">
- <span>是否发布:<em>*</em></span>
- <div class="flex-item">
- <div style="width:50%" class="radio">
- <el-radio v-model="postData.Status" label='1' >是</el-radio>
- <el-radio v-model="postData.Status" label='0' >否</el-radio>
- </div>
- </div>
- </li>
- <li class="flex-h">
- <span>图片位置:<em>*</em></span>
- <div class="flex-item">
- <div style="width:50%">
- <el-select style="width:100%" v-model="postData.LocationIds" multiple placeholder="请选择">
- <el-option
- v-for="item in positionList"
- :key="item.LocationId"
- :label="item.LocationName"
- :value="item.LocationId">
- </el-option>
- </el-select>
- </div>
- </div>
- </li>
- <li class="flex-h">
- <span>标题:<em>*</em></span>
- <div class="flex-item">
- <div style="width:50%">
- <el-input
- placeholder="请输入标题"
- v-model="postData.Title"
- clearable>
- </el-input>
- </div>
- </div>
- </li>
- <li class="flex-h">
- <span>图片:<em>*</em></span>
- <div class="flex-item">
- <el-upload
- class="avatar-uploader"
- action='string'
- :http-request="toolClass.upload"
- :show-file-list="false"
- :on-success="handleAvatarSuccess">
- <img v-if="postData.ImageUrl" :src="postData.ImageUrl" class="avatar">
- <i v-else class="el-icon-plus avatar-uploader-icon"></i>
- </el-upload>
- </div>
- </li>
- <li style="text-align:center">
- <el-button type="primary" size="mini" @click="submit">保存</el-button>
- <el-button type="danger" size="mini" @click="cancel">取消</el-button>
- </li>
- </ul>
- </form>
- </div>
- </template>
-
- <script>
- import { mapState, createNamespacedHelpers } from 'vuex'
- const { mapActions: mapCmsActions } = createNamespacedHelpers('cms')
- const { mapState: mapCourseState, mapActions: mapCourseActions } = createNamespacedHelpers('course')
- export default {
- name: '',
- data () {
- return {
- postData: {
- ForwardType: 'url',
- ForwardUrl: '',
- ForwardResourceId: '',
- Status: '1',
- LocationIds: [],
- ImageUrl: '',
- Title: '',
- OrgId: '',
- CaseId: ''
- },
- dialogVisible: false,
- imgs: '',
- imgsArr: [],
- limit: 1
- }
- },
- components: {},
- created () {
- this.updateLocationAllInfo().then(() => {
- this.getDetail()
- this.GetCourseList({ page: 1, pagesize: 10000 })
- })
- },
- computed: {
- ...mapState({
- positionList: x => x.cms.locationAll
- }),
- ...mapCourseState({
- courses: x => x.courseList,
- })
- },
- methods: {
- ...mapCourseActions([
- 'GetCourseList',
- ]),
- ...mapCmsActions(['updateLocationAllInfo']),
- submit () {
- if (this.postData.ForwardType === 'url') {
- this.postData.ForwardResourceId = ''
- if (this.postData.ForwardUrl === '') {
- this.$message({
- message: '链接地址不能为空',
- type: 'error',
- })
- return false
- } else {
- var reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/ // eslint-disable-line
- if (!reg.test(this.postData.ForwardUrl)) {
- this.$message({
- message: '链接地址格式不正确',
- type: 'error',
- })
- return false
- }
- }
- } else {
- this.postData.ForwardUrl = ''
- if (this.postData.ForwardCourseId === '') {
- this.$message({
- message: '课程不能为空',
- type: 'error',
- })
- return false
- }
- }
- if (!this.postData.LocationIds.length) {
- this.$message({
- message: '图片位置不能为空',
- type: 'error',
- })
- return false
- }
- if (this.postData.Title === '') {
- this.$message({
- message: '标题不能为空',
- type: 'error',
- })
- return false
- }
- if (this.postData.ImageUrl === '') {
- this.$message({
- message: '图片不能为空',
- type: 'error',
- })
- return false
- }
- this.postData.locationids = this.postData.LocationIds.join(',')
- this.$ajax(this.$api.cms.editNews.url, {
- method: this.$api.cms.editNews.method,
- urlData: {
- id: this.$route.query.id
- },
- data: this.postData
- }).then(res => {
- this.$message({
- message: '编辑成功',
- type: 'success',
- duration: 1000
- })
- setTimeout(() => {
- this.$router.push({ name: 'newsManager' })
- }, 1000)
- }).catch(msg => {
-
- })
- },
- cancel () {
- this.$router.go(-1)
- },
- getDetail () {
- this.$ajax(this.$api.cms.newsDetail.url, {
- method: this.$api.cms.newsDetail.method,
- urlData: {
- id: this.$route.query.id
- }
- }).then(res => {
- res.Status += ''
- res.LocationIds = res.NewsLocations.reduce((previousValue, currentValue, index, array) => {
- previousValue.push(currentValue.LocationId)
- return previousValue
- }, [])
- this.postData = res
- }).catch(msg => {
-
- })
- },
- handleAvatarSuccess (res, file) {
- this.postData.ImageUrl = res.result.url
- }
- }
- }
- </script>
-
- <!-- Add "scoped" attribute to limit CSS to this component only -->
- <style lang="scss" scoped>
- </style>
|