Przeglądaj źródła

fix: dedupe withdraw records

root 1 dzień temu
rodzic
commit
1605a1a4c3

+ 21 - 2
packageUser/pages/user/withdraw/withdraw.js

@@ -5,6 +5,23 @@ function formatWithdrawStateText (state) {
   }
   return state || ''
 }
+function uniqueWithdrawList (list) {
+  var result = []
+  var seen = {}
+  ;(list || []).forEach(function (item) {
+    var key = item.order_id || item.id
+    if (!key) {
+      result.push(item)
+      return
+    }
+    if (seen[key]) {
+      return
+    }
+    seen[key] = true
+    result.push(item)
+  })
+  return result
+}
 Page({
 
   /**
@@ -75,12 +92,14 @@ Page({
   getCashList () {
     console.log(this.data.page)
     var that = this
+    var requestPage = that.data.page
     var url = 'v1/user/takecash/flow'
     var params = {
-      page: that.data.page,
+      page: requestPage,
       per_page: that.data.per_page
     }
     var success = function (res) {
+      var shouldReplace = requestPage === 1 || that.data.cashList_change
       if (that.data.cashList_change) {
         that.setData({
           cashList: [],
@@ -99,7 +118,7 @@ Page({
           item.can_confirm_transfer = false
         }
       })
-      var result = that.data.cashList.concat(list)
+      var result = uniqueWithdrawList((shouldReplace ? [] : that.data.cashList).concat(list))
       var listMore = res.data.list_count > result.length
       that.setData({
         cashList: result,

+ 1 - 1
packageUser/pages/user/withdraw/withdraw.wxml

@@ -21,7 +21,7 @@
 
   <view class="withdraw-list" wx:if="{{cashList.length > 0}}">
 
-    <view class="withdraw-info" wx:key="{{index}}" wx:for="{{cashList}}">
+    <view class="withdraw-info" wx:key="order_id" wx:for="{{cashList}}">
       <view class="withdraw-goods">
         <view class="name"><!-- 【{{item.source_name}}】{{item.remark}} -->申请提现
         <view class="money"><currency symbol="-" value="{{item.count}}" ></currency>元</view>