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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<template>
  <div>
    <list-condition-template ref="table" :isExistBtn="true" :form="listQuery" :formLabel="formLabel"
                             :tableData="tableData" :total="total"
                             @page-info-change="handlePageInfoChange">
      <template slot="otherElement">
        <el-col class="formLayout" :xs='12' :sm='12' :md='12' :lg='6' :offset="0"
                style="display: flex;">
          <el-form-item label="会员等级:" style="flex-grow:1;" prop="memberLevelName">
            <el-select placeholder="请选择会员等级" style="width:calc(100% - 72px);"
                       v-model="listQuery.memberLevelName" clearable>
              <el-option v-for="item in levelArray" :key="item.memberLevelId"
                         :value="item.memberLevelName" :label="item.memberLevelName"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" :offset="0" class="buttonPosition">
          <el-button size="mini" type="primary" @click="queryData">查询</el-button>
          <el-button size="mini" @click="resetQuery">重置</el-button>
        </el-col>
      </template>
      <template slot="operationSection">
        <el-button size="mini" type="warning" @click="importMemberInfo">导入</el-button>
        <el-button size="mini" @click="downTemplate">下载模板</el-button>
      </template>
      <template slot="columns">
        <el-table-column label="会员账号" prop="memberName" width="160px" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="会员昵称" prop="memberNickName" width="160px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.memberNickName ? scope.row.memberNickName : '-'}}
          </template>
        </el-table-column>
        <el-table-column label="会员等级" prop="memberLevelName">
          <template slot-scope="scope">
            {{scope.row.memberLevelName ? scope.row.memberLevelName : '-'}}
          </template>
        </el-table-column>
        <el-table-column label="会员积分" prop="memberIntegral"></el-table-column>
        <el-table-column label="经验值" prop="empiricalNowValue"></el-table-column>
        <el-table-column label="手机号码" prop="memberPhone" width="180px"></el-table-column>
        <el-table-column label="注册时间" prop="regTime" width="180px"></el-table-column>
        <el-table-column label="会员状态" prop="state">
          <template slot-scope="scope">
            {{getArrayLable(stateArray,scope.row.state)}}
          </template>
        </el-table-column>
        <el-table-column label="会员来源" prop="state">
          <template slot-scope="scope">
            {{scope.row.memberSource?getArrayLable(memberSource,scope.row.memberSource):'APP'}}
          </template>
        </el-table-column>
        <el-table-column label="操作" :width="`${(2 * $store.getters.colSize)+20}px`">
          <template slot-scope="scope">
            <wly-btn @click="lookInfo(scope.row)">详情</wly-btn>
            <wly-btn :type="'warning'" @click="editInfo(scope.row)">状态修改</wly-btn>
          </template>
        </el-table-column>
      </template>
    </list-condition-template>
    <el-dialog :visible.sync="dialogVisible" :title="title" :close-on-click-modal="false"
               :modal-append-to-body="false" width="40%">
      <el-form size="mini" v-show="isUpdate" ref="form" :model="form" label-width="120px"
               class="detailsInfo">
        <el-form-item label="会员状态:" prop="state" :rules="{required: true, message: '请选择会员状态'}">
          <el-select placeholder="请选择会员状态" v-model="form.state" clearable>
            <el-option v-for="item in stateArray" :key="item.id" :value="item.id"
                       :label="item.name"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="原因" prop="reason" v-if="form.state === '3'" :rules="[{required: true, message: '请输入原因'},{max: 200, message: '原因最多只能输入 200 个字'}]">
                     <el-input type="textarea" v-model="form.reason" placeholder="请输入原因"  :autosize="{minRows:2,maxRows:6}"></el-input>
                </el-form-item> -->
      </el-form>
      <member-info v-show="!isUpdate" :form='form'></member-info>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" v-show="isUpdate" :loading="loading" @click="submit">
          保存</el-button>
        <el-button size="mini" @click="dialogVisible=false">关闭</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="importDialogVisible" title="导入" :close-on-click-modal="false"
               :modal-append-to-body="false" width="450px">
      <el-form ref="form" size="mini">
        <el-upload class="upload-demo" action="api" ref="upload" :limit="1" :accept="'.xlsx, .xls'"
                   :http-request="handleRequrst" :auto-upload="false" :file-list="fileList" drag>
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">只能上传一个文件,且文件格式只支持.xlsx, .xls文件</div>
        </el-upload>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" :loading="loading" @click="submitImport">确定
        </el-button>
        <el-button size="mini" @click="importDialogVisible=false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import memberInfoApi from '@/api/member/memberInfo'
import memberInfo from '@/views/memberMgt/memberInfoList/info.vue'
import { objectCopy } from '@/utils/objectCopyHelper'
import memberLevelApi from '@/api/member/memberLevel'
import { getArrayLable } from '@/utils/getArrayLable'
import { downloadFile } from '@/utils/downloadFile'
 
var _this = null
const stateArray = [
  // {
  //   id: '0',
  //   name: '注销'
  // },
  {
    id: '1',
    name: '启用'
  },
  // {
  //   id: '2',
  //   name: '禁用'
  // },
  {
    id: '3',
    name: '冻结'
  }
]
var memberSource = [
  {
    id: 'WLY',
    name: 'APP'
  },
  {
    id: 'YDJS',
    name: '缘定晶生'
  },
  {
    id: 'YDJS_YYS',
    name: '缘定晶生运营商'
  }
]
export default {
  components: { memberInfo },
  data() {
    return {
      listQuery: {
        memberNickName: null,
        memberName: null,
        startTime: null,
        state: null,
        memberLevelName: null,
        endTime: null,
        memberSource: null
      },
      formLabel: [
        {
          model: 'startTime',
          label: '注册时间',
          type: 'date',
          pickerOptions: {
            disabledDate(time) {
              return _this.listQuery.endTime && time.getTime() >= new Date(_this.listQuery.endTime).getTime() + 86400000
            }
          },
          timeClass: 'start-time-style'
        },
        {
          model: 'endTime',
          label: '-',
          customLabel: '注册时间',
          type: 'date',
          valueFormat: 'yyyy-MM-dd 23:59:59',
          labelWidth: '20px',
          pickerOptions: {
            disabledDate(time) {
              return _this.listQuery.startTime && time.getTime() <= new Date(_this.listQuery.startTime).getTime() - 86400000
            }
          },
          timeClass: 'end-time-style'
        },
        {
          model: 'memberNickName',
          label: '会员昵称',
          type: 'input'
        },
        {
          model: 'memberName',
          label: '会员账号',
          type: 'input'
        },
        {
          model: 'state',
          label: '会员状态',
          type: 'select',
          opts: stateArray
        },
        {
          model: 'memberSource',
          label: '会员来源',
          type: 'select',
          opts: memberSource
        }
      ],
      tableData: [],
      show: false,
      title: null,
      row: {},
      dialogVisible: false,
      form: {},
      total: 0,
      isUpdate: false,
      loading: false,
      levelArray: [],
      fileList: [],
      importDialogVisible: false,
      stateArray,
      memberSource
    }
  },
  created() {
    this.queryLevelList() // 查询等级
    _this = this
  },
  /*
     * 数据变化后刷新列表
   */
  activated() {
    this.queryList(this.$refs.table.getPageInfo())
  },
  methods: {
    // 下载模板
    async downTemplate() {
      const config = {
        url: 'awl-member-service/member/download/demoExcel',
        data: null,
        fileName: '会员导入模板',
        Method: 'get',
        type: '.xlsx'
      }
      const res = await downloadFile(config)
      if (res) {
        this.percentage = 100
        this.isLoading = false
      } else {
        this.percentage = 100
        this.isLoading = false
      }
    },
    // 手动上传文件
    async handleRequrst(param) {
      this.loading = true
      const formData = new FormData()
      formData.append('file', param.file)
      try {
        const res = await memberInfoApi.importMember(formData)
        if (res.code === '0') {
          this.loading = false
          this.$message.success('导入成功!')
          this.fileList = []
          this.$refs.table.reloadCurrent()
          this.importDialogVisible = false
        } else {
          this.loading = false
          this.fileList = []
        }
      } catch (error) {
        this.fileList = []
        this.$message.error('上传文件失败!请重新上传')
        this.loading = false
      }
    },
    // 打开导入三方系统会员信息窗口
    importMemberInfo() {
      this.importDialogVisible = true
    },
    // 导入三方系统会员信息
    submitImport() {
      this.$refs.upload.submit()
    },
    /**
       * '分页信息改变时查询列表
       */
    handlePageInfoChange(pageInfo) {
      this.queryList(pageInfo)
    },
 
    /**
     * 重置
     */
    resetQuery() {
      this.$refs.table.reloadCurrent()
    },
    /**
     * 点击查询按钮
     */
    queryData() {
      this.$refs.table.changeCondition()
    },
    /**
     * 查询等级
     */
    queryLevelList() {
      const query = {
        pageNum: 1,
        pageSize: 100
      }
      memberLevelApi.getList(query).then(res => {
        if (res.data) {
          this.levelArray = res.data.list
        }
      })
    },
    /**
       * 修改会员状态
       */
    submit() {
      this.loading = true
      this.$refs.form.validate().then(res => {
        memberInfoApi.updateState(this.form).then(res => {
          if (res.data) {
            this.dialogVisible = false
            this.$message({
              message: '状态修改成功',
              type: 'success'
            })
            this.row.state = this.form.state
          }
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      }).catch(() => {
        this.loading = false
      })
    },
    /**
     * 获取数组的label
     */
    getArrayLable,
    /**
     * 查看详情
     */
    lookInfo(row) {
      this.isUpdate = false
      this.dialogVisible = true
      row.stateName = getArrayLable(this.stateArray, row.state)
      this.form = row
      this.title = '会员详情'
    },
    /**
     * 修改
     */
    editInfo(row) {
      this.title = '会员状态修改'
      this.dialogVisible = true
      this.isUpdate = true
      this.form = objectCopy(row)
      this.row = row
    },
    /**
     * 查询列表
     */
    queryList(pageInfo = { pageNum: 1, pageSize: 10 }) {
      this.listQuery.state = this.listQuery.state === '' ? null : this.listQuery.state
      for (const key in this.listQuery) {
        if (!this.listQuery[key]) {
          this.listQuery[key] = null
        }
      }
      memberInfoApi.getList({ ...this.listQuery, ...pageInfo }).then(res => {
        if (res.data) {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      })
    }
  }
}
</script>