AddDisclInfo.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <!-- 免责声明修改 By_liucf -->
  2. <template>
  3. <div>
  4. <crumbs :title="topInfo"
  5. :param="$route.params" linkTo="DisclaimerInformation">
  6. </crumbs>
  7. <div class="contents">
  8. <el-form ref="form" :label-position="labelPosition" :model="form" :rules="rules" label-width="65px" class="add-discl-form">
  9. <el-form-item label="标题:" prop="title" class="discl-title">
  10. <el-input v-model="form.title" placeholder="请输入标题" maxlength="30"></el-input>
  11. </el-form-item>
  12. <el-form-item label="内容:" prop="description" class="discDesc">
  13. <el-input type="textarea" :rows="3" placeholder="请输入内容述" v-model="form.description" maxlength="1024"></el-input>
  14. </el-form-item>
  15. <el-form-item label="归属:" prop="disclaimerCode">
  16. <el-select v-model="form.disclaimerCode" clearable placeholder="请选择">
  17. <el-option
  18. v-for="item in options"
  19. :key="item.key"
  20. :label="item.name"
  21. :value="item.key">
  22. </el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-button class="disclButn" size="small" :disabled = 'saveDisable' type="primary" @click="addDiscl">{{text}}</el-button>
  26. </el-form>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import api from '@api/icss.js';
  32. export default {
  33. name: 'AddDisclInfo',
  34. data(){
  35. const titleVaild = (rule, value, callback) => {
  36. if (!value) {
  37. return callback(new Error('请输入标题'));
  38. }
  39. if (value.length >= 30) {
  40. this.form.name = value.substr(0, 30);
  41. this.$message({
  42. showClose: true,
  43. type: 'warning',
  44. message: '标题已超过最大字数限制'
  45. })
  46. }
  47. callback();
  48. };
  49. const descVaild = (rule, value, callback) => {
  50. if (!value) {
  51. return callback(new Error('请输入内容'));
  52. }
  53. if (value.length >= 1024) {
  54. this.form.name = value.substr(0, 1024);
  55. this.$message({
  56. showClose: true,
  57. type: 'warning',
  58. message: '内容已超过最大字数限制'
  59. })
  60. }
  61. callback();
  62. };
  63. const disclVaild = (rule, value, callback) => {
  64. if (!value) {
  65. return callback(new Error('请选择归属'));
  66. }
  67. callback();
  68. };
  69. return {
  70. id:null,
  71. labelPosition:'right',
  72. options:[],
  73. form: {
  74. title: '',
  75. description: '',//内容
  76. disclaimerCode:'' //归属
  77. },
  78. rules: {
  79. title:[
  80. { required: true, validator: titleVaild, trigger: [ 'change'] },
  81. { required: true, message: '请输入标题', trigger: ['blur', 'change'] }
  82. ],
  83. description:[
  84. { required: true, validator: descVaild, trigger: [ 'change'] },
  85. { required: true, message: '请输入内容', trigger: ['blur', 'change'] }
  86. ],
  87. disclaimerCode:[
  88. { required: true, validator: disclVaild, trigger: ['blur', 'change'] },
  89. { required: true, message: '请选择归属', trigger: ['blur', 'change'] }
  90. ],
  91. },
  92. text:'确定添加',
  93. topInfo:'免责声明维护-添加免责声明',
  94. toast:'添加成功',
  95. saveDisable: false
  96. }
  97. },
  98. created(){
  99. const params = JSON.parse(localStorage.getItem("knowledgeEnumsData"));
  100. this.options = params.disclaimerCodeEnum;
  101. // 修改
  102. const data = this.$route.params.info;
  103. if(data){
  104. this.id = data.id;
  105. this.text = "确定修改";
  106. this.topInfo = "免责声明维护-修改";
  107. this.toast = "修改成功";
  108. this.form.title = data.title;
  109. this.form.description = data.description;
  110. this.form.disclaimerCode = data.disclaimerCode;
  111. }
  112. },
  113. methods: {
  114. addDiscl() {
  115. this.$refs.form.validate((valid)=> {
  116. if (valid) {
  117. // 过滤空格
  118. if(!this.form.title.trim()|| !this.form.description.trim()){
  119. this.$message({
  120. message: "必填项不能为空",
  121. type: 'warning'
  122. });
  123. return
  124. }
  125. // 有id是修改,没有id是添加
  126. if(this.id){
  127. let code = this.form.disclaimerCode;
  128. // 修改没有操作时 code为字符串,需转成code
  129. if(typeof code == 'string'){
  130. for(let i in this.options){
  131. if(this.options[i].name==code){
  132. code = this.options[i].key;
  133. }
  134. }
  135. }
  136. let param = {
  137. id:this.id,
  138. title:this.form.title.trim(),
  139. description:this.form.description.trim(),
  140. disclaimerCode:code
  141. }
  142. this.saveDisable = true //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  143. api.modifDiscInformation(param).then((res) => {
  144. if (res.data.code == '0') {
  145. this.$message({showClose: true,message: this.toast, type: 'success'});
  146. this.$router.push({name: 'DisclaimerInformation',params: Object.assign({}, this.$route.params, {currentPage: 1})});
  147. } else {
  148. this.$message({
  149. showClose: true,
  150. message: res.data.msg,
  151. type: 'warning'
  152. });
  153. }
  154. this.saveDisable = false
  155. }).catch((error) => {
  156. this.$message({
  157. showClose: true,
  158. message: "服务器正忙...",
  159. type: 'warning'
  160. });
  161. })
  162. }else{
  163. let param = {
  164. title:this.form.title.trim(),
  165. description:this.form.description.trim(),
  166. disclaimerCode:this.form.disclaimerCode
  167. }
  168. this.saveDisable = true //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  169. api.addDiscInformation(param).then((res) => {
  170. if (res.data.code == '0') {
  171. this.$message({showClose: true,message: this.toast, type: 'success'});
  172. this.$router.push({name: 'DisclaimerInformation',params: Object.assign({}, this.$route.params, {currentPage: 1})});
  173. } else {
  174. this.$message({
  175. showClose: true,
  176. message: res.data.msg,
  177. type: 'warning'
  178. });
  179. }
  180. this.saveDisable = false
  181. }).catch((error) => {
  182. this.$message({
  183. showClose: true,
  184. message: "服务器正忙...",
  185. type: 'warning'
  186. });
  187. })
  188. }
  189. }
  190. });
  191. },
  192. back(){
  193. this.$router.go(-1);
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="less" >
  199. @import "../../less/admin.less";
  200. .add-discl-form {
  201. background: #fff;
  202. padding: 20px 20px 30px;
  203. .discl-title{
  204. width:500px;
  205. }
  206. }
  207. // .el-button{
  208. .disclButn{
  209. margin: 30px 0 0 20px;
  210. }
  211. .discDesc{
  212. // .el-textarea{
  213. // width: 97%;
  214. // }
  215. margin-top: 10px;
  216. margin-bottom: 25px;
  217. .el-form-item__error{
  218. top:70px;
  219. }
  220. }
  221. </style>