Ver código fonte

订单编辑详情增加选商品功能

徐鹏 2 anos atrás
pai
commit
7ec279fd47

+ 216 - 0
app/containers/commodity/commoditydetail/GoodsFlatList.js

@@ -0,0 +1,216 @@
+import React, { Component } from 'react'
+import {
+  StyleSheet,
+  View,
+  Dimensions,
+  TouchableOpacity,
+  Text,
+  FlatList,
+} from 'react-native'
+import Toast from 'react-native-root-toast'
+import { connect } from 'react-redux'
+import { createAction } from '../../../utils'
+import Input from '../../../components/input'
+import * as authService from '../../../services/auth'
+const { width, height } = Dimensions.get('window')
+// @connect(({ optional }) => ({ ...optional }))
+class GoodsFlatList extends Component {
+  constructor(props) {
+    super(props)
+    this.state = { goodsList: [], kw: '', checkList: [] }
+  }
+
+  async componentDidMount() {
+    this.getGoodsByKW('', true)
+  }
+
+  //颜色卡片列表
+  _goodsList( item, index,goodsList) {
+    return(
+      <View>
+        <TouchableOpacity
+          disabled={false}
+          key={item.attrValId}
+          activeOpacity={1}
+          style={{
+            paddingHorizontal: 16,
+            paddingVertical: 2,
+            borderBottomColor: item.isChecked ? '#E14C46' : '#DDD',
+            borderBottomWidth: item.isChecked ? 3 : 1,
+            justifyContent: 'flex-start',
+            alignItems: 'flex-start',
+            marginRight: 15,
+            width: 320,
+            marginTop : 5
+          }}
+          onPress={() => {
+            goodsList.forEach(e => {e.isChecked = false})
+            item.isChecked = true
+            goodsList.splice(goodsList.findIndex(e => e.code == item.code),1,item)
+            this.setState({goodsList})
+            if (item.basePrice) {
+                this.props.addGoods && this.props.addGoods(item)
+            } else {
+                Toast.show("未获取该商品价格,请选择其他商品",{position : toastHeight});
+            }
+          }}
+        >
+        <View>
+          <Text
+            style={{
+              color: item.isChecked ? '#E14C46' : '#333',
+              fontSize: 12,
+              lineHeight: 17,
+            }}
+            numberOfLines={1}
+          >
+            {item.name}
+          </Text>
+        </View>
+        <View>      
+          <Text
+            style={{
+              color: item.isChecked ? '#E14C46' : '#333',
+              fontSize: 12,
+              lineHeight: 17,
+            }}
+            numberOfLines={1}
+          >
+            编码:{item.code}
+          </Text>
+        </View>
+        <View>  
+          <Text
+            style={{
+              color: item.isChecked ? '#E14C46' : '#333',
+              fontSize: 12,
+              lineHeight: 17,
+            }}
+            numberOfLines={1}
+          >
+            型号:{item.specification}
+          </Text>
+        </View>
+        <View>  
+          <Text
+            style={{
+              color: item.isChecked ? '#E14C46' : '#333',
+              fontSize: 12,
+              lineHeight: 17,
+            }}
+            numberOfLines={1}
+          >
+            规格:{item.model}
+          </Text>     
+        </View>
+        <View>  
+          <Text
+            style={{
+              color: item.isChecked ? '#E14C46' : '#333',
+              fontSize: 12,
+              lineHeight: 17,
+            }}
+            numberOfLines={1}
+          >
+            价格:¥ {item.basePrice || "--"}
+          </Text>     
+        </View>        
+        </TouchableOpacity>
+      </View>
+    )
+  }
+
+  //根据色卡号查询调色
+  async getGoodsByKW(kw,init) {
+    if (!kw && !init) {
+        Toast.show("请输入商品信息",{position : toastHeight});
+        return 
+    }
+    const search = {
+        page: 0,
+        size: 10,
+        search_EQ_isEnable: 1,
+        search_keywords: kw,
+        search_customerId: CUSTOMERINFO.id,
+        search_customerRankCode: CUSTOMERINFO.customerRankCode
+      }
+    const goodsData = await authService.searchCommodityList(search)
+    console.log('goodsData=================>', goodsData)
+    // const goodsData = {}
+    if (goodsData.status == 200) {
+        this.setState({goodsList: goodsData.data.content})
+    } else {
+        Toast.show("未搜索到商品信息",{position : toastHeight});
+        return
+    }
+  }
+
+  render() {
+      return (
+        <View>
+          <Input
+            style={{
+            height: 28,
+            width: width - 50,
+            marginTop: 20,
+            borderRadius: width / 2,
+            alignSelf: 'center',
+            paddingLeft: 14,
+            }}
+            textStyle={{
+              paddingLeft: 10,
+              height: 28,
+              fontSize: 11,
+              padding: 0,
+            }}
+            iconSize={14}
+            //blurOnSubmit={true}
+            multiline={false}
+            textInputBacg={'#F5F5F5'}
+            iconColor={'#CCC'}
+            placeholderTextColor={'#CCC'}
+            placeholderSize={8}
+            placeholder = {'请输入颜色编码'}
+            onchangeFn={async e => {
+              this.getGoodsByKW(e)
+            }}
+          />
+          <Text
+            style={{
+              color: '#999',
+              fontSize: 14,
+              marginTop: 15,
+              lineHeight: 20,
+              letterSpacing: 0.17,
+            }}
+          >
+            商品列表
+          </Text>
+           
+            <FlatList
+                keyExtractor={(item, index) => index}
+                style={{height:280}} 
+                data={this.state.goodsList}
+                renderItem={({ item, key}) => this._goodsList(item, key,this.state.goodsList)}
+                numColumns= {1}
+            />
+
+        </View>
+      )
+  }
+}
+
+const styles = StyleSheet.create({
+  titleText: {
+    fontSize: 14,
+    lineHeight: 20,
+    color: '#999',
+  },
+  contentText: {
+    flex: 1,
+    fontSize: 13,
+    lineHeight: 18,
+    color: '#333',
+  },
+})
+export default GoodsFlatList

+ 167 - 1
app/containers/order/OrderEdit.js

@@ -47,6 +47,8 @@ import moment from 'moment'
 import Toast from 'react-native-root-toast'
 import DetailModels from '../../models/commodity/DetailModels'
 import OptFlatList from '../commodity/commoditydetail/OptFlatList'
+import GoodsFlatList from '../commodity/commoditydetail/GoodsFlatList'
+
 /**
  * saleModel
  *
@@ -70,6 +72,7 @@ class OrderEdit extends Component {
     super(props)
     this.state = {
       optionData: [],
+      showGoodsModal: false,  // 增加商品列表
       showOptModal : false,
       modalVisible : false,
       activeSection: true,
@@ -307,6 +310,14 @@ class OrderEdit extends Component {
       console.log(result)
       if (result.data && result.data.length && result.data[0].goodsOptDtos.length) {
         newRow.baseGoodsOptId = result.data[0].goodsOptDtos[0].id
+        let existIndex = this.state.EditPromData.findIndex(e => e.goodsId == newRow.goodsId && e.ext05 == colorData.children.attrValId);
+        if (existIndex >= 0 && existIndex != selectRow) {
+          Toast.show("已存在相同颜色的商品,请重新选择颜色!",{position : toastHeight});
+          return
+        }
+      } else {
+        this.toast = Toast.show("改颜色未设置价格,请重新选择颜色!",{position : toastHeight});
+        return
       }
       newRow.baseGoodsOptValue = colorData.children.custDocGroupName + ":" + colorData.children.attrValName
       newRow.ext05 = colorData.children.attrValId
@@ -321,8 +332,10 @@ class OrderEdit extends Component {
       let newEditPromData = [...this.state.EditPromData];
       newEditPromData.splice(selectRow, 1, newRow)
       let totalAmount = 0
+      let totalNum = 0
       newEditPromData.forEach(item => {
         totalAmount = totalAmount + item.amount
+        totalNum = totalNum + item.orderNum
       })
       let goodsAmount = totalAmount
       let totalAmountCopy = totalAmount
@@ -331,6 +344,7 @@ class OrderEdit extends Component {
         EditPromData : newEditPromData,
         totalAmount,
         goodsAmount,
+        totalNum,
         totalAmountCopy
       })
       currRow = {}
@@ -343,6 +357,92 @@ class OrderEdit extends Component {
     }
   }
 
+  addGoods(goods) {
+    console.log('goods==========>',goods)
+    console.log('this.state.EditPromData======>',this.state.EditPromData)
+    let existItem = this.state.EditPromData.find(e => e.goodsCode == goods.code && !e.baseGoodsOptId)
+    if (existItem) {
+      Toast.show("已存在重复的商品,请重新选择!",{position : toastHeight});
+      return
+    }
+    if (goods.id) {
+      let newItem = {
+        amount: goods.basePrice,
+        baseGoodsOptId: "",
+        baseGoodsOptValue: "",
+        basePrice: goods.basePrice,
+        conversionRate: 1,
+        dealAmount: goods.basePrice,
+        dealPrice: goods.basePrice,
+        deliveryNum: 0,
+        dr: 0,
+        expenseOrderCode: "",
+        ext14: goods.categoryCode,
+        ext15: goods.categoryName,
+        goodsCode: goods.code,
+        goodsDisplayName: goods.displayName,
+        goodsId: goods.id,
+        goodsName: goods.name,
+        id: '',
+        isGift: 0,
+        isOptional: goods.isOptional,
+        mainNum: 1,
+        mainNumUnitCode: goods.basicUnitCode,
+        mainNumUnitId: goods.basicUnitId,
+        mainNumUnitName: goods.basicUnitName,
+        model: goods.model,
+        ncProductCode: goods.ncProductCode,
+        offsetAmount: 0,
+        orderNum: 1,
+        orderNumUnitCode: goods.basicUnitCode,
+        orderNumUnitId: goods.basicUnitId,
+        orderNumUnitName: goods.basicUnitName,
+        originalGoodsId: goods.id,
+        persistStatus: 'nrm',
+        productGradeCode: goods.productGradeCode,
+        productGradeId: goods.productGradeId,
+        productGradeName: goods.productGradeName,
+        productId: goods.productId,
+        productLineCode: goods.productLineCode,
+        productLineId: goods.productLineId,
+        productLineName: goods.productLineName,
+        promAmount: 0,
+        promPrice: goods.basePrice,
+        refundNum: 0,
+        reqOrderAttachments: [],
+        reqOrderId: this.props.promData.reqOrderItems[0].reqOrderId,
+        reqOrderItemBoms: [],
+        reqOrderPromRels: [],
+        returnMaxOrderNum: 0,
+        returnNum: 0,
+        // rowNum: (this.state.EditPromData.length * 10) + "",
+        salePrice: goods.basePrice,
+        signNum: 0,
+        specification: goods.specification,
+        stockInNum: 0,
+        stockOutNum: 0,
+        weight: goods.netWeight
+      }
+      const newData = [...this.state.EditPromData];
+      newData.push(newItem);
+      console.log('this.props.promData.reqOrderItems[0].reqOrderId',this.props.promData.reqOrderItems[0].reqOrderId)
+      let totalAmount = 0
+      let totalNum = 0
+      newData.forEach(item => {
+        totalAmount = totalAmount + item.amount
+        totalNum = totalNum + item.orderNum
+      })
+      let goodsAmount = totalAmount
+      let totalAmountCopy = totalAmount
+      this.setState({EditPromData: newData,
+        showGoodsModal: false,        
+        totalAmount,
+        totalNum,
+        goodsAmount,
+        totalAmountCopy})
+    }
+  }
+
   //删除商品
   deleteGoodsFn(indexParent) {
     this.state.EditPromData.splice(indexParent, 1)
@@ -1415,7 +1515,7 @@ class OrderEdit extends Component {
       optFlag = true
     }
     return (
-      <View>
+      <View key={item.rowNum}>
         <View style={{ padding: 10, marginTop: 10, backgroundColor: '#FFF' }}>
           {/* 满减/买赠 */}
           <View style={{ paddingBottom: 10 }}>
@@ -2269,6 +2369,24 @@ class OrderEdit extends Component {
             </View>
           ) : null}
 
+          {/* 增加商品 */}
+          <View style={{ marginTop: 10, padding: 10, backgroundColor: '#FFF' }}>
+            <View
+              style={{
+                flexDirection: 'row',
+                justifyContent: 'center',
+              }}
+            >
+              <TouchableOpacity onPress={() =>{
+                      this.setState({
+                        showGoodsModal: true
+                      })
+                  }}>
+                    <Text style={styles.text666}>增加商品+</Text>
+              </TouchableOpacity>
+            </View>
+          </View>
+
           {/* 总体积、数量 */}
           <View style={{ marginTop: 10, padding: 10, backgroundColor: '#FFF' }}>
             <View
@@ -2441,6 +2559,54 @@ class OrderEdit extends Component {
               </View>
             </View>
           </View>
+          
+          {/* 增加商品 */}
+          <Modal
+            animationType="slide"
+            presentationStyle="formSheet"
+            transparent={true}
+            visible={this.state.showGoodsModal}
+            onRequestClose={() => {
+              this.setState({
+                showGoodsModal: false
+              })
+            }}
+          >
+            <View 
+            style={{
+              backgroundColor:'#FFF',
+              top:'50%',
+              paddingBottom: 50,
+              width:'100%',
+              height:'50%',
+              alignItems : 'center',
+              elevation : 5,
+              }}>
+          {this.state.optLoading ? (
+            <View style={{marginTop:100}}>
+              <ActivityIndicator />
+            </View>
+          ) : <View>           
+              <View style={{flexDirection:'row'}}>
+                <Text style={{ fontSize: 13, lineHeight: 18, color: '#333',width:'90%',marginTop:10 }}>选择商品</Text>
+                  <TouchableOpacity onPress={() =>{
+                      this.setState({
+                        showGoodsModal: false
+                      })
+                  }}>
+                    <Image 
+                      source={deletePng}
+                      style={{ width: 20, height: 20}}
+                    />
+                  </TouchableOpacity>
+                </View>
+                <GoodsFlatList addGoods={this.addGoods.bind(this)}/>
+                </View>
+            }
+            </View> 
+          </Modal>    
+
+          {/* 颜色选配 */}
           <Modal
             animationType="slide"
             presentationStyle="formSheet"

+ 1 - 0
app/models/commodity/SearchResult.js

@@ -73,6 +73,7 @@ export default {
           if (action.payload.pageInfo.page >= listData.data.totalPages) {
             foot = 1
           }
+          console.log("listData==============>",listData)
           yield put(
             createAction('commodityList')({
               listDatas: action.payload.actionData.concat(