edit.vue 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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%">
  9. <el-input
  10. placeholder="请输入标题"
  11. v-model="postData.InfoName"
  12. clearable>
  13. </el-input>
  14. </div>
  15. </div>
  16. </li>
  17. <li class="flex-h">
  18. <span>跳转链接:<em>*</em></span>
  19. <div class="flex-item">
  20. <div style="width:50%">
  21. <el-input
  22. placeholder="请输入链接"
  23. v-model="postData.InfoUrl"
  24. clearable>
  25. </el-input>
  26. </div>
  27. </div>
  28. </li>
  29. <li class="flex-h">
  30. <span>对应案场:<em>*</em></span>
  31. <div class="flex-item">
  32. <div style="width:50%">
  33. <el-select v-model="postData.CaseId" placeholder="请选择">
  34. <el-option
  35. v-for="item in caseList"
  36. :key="item.CaseId"
  37. :label="item.CaseName"
  38. :value="item.CaseId">
  39. </el-option>
  40. </el-select>
  41. </div>
  42. </div>
  43. </li>
  44. <li style="text-align:center">
  45. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  46. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  47. </li>
  48. </ul>
  49. </form>
  50. </div>
  51. </template>
  52. <script>
  53. import { mapState, createNamespacedHelpers } from 'vuex'
  54. const { mapActions: mapCmsActions } = createNamespacedHelpers('cms')
  55. export default {
  56. name: '',
  57. data () {
  58. return {
  59. ajaxOff: true,
  60. postData: {
  61. InfoName: '',
  62. InfoUrl: '',
  63. OrgId: '',
  64. CaseId: '',
  65. LocationId: 'index'
  66. }
  67. }
  68. },
  69. components: {},
  70. created () {
  71. this.updateLocationInfo()
  72. this.getDetail()
  73. },
  74. computed: {
  75. ...mapState({
  76. // positionList: x => x.cms.location,
  77. OrgId: x => x.app.user.OrgId,
  78. caseList: x => x.app.cases.list
  79. })
  80. },
  81. methods: {
  82. ...mapCmsActions(['updateLocationInfo']),
  83. submit () {
  84. if (this.ajaxOff) {
  85. if (this.postData.InfoName === '') {
  86. this.$message({
  87. message: '标题不能为空',
  88. type: 'error',
  89. })
  90. return false
  91. }
  92. if (this.postData.InfoUrl === '') {
  93. this.$message({
  94. message: '链接地址不能为空',
  95. type: 'error',
  96. })
  97. return false
  98. }
  99. // var reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/ // eslint-disable-line
  100. // if (!reg.test(this.postData.InfoUrl)) {
  101. // this.$message({
  102. // message: '链接地址格式不正确',
  103. // type: 'error',
  104. // })
  105. // return false
  106. // }
  107. var strRegex = /^(ftp|https?)\:\/\/([\w\_\-]+)\.([\w\-]+[\.]?)*[\w]+\.[a-zA-Z]{2,10}(.*)/ // eslint-disable-line
  108. if (this.postData.InfoUrl.match(strRegex) === null) {
  109. this.$message({
  110. message: '链接地址格式不正确',
  111. type: 'error',
  112. })
  113. return false
  114. }
  115. this.postData.OrgId = this.OrgId
  116. this.$ajax(this.$api.cms.editInfo.url, {
  117. method: this.$api.cms.editInfo.method,
  118. urlData: {
  119. id: this.$route.query.id
  120. },
  121. data: this.postData
  122. }).then(res => {
  123. this.ajaxOff = true
  124. this.$message({
  125. message: '编辑成功',
  126. type: 'success',
  127. duration: 1000
  128. })
  129. this.$router.push({ name: 'indexMsg' })
  130. }).catch(msg => {
  131. })
  132. }
  133. },
  134. cancel () {
  135. this.$router.go(-1)
  136. },
  137. getDetail () {
  138. this.$ajax(this.$api.cms.infoDetail.url, {
  139. method: this.$api.cms.infoDetail.method,
  140. urlData: {
  141. id: this.$route.query.id
  142. }
  143. }).then(res => {
  144. console.log(res)
  145. // this.postData.InfoName = res.InfoName
  146. // this.postData.InfoUrl = res.InfoUrl
  147. // this.postData.CaseId = res.CaseId
  148. this.postData = res
  149. }).catch(msg => {
  150. })
  151. }
  152. }
  153. }
  154. </script>
  155. <!-- Add "scoped" attribute to limit CSS to this component only -->
  156. <style lang="scss" scoped>
  157. </style>