import React, { Component } from 'react'
import {
View,
Image,
Text,
PixelRatio,
SectionList,
TouchableOpacity,
ImageBackground,
} from 'react-native'
import CountNum from '../../components/CountNum'
import Checkbox from '../../components/checkbox/index'
import png from '../../static/images/defaultimg.jpg'
import Row from './SwipeList'
import Collapsible from 'react-native-collapsible'
import Icon from '../../components/Iconfont/Iconfont'
import dropDown from '../../static/images/shop-dropdown.png'
import { NavigationActions, createAction } from '../../utils'
import { ScaleUtil, accMul } from '../../utils/utils'
import { ImageBaseUrl } from '../../utils/fetch/Fetchx'
import Toast from 'react-native-root-toast'
class ShoppingCart extends Component {
constructor(props) {
super(props)
this.state = {
// data: this.props.ShopList,
sectionActive: 'aaasd',
reflish: true,
deleteId: '',
selectSup: '',
clickNum: 0,
}
}
checkStockNum(data) {
lessStock = []
data.map(item => {
if (item.stock < 1) {
lessStock.push(item.goodsDisplayName)
}
})
return lessStock
}
async _settleTou() {
let newShopData = JSON.parse(JSON.stringify(this.props.ShopList)),
editData = [],
// 供应商或销售商
SaleOrSupplier = {}
const cartIds = []
for (val of newShopData) {
for (valSec of val.data) {
if (valSec.isChecked) {
editData.push(valSec)
}
}
}
if (this.toast) {
Toast.hide(this.toast)
}
if (editData && editData.length > 0) {
// if (this.checkStockNum(editData).length > 0) {
// let lessStockName = this.checkStockNum(editData).join()
// this.toast = Toast.show(
// `您所选的商品: ${lessStockName}\n库存不足,请重新选择!`,
// { position: toastHeight }
// )
// } else {
// 测试时 如果没有价格 加个 editData[0].salePrice =100
let index = 1;
for (data of editData) {
cartIds.push(data.id)
delete data.isChecked
data.id = null
data.rowNum = index * 10 + ""
index++
data.promPrice = data.salePrice
data.dealPrice = data.salePrice
data.isGift = 0
if (!data.goodsName) {
data.goodsName = data.goodsDisplayName
} else if (!data.goodsDisplayName) {
data.goodsDisplayName = data.goodsName
}
// data.currency = currency.id;
// data.currencySign = currency.currencySign;
// data.currencyPriceScale = currency.currencyPriceScale || 2; // 币种单价精度
// data.currencyAmountScale = currency.currencyAmountScale || 2; // 币种金额精度
// data.stock = data.stockNum;
data.mainNum = accMul(data.orderNum, data.conversionRate)
data.amount = accMul(data.salePrice, data.orderNum)
data.dealAmount = accMul(data.salePrice, data.orderNum)
}
SaleOrSupplier.SaleOrSupplierId =
editData[0].saleOrgId || editData[0].supplierId
SaleOrSupplier.SaleOrSupplierName =
editData[0].saleOrgName || editData[0].supplierName
SaleOrSupplier.SaleOrSupplierCode =
editData[0].saleOrgCode || editData[0].supplierCode
SaleOrSupplier.isPrimaryChannel = editData[0].isPrimaryChannel
this.props.pressLoading(true)
// 促销服务请求
await this.props.dispatch(
createAction('orderedit/getProm')({
promInfo: {
customerId: CUSTOMERINFO.id,
saleOrgId: SaleOrSupplier.SaleOrSupplierId,
reqOrderItems: editData,
isPrimaryChannel: SaleOrSupplier.isPrimaryChannel,
},
})
)
this.props.pressLoading(false)
this.props.dispatch(
NavigationActions.navigate({
routeName: 'OrderEdit',
params: {
ShopData: editData,
SaleOrSupplier: SaleOrSupplier,
cartId: cartIds,
},
})
)
// }
} else {
this.toast = Toast.show('请选择商品再结算!', { position: toastHeight })
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.edited !== this.props.edited) {
for (val of this.props.ShopList) {
val.isChecked = false
for (valSec of val.data) {
valSec.isChecked = false
}
}
}
if (nextProps.change) {
if (nextProps.secectAll) {
for (let val of this.props.ShopList) {
val.isChecked = true
val.data.map(item => {
item.isChecked = true
})
}
this.setState({ reflish: !this.state.reflish })
} else {
for (let val of this.props.ShopList) {
val.isChecked = false
val.data.map(item => {
item.isChecked = false
})
}
this.setState({ reflish: !this.state.reflish })
}
}
}
Header(section) {
return (
{
if (this.props.edited) {
// 编辑状态下
section.isChecked = bool
if (section.isChecked) {
for (let item of section.data) {
item.isChecked = true
}
} else {
for (let item of section.data) {
item.isChecked = false
}
}
if (
this.props.ShopList.every(items => items.isChecked == true)
) {
this.props.secectOnchange(true)
} else {
this.props.secectOnchange(false)
}
} else {
// 非编辑状态下
if (
this.props.ShopList.some(
item =>
Object.keys(item).indexOf('isChecked') !== -1 &&
item.isChecked == true
)
) {
for (val of this.props.ShopList) {
val.isChecked = false
for (secVal of val.data) {
secVal.isChecked = false
}
}
section.isChecked = bool
} else {
for (val of this.props.ShopList) {
for (valsec of val.data) {
if (valsec.isChecked) {
if (valsec.saleOrgId !== section.saleOrgId) {
valsec.isChecked = false
}
}
}
}
section.isChecked = bool
}
this.props.calAmount(this.props.ShopList)
}
if (section.isChecked) {
for (let item of section.data) {
item.isChecked = true
}
} else {
for (let item of section.data) {
item.isChecked = false
}
}
this.setState({
selectSup: section.saleOrgId,
})
}}
label={
{section.saleOrgName}
}
/>
this.state.sectionActive !== section.saleOrgName
? this.setState({ sectionActive: section.saleOrgName })
: this.setState({ sectionActive: 'aaaasd' })
}
style={{ alignSelf: 'center' }}
>
{
section.data.sort((a, b) => a.goodsCode - b.goodsCode)
this.setState({ sectionActive: 'aaasd' })
}}
style={{
flexDirection: 'row',
}}
>
按编码正序
{
section.data.sort((a, b) => b.goodsCode - a.goodsCode)
this.setState({ sectionActive: 'aaasd' })
}}
style={{
marginTop: 14,
flexDirection: 'row',
}}
>
按编码倒序
{
section.data.sort((a, b) => a.creationTime - b.creationTime)
this.setState({ sectionActive: 'aaasd' })
}}
style={{
paddingTop: 10,
paddingBottom: 15,
borderTopColor: '#EEE',
borderTopWidth: 1 / PixelRatio.get(),
}}
>
取消排序
)
}
ListItem(item, index) {
return (
this.props.addThis && this.props.addThis(e)}
deleteTouch={e => {
this.props.onRefresh()
this.setState({ deleteId: e })
}}
>
{
if (this.props.edited) {
// 编辑状态
item.isChecked = bool
for (let val of this.props.ShopList) {
if (item.saleOrgId == val.saleOrgId) {
if (val.data.every(item => item.isChecked == true)) {
val.isChecked = true
} else {
val.isChecked = false
}
}
}
if (
this.props.ShopList.every(
itemsec => itemsec.isChecked == true
)
) {
this.props.secectOnchange(true)
} else {
this.props.secectOnchange(false)
}
} else {
// 费编辑状态下
if (this.state.clickNum == 0) {
item.isChecked = bool
}
if (item.saleOrgId == this.state.selectSup) {
item.isChecked = bool
} else {
for (val of this.props.ShopList) {
val.isChecked = false
for (secVal of val.data) {
secVal.isChecked = false
}
}
item.isChecked = bool
}
for (let valth of this.props.ShopList) {
if (item.saleOrgName == valth.saleOrgName) {
if (valth.data.every(item => item.isChecked == true)) {
valth.isChecked = true
} else {
valth.isChecked = false
}
}
}
this.props.calAmount(this.props.ShopList)
}
this.setState({
clickNum: this.state.clickNum + 1,
selectSup: item.saleOrgId,
})
}}
/>
{item.goodsDisplayName}
编码:{item.goodsCode}
{/* 型号:{item.model?(item.model.length>10?item.model.substr(0,10)+"...":item.model):""} */}
型号:{item.model?item.model:""}
规格:{item.specification?(item.specification.split("/")[0]+"/"+item.mainNumUnitName):""}
颜色:{item.baseGoodsOptValue}
{/*
库存:{item.stock} 件
*/}
{CURRENCY.currencySign}
{item.salePrice || item.basePrice}/件
{
item.mainNum = accMul(item.orderNum, item.conversionRate)
this.props.dispatch(
createAction('shoppingcart/editShop')({
item: item,
cbNumber: nv,
})
)
this.props.calAmount(this.props.ShopList)
}}
/>
主数量:{accMul(item.orderNum, item.conversionRate)}
{item.mainNumUnit}
金额:
{CURRENCY.currencySign}
{item.salePrice
? accMul(item.orderNum, item.salePrice)
: accMul(item.orderNum, item.basePrice || 0)}
)
}
render() {
extradata = { ...this.state, ...this.props }
return (
index}
extraData={extradata}
renderSectionHeader={({ section }) => this.Header(section)}
renderItem={({ item, index }) => this.ListItem(item, index)}
stickySectionHeadersEnabled={true}
sections={this.props.ShopList}
/>
)
}
}
export default ShoppingCart