IREdit.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-loading="loading"
  5. :show-close="false"
  6. :close-on-click-modal="false"
  7. :visible.sync="isShow"
  8. :title="this.curObj && this.curObj.id ? '编辑规则' : '添加规则'"
  9. :fullscreen="false"
  10. width="800px"
  11. custom-class="xl-dialog"
  12. center
  13. >
  14. <base-form ref="ruleForm" class="lib-edit" :data="formData" :is-inline="false" label-width="110px">
  15. <div slot="footer">
  16. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  17. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  18. </div>
  19. </base-form>
  20. </el-dialog>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. components: {},
  26. mixins: [...mixins],
  27. props: {
  28. isShow: Boolean,
  29. curObj: Object
  30. },
  31. inject: ['parentData'],
  32. data() {
  33. return {
  34. formData: [],
  35. loading: true,
  36. cObj: {},
  37. isShowMap: false
  38. }
  39. },
  40. watch: {
  41. isShow: function(val) {
  42. if (val) {
  43. this.getDef()
  44. }
  45. },
  46. },
  47. methods: {
  48. getDef() {
  49. const params = { ...this.curObj }
  50. if (params.id) {
  51. this.formData = [
  52. { label: '标题', key: 'title', rules: 1 },
  53. { label: '排序', key: 'sort', class: 'c-2', rules: 1 },
  54. { label: '奖励积分', key: 'reward_point', class: 'c-2', rules: 1 },
  55. { label: '奖励次数', key: 'reward_num', class: 'c-2', rules: 1 },
  56. { label: '奖励周期(天)', key: 'cycle', class: 'c-2', rules: 1},
  57. { label: '小程序图标', key: 'icon', class: 'c-2', type: 'uploads'},
  58. { label: '小程序描述', key: 'remark', class: 'c-2', type: 'textarea'},
  59. ]
  60. } else {
  61. this.formData = [
  62. { label: '标题', key: 'title', class: 'c-2', rules: 1 },
  63. { label: '排序', key: 'sort', class: 'c-2', rules: 1 },
  64. { label: '分类', key: 'type', class: 'c-2', rules: 1 },
  65. { label: '奖励积分', key: 'reward_point', class: 'c-2', rules: 1 },
  66. { label: '奖励次数', key: 'reward_num', class: 'c-2', rules: 1 },
  67. { label: '奖励周期(天)', key: 'cycle', class: 'c-2', rules: 1},
  68. { label: '小程序图标', key: 'icon', class: 'c-2', type: 'uploads'},
  69. { label: '小程序描述', key: 'remark', class: 'c-2', type: 'textarea'},
  70. ]
  71. }
  72. this.setDefaultValue(params)
  73. },
  74. close(str) {
  75. if (str === 'confirm') {
  76. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  77. if (valid) {
  78. const oldform = this.$refs.ruleForm.baseForm
  79. let newForm = { ...oldform }
  80. let apiStr = 'admintegralruleadd'
  81. if (this.curObj.id) {
  82. apiStr = 'admintegralruleedit'
  83. newForm.id = this.curObj.id
  84. }
  85. this.$api.user[apiStr](newForm).then(data => {
  86. this.$msgs(this.curObj.id ? '编辑成功' : '新增成功')
  87. this.$emit('close', newForm)
  88. })
  89. }
  90. })
  91. } else {
  92. this.$emit('close')
  93. this.setDefaultValue()
  94. }
  95. },
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. @import "../../../../styles/libEdit.scss";
  101. .lib-edit {
  102. padding-top: 0;
  103. width:100%;
  104. ::v-deep .el-form-item {
  105. margin-bottom: 10px;
  106. }
  107. ::v-deep .el-date-editor.el-input {
  108. width: 100%;
  109. }
  110. }
  111. </style>