AddDisclInfo.vue 7.5 KB

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