edit.vue 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <ul>
  5. <li class="flex-h">
  6. <span>跳转类型:<em>*</em></span>
  7. <div class="flex-item">
  8. <div style="width:50%" class="radio">
  9. <el-radio v-model="postData.ForwardType" label='url' >链接</el-radio>
  10. <el-radio v-model="postData.ForwardType" label='course' >课程</el-radio>
  11. </div>
  12. </div>
  13. </li>
  14. <li class="flex-h" v-if="postData.ForwardType==='url'">
  15. <span>链接:<em>*</em></span>
  16. <div class="flex-item">
  17. <div style="width:50%">
  18. <el-input
  19. placeholder="请输入链接"
  20. v-model="postData.ForwardUrl"
  21. clearable>
  22. </el-input>
  23. </div>
  24. </div>
  25. </li>
  26. <li class="flex-h" v-else>
  27. <span>课程:<em>*</em></span>
  28. <div class="flex-item">
  29. <div style="width:50%">
  30. <el-select v-model="postData.ForwardCourseId" placeholder="请选择课程">
  31. <el-option
  32. v-for="item in courses.list"
  33. :key="item.CourseId"
  34. :label="item.CourseName"
  35. :value="item.CourseId">
  36. </el-option>
  37. </el-select>
  38. </div>
  39. </div>
  40. </li>
  41. <li class="flex-h">
  42. <span>是否发布:<em>*</em></span>
  43. <div class="flex-item">
  44. <div style="width:50%" class="radio">
  45. <el-radio v-model="postData.Status" label='1' >是</el-radio>
  46. <el-radio v-model="postData.Status" label='0' >否</el-radio>
  47. </div>
  48. </div>
  49. </li>
  50. <li class="flex-h">
  51. <span>图片位置:<em>*</em></span>
  52. <div class="flex-item">
  53. <div style="width:50%">
  54. <el-select style="width:100%" v-model="postData.LocationIds" multiple placeholder="请选择">
  55. <el-option
  56. v-for="item in positionList"
  57. :key="item.LocationId"
  58. :label="item.LocationName"
  59. :value="item.LocationId">
  60. </el-option>
  61. </el-select>
  62. </div>
  63. </div>
  64. </li>
  65. <li class="flex-h">
  66. <span>标题:<em>*</em></span>
  67. <div class="flex-item">
  68. <div style="width:50%">
  69. <el-input
  70. placeholder="请输入标题"
  71. v-model="postData.Title"
  72. clearable>
  73. </el-input>
  74. </div>
  75. </div>
  76. </li>
  77. <li class="flex-h">
  78. <span>图片:<em>*</em></span>
  79. <div class="flex-item">
  80. <el-upload
  81. class="avatar-uploader"
  82. action='string'
  83. :http-request="toolClass.upload"
  84. :show-file-list="false"
  85. :on-success="handleAvatarSuccess">
  86. <img v-if="postData.ImageUrl" :src="postData.ImageUrl" class="avatar">
  87. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  88. </el-upload>
  89. </div>
  90. </li>
  91. <li style="text-align:center">
  92. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  93. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  94. </li>
  95. </ul>
  96. </form>
  97. </div>
  98. </template>
  99. <script>
  100. import { mapState, createNamespacedHelpers } from 'vuex'
  101. const { mapActions: mapCmsActions } = createNamespacedHelpers('cms')
  102. const { mapState: mapCourseState, mapActions: mapCourseActions } = createNamespacedHelpers('course')
  103. export default {
  104. name: '',
  105. data () {
  106. return {
  107. postData: {
  108. ForwardType: 'url',
  109. ForwardUrl: '',
  110. ForwardResourceId: '',
  111. Status: '1',
  112. LocationIds: [],
  113. ImageUrl: '',
  114. Title: '',
  115. OrgId: '',
  116. CaseId: ''
  117. },
  118. dialogVisible: false,
  119. imgs: '',
  120. imgsArr: [],
  121. limit: 1
  122. }
  123. },
  124. components: {},
  125. created () {
  126. this.updateLocationAllInfo().then(() => {
  127. this.getDetail()
  128. this.GetCourseList({ page: 1, pagesize: 10000 })
  129. })
  130. },
  131. computed: {
  132. ...mapState({
  133. positionList: x => x.cms.locationAll
  134. }),
  135. ...mapCourseState({
  136. courses: x => x.courseList,
  137. })
  138. },
  139. methods: {
  140. ...mapCourseActions([
  141. 'GetCourseList',
  142. ]),
  143. ...mapCmsActions(['updateLocationAllInfo']),
  144. submit () {
  145. if (this.postData.ForwardType === 'url') {
  146. this.postData.ForwardResourceId = ''
  147. if (this.postData.ForwardUrl === '') {
  148. this.$message({
  149. message: '链接地址不能为空',
  150. type: 'error',
  151. })
  152. return false
  153. } else {
  154. var reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/ // eslint-disable-line
  155. if (!reg.test(this.postData.ForwardUrl)) {
  156. this.$message({
  157. message: '链接地址格式不正确',
  158. type: 'error',
  159. })
  160. return false
  161. }
  162. }
  163. } else {
  164. this.postData.ForwardUrl = ''
  165. if (this.postData.ForwardCourseId === '') {
  166. this.$message({
  167. message: '课程不能为空',
  168. type: 'error',
  169. })
  170. return false
  171. }
  172. }
  173. if (!this.postData.LocationIds.length) {
  174. this.$message({
  175. message: '图片位置不能为空',
  176. type: 'error',
  177. })
  178. return false
  179. }
  180. if (this.postData.Title === '') {
  181. this.$message({
  182. message: '标题不能为空',
  183. type: 'error',
  184. })
  185. return false
  186. }
  187. if (this.postData.ImageUrl === '') {
  188. this.$message({
  189. message: '图片不能为空',
  190. type: 'error',
  191. })
  192. return false
  193. }
  194. this.postData.locationids = this.postData.LocationIds.join(',')
  195. this.$ajax(this.$api.cms.editNews.url, {
  196. method: this.$api.cms.editNews.method,
  197. urlData: {
  198. id: this.$route.query.id
  199. },
  200. data: this.postData
  201. }).then(res => {
  202. this.$message({
  203. message: '编辑成功',
  204. type: 'success',
  205. duration: 1000
  206. })
  207. setTimeout(() => {
  208. this.$router.push({ name: 'newsManager' })
  209. }, 1000)
  210. }).catch(msg => {
  211. })
  212. },
  213. cancel () {
  214. this.$router.go(-1)
  215. },
  216. getDetail () {
  217. this.$ajax(this.$api.cms.newsDetail.url, {
  218. method: this.$api.cms.newsDetail.method,
  219. urlData: {
  220. id: this.$route.query.id
  221. }
  222. }).then(res => {
  223. res.Status += ''
  224. res.LocationIds = res.NewsLocations.reduce((previousValue, currentValue, index, array) => {
  225. previousValue.push(currentValue.LocationId)
  226. return previousValue
  227. }, [])
  228. this.postData = res
  229. }).catch(msg => {
  230. })
  231. },
  232. handleAvatarSuccess (res, file) {
  233. this.postData.ImageUrl = res.result.url
  234. }
  235. }
  236. }
  237. </script>
  238. <!-- Add "scoped" attribute to limit CSS to this component only -->
  239. <style lang="scss" scoped>
  240. </style>