productLogic.js
5.76 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
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
import {observable,computed} from 'mobx'
import {
_allCategoryShow,
_categorySearhCondition,
_findCommodityExtend,
_addToCarByCenter,
_addPk,
_pk
} from "../integralMall/utils/AppService";
import {systemSite} from "../../index";
import {AsyncStorage} from 'react-native'
import { xnToast } from '../../utils/utils';
export default class productLogic {
@observable
activeCategory = 0
@observable
priceUp = true
@observable
saleUp = true
@observable
activeItem = null
@observable
activeBar = 0
@observable
comparedArray = []
@observable
filterActive = [0, 0]
@observable
dropActive = 0
@observable
showDrop = false
@observable
category = []
@observable
condition = []
@observable
list = []
@observable
loading = false
@observable
brandId = []
@observable
attributes = []
@observable
price = []
@observable
type = ""
@observable
sort = ""
@observable
pkList=[]
@observable
text=""
@observable
activeCategoryIndex=0
@observable
filterDisabled=false
@observable
conditionLoading=true
@observable
pageNumber=1
@observable
totalCount=0 //数据总数
@observable
supplierId=''
async getCategory() {
try {
const data = await _allCategoryShow({type: "STANDARD"})
data.result=[{id:"_null_",categoryName:"全部",categoryCode:"_null_"},...data.result]
this.category.replace(data.result)
if(!!!this.activeCategory){
this.activeCategory = data.result[0].id
}
// const {id,tenantId,categoryName,pictureId,pictureUrl}=result
if (data.error.length > 0) {
xnToast(data.firstErrorMessage)
}
} catch (e) {
}
}
async getList(flag) {
if (this.loading || ((!!this.totalCount && this.pageNumber * 30 >= this.totalCount-0)&&flag)) {
return
}
if (!!this.totalCount && (30 * this.pageNumber < this.totalCount-0)) {
this.pageNumber = this.pageNumber + 1
}
if(!flag){
//不是滚动页面
this.pageNumber=1;
}
// debugger;
this.loading = true
const options = {
operatingUnitId: systemSite.operatingUnitId,
pageSize:30,
pageNumber:this.pageNumber
}
const memberId=await AsyncStorage.getItem("memberId")
if(memberId){
options.memberId=memberId
}
if(this.activeCategory!=="_null_"){
options.categoryIds= [this.activeCategory]
}
if (!!this.type) {
console.log(this.type)
options.sortColumn = this.type
options.sortType = this.sort
}
if (this.brandId.length > 0) {
options.brandIdList = this.brandId.peek()
}
if (this.attributes.length > 0) {
options.categoryAttributeAndValuesList = this.attributes.peek()
}
if (this.price.length > 0) {
options.priceRangeList = this.price.peek()
}
if(!!this.text){
options.keyword=this.text
}
if(!!this.supplierId){
options.supplierId=this.supplierId
}
try {
console.log('options????????????????:',options);
const data = await _findCommodityExtend(options)
const {result,totalCount} = data
console.log('result--',result);
this.totalCount=totalCount
// debugger;
let array=[];
console.log('flag===========',flag);
if(flag){
//分页
if(result.length){
array=this.list.slice().concat(result);
}else{
array=this.list.slice();
}
}else{
array=result;
}
this.list.replace(array)
// this.list.concat(result)
console.log('this.list--',this.list);
} catch (e) {
}
this.loading = false
}
async getCondition() {
this.conditionLoading=true
try {
if(this.activeCategory==="_null_"){
this.condition.clear()
this.condition.push({name: "品牌", items: []})
this.condition.push({name: "属性", items: []})
this.condition.push({name: "价格", items: []})
this.filterDisabled=true
this.conditionLoading=false
return
}
const result = await _categorySearhCondition({categoryId: this.activeCategory})
if (result.errors.length > 0) {
xnToast(result.firstErrorMessage)
} else {
const {brandsList, category, categoryPriceList, categoryAttributesList} = result
this.filterDisabled=false
if(brandsList.length===0&&categoryAttributesList.length===0&&categoryPriceList.length===0){
this.filterDisabled=true
}
this.condition.clear()
this.condition.push({name: "品牌", items: []})
this.condition.push({name: "属性", items: []})
this.condition.push({name: "价格", items: []})
brandsList.map(v => this.condition[0].items.push(v))
categoryAttributesList.map(v => this.condition[1].items.push(v))
categoryPriceList.map(v => this.condition[2].items.push(v))
}
} catch (e) {
console.log(e)
}
this.conditionLoading=false
}
async addCar(id, memberId,navigation) {
try {
const data = await _addToCarByCenter({
commodityId: id,
operatingUnitId: systemSite.operatingUnitId,
storeId: systemSite.storeId,
memberId: memberId
})
const {errors, firstErrorMessage,code} = data
if(code){
await AsyncStorage.removeItem("memberId")
navigation.navigate("Login")
return false
}
if (errors.length > 0) {
xnToast(firstErrorMessage)
return false
} else {
xnToast("添加成功")
return true
}
} catch (e) {
console.log(e)
}
}
async addPk(id) {
try {
const data = await _addPk({
commodityId: id,
operatingUnitId: systemSite.operatingUnitId,
})
const {errors, firstErrorMessage,itemId} = data
if (errors.length > 0) {
xnToast(firstErrorMessage)
} else {
return itemId
}
} catch (e) {
console.log(e)
}
}
async pk(ids){
try{
const data=await _pk({
operatingUnitId: systemSite.operatingUnitId,
itemIdList:ids
})
const {errors, firstErrorMessage,result} = data
if (errors.length > 0) {
xnToast(firstErrorMessage)
} else {
this.pkList.replace(result)
}
}catch(e){
console.log(e)
}
}
}