edit.vue 7.4KB

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