fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<template>
  <div class="integral-control-form" id="integral-control-form">
    <list-condition-template ref="table" :isExistBtn="true" :tableData="tableData" @page-info-change="handlePageInfoChange">
      <template slot="otherElement">
        <el-form size="mini" :model="listData" class="control-form" :rules="formRules" ref="form">
          <el-row>
            <el-col class="integral-control-area" :span="12">
              <h6>用户积分控制</h6>
              <hr/>
              <el-form-item label="用户名称:">
                <el-input v-show="!isIntegralAdjust" style="width:256px" v-model.trim="listData.memberPhone" placeholder="请输入手机号进行查询">
                  <el-button slot="append" @click="query">查询</el-button>
                </el-input>
                <span v-show="isIntegralAdjust">
                  {{listData.memberPhone}},当前剩余积分{{listData.memberIntegral}}
                  <el-button @click="query">取消</el-button>
                </span>
              </el-form-item>
              <el-form-item label="积分调整:" prop="modifyTurn" v-show="isIntegralAdjust">
                <el-row>
                  <el-col :span="7" style="width:200px">
                    <el-select  v-model="listData.modifyTurn">
                      <el-option label="扣除" key="2" value="2"></el-option>
                    </el-select>
                  </el-col>
                  <el-col :span="6" style="width:150px" >
                    <el-input-number :min="1" v-model="listData.modifyValue"></el-input-number>
                  </el-col>
                  <el-col :span="2">
                    <el-button type="primary" @click="openIntegralAdjust">确定</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
              <div>
               <el-form-item label="积分调整:" v-show="!isIntegralAdjust">请先输入用户名称后点击“查询”</el-form-item>
              </div>
              <el-form-item label="操作提示:">输入用户名称>查询>修改积分>输入理由>确定</el-form-item>
            </el-col>
            <el-col class="integral-control-area" :span="12">
              <h6>积分当前执行标准</h6>
              <hr/>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="积分规则:">消费送积分</el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="执行期限:">长期</el-form-item>
                </el-col>
              </el-row>
              <el-form-item label="获取比例:">用户确认收货时,每实际消费200元,获得1积分</el-form-item>
              <el-form-item label="特殊备注:">消费不满200元不计分,后续累计满足时仍可发放</el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column label="用户名称" align="center" prop="useId"></el-table-column>
        <el-table-column label="修改前积分" align="center" prop="modifyBeforeIntegral"></el-table-column>
        <el-table-column label="修改值" align="center" prop="modifyValue">
          <template slot-scope="scope">
            {{scope.row.modifyTurn === '2'?'-':'+'}} {{scope.row.modifyValue}}
          </template>
        </el-table-column>
        <el-table-column label="修改后积分" align="center" prop="modifyAfterIntegral"></el-table-column>
        <el-table-column label="操作人" align="center" prop="operatorId"></el-table-column>
        <el-table-column label="操作时间" align="center" prop="operatorTime"></el-table-column>
        <el-table-column label="更改理由" prop="modifyReason" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.modifyReason ? scope.row.modifyReason : '-'}}
          </template>
        </el-table-column>
      </template>
    </list-condition-template>
    <el-dialog
      :visible.sync="dialogVisible"
      title="调整理由"
      :close-on-click-modal="false"
      :modal-append-to-body="false"
      width="564px"
      >
      <integral-adjust-reason :form="listData" :memberPhone="memberPhone"></integral-adjust-reason>
      <div slot="footer" class="dialog-footer buttonPosition">
        <el-button size="mini" @click="submit" type="primary"  :loading="loading">确定</el-button>
        <el-button size="mini" @click="dialogVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import integralAdjustReason from '@/views/integralControl/components/integralAdjustReason.vue'
import integralControlApi from '@/api/member/integralControl'
 
export default {
  components: { integralAdjustReason },
  data() {
    const validateIntegral = (rule, value, callback) => {
      const reg = /^[0-9]*$/ // 只能输入正整数
      if (!value) {
        callback(new Error('请选择积分扣减方式'))
      } else if (!this.listData.modifyValue || !reg.test(this.listData.modifyValue)) {
        callback(new Error('积分修改值应为大于0的整数'))
      } else if (value === '2' && this.listData.modifyValue > this.listData.memberIntegral) {
        callback(new Error('积分扣减数不能大于剩余积分数'))
      } else {
        callback()
      }
    }
    return {
      listData: {
        modifyTurn: null,
        modifyValue: null,
        memberPhone: null
      },
      form: {},
      isIntegralAdjust: false, // 是否积分调整
      dialogVisible: false,
      loading: false,
      tableData: [],
      formRules: {
        modifyTurn: [
          { validator: validateIntegral, trigger: 'change' }
        ]
      },
      memberPhone: null
    }
  },
  /*
     * 数据变化后刷新列表
   */
  activated() {
    this.queryList(this.$refs.table.getPageInfo())
  },
  methods: {
    // 查询用户
    async query() {
      if (!this.listData.memberPhone) {
        this.$message({
          type: 'warning',
          message: '请输入手机号'
        })
        return
      } else {
        const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
        if (!reg.test(this.listData.memberPhone)) {
          this.$message({
            type: 'warning',
            message: '请输入正确的手机号码'
          })
          return
        }
      }
      if (!this.isIntegralAdjust) {
        try {
          const res = await integralControlApi.queryUserInfo({ memberPhone: this.listData.memberPhone })
          if (res.code === '0' && res.data) {
            this.isIntegralAdjust = !this.isIntegralAdjust
            this.listData = res.data
            this.memberPhone = this.listData.memberPhone
          }
        } catch (error) {
        }
      } else {
        this.isIntegralAdjust = !this.isIntegralAdjust
        this.listData.memberPhone = null
      }
    },
    // 保存调整理由
    async submit() {
      const param = {
        modifyAfterIntegral: this.listData.memberIntegral - this.listData.modifyValue,
        modifyBeforeIntegral: this.listData.memberIntegral,
        modifyReason: this.listData.modifyReason,
        modifyTurn: this.listData.modifyTurn,
        modifyValue: this.listData.modifyValue,
        memberId: this.listData.memberId,
        useId: this.memberPhone
      }
      try {
        this.loading = true
        const res = await integralControlApi.adjustIntegral(param)
        if (res.code === '0' && res.data) {
          this.loading = false
          this.dialogVisible = false
          this.memberPhone = null
        } else {
          this.loading = false
        }
      } catch (error) {
        this.loading = false
      }
      if (!this.dialogVisible) {
        await this.$refs.table.changeCondition()
      }
    },
    // 打开积分调整弹窗
    openIntegralAdjust() {
      this.$refs.form.validate().then((res) => {
        this.isIntegralAdjust = false
        this.dialogVisible = true
        this.listData.memberPhone = null
      })
    },
    /**
       * '分页信息改变时查询列表
       */
    handlePageInfoChange(pageInfo) {
      this.queryList(pageInfo)
    },
 
    /**
     * 重置
     */
    resetQuery() {
      this.$refs.table.reloadCurrent()
    },
    /**
     * 点击查询按钮
     */
    queryData() {
      this.$refs.table.changeCondition()
    },
    /**
     * 查询列表
     */
    async queryList(pageInfo = { pageNum: 1, pageSize: 10 }) {
      try {
        const res = await integralControlApi.queryUserIntegralList(pageInfo)
        if (res.code === '0') {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      } catch (error) {
      }
    }
  }
}
</script>
 
<style lang="scss">
.integral-control-form{
  .el-row{
    display: block;
  }
  hr{
    height:1px;
    border:none;
    background-color: #ccc;
  }
  .control-form{
    //  width: 1500px;
    .integral-control-area{
      // width: 750px;
      padding: 0 20px;
    }
  }
}
</style>