hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<template>
    <el-dialog
    title="编辑"
    :visible="value"
    width="40%"
    :show-close="false"
    :modal='false'
    :before-close="onCancel">
    <el-form  :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="ruleForm">
      <el-form-item label="积分任务">
        <span>{{itemData.name}}</span>
      </el-form-item>
 
      <el-form-item label="积分值" prop="amount">
        <el-input v-model="ruleForm.amount"></el-input>
      </el-form-item>
 
      <el-form-item label="次数限制" prop="isRestrict">
        <el-radio-group v-model="ruleForm.isRestrict">
          <el-radio     
             v-for="item in configTyperadio"
            :key="item.value"
            :label="item.value"
          >{{item.label}}</el-radio>
        </el-radio-group>
 
        <el-form-item class="isShowinpput" label="" prop="count" v-if="ruleForm.isRestrict !== '2'">
          <el-select class="width50" v-model="ruleForm.type"  placeholder="请选择">
            <el-option
              v-for="item in configTypeSelect"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input class="input-width" v-model="ruleForm.count" placeholder="输入次数"></el-input>
        </el-form-item>
      </el-form-item>
 
      <el-form-item label="描述">
        <el-input   
          type="textarea"
          placeholder="请输入内容"
          maxlength="100"
          rows="5"
          show-word-limit 
          v-model="ruleForm.integralDescribe"
          ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="onCancel('ruleForm')">取 消</el-button>
      <el-button type="primary" @click="onOk('ruleForm')" :loading="okLoading">确 定</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
import vUpload from "com/upload/upload1";
export default {
  props: {
    value: {type: Boolean},
    item: {type:Object}
  },
  components:{vUpload},
 
  data() {
    const validateNum = (rule, value, callback) => {
      const num= /^[0-9]*$/
      if (!num.test(value)) {
        callback(new Error('只能输入0或正整数'))
      }else{
        callback()
      }
    };
 
    return {
      ruleForm: {
        isRestrict:"2",
        amount:"",
        type:"2",
        integralDescribe:"",
          count: '',
          id: '',
      },
      okLoading: false,
      rules: {
        amount: [
          { required: true, message: '请输入积分值', trigger: 'blur' },
          {validator:validateNum,trigger: 'blur'}
        ],
        count: [
          { required: true, message: '请输入次数限制', trigger: 'blur' },
          {validator:validateNum,trigger: 'blur'}
        ],
        // isRestrict: [
        //   { required: true,  trigger: 'change'},
        // ],
       },
       itemData:{},
       configTypeSelect:[
        {
          value:"2",
          label:"每日"
        },
         {
          value:"1",
          label:"每月"
        },
       ],
       configTyperadio: [
        {
          value:"2",
          label:"无限制"
        },
         {
          value:"1",
          label:"限制"
        },
       ]
    }
  },
 
  watch: {
    item (val) {
      if (val) {
        console.log(val)
        this.itemData = val;
        this.ruleForm.id = val.id;
        this.ruleForm = val;
        this.ruleForm.isRestrict = String(val.isRestrict);
        if(val.type) {
          this.ruleForm.type = String(val.type);
        }    
      }
    }
  },
 
  mounted() {
  },
 
  methods: {
    /** 取消 */
    onCancel (formName) {
      this.$emit('change', false);
      this.$refs[formName].resetFields();
    },
 
    /** 确认表单提交 */
    onOk(formName) {
      console.log(this.ruleForm)
      if(this.ruleForm.isRestrict === '1') {
        if(!this.ruleForm.type) {
          demo.toast("请选择限制的方式")
          return;
        }
        // if(!this.ruleForm.count) {
        //   demo.toast("请填写限制的次数")
        //   return;
        // }
        // if (this.ruleForm.count.match(/^[0-9]*$/)) {
        //   return demo.toast("请填写整数")
        // }
 
      }
 
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.okLoading = true;
          this.$api.post("integral/rule/edit", this.ruleForm, 
            e => {
              demo.toast("编辑成功");
              this.$emit('success');
              this.onCancel();
            },
            err=> {
              demo.toast(err.msg)
            }
          )
          this.okLoading = false;
 
        } else {
          // demo.toast("验证不通过")
          return false;
        }
      });
    }
  }
 
}
</script>
 
<style>
.width50 {
  width: 80px;
  height: 30px;
}
.input-width {
  width: 150px;
}
.isShowinpput {
  display: initial;
}
</style>