shoppingCarLogic.js
2.25 KB
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
import {observable,computed} from 'mobx'
import {_getCarList, _carUpdate, _carDelete} from "../integralMall/utils/AppService";
import {AsyncStorage} from 'react-native';
import {systemSite} from "../../index";
import carCount from '../logic/carCountLogic'
import { xnToast } from '../../utils/utils';
class shoppingCarLogic {
@observable
itemList = []
@observable
edit = false
@observable
loading = false
@observable
chooseArray = []
@observable
carLength=0
@observable
isLogin=false
@computed
get check(){
if(this.chooseArray.length>0){
return true
}
return false
}
@computed
get isAllChoose(){
console.log('count===>',this.chooseCount,carCount.count);
if(this.chooseCount===carCount.count){
return true
}
return false
}
@computed
get chooseCount(){
let count=0
if(this.chooseArray.length>0){
for(let v of this.chooseArray){
count=v.quantity+count
}
}
return count
}
async getList(memberId,navigation) {
this.loading = true
try {
const {operatingUnitId, storeId} = systemSite
const data = await _getCarList({memberId, operatingUnitId, storeId})
const {errors, firstErrorMessage, supplierCartList,code} = data
if(code){
await AsyncStorage.removeItem("memberId")
navigation.navigate("Login")
return
}
if (errors.length > 0) {
xnToast(firstErrorMessage)
} else {
this.itemList.replace(supplierCartList)
this.carLength=0
for(let v of this.itemList){
this.carLength=this.carLength+v.cartList.length
}
}
} catch (e) {
console.log(e)
}
this.loading = false
}
async carUpdate(id, quantity) {
try {
const data = await _carUpdate({
id,
quantity,
})
const {errors, firstErrorMessage} = data
if (errors.length > 0) {
xnToast(firstErrorMessage)
return false
} else {
return true
}
} catch (e) {
console.log(e)
}
}
async del() {
try {
const ids = this.chooseArray.map(v => v.id)
const data = await _carDelete({ids})
this.chooseArray.clear()
const {errors, firstErrorMessage} = data
if (errors.length > 0) {
xnToast(firstErrorMessage)
return false
} else {
return true
}
} catch (e) {
console.log(e)
}
}
}
export default new shoppingCarLogic()