edit.vue 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <ul>
  5. <li class="flex-h">
  6. <span>跳转类型:</span>
  7. <div class="flex-item">
  8. <div style="width:50%" class="radio">
  9. <el-radio v-model="postData.ForwardType" label='1' >连接</el-radio>
  10. <el-radio v-model="postData.ForwardType" label='0' >课程</el-radio>
  11. </div>
  12. </div>
  13. </li>
  14. <li class="flex-h">
  15. <span>连接:</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">
  27. <span>是否发布:</span>
  28. <div class="flex-item">
  29. <div style="width:50%" class="radio">
  30. <el-radio v-model="postData.Status" label='1' >是</el-radio>
  31. <el-radio v-model="postData.Status" label='0' >否</el-radio>
  32. </div>
  33. </div>
  34. </li>
  35. <li class="flex-h">
  36. <span>图片位置:</span>
  37. <div class="flex-item">
  38. <div style="width:50%">
  39. <el-select v-model="postData.LocationIds" multiple placeholder="请选择">
  40. <el-option
  41. v-for="item in positionList"
  42. :key="item.LocationId"
  43. :label="item.LocationName"
  44. :value="item.LocationId">
  45. </el-option>
  46. </el-select>
  47. </div>
  48. </div>
  49. </li>
  50. <li class="flex-h">
  51. <span>标题:</span>
  52. <div class="flex-item">
  53. <div style="width:50%">
  54. <el-input
  55. placeholder="请输入标题"
  56. v-model="postData.Title"
  57. clearable>
  58. </el-input>
  59. </div>
  60. </div>
  61. </li>
  62. <li class="flex-h">
  63. <span>图片:</span>
  64. <div class="flex-item">
  65. <el-upload
  66. :action="$api.file.image.url"
  67. :limit='limit'
  68. list-type="picture-card"
  69. :file-list='imgsArr'
  70. :on-success="handlePictureCardPreview"
  71. :on-remove="handleRemove"
  72. :on-exceed="exceed">
  73. <i class="el-icon-plus"></i>
  74. </el-upload>
  75. <el-dialog :visible.sync="dialogVisible">
  76. <img width="100%" :src="imgs" alt="">
  77. </el-dialog>
  78. </div>
  79. </li>
  80. <li style="text-align:center">
  81. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  82. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  83. </li>
  84. </ul>
  85. </form>
  86. </div>
  87. </template>
  88. <script>
  89. import { mapState, createNamespacedHelpers } from 'vuex'
  90. const { mapActions: mapCmsActions } = createNamespacedHelpers('cms')
  91. export default {
  92. name: '',
  93. data () {
  94. return {
  95. postData: {
  96. ForwardType: '1',
  97. ForwardUrl: '',
  98. ForwardResourceId: '',
  99. Status: '1',
  100. LocationIds: [],
  101. ImageUrl: '',
  102. Title: '',
  103. OrgId: '',
  104. CaseId: ''
  105. },
  106. dialogVisible: false,
  107. imgs: '',
  108. imgsArr: [],
  109. limit: 1
  110. }
  111. },
  112. components: {},
  113. created () {
  114. this.updateLocationInfo().then(() => {
  115. this.getDetail()
  116. })
  117. },
  118. computed: {
  119. ...mapState({
  120. positionList: x => x.cms.location
  121. })
  122. },
  123. methods: {
  124. ...mapCmsActions(['updateLocationInfo']),
  125. submit () {
  126. console.log(this.postData)
  127. this.postData.ForwardType === '1' ? this.postData.ForwardType = 'url' : this.postData.ForwardType = 'course'
  128. this.postData.locationids = this.postData.LocationIds.join(',')
  129. this.postData.ImageUrl = ''
  130. for (let i = 0; i < this.imgsArr.length; i++) {
  131. this.postData.ImageUrl += this.imgsArr[i].response.result.url + ','
  132. }
  133. if (this.postData.ImageUrl) {
  134. this.postData.ImageUrl = this.postData.ImageUrl.substr(0, this.postData.ImageUrl.length - 1)
  135. }
  136. this.$ajax(this.$api.cms.editNews.url, {
  137. method: this.$api.cms.editNews.method,
  138. urlData: {
  139. id: this.$route.query.id
  140. },
  141. data: this.postData
  142. }).then(res => {
  143. this.$message({
  144. message: '编辑成功',
  145. type: 'success',
  146. duration: 1000
  147. })
  148. setTimeout(() => {
  149. this.$router.push({ name: 'newsManager' })
  150. }, 1000)
  151. }).catch(msg => {
  152. })
  153. },
  154. cancel () {
  155. this.$router.go(-1)
  156. },
  157. handlePictureCardPreview (res, file, fileList) {
  158. this.imgs = res.result.url
  159. this.dialogVisible = true
  160. this.imgsArr = fileList
  161. },
  162. handleRemove (file, fileList) {
  163. this.imgsArr = fileList
  164. },
  165. exceed () {
  166. this.$message({
  167. message: '超过可传的图片上限',
  168. type: 'info',
  169. duration: 1000
  170. })
  171. },
  172. getDetail () {
  173. this.$ajax(this.$api.cms.newsDetail.url, {
  174. method: this.$api.cms.newsDetail.method,
  175. urlData: {
  176. id: this.$route.query.id
  177. }
  178. }).then(res => {
  179. res.ForwardType === 'url' ? res.ForwardType = '1' : res.ForwardType = '0'
  180. res.Status += ''
  181. res.LocationIds = res.NewsLocations.reduce((previousValue, currentValue, index, array) => {
  182. console.log(previousValue)
  183. previousValue.push(currentValue.LocationId)
  184. return previousValue
  185. }, [])
  186. console.log(res.LocationIds)
  187. let imgsArr = []
  188. let item = {
  189. url: res.ImageUrl,
  190. response: {
  191. result: {
  192. url: res.ImageUrl
  193. }
  194. }
  195. }
  196. imgsArr.push(item)
  197. this.imgsArr = imgsArr
  198. this.postData = res
  199. }).catch(msg => {
  200. })
  201. }
  202. }
  203. }
  204. </script>
  205. <!-- Add "scoped" attribute to limit CSS to this component only -->
  206. <style lang="scss" scoped>
  207. </style>