PkRuleCreate.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div style="display: inline;" v-loading="loading">
  3. <el-button @click="FormReset" type="primary" plain>增加规则</el-button>
  4. <el-dialog
  5. append-to-body
  6. :title="title"
  7. width="450px"
  8. height="150px"
  9. :visible.sync="dialogCreateVisible"
  10. :close-on-click-modal="false"
  11. >
  12. <el-form style="padding:0 30px;" :model="Formdata" ref="newTaskForm" :rules="FormRules" @submit.native.prevent>
  13. <el-form-item prop="rule_name">
  14. <el-input type="textarea" placeholder="规则内容,最多100字" v-model="Formdata.rule_name"></el-input>
  15. </el-form-item>
  16. </el-form>
  17. <div slot="footer" class="dialog-footer">
  18. <el-button type="primary" @click="FormSend">保 存</el-button>
  19. </div>
  20. </el-dialog>
  21. </div>
  22. </template>
  23. <script>
  24. import qs from 'qs'
  25. export default {
  26. data() {
  27. return {
  28. loading: false,
  29. title:'新增规则',
  30. dialogCreateVisible:false,
  31. profile: this.$store.getters.user_info,
  32. FormApi: '/api/integral/pk/rules/create', // pk 创建
  33. Formdata: {
  34. rule_name: '',
  35. pk_id:0
  36. },
  37. FormRules: {
  38. rule_name: [
  39. {required: true, message: '请输入规则', trigger: 'blur'},
  40. {min: 1, max: 100, message: '长度在 1 到 100字符', trigger: 'blur'}
  41. ]
  42. }
  43. }
  44. },
  45. methods: {
  46. FormReset: function (id) {
  47. this.title = '新增规则'
  48. this.Formdata = {
  49. rule_name: '',
  50. pk_id:this.$parent.$parent.$parent.pk_info.id
  51. }
  52. this.$nextTick(() => {
  53. const form = this.$refs['newTaskForm']
  54. if (typeof(id) == 'undefined') {
  55. form.resetFields()
  56. form.clearValidate()
  57. }
  58. })
  59. this.dialogCreateVisible = true;
  60. this.FormApi = '/api/integral/pk/rules/create'
  61. },
  62. // 修改规则
  63. loadInfo(data){
  64. this.title = '修改规则'
  65. this.FormApi = '/api/integral/pk/rules'
  66. this.Formdata.rule_name = data.row.name
  67. this.Formdata.pk_id = data.pk_id
  68. this.Formdata.rule_id= data.row.id
  69. console.log(this.Formdata)
  70. this.dialogCreateVisible = true
  71. },
  72. FormSend() {
  73. console.log(this.Formdata)
  74. const self = this
  75. const form = this.$refs['newTaskForm'];
  76. form.validate((valid) => {
  77. if (valid) {
  78. this.$http('post',self.FormApi,this.Formdata,
  79. // headers: {
  80. // 'Content-Type': 'application/x-www-form-urlencoded'
  81. // }
  82. ).then(function (response) {
  83. var message = "";
  84. var status = 0;
  85. if (response.status == 200) {
  86. var data = response.data;
  87. message = data.msg
  88. if (data.code == 1) {
  89. self.dialogCreateVisible = false
  90. self.$parent.$parent.$parent.loadPkRule()
  91. self.$message({
  92. message: message,
  93. type: 'success'
  94. });
  95. } else {
  96. self.$message({
  97. message: message,
  98. type: 'error'
  99. });
  100. }
  101. } else {
  102. message = "服务器太忙了";
  103. }
  104. }).catch(function (error) {
  105. console.log(error);
  106. })
  107. } else {
  108. return false
  109. }
  110. })
  111. }
  112. },
  113. created() {
  114. }
  115. }
  116. </script>