edit.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <el-form ref="form" :model="form" label-width="100px" style="">
  5. <el-form-item label="标题">
  6. <el-input v-model="form.title" style="width: 400px;">></el-input>
  7. </el-form-item>
  8. <el-form-item label="广告位">
  9. <el-select v-model="form.lid" placeholder="请选择广告位" style="width: 400px;">
  10. <el-option v-for="item in allLocation" :label="item.LOCATION_NAME" :value="item.ID"
  11. :key="item.ID"></el-option>
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="广告类型">
  15. <el-select v-model="form.type" placeholder="请选择广告类型" style="width: 400px;">
  16. <el-option label="外链" value="1" :key="1"></el-option>
  17. <el-option label="文章" value="2" :key="2"></el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item :label="form.type==='1' ? '链接地址' : '文章ID'">
  21. <el-input v-model="form.content" style="width: 400px;">></el-input>
  22. <span class="note">注:外链请明确输入 http://或https://,文章则不需要输入</span>
  23. </el-form-item>
  24. <el-form-item label="广告图片">
  25. <leo-uploader :requestRoute="'ad/upload'" :defaultImageUrl="defaultImageUrl" width="400px" height="160px"
  26. @on-success="handleSuccess"></leo-uploader>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button type="primary" :loading="submitButtonStat" @click="onSubmit">提交</el-button>
  30. </el-form-item>
  31. </el-form>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import network from '../../utils/network'
  37. import LeoUploader from '../../components/Uploader'
  38. import tool from '@/utils/tool'
  39. export default {
  40. name: 'ad_edit',
  41. components: {LeoUploader},
  42. mounted () {
  43. if (this.$route.name === 'ad_edit') {
  44. network.getData('ad/edit/' + this.$route.params.id).then(response => {
  45. this.form.title = response.oneData.TITLE
  46. this.form.lid = response.oneData.LID
  47. this.form.type = response.oneData.TYPE
  48. this.form.content = response.oneData.CONTENT
  49. this.imageAd = response.oneData.IMAGE;
  50. this.form.image = tool.getLocaleLink(response.oneData.IMAGE, '/files/');
  51. this.defaultImageUrl = tool.getLocaleLink(response.oneData.IMAGE, '/files/');
  52. this.allLocation = response.allLocation
  53. this.loading = false
  54. this.isEdit = true
  55. })
  56. } else {
  57. network.getData('ad/add').then(response => {
  58. this.allLocation = response.allLocation
  59. this.loading = false
  60. })
  61. }
  62. },
  63. data () {
  64. return {
  65. form: {
  66. title: '',
  67. lid: null,
  68. type: '',
  69. content: '',
  70. image: '',
  71. },
  72. defaultImageUrl: null,
  73. allLocation: null,
  74. loading: false,
  75. submitButtonStat: false,
  76. isEdit: false,
  77. imageAd: '',
  78. }
  79. },
  80. methods: {
  81. onSubmit () {
  82. this.submitButtonStat = true
  83. let path = 'ad/add'
  84. if (this.$route.name === 'ad_edit') {
  85. path = 'ad/edit/' + this.$route.params.id
  86. }
  87. this.form.image = this.imageAd
  88. network.postData(path, this.form).then(response => {
  89. this.submitButtonStat = false
  90. this.$message({
  91. message: response,
  92. type: 'success'
  93. })
  94. this.$router.go(-1)
  95. }).catch(response => {
  96. this.submitButtonStat = false
  97. })
  98. },
  99. handleSuccess (imageUrl) {
  100. this.imageAd = imageUrl
  101. this.form.image = tool.getLocaleLink(imageUrl, '/files/')
  102. this.defaultImageUrl = tool.getLocaleLink(imageUrl, '/files/')
  103. },
  104. }
  105. }
  106. </script>
  107. <style>
  108. .note {
  109. color:red;
  110. }
  111. </style>