index.vue 25.2 KB
Newer Older
1 2 3
<template>
  <div class="app-container">
    <div class="container">
chenwei's avatar
chenwei committed
4
      <div class="formBox exchangeRecordOperation">
chenwei's avatar
chenwei committed
5
        <el-form v-for="(item, index) in queryParamsList" :key="item.memberId" :model="queryParamsList[index]" :ref="`queryForm${item.memberId}`" size="small" :inline="true" :rules="rules" :disabled="viewRecordDisable" label-width="148px">
6 7
          <el-card class="box-card">
            <div slot="header" class="clearfix">
8 9 10 11 12 13 14 15 16 17
              <div>
                <el-row :gutter="10" v-if="$route.query.pageStatus != 'add'">
                  <el-form-item :label="$t('记录ID')">
                    <el-input :placeholder="$t('请输入记录ID')" clearable disabled v-model="item.redemptionNumber" />
                  </el-form-item>
                  <el-form-item :label="$t('状态')">
                    <el-input :placeholder="$t('请输入状态')" clearable disabled v-model="item.exchangeStatusName" />
                  </el-form-item>
                </el-row>
              </div>
18 19 20 21 22
              <el-row :gutter="10">
                <span class="card-title">{{ $t("基础信息") }}</span>
              </el-row>
              <el-row :gutter="10">
                <el-form-item :label="$t('会员名称')">
chenwei's avatar
chenwei committed
23
                  <el-autocomplete v-model="item.memberName" :disabled="rewardEdit || veriftyDisable" :fetch-suggestions="querySearchAsync" :placeholder="$t('请输入会员名称')" @select="handleSelectMemberQuery"></el-autocomplete>
24 25 26 27 28 29 30 31
                  <!-- <el-input
                    :placeholder=""
                    clearable
                    v-model="item.memberName"
                    onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')"
                  /> -->
                </el-form-item>
                <el-form-item id="colorRedInput" :label="$t('当前积分')">
chenwei's avatar
chenwei committed
32
                  <el-input :placeholder="$t('请输入当前积分')" clearable :disabled="true" v-model="item.holdScore" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
33
                </el-form-item>
chenwei's avatar
chenwei committed
34 35
                <el-form-item :label="$t('礼品选择')" prop="rewardName" id="colorRedInput">
                  <el-input :placeholder="$t('请选择礼品')" clearable :disabled="true" v-model="item.rewardName" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
36
                </el-form-item>
37
                <el-button :disabled="rewardEdit || veriftyDisable" type="success" size="small" @click="handleSelectMember"> {{ $t("选择") }}</el-button>
38
                <el-form-item :label="$t('礼品积分')" id="colorRedInput">
chenwei's avatar
chenwei committed
39
                  <el-input :placeholder="$t('请输入礼品积分')" clearable :disabled="true" v-model="item.pointsRequire" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
40 41 42 43 44 45 46 47 48
                </el-form-item>
                <el-form-item :label="$t('兑换数量')" prop="rewardCount">
                  <el-input
                    :placeholder="$t('请输入兑换数量')"
                    :disabled="rewardEdit || veriftyDisable"
                    clearable
                    v-model.number="item.rewardCount"
                    @change="
                      (val) => {
chenwei's avatar
chenwei committed
49
                        handleRewardCount(item, index, val)
50 51 52 53 54 55
                      }
                    "
                    onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')"
                  />
                </el-form-item>
                <el-form-item :label="$t('本次兑换积分')" id="colorRedInput">
chenwei's avatar
chenwei committed
56
                  <el-input :placeholder="$t('请输入本次兑换积分')" clearable :disabled="true" v-model="item.spendCredit" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
57 58
                </el-form-item>
                <el-form-item :label="$t('兑换后剩余积分')" id="colorRedInput">
chenwei's avatar
chenwei committed
59
                  <el-input :placeholder="$t('兑换后剩余积分')" clearable :disabled="true" id="colorRedInput" v-model="item.remainingPoints" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
60 61 62 63 64 65 66 67
                </el-form-item>
              </el-row>
              <el-row :gutter="10">
                <el-row>
                  <span class="card-title">{{ $t("详细信息") }}</span>
                </el-row>
                <el-row>
                  <el-form-item :label="$t('兑换方式')" prop="redeemType">
chenwei's avatar
chenwei committed
68
                    <dict-selector clearable :disabled="veriftyDisable" :type="DICT_TYPE.WAY_OF_RECEIVING" v-model="item.redeemType"> </dict-selector>
69 70
                  </el-form-item>
                  <el-form-item :label="$t('兑换入口')">
chenwei's avatar
chenwei committed
71
                    <dict-selector clearable :disabled="true" v-model="item.entrance" :type="DICT_TYPE.PLATFORM_TYPE"> </dict-selector>
72
                  </el-form-item>
chenwei's avatar
chenwei committed
73
                  <el-form-item class="expenses" :label="$t('费用')">
chenwei's avatar
chenwei committed
74
                    <el-row>
75 76
                      <el-col :span="12">
                        <el-form-item prop="expenses">
chenwei's avatar
chenwei committed
77
                          <el-input v-model="item.expenses" :disabled="veriftyDisable" :placeholder="$t('请输入数字')" clearable onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
78 79
                        </el-form-item>
                      </el-col>
chenwei's avatar
chenwei committed
80
                      <el-col :span="12">
81
                        <el-form-item prop="currency">
chenwei's avatar
chenwei committed
82 83
                          <el-select v-model="item.currency" :disabled="veriftyDisable" clearable :placeholder="$t('请选择币种')">
                            <el-option v-for="nodeItem in currencyList" :key="nodeItem.id" :label="isChinese ? nodeItem.titleZh : nodeItem.titleEn" :value="nodeItem.id" />
84 85 86 87 88
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form-item>
chenwei's avatar
chenwei committed
89
                  <el-form-item :label="$t('收件人姓名')"><el-input :placeholder="$t('请输入收件人姓名')" clearable v-model="item.recipientName" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" /> </el-form-item>
chenwei's avatar
chenwei committed
90
                  <el-form-item :label="$t('收件人电话')">
chenwei's avatar
chenwei committed
91
                    <el-input :placeholder="$t('请输入收件人电话')" clearable v-model="item.recipientPhoneNum" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
92
                  </el-form-item>
chenwei's avatar
chenwei committed
93 94
                  <el-form-item :label="$t('收件人地址')" v-if="item.redeemType != '1'">
                    <el-input :placeholder="$t('请输入收件人地址')" clearable v-model="item.recipientAddress" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
95 96
                  </el-form-item>
                  <el-form-item :label="$t('兑换人')">
chenwei's avatar
chenwei committed
97
                    <el-input :placeholder="$t('请输入兑换人')" clearable v-model="item.redeemer" :disabled="veriftyDisable" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
98 99
                  </el-form-item>
                  <el-form-item :label="$t('兑换时间')">
100
                    <el-date-picker type="datetime" placement="bottom-start" :disabled="veriftyDisable" value-format="yyyy-MM-dd HH:mm:ss" :placeholder="$t('选择兑换时间')" v-model="item.redemptionTime"></el-date-picker>
101
                  </el-form-item>
chenwei's avatar
chenwei committed
102 103 104
                  <el-form-item :label="$t('快递公司')" v-if="item.redeemType != '1'">
                    <el-select v-model="item.courierCompany" :placeholder="$t('请选择快递公司')">
                      <el-option v-for="nodeItem in expressList" :key="nodeItem.id" :label="nodeItem.companyName" :value="nodeItem.id" />
105 106
                    </el-select>
                  </el-form-item>
chenwei's avatar
chenwei committed
107 108
                  <el-form-item :label="$t('快递单号')" v-if="item.redeemType != '1'">
                    <el-input :placeholder="$t('请输入快递单号')" clearable v-model="item.expressNo" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
109
                  </el-form-item>
chenwei's avatar
chenwei committed
110 111
                  <el-form-item :label="$t('快递日期')" v-if="item.redeemType != '1'">
                    <el-date-picker type="date" :placeholder="$t('选择快递日期')" v-model="item.expressDate" value-format="yyyy-MM-dd HH:mm:ss" placement="bottom-start"></el-date-picker>
112 113
                  </el-form-item>
                  <el-form-item :label="$t('快递寄出人')">
chenwei's avatar
chenwei committed
114
                    <el-input :placeholder="$t('请输入快递寄出人')" clearable v-model="item.expressSender" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')" />
115 116
                  </el-form-item>
                  <el-form-item :label="$t('上传附件')">
117
                    <file-upload v-model="item.annex" :fileType="['doc', 'docx', 'xls', 'xlsx', 'txt', 'pdf', 'jpg', 'jpeg', 'png']" :disabled="veriftyDisable || viewRecordDisable"></file-upload>
118 119
                  </el-form-item>
                  <el-form-item :label="$t('备注')">
chenwei's avatar
chenwei committed
120
                    <el-input style="width: 500px" :disabled="veriftyDisable" type="textarea" v-model="item.remark"></el-input>
121 122 123 124 125 126
                  </el-form-item>
                  <div class="view" v-if="viewRecordDisable || veriftyDisable">
                    <el-form-item :label="$t('核销人')">
                      <el-input v-model="item.verifyUser"></el-input>
                    </el-form-item>
                    <el-form-item :label="$t('核销时间')">
127
                      <el-date-picker type="datetime" :placeholder="$t('选择核销时间')" v-model="item.verifyTime" value-format="yyyy-MM-dd HH:mm:ss" placement="bottom-start"></el-date-picker>
128 129 130 131
                    </el-form-item>
                    <el-form-item :label="$t('创建人')" v-if="!veriftyDisable">
                      <el-input v-model="item.creatorName"></el-input>
                    </el-form-item>
chenwei's avatar
chenwei committed
132
                    <el-form-item :label="$t('创建时间')" v-if="!veriftyDisable">
133
                      <el-date-picker type="datetime" :placeholder="$t('创建时间')" v-model="item.createTime" value-format="yyyy-MM-dd HH:mm:ss" placement="bottom-start"></el-date-picker>
134
                    </el-form-item>
chenwei's avatar
chenwei committed
135
                    <el-form-item :label="$t('最后更新人')" v-if="!veriftyDisable">
136
                      <el-input v-model="item.updaterName"></el-input>
137
                    </el-form-item>
chenwei's avatar
chenwei committed
138
                    <el-form-item :label="$t('最后更新时间')" v-if="!veriftyDisable">
139
                      <el-date-picker type="datetime" :placeholder="$t('最后更新时间')" v-model="item.updateTime" value-format="yyyy-MM-dd HH:mm:ss" placement="bottom-start"></el-date-picker>
140 141 142 143 144 145 146 147 148 149 150
                    </el-form-item>
                  </div>
                </el-row>
              </el-row>
            </div>
          </el-card>
        </el-form>
      </div>

      <el-row justify="end" :gutter="20" type="flex" class="handleButton">
        <el-col :span="3">
chenwei's avatar
chenwei committed
151
          <el-button type="primary" @click="handleBulkConversion" v-if="!viewRecordDisable">{{ submitButtonText }}</el-button>
152 153 154 155 156 157 158
        </el-col>
        <el-col :span="3">
          <el-button @click="handleBack">{{ $t("返回") }}</el-button>
        </el-col>
      </el-row>
    </div>

chenwei's avatar
chenwei committed
159
    <choose-Gift :dialogVisible.sync="dialogVisible" @transferSelectRewards="onGetSelectRewardsInfo"> </choose-Gift>
160 161 162
  </div>
</template>
<script>
chenwei's avatar
chenwei committed
163
import { bulkConversion } from "@/api/ecw/giftManagement"
164
import FileUpload from "@/components/FileUpload/fileUpload.vue"
chenwei's avatar
chenwei committed
165 166 167 168 169 170 171 172
import chooseGift from "./components/chooseGift.vue"
import { getExpressPage } from "@/api/ecw/express"
import { getCurrencyList } from "@/api/ecw/currency"
import { getNowDateTime, parseTime } from "@/utils/ruoyi"
import { getMemberList } from "@/api/ecw/giftManagement"
import { getRewardDetailQuery, updatedRewardsDetails, verifyRedeem } from "@/api/ecw/memberManagement"
import { memberUserGet } from "@/api/member/user"
import { getDictDatas, DICT_TYPE } from "@/utils/dict"
173 174 175 176
export default {
  name: "exchangeRecordOperation",
  components: {
    chooseGift,
chenwei's avatar
chenwei committed
177
    FileUpload
178 179 180 181
  },
  data() {
    var validatePass2 = (rule, value, callback) => {
      if (!this.quantityComputation) {
chenwei's avatar
chenwei committed
182
        return callback(new Error(this.$t("兑换积分大于当前总积分,请重新输入兑换数量")))
183
      } else {
chenwei's avatar
chenwei committed
184
        return callback()
185
      }
chenwei's avatar
chenwei committed
186
    }
chenwei's avatar
chenwei committed
187 188
    var expensesCurrency = (rule, value, callback) => {
      if (this.queryParamsList[0].expenses && !value) {
chenwei's avatar
chenwei committed
189
        return callback(new Error(this.$t("请选择币种")))
chenwei's avatar
chenwei committed
190
      } else {
chenwei's avatar
chenwei committed
191
        return callback()
chenwei's avatar
chenwei committed
192
      }
chenwei's avatar
chenwei committed
193
    }
chenwei's avatar
chenwei committed
194
    var expensesValidate = (rule, value, callback) => {
chenwei's avatar
chenwei committed
195
      if (this.queryParamsList[0].currency && !value) {
chenwei's avatar
chenwei committed
196
        return callback(new Error(this.$t("请输入")))
chenwei's avatar
chenwei committed
197
      } else {
chenwei's avatar
chenwei committed
198
        return callback()
chenwei's avatar
chenwei committed
199
      }
chenwei's avatar
chenwei committed
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
    return {
      env: process.env.NODE_ENV,
      // 是否显示弹出层
      dialogVisible: false,

      // 查询参数
      queryParamsList: [
        {
          memberId: null,
          holdScore: null,
          rewardId: "",
          pointsRequire: "",
          rewardCount: null,
          spendCredit: null, //本次兑换花费积分
          remainingPoints: null, //剩余积分
          redeemType: null,
          entrance: 1,
          expenses: null,
          currency: null,
          recipientName: null,
          recipientPhoneNum: null,
          recipientAddress: null,
          redeemer: this.$store.getters.name,
          redemptionTime: getNowDateTime(),
          courierCompany: null,
          expressNo: null,
          expressSender: this.$store.getters.name,
          expressDate: null,
          remark: null,
          annex: null,
          memberName: null,
chenwei's avatar
chenwei committed
232 233
          rewardName: null
        }
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
      ],
      // 网点
      nodeList: [],
      //快递公司列表
      expressList: [],
      currencyList: [],
      quantityComputation: null,
      checkFormResult: [],
      rewardEdit: false,
      submitButtonText: "确认兑换",
      viewRecordDisable: false,
      veriftyDisable: false,
      rules: {
        rewardCount: [
          {
            required: true,
            message: this.$t("请输入兑换数量"),
chenwei's avatar
chenwei committed
251
            trigger: "blur"
252 253 254
          },
          {
            validator: validatePass2,
chenwei's avatar
chenwei committed
255 256
            trigger: ["blur", "change"]
          }
257
        ],
258 259 260 261
        rewardName: [
          {
            required: true,
            message: this.$t("请选择礼品"),
chenwei's avatar
chenwei committed
262 263
            trigger: "blur"
          }
264
        ],
265
        expenses: [
chenwei's avatar
chenwei committed
266 267 268 269 270
          // {
          //   required: true,
          //   message: this.$t("请输入费用"),
          //   trigger: "blur",
          // },
271 272 273
          {
            pattern: /^\d+(\.\d{1,2})?$/,
            message: this.$t("请输入整数或保留小数点后两位"),
chenwei's avatar
chenwei committed
274
            trigger: "blur"
275
          },
chenwei's avatar
chenwei committed
276
          {
chenwei's avatar
chenwei committed
277
            validator: expensesValidate,
chenwei's avatar
chenwei committed
278 279
            trigger: "change"
          }
280 281 282
        ],
        currency: [
          {
chenwei's avatar
chenwei committed
283 284
            // required: true,
            // message: this.$t("请选择币种"),
chenwei's avatar
chenwei committed
285
            validator: expensesCurrency,
chenwei's avatar
chenwei committed
286 287
            trigger: "change"
          }
288 289 290 291 292
        ],
        redeemType: [
          {
            required: true,
            message: this.$t("请选择兑换方式"),
chenwei's avatar
chenwei committed
293 294
            trigger: "change"
          }
295 296 297 298 299
        ],
        recipientName: [
          {
            required: true,
            message: this.$t("请输入收件人姓名"),
chenwei's avatar
chenwei committed
300 301
            trigger: "blur"
          }
302 303 304 305 306
        ],
        recipientPhoneNum: [
          {
            required: true,
            message: this.$t("请输入收件人电话"),
chenwei's avatar
chenwei committed
307 308
            trigger: "blur"
          }
309 310 311 312 313
        ],
        recipientAddress: [
          {
            required: true,
            message: this.$t("请输入收件人地址"),
chenwei's avatar
chenwei committed
314 315 316 317 318
            trigger: "blur"
          }
        ]
      }
    }
319 320 321
  },
  computed: {
    isChinese() {
chenwei's avatar
chenwei committed
322 323
      return this.$i18n.locale === "zh_CN"
    }
324 325
  },
  created() {
chenwei's avatar
chenwei committed
326 327
    this.getExpressList()
    this.currencyListAPI()
328 329 330

    switch (this.$route.query.pageStatus) {
      case "edit":
chenwei's avatar
chenwei committed
331 332 333
        this.submitButtonText = this.$t("保存")
        this.getExchangeDetail()
        break
334
      case "view":
chenwei's avatar
chenwei committed
335 336 337
        this.viewRecordDisable = true
        this.getExchangeDetail()
        break
338
      case "verify":
chenwei's avatar
chenwei committed
339 340 341 342
        this.veriftyDisable = true
        this.submitButtonText = this.$t("确认核销")
        this.getExchangeDetail()
        break
343
      case "add":
chenwei's avatar
chenwei committed
344
        this.submitButtonText = this.$t("确认兑换")
345
        // this.getDetails()
chenwei's avatar
chenwei committed
346
        break
347 348

      default:
chenwei's avatar
chenwei committed
349 350
        this.submitButtonText = this.$t("确认兑换")
        break
351 352 353 354 355
    }
  },

  activated() {},
  methods: {
356 357 358 359
    // 兑换状态
    handleExchangeStatus(id) {
      return this.isChinese ? this.getDictDatas(DICT_TYPE.REWARD_REDEEM_STATUS).filter((item) => item.value == id)[0].label : this.getDictDatas(DICT_TYPE.REWARD_REDEEM_STATUS).filter((item) => item.value == id)[0].labelEn
    },
360 361 362
    getDetails() {
      memberUserGet({ id: this.$route.query.memberId }).then((r) => {
        // this.details = r.data;
363

chenwei's avatar
chenwei committed
364 365 366 367
        this.isChinese ? (this.queryParamsList[0].memberName = r.data.nickname) : (this.queryParamsList[0].memberName = r.data.englishName)
        this.queryParamsList[0].holdScore = r.data.userScoreLevelInfo.holdScore
        this.queryParamsList[0].memberId = r.data.id
      })
368 369
    },
    getExchangeDetail() {
chenwei's avatar
chenwei committed
370
      this.queryParamsList = []
371 372
      this.$nextTick(() => {
        let params = {
chenwei's avatar
chenwei committed
373 374
          id: this.$route.query.exchangeRewardID
        }
375
        getRewardDetailQuery(params).then((res) => {
chenwei's avatar
chenwei committed
376 377 378 379
          this.rewardEdit = true
          const data = res.data
          let params = this.queryParamsList[0]
          this.queryParamsList = [{ ...data, params }]
380 381

          if (this.isChinese) {
chenwei's avatar
chenwei committed
382 383
            this.queryParamsList[0].memberName = data.memberNameZh
            this.queryParamsList[0].rewardName = data.rewardTitleZh
384
          } else {
chenwei's avatar
chenwei committed
385 386
            this.queryParamsList[0].memberName = data.memberNameEn
            this.queryParamsList[0].rewardName = data.rewardTitleEn
387
          }
chenwei's avatar
chenwei committed
388
          this.queryParamsList[0].redemptionTime = parseTime(data.redemptionTime) //兑换时间
389

390
          this.queryParamsList[0].verifyUser = data.verifyUser
391

chenwei's avatar
chenwei committed
392 393 394 395
          this.queryParamsList[0].verifyTime = parseTime(data.verifyTime)
          this.queryParamsList[0].updateTime = parseTime(data.updateTime)
          this.queryParamsList[0].createTime = parseTime(data.createTime)
          this.queryParamsList[0].expressDate = parseTime(data.expressDate) //快递时间
396
          this.queryParamsList[0].exchangeStatusName = this.handleExchangeStatus(data.status)
chenwei's avatar
chenwei committed
397
          this.handleRewardCount(data, 0, data.rewardCount)
398
          if (this.$route.query.pageStatus == "verify") {
399
            this.queryParamsList[0].verifyUser = this.$store.getters.name
chenwei's avatar
chenwei committed
400
            this.queryParamsList[0].verifyTime = getNowDateTime()
401
          }
chenwei's avatar
chenwei committed
402 403 404
          this.$forceUpdate()
        })
      })
405 406
    },
    handleSelectMemberQuery(item) {
chenwei's avatar
chenwei committed
407 408 409
      this.isChinese ? (this.queryParamsList[0].memberName = item.memberNameZh) : (this.queryParamsList[0].memberName = item.englishName)
      this.queryParamsList[0].holdScore = item.holdScore
      this.queryParamsList[0].memberId = item.id
410

chenwei's avatar
chenwei committed
411
      this.queryParamsList[0].spendCredit = this.queryParamsList[0].pointsRequire * this.queryParamsList[0].rewardCount
412

chenwei's avatar
chenwei committed
413 414
      this.queryParamsList[0].remainingPoints = this.queryParamsList[0].holdScore - this.queryParamsList[0].spendCredit
      this.quantityComputation = this.queryParamsList[0].remainingPoints >= 0 ? true : false
415 416
    },
    querySearchAsync(queryString, cb) {
chenwei's avatar
chenwei committed
417
      let result = []
418
      if (queryString == "") {
chenwei's avatar
chenwei committed
419
        cb(result)
420 421 422 423 424 425 426 427 428 429 430 431 432
      } else {
        try {
          let params = {
            country: null,
            city: null,
            endTime: "",
            holdScore: null,
            holdScoreOperate: null,
            key: this.queryParamsList[0].memberName,
            pageNo: 1,
            pageSize: 20,
            startTime: "",
            usedScore: null,
chenwei's avatar
chenwei committed
433 434
            usedScoreOperate: null
          }
435 436 437 438 439
          getMemberList(params).then((res) => {
            result = res.data.list.map((item) => {
              if (this.isChinese) {
                return {
                  ...item,
chenwei's avatar
chenwei committed
440 441
                  value: `${item.memberNameZh}(${item.mobile})`
                }
442 443 444
              } else {
                return {
                  ...item,
chenwei's avatar
chenwei committed
445 446
                  value: `${item.memberNameEn}(${item.mobile})`
                }
447
              }
chenwei's avatar
chenwei committed
448 449 450
            })
            cb(result)
          })
451
        } catch {
chenwei's avatar
chenwei committed
452
          this.$message.success(this.$t("获取数据失败"))
453 454 455 456
        }
      }
    },
    handleRewardCount(item, index, value) {
chenwei's avatar
chenwei committed
457 458 459
      this.queryParamsList[index].spendCredit = this.queryParamsList[index].pointsRequire * value
      this.queryParamsList[index].remainingPoints = this.queryParamsList[index].holdScore - this.queryParamsList[index].spendCredit
      this.quantityComputation = this.queryParamsList[index].remainingPoints >= 0 ? true : false
460 461 462 463
    },

    currencyListAPI() {
      getCurrencyList().then((res) => {
chenwei's avatar
chenwei committed
464 465
        this.currencyList = res.data
      })
466 467
    },
    onGetSelectRewardsInfo(item) {
chenwei's avatar
chenwei committed
468
      this.queryParamsList[0].rewardId = item.id
469
      this.queryParamsList[0].redeemType = item.pickMethod.split(",")[0]
470
      if (this.isChinese) {
chenwei's avatar
chenwei committed
471
        this.queryParamsList[0].rewardName = item.titleZh
472
      } else {
chenwei's avatar
chenwei committed
473
        this.queryParamsList[0].rewardName = item.titleEn
474
      }
chenwei's avatar
chenwei committed
475
      this.queryParamsList[0].pointsRequire = item.pointsRequire
476

chenwei's avatar
chenwei committed
477 478 479 480
      this.queryParamsList[0].rewardCount = "1"
      this.queryParamsList[0].spendCredit = ""
      this.queryParamsList[0].remainingPoints = this.queryParamsList[0].holdScore
      this.quantityComputation = this.queryParamsList[0].remainingPoints >= 0 ? true : false
chenwei's avatar
chenwei committed
481
      // if (this.queryParamsList[0].holdScore) {
chenwei's avatar
chenwei committed
482
      this.handleRewardCount({}, 0, 1)
chenwei's avatar
chenwei committed
483
      // }
484 485
    },
    handleSelectMember() {
chenwei's avatar
chenwei committed
486
      this.dialogVisible = true
487 488 489 490
    },
    getExpressList() {
      let params = {
        pageNo: 1,
chenwei's avatar
chenwei committed
491 492
        pageSize: 1000
      }
493
      getExpressPage(params).then((res) => {
chenwei's avatar
chenwei committed
494 495
        this.expressList = res.data.list
      })
496 497
    },
    handleBack() {
chenwei's avatar
chenwei committed
498
      this.$store.dispatch("tagsView/delCurrentView")
499 500 501 502 503
    },
    checkForm(formName) {
      const result = new Promise((resolve, reject) => {
        this.$refs[formName][0].validate((valid) => {
          if (valid) {
chenwei's avatar
chenwei committed
504
            resolve()
505
          } else {
chenwei's avatar
chenwei committed
506
            reject()
507
          }
chenwei's avatar
chenwei committed
508 509 510
        })
      })
      this.checkFormResult.push(result)
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
    },
    resetForm() {
      this.queryParamsList = [
        {
          memberId: null,
          holdScore: null,
          rewardId: "",
          pointsRequire: "",
          rewardCount: null,
          spendCredit: null, //本次兑换花费积分
          remainingPoints: null, //剩余积分
          redeemType: null,
          entrance: 1,
          expenses: null,
          currency: null,
          recipientName: null,
          recipientPhoneNum: null,
          recipientAddress: null,
          redeemer: this.$store.getters.name,
          redemptionTime: getNowDateTime(),
          courierCompany: null,
          expressNo: null,
          expressSender: this.$store.getters.name,
          expressDate: null,
          remark: null,
          annex: null,
          memberName: null,
chenwei's avatar
chenwei committed
538 539 540
          rewardName: null
        }
      ]
541 542 543
    },
    handleBulkConversion() {
      this.queryParamsList.forEach((element) => {
chenwei's avatar
chenwei committed
544 545
        this.checkForm(`queryForm${element.memberId}`)
      })
546 547 548

      Promise.all(this.checkFormResult)
        .then((res) => {
chenwei's avatar
chenwei committed
549
          this.checkFormResult = []
550 551
          let params = this.queryParamsList.map((item) => {
            if (item.redeemType == "1") {
chenwei's avatar
chenwei committed
552 553
              let { recipientAddress, expressNo, expressDate, courierCompany, ...itemNew } = item
              return itemNew
554
            } else {
chenwei's avatar
chenwei committed
555
              return item
556
            }
chenwei's avatar
chenwei committed
557
          })
558 559
          if (this.$route.query.pageStatus == "edit") {
            updatedRewardsDetails(params[0]).then((res) => {
chenwei's avatar
chenwei committed
560 561 562
              this.$message.success(this.$t("更新成功"))
              this.$router.go(-1)
            })
563 564 565
            //编辑
          } else if (this.$route.query.pageStatus == "verify") {
            verifyRedeem(params[0]).then((res) => {
chenwei's avatar
chenwei committed
566 567 568
              this.$message.success(this.$t("核销成功"))
              this.$router.go(-1)
            })
569 570 571 572
          } else {
            //兑换
            bulkConversion(params).then((res) => {
              if (res.code == "0") {
chenwei's avatar
chenwei committed
573 574 575
                this.queryParamsList = this.resetForm()
                this.$message.success(this.$t("兑换成功"))
                this.$router.go(-1)
576
              }
chenwei's avatar
chenwei committed
577
            })
578 579 580
          }
        })
        .catch(() => {
chenwei's avatar
chenwei committed
581 582 583 584 585 586
          this.checkFormResult = []
          this.$message.error(this.$t("请填写必要的信息"))
        })
    }
  }
}
587
</script>
chenwei's avatar
chenwei committed
588 589
<style scoped lang="scss">
::v-deep #colorRedInput .el-input__inner {
590 591 592
  color: red;
  font-size: 14px;
}
chenwei's avatar
chenwei committed
593 594 595 596 597 598
::v-deep .exchangeRecordOperation {
  .el-input,
  .upload-file {
    width: 286px;
  }
  .expenses {
chenwei's avatar
chenwei committed
599 600 601 602 603 604 605 606 607 608
    width: 434px;
    .el-form-item {
      margin-right: 0;
    }
    .el-row {
      width: 286px;
    }
    .el-input {
      width: 140px;
    }
chenwei's avatar
chenwei committed
609 610 611 612
    .el-form-item--small.el-form-item {
      margin-bottom: 0;
    }
  }
chenwei's avatar
chenwei committed
613
}
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
.card-title {
  padding-right: 10px;
  border-right: 4px solid rgb(64, 158, 255);
  font-size: 16px;
  font-weight: 600;
}
.del-btn {
  color: red;
}
.container {
  padding: 20px 0;
}
.emptyText {
  font-size: 20px;
  padding: 20px;
  line-height: 200px;
  text-align: center;
  color: #97a8be;
}
.handleButton {
  padding-right: 160px;
  margin-top: 50px;
  button {
    width: 100%;
  }
}
</style>