edit.vue 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 style="width:100%" 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='string'
  67. :http-request="toolClass.upload"
  68. :limit='limit'
  69. list-type="picture-card"
  70. :file-list='imgsArr'
  71. :on-success="handlePictureCardPreview"
  72. :on-remove="handleRemove"
  73. :on-exceed="exceed">
  74. <i class="el-icon-plus"></i>
  75. </el-upload>
  76. <el-dialog :visible.sync="dialogVisible">
  77. <img width="100%" :src="imgs" alt="">
  78. </el-dialog> -->
  79. <el-upload
  80. class="avatar-uploader"
  81. action='string'
  82. :http-request="toolClass.upload"
  83. :show-file-list="false"
  84. :on-success="handleAvatarSuccess">
  85. <img v-if="postData.ImageUrl" :src="postData.ImageUrl" class="avatar">
  86. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  87. </el-upload>
  88. </div>
  89. </li>
  90. <li style="text-align:center">
  91. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  92. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  93. </li>
  94. </ul>
  95. </form>
  96. </div>
  97. </template>
  98. <script>
  99. import { mapState, createNamespacedHelpers } from 'vuex'
  100. const { mapActions: mapCmsActions } = createNamespacedHelpers('cms')
  101. export default {
  102. name: '',
  103. data () {
  104. return {
  105. postData: {
  106. ForwardType: '1',
  107. ForwardUrl: '',
  108. ForwardResourceId: '',
  109. Status: '1',
  110. LocationIds: [],
  111. ImageUrl: '',
  112. Title: '',
  113. OrgId: '',
  114. CaseId: ''
  115. },
  116. dialogVisible: false,
  117. imgs: '',
  118. imgsArr: [],
  119. limit: 1
  120. }
  121. },
  122. components: {},
  123. created () {
  124. this.updateLocationInfo().then(() => {
  125. this.getDetail()
  126. })
  127. },
  128. computed: {
  129. ...mapState({
  130. positionList: x => x.cms.location
  131. })
  132. },
  133. methods: {
  134. ...mapCmsActions(['updateLocationInfo']),
  135. submit () {
  136. if (this.postData.ForwardType === '1') {
  137. if (this.postData.ForwardUrl === '') {
  138. this.$message({
  139. message: '链接地址不能为空',
  140. type: 'error',
  141. })
  142. return false
  143. } else {
  144. var reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/ // eslint-disable-line
  145. if (!reg.test(this.postData.ForwardUrl)) {
  146. this.$message({
  147. message: '链接地址格式不正确',
  148. type: 'error',
  149. })
  150. return false
  151. }
  152. }
  153. }
  154. this.postData.ForwardType === '1' ? this.postData.ForwardType = 'url' : this.postData.ForwardType = 'course'
  155. this.postData.locationids = this.postData.LocationIds.join(',')
  156. // this.postData.ImageUrl = ''
  157. // for (let i = 0; i < this.imgsArr.length; i++) {
  158. // this.postData.ImageUrl += this.imgsArr[i].response.result.url + ','
  159. // }
  160. // if (this.postData.ImageUrl) {
  161. // this.postData.ImageUrl = this.postData.ImageUrl.substr(0, this.postData.ImageUrl.length - 1)
  162. // }
  163. this.$ajax(this.$api.cms.editNews.url, {
  164. method: this.$api.cms.editNews.method,
  165. urlData: {
  166. id: this.$route.query.id
  167. },
  168. data: this.postData
  169. }).then(res => {
  170. this.$message({
  171. message: '编辑成功',
  172. type: 'success',
  173. duration: 1000
  174. })
  175. setTimeout(() => {
  176. this.$router.push({ name: 'newsManager' })
  177. }, 1000)
  178. }).catch(msg => {
  179. })
  180. },
  181. cancel () {
  182. this.$router.go(-1)
  183. },
  184. // handlePictureCardPreview (res, file, fileList) {
  185. // this.imgs = res.result.url
  186. // this.dialogVisible = false
  187. // this.imgsArr = fileList
  188. // },
  189. // handleRemove (file, fileList) {
  190. // this.imgsArr = fileList
  191. // },
  192. // exceed () {
  193. // this.$message({
  194. // message: '超过可传的图片上限',
  195. // type: 'info',
  196. // duration: 1000
  197. // })
  198. // },
  199. getDetail () {
  200. this.$ajax(this.$api.cms.newsDetail.url, {
  201. method: this.$api.cms.newsDetail.method,
  202. urlData: {
  203. id: this.$route.query.id
  204. }
  205. }).then(res => {
  206. res.ForwardType === 'url' ? res.ForwardType = '1' : res.ForwardType = '0'
  207. res.Status += ''
  208. res.LocationIds = res.NewsLocations.reduce((previousValue, currentValue, index, array) => {
  209. console.log(previousValue)
  210. previousValue.push(currentValue.LocationId)
  211. return previousValue
  212. }, [])
  213. console.log(res.LocationIds)
  214. // let imgsArr = []
  215. // let item = {
  216. // url: res.ImageUrl,
  217. // response: {
  218. // result: {
  219. // url: res.ImageUrl
  220. // }
  221. // }
  222. // }
  223. // imgsArr.push(item)
  224. // this.imgsArr = imgsArr
  225. this.postData = res
  226. }).catch(msg => {
  227. })
  228. },
  229. handleAvatarSuccess (res, file) {
  230. this.postData.ImageUrl = res.result.url
  231. }
  232. }
  233. }
  234. </script>
  235. <!-- Add "scoped" attribute to limit CSS to this component only -->
  236. <style lang="scss" scoped>
  237. </style>