AddDisclInfo.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <!-- 免责声明修改 By_liucf -->
  2. <template>
  3. <div>
  4. <crumbs :title="topInfo" linkTo="/admin/LT-YXSJKWH-MZSMWH">
  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="120"></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" 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 >= 120) {
  53. this.form.name = value.substr(0, 120);
  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. }
  95. },
  96. created(){
  97. const params = JSON.parse(localStorage.getItem("knowledgeEnumsData"));
  98. this.options = params.disclaimerCodeEnum;
  99. // 修改
  100. const data = this.$route.params.info;
  101. if(data){
  102. this.id = data.id;
  103. this.text = "确定修改";
  104. this.topInfo = "免责声明维护-修改";
  105. this.toast = "修改成功";
  106. this.form.title = data.title;
  107. this.form.description = data.description;
  108. this.form.disclaimerCode = data.disclaimerCode;
  109. }
  110. },
  111. methods: {
  112. addDiscl() {
  113. this.$refs.form.validate((valid)=> {
  114. if (valid) {
  115. // 过滤空格
  116. if(!this.form.title.trim()|| !this.form.description.trim()){
  117. this.$message({
  118. message: "必填项不能为空",
  119. type: 'warning'
  120. });
  121. return
  122. }
  123. // 有id是修改,没有id是添加
  124. if(this.id){
  125. let code = this.form.disclaimerCode;
  126. // 修改没有操作时 code为字符串,需转成code
  127. if(typeof code == 'string'){
  128. for(let i in this.options){
  129. if(this.options[i].name==code){
  130. code = this.options[i].key;
  131. }
  132. }
  133. }
  134. let param = {
  135. id:this.id,
  136. title:this.form.title.trim(),
  137. description:this.form.description.trim(),
  138. disclaimerCode:code
  139. }
  140. api.modifDiscInformation(param).then((res) => {
  141. if (res.data.code == '0') {
  142. this.$message({showClose: true,message: this.toast, type: 'success'});
  143. this.$router.push({path: 'LT-YXSJKWH-MZSMWH'});
  144. } else {
  145. this.$message({
  146. showClose: true,
  147. message: res.data.msg,
  148. type: 'warning'
  149. });
  150. }
  151. }).catch((error) => {
  152. this.$message({
  153. showClose: true,
  154. message: "服务器正忙...",
  155. type: 'warning'
  156. });
  157. })
  158. }else{
  159. let param = {
  160. title:this.form.title.trim(),
  161. description:this.form.description.trim(),
  162. disclaimerCode:this.form.disclaimerCode
  163. }
  164. api.addDiscInformation(param).then((res) => {
  165. if (res.data.code == '0') {
  166. this.$message({showClose: true,message: this.toast, type: 'success'});
  167. this.$router.push({path: 'LT-YXSJKWH-MZSMWH'});
  168. } else {
  169. this.$message({
  170. showClose: true,
  171. message: res.data.msg,
  172. type: 'warning'
  173. });
  174. }
  175. }).catch((error) => {
  176. this.$message({
  177. showClose: true,
  178. message: "服务器正忙...",
  179. type: 'warning'
  180. });
  181. })
  182. }
  183. }
  184. });
  185. },
  186. back(){
  187. this.$router.go(-1);
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="less" >
  193. @import "../../less/admin.less";
  194. .add-discl-form {
  195. background: #fff;
  196. padding: 20px 20px 30px;
  197. .discl-title{
  198. width:500px;
  199. }
  200. }
  201. // .el-button{
  202. .disclButn{
  203. margin: 30px 0 0 20px;
  204. }
  205. .discDesc{
  206. // .el-textarea{
  207. // width: 97%;
  208. // }
  209. margin-top: 10px;
  210. margin-bottom: 25px;
  211. .el-form-item__error{
  212. top:70px;
  213. }
  214. }
  215. </style>