OrderEdit.js 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. Image,
  6. StatusBar,
  7. Text,
  8. TouchableOpacity,
  9. Dimensions,
  10. PixelRatio,
  11. ScrollView,
  12. FlatList,
  13. Platform,
  14. DatePickerAndroid,
  15. ActivityIndicator,
  16. Modal,
  17. TextInput,
  18. Button
  19. } from 'react-native'
  20. import { connect } from 'react-redux'
  21. import Collapsible from 'react-native-collapsible'
  22. import CountNum from '../../components/CountNum'
  23. import Input from '../../components/input'
  24. import png from '../../static/images/defaultimg.jpg'
  25. import { ImageBaseUrl } from '../../utils/fetch/Fetchx'
  26. import {
  27. ScaleUtil,
  28. accAdd,
  29. accMul,
  30. accDiv,
  31. accSub,
  32. NumberTranslate,
  33. setNowFormatDate,
  34. } from '../../utils/utils'
  35. import Icon from '../../components/Iconfont/Iconfont'
  36. import { NavigationActions, createAction } from '../../utils'
  37. import redblue from '../../static/images/ic-redblue.png'
  38. //import moreDian from '../../static/images/ic-moredian.png'
  39. import OrderCredit from './orderamanage/OrderCredit'
  40. import OrderOptional from './orderamanage/OrderOptional'
  41. import SelectTime from '../common/SelectTime'
  42. import * as authService from '../../services/auth'
  43. //import orderCreditPng from '../../static/images/order-credit.png'
  44. import deletePng from '../../static/images/delete.png'
  45. import moment from 'moment'
  46. import Toast from 'react-native-root-toast'
  47. import DetailModels from '../../models/commodity/DetailModels'
  48. /**
  49. * saleModel
  50. *
  51. * Sale("01", "正向销售", "正向销售"),
  52. * Return("02", "退货", "退货"),
  53. * Cost("03", "费用货补", "费用货补"),
  54. * CostReturn("04", "货补退货", "货补退货");
  55. */
  56. const { width, height } = Dimensions.get('window')
  57. @connect(({ theme, mine, orderedit, optional }) => ({
  58. ...theme,
  59. ...mine,
  60. ...orderedit,
  61. ...optional,
  62. }))
  63. class OrderEdit extends Component {
  64. constructor(props) {
  65. const date = new Date()
  66. super(props)
  67. this.state = {
  68. modalVisible : false,
  69. activeSection: true,
  70. // activeAllCollaps: true,
  71. optCollapse: 'shouqi',
  72. baseIndex: 0,
  73. activeAllCollaps: true,
  74. transportSel:
  75. (props.transportDefault && props.transportDefault.name) || 0,
  76. billWaySel: (props.billwayDefault && props.billwayDefault.name) || 0,
  77. activeMethod: 'ffsa',
  78. cicleActive: true,
  79. creditShow: false,
  80. // 购物车选中
  81. EditPromData:
  82. Object.keys(props.promData).length > 0 && props.promData.reqOrderItems
  83. ? props.promData.reqOrderItems
  84. : props.navigation.state.params.ShopData,
  85. EditPromDataCopy:
  86. Object.keys(props.promData).length > 0 && props.promData.reqOrderItems
  87. ? props.promData.reqOrderItems
  88. : props.navigation.state.params.ShopData,
  89. // 选中赠品信息
  90. giftSelected: [],
  91. // 产品线id集合
  92. productLineIds: [],
  93. // 发货日期
  94. deliveryTime: setNowFormatDate(),
  95. // 支付方式
  96. payWayDef: props.navigation.state.params.payWayDef
  97. ? props.navigation.state.params.payWayDef
  98. : '',
  99. paySel: props.navigation.state.params.payWayDef
  100. ? props.navigation.state.params.payWayDef.name
  101. : 0,
  102. //备注
  103. remark:
  104. (props.navigation.state.params.ShopData &&
  105. props.navigation.state.params.ShopData.remark) ||
  106. '',
  107. // 冲抵金额
  108. offsetAmount: 0,
  109. // 冲抵前金额
  110. goodsAmount: 0,
  111. // 促销金额
  112. totalPromAmt: 0,
  113. // 总成交金额最终用
  114. totalAmount: 0,
  115. // 成交金额不变的值
  116. totalAmountCopy: 0,
  117. // 总数量
  118. totalNum: 0,
  119. // 总重量
  120. totalWeight: 0,
  121. // 重量单位
  122. volumeUnit: '',
  123. // 总体积
  124. totoalVolume: 0,
  125. // 体积单位
  126. volumeUnit: '',
  127. Loading: false,
  128. submitLoading: false,
  129. temporaryLoading: false,
  130. }
  131. // 保存互斥关系,点击之后如果无返回值,则使用上一次互斥关系
  132. this.RelationShipCopy
  133. // 圆形按钮滑动前状态
  134. this.cicleActive = true
  135. }
  136. componentDidMount() {
  137. //this.creditCheck()
  138. // 费用冲抵比率请求
  139. this.props.dispatch(
  140. createAction('orderedit/getCastRate')({
  141. castInfo: {
  142. saleOrgId: this.props.navigation.state.params.SaleOrSupplier
  143. .SaleOrSupplierId,
  144. customerId: CUSTOMERINFO.id,
  145. },
  146. })
  147. )
  148. // 地址、结算方式等参照请求
  149. this.props.dispatch(
  150. createAction('mine/getAdress')({
  151. // customer: "d4b4677f-93ec-49b5-bcaa-c134df0f7295",
  152. customer: CUSTOMERINFO.id,
  153. comefrom: {
  154. comefrom: this.props.navigation.state.params.comefrom,
  155. reqOrderInvoice: this.props.navigation.state.params.reqOrderInvoice,
  156. reqOrderReceiveAddress: this.props.navigation.state.params
  157. .reqOrderReceiveAddress,
  158. transportDefault: this.props.navigation.state.params.transportDefault,
  159. billwayDefault: this.props.navigation.state.params.billwayDefault,
  160. },
  161. transform: true,
  162. billway: true,
  163. invoice: true,
  164. })
  165. )
  166. if (this.props.navigation.state.params.comefrom == 'temporarily') {
  167. let newTime = new Date(
  168. this.props.navigation.state.params.data.deliveryDate
  169. )
  170. this.setState({
  171. transportSel: this.props.navigation.state.params.transportDefault.name,
  172. billWaySel: this.props.navigation.state.params.billwayDefault.name,
  173. deliveryTime: this.props.navigation.state.params.data.deliveryDate
  174. ? moment(this.props.navigation.state.params.data.deliveryDate).format(
  175. 'YYYY-MM-DD'
  176. )
  177. : moment().format('YYYY-MM-DD'),
  178. })
  179. }
  180. // 支付方式
  181. // this.props.dispatch(createAction('mine/payMentMode')()).finally(() => {
  182. // if (!this.props.navigation.state.params.payWayDef) {
  183. // this.setState({ payWayDef: this.props.orderPayStatus[0] })
  184. // }
  185. // })
  186. this.setState({
  187. productLineIds: this.getProductLines(),
  188. })
  189. this.combinedFn(true)
  190. }
  191. // 为选择商品挂载Boom信息
  192. addBoomToData() {
  193. const ids = [],
  194. EditPromData = this.state.EditPromData
  195. EditPromData.forEach(item => {
  196. ids.push(item.goodsId)
  197. })
  198. let flag = true
  199. this.props
  200. .dispatch(createAction('optional/getBoomInfo')(ids.join()))
  201. .finally(() => {
  202. // 如果有子件,则暂时把子件挂在商品行下,便于展示
  203. if (this.props.goodsBoom && this.props.goodsBoom.length > 0) {
  204. const goodsBom = this.props.goodsBoom,
  205. newOptIds = []
  206. EditPromData.forEach((editData, editIndex) => {
  207. goodsBom.forEach((bomData, index) => {
  208. bomData.goodsBomChildren.forEach((bomChild, childIndex) => {})
  209. if (editData.goodsId == bomData.parentGoodsId) {
  210. editData.reqOrderItemBoms = bomData.goodsBomChildren
  211. }
  212. if (
  213. editData.baseGoodsOptId &&
  214. editData.baseGoodsOptId.length > 0
  215. ) {
  216. newOptIds.push(editData.baseGoodsOptId)
  217. }
  218. })
  219. })
  220. // 初始选中;
  221. if (newOptIds && newOptIds.length > 0) {
  222. const optIdsJoin = newOptIds.join()
  223. this.props
  224. .dispatch(createAction('optional/optionalByIds')(optIdsJoin))
  225. .finally(() => {
  226. if (
  227. this.props.optDataByIds &&
  228. this.props.optDataByIds.length > 0
  229. ) {
  230. const optDataByIds = this.props.optDataByIds
  231. optDataByIds.forEach(data => {
  232. data.optids = []
  233. data.goodsOptVals.forEach(dataSec => {
  234. data.optids.push(dataSec.id)
  235. })
  236. })
  237. EditPromData.forEach(itemFir => {
  238. itemFir.reqOrderItemBoms.forEach(itemSec => {
  239. optDataByIds.forEach(optData => {
  240. if (itemSec.childGoodsId == optData.goodsId) {
  241. itemSec.baseGoodsOptId = optData.optids.join()
  242. itemSec.baseGoodsOptValue = optData.optResult
  243. }
  244. })
  245. })
  246. })
  247. this.setState({ EditPromData: this.state.EditPromData })
  248. flag = false
  249. }
  250. })
  251. }
  252. }
  253. if (flag) {
  254. this.setState({ EditPromData: this.state.EditPromData })
  255. }
  256. })
  257. }
  258. //删除商品
  259. deleteGoodsFn(indexParent) {
  260. this.state.EditPromData.splice(indexParent, 1)
  261. this.setState({ Loading: true, giftSelected: [] })
  262. if (
  263. this.props.navigation.state.params.SaleOrSupplier.isPrimaryChannel == 1
  264. ) {
  265. this.props
  266. .dispatch(
  267. createAction('orderedit/getProm')({
  268. promInfo: {
  269. customerId: CUSTOMERINFO.id,
  270. saleOrgId: this.props.navigation.state.params.SaleOrSupplier
  271. .SaleOrSupplierId,
  272. isPrimaryChannel: this.props.navigation.state.params
  273. .SaleOrSupplier.isPrimaryChannel,
  274. reqOrderItems: this.state.EditPromData,
  275. },
  276. })
  277. )
  278. .finally(() => {
  279. if (this.props.promData) {
  280. this.CountNumFn(
  281. true,
  282. '',
  283. '',
  284. this.props.promData.reqOrderItems || this.state.EditPromData
  285. )
  286. }
  287. //this.autoShowGiftRow()
  288. this.setState({ Loading: false })
  289. })
  290. } else {
  291. this.CountNumFn(true, '', '', this.state.EditPromData)
  292. this.setState({ Loading: false })
  293. }
  294. }
  295. // 抽出所有商品的产品线
  296. getProductLines() {
  297. let productLineIds = []
  298. this.state.EditPromData.map(item => {
  299. productLineIds.push(item.productLineId)
  300. })
  301. return productLineIds
  302. }
  303. // 检查信用
  304. creditCheck(reqOrderItems) {
  305. this.props.dispatch(
  306. createAction('orderedit/getCreditCheck')({
  307. searchInfo: {
  308. saleOrgId: this.props.navigation.state.params.SaleOrSupplier
  309. .SaleOrSupplierId,
  310. customerId: CUSTOMERINFO.id,
  311. reqOrderItems: reqOrderItems || this.state.EditPromData,
  312. saleModel: '01',
  313. },
  314. })
  315. )
  316. }
  317. // 订单数据集 正常态
  318. getOrderData() {
  319. this.state.EditPromData.map(
  320. item => (item.id = null)
  321. // dealPrice:,//成交价格
  322. // offsetAmount:,//行分摊促销金额
  323. // (dealAmount = (item.basePrice || item.salePrice) * item.orderNum), //成交金额
  324. // (amount = (item.basePrice || item.salePrice) * item.orderNum)
  325. // currency,//行币种
  326. )
  327. const {
  328. addressDefault,
  329. billwayDefault,
  330. invoiceDefault,
  331. transportDefault,
  332. } = this.props
  333. const postData = {
  334. id: this.props.navigation.state.params.id || '',
  335. currency: CURRENCY.id, // 币种
  336. currencySign: CURRENCY.currencySign, // 币符
  337. currencyPriceScale: CURRENCY.currencyPriceScale, // 币种单价精度
  338. currencyAmountScale: CURRENCY.currencyAmountScale, // 币种金额精度
  339. customerId: CUSTOMERINFO.id,
  340. // persistStatus: "nrm", //数据操作状态 'nrm'为无变化 'new'为新增
  341. saleOrgId: this.props.navigation.state.params.SaleOrSupplier
  342. .SaleOrSupplierId, // 销售组织,即供应商
  343. deliveryDate: new Date(this.state.deliveryTime).getTime(), // 期望收货日期
  344. totalNum: this.state.totalNum, // 总数量
  345. totalDealAmount: this.state.totalAmount, // 总成交金额
  346. totalWeight: this.state.totalWeight, // 总重量
  347. totoalVolume: this.state.totoalVolume, // 总体积
  348. // orderSource: "portal", // 订单来源
  349. remark: this.state.remark, // 订单备注
  350. totalAmount: this.state.goodsAmount, // 冲抵前金额
  351. offsetAmount: this.state.offsetAmount, // 费用冲抵金额
  352. saleModel: '01', //销售模式 具体开头部
  353. reqOrderSource: '01', //订单来源
  354. underPaymentModeId: this.state.payWayDef.code, //订单支付方式
  355. srcOrderId: this.props.navigation.state.params.id || '',
  356. reqOrderReceiveAddress: {
  357. reqOrderId: addressDefault.id,
  358. receiveAddressId: addressDefault.id, // 收货地址id
  359. receiver: addressDefault.receiver, // 收货人
  360. receiverTel: addressDefault.receiverTel, // 电话
  361. receiverPhone: addressDefault.receiverPhone, // 手机
  362. receiverProvince: addressDefault.receiverProvince, // 省
  363. receiverCity: addressDefault.receiverCity, // 市
  364. receiverDistrict: addressDefault.receiverDistrict, // 区
  365. receiverTown: addressDefault.receiverTown, // 镇
  366. receiverAddress: addressDefault.receiverAddress, // 详细地址
  367. receiverZipcode: addressDefault.receiverZipcode, // 邮编
  368. },
  369. reqOrderInvoice: {
  370. reqOrderId: invoiceDefault.id,
  371. invoiceId: invoiceDefault.id, // 发票id
  372. invoiceType: invoiceDefault.invoiceType, // 发票类型
  373. invoiceContent: invoiceDefault.invoiceContent, // 开票项目
  374. invoiceTitle: invoiceDefault.invoiceTitle, // 发票抬头
  375. invoiceTaxId: invoiceDefault.invoiceTaxId, // 纳税人识别码
  376. invoiceBank: invoiceDefault.invoiceBank, // 开户银行
  377. invoiceAccount: invoiceDefault.invoiceAccount, // 开户账户
  378. invoiceSubBank: invoiceDefault.invoiceSubBank, // 支行
  379. },
  380. reqOrderItems: this.state.EditPromData,
  381. }
  382. transportDefault && transportDefault.id
  383. ? (postData.transportModeId = transportDefault.id)
  384. : null // 运输方式
  385. billwayDefault && billwayDefault.id
  386. ? (postData.settleModeId = billwayDefault.id)
  387. : null // 结算方式
  388. return postData
  389. }
  390. // 从订单列表过来的订单数据集 封装暂存态的数据
  391. getOrderFromList() {
  392. this.state.EditPromData.map(item => (item.id = null))
  393. let EditDataCopy = JSON.parse(JSON.stringify(this.state.EditPromData)),
  394. EditData = {}
  395. const {
  396. addressDefault,
  397. billwayDefault,
  398. invoiceDefault,
  399. transportDefault,
  400. } = this.props
  401. EditData.id = this.props.navigation.state.params.type?'':(this.props.navigation.state.params.id || '')
  402. EditData.orderCode = this.props.navigation.state.params.type?'':(this.props.navigation.state.params.data.orderCode || '')
  403. EditData.currency = CURRENCY.id // 币种
  404. EditData.currencySign = CURRENCY.currencySign // 币符
  405. EditData.currencyPriceScale = CURRENCY.currencyPriceScale // 币种单价精度
  406. EditData.currencyAmountScale = CURRENCY.currencyAmountScale // 币种金额精度
  407. EditData.customerId = CUSTOMERINFO.id
  408. // 地址
  409. EditData.reqOrderReceiveAddress = addressDefault
  410. // 发票信息
  411. EditData.reqOrderInvoice = invoiceDefault
  412. // EditData.orderSource = "portal"; // 订单来源
  413. EditData.srcOrderId = this.props.navigation.state.params.id || ''
  414. // 供应商
  415. EditData.saleOrgId = this.props.navigation.state.params.SaleOrSupplier.SaleOrSupplierId
  416. EditData.saleOrgCode = this.props.navigation.state.params.SaleOrSupplier.SaleOrSupplierCode
  417. EditData.saleOrgName = this.props.navigation.state.params.SaleOrSupplier.SaleOrSupplierName
  418. EditData.isPrimaryChannel = this.props.navigation.state.params.SaleOrSupplier.isPrimaryChannel
  419. // 结算方式
  420. EditData.settleModeCode = billwayDefault.code
  421. EditData.settleModeId = billwayDefault.id
  422. EditData.settleModeName = billwayDefault.name
  423. // 运输方式
  424. EditData.transportModeId = transportDefault.id
  425. EditData.transportModeCode = transportDefault.code
  426. EditData.transportModeName = transportDefault.name
  427. EditData.reqOrderItems = EditDataCopy
  428. ;(EditData.underPaymentModeId = this.state.payWayDef.code), //订单支付方式
  429. (EditData.remark = this.state.remark) // 订单备注
  430. EditData.totalAmount = this.state.goodsAmount // 冲抵前金额
  431. EditData.offsetAmount = this.state.offsetAmount // 费用冲抵金额
  432. EditData.deliveryDate = new Date(this.state.deliveryTime).getTime() // 期望收货日期
  433. EditData.totalNum = this.state.totalNum // 总数量
  434. EditData.totalDealAmount = this.state.totalAmount // 总成交金额
  435. EditData.totalWeight = this.state.totalWeight // 总重量
  436. EditData.totoalVolume = this.state.totoalVolume // 总体积
  437. EditData.saleModel = '01' //销售模式 具体开头部
  438. EditData.reqOrderSource = '01' //订单来源
  439. return EditData
  440. }
  441. // 促销后补充商品行
  442. transportPromData(postData) {
  443. const giftData = JSON.parse(JSON.stringify(this.state.giftSelected))
  444. // 如果为整单则在表头加入促销信息
  445. if (
  446. this.props.promData &&
  447. this.props.promData.orderPriceProm &&
  448. Object.keys(this.props.promData.orderPriceProm).length > 0
  449. ) {
  450. const orderPriceProm = this.props.promData.orderPriceProm
  451. postData.reqOrderPromRels = [
  452. {
  453. activityId: orderPriceProm.activityId,
  454. ruleId: orderPriceProm.ruleId,
  455. description: orderPriceProm.description,
  456. promWay: 2, // 1 买赠 2 降价
  457. isWhole: 1, // 1 整单
  458. },
  459. ]
  460. }
  461. // 如果选择促销商品后,在商品行加入买赠商品,其中商品行中的促销信息在OrderGifts中回调封装
  462. if (giftData && giftData.length > 0) {
  463. giftData.map((item,index) => {
  464. item.id = null
  465. item.isGift = 1
  466. item.basePrice = 0
  467. item.salePrice = 0
  468. item.promPrice = 0
  469. item.dealPrice = 0
  470. item.amount = 0 // 金额
  471. item.promAmount = 0 // 均摊到行上的整单降价促销金额
  472. item.dealAmount = 0 // 成交金额
  473. item.ffsetAmount = 0 // 均摊到行上的费用冲抵金额
  474. item.orderNum = 0
  475. item.rowNum = postData.reqOrderItems.length+parseInt(index)+1
  476. item.promotinId = item.activityId
  477. })
  478. postData.reqOrderItems = postData.reqOrderItems.concat(giftData)
  479. }
  480. return postData
  481. }
  482. // 补充BOM信息
  483. fillGoodsBomInfo(postData) {
  484. // 之前步骤方便显示,将子件信息存在每个母件reqOrderItems中,在补充Bom时,将子件信息抽出赋在外部字段(reqOrderItemBoms)中,并将母件的自己字段删除
  485. let newReqOrderItemBoms = []
  486. postData.reqOrderItems.forEach((data, index) => {
  487. data.persistStatus = 'new'
  488. data.rowNum = (index + 1) * 10
  489. data.ext09 = data.dealPrice;
  490. data.ext10 = data.dealAmount;
  491. if (data.reqOrderItemBoms && data.reqOrderItemBoms.length > 0) {
  492. data.reqOrderItemBoms.forEach(bomData => {
  493. bomData.parentRowNum = data.rowNum
  494. bomData.parentGoodsName = data.goodsDisplayName
  495. })
  496. newReqOrderItemBoms = newReqOrderItemBoms.concat(data.reqOrderItemBoms)
  497. }
  498. delete data.reqOrderItemBoms
  499. })
  500. postData.reqOrderItemBoms = newReqOrderItemBoms
  501. // 判断是否母件是否有子件信息,如果有:则将子件信息集合中数据封装为新结构;如果无,则将商品行复制添加到子件信息集合中
  502. if (postData.reqOrderItemBoms && postData.reqOrderItemBoms.length > 0) {
  503. const reqOrderItemBoms = this.bomStructureDeal(postData.reqOrderItemBoms)
  504. postData.reqOrderItemBoms = reqOrderItemBoms
  505. } else {
  506. const reqOrderItems = postData.reqOrderItems
  507. const reqOrderItemBoms = reqOrderItems.map((item, index) => {
  508. const translate = {
  509. parentRowNum: item.rowNum,
  510. parentGoodsId: item.goodsId,
  511. persistStatus: 'new',
  512. parentGoodsCode: '', // item.goodsCode,
  513. parentGoodsName: '', // item.goodsDisplayName,
  514. childGoodsQty: 1,
  515. orderNumUnit: item.orderNumUnitName,
  516. mainNumUnit: item.mainNumUnitName,
  517. }
  518. const newItem = { ...item, ...translate }
  519. return newItem
  520. })
  521. postData.reqOrderItemBoms = reqOrderItemBoms
  522. }
  523. return postData
  524. }
  525. // 子件信息数据结构处理
  526. bomStructureDeal(bomData) {
  527. const reqOrderItemBoms = bomData.map((child, index) => {
  528. const translate = {
  529. baseGoodsOptId: child.baseGoodsOptId,
  530. baseGoodsOptValue: child.baseGoodsOptValue,
  531. rowNum: (index + 1) * 10,
  532. parentRowNum: child.parentRowNum,
  533. parentGoodsId: child.parentGoodsId,
  534. parentGoodsName: child.parentGoodsName,
  535. mainNum: '',
  536. goodsName: child.childGoodsName,
  537. goodsCode: child.childGoodsCode,
  538. goodsId: child.childGoodsId,
  539. version: child.childGoodsVersion,
  540. measurementUnitId: child.childGoodsUnitId,
  541. measurementUnitCode: child.childGoodsUnitCode,
  542. measurementUnitName: child.childGoodsUnitName,
  543. orderNumUnitId: child.childGoodsUnitId,
  544. orderNumUnitCode: child.childGoodsUnitCode,
  545. orderNumUnitName: child.childGoodsUnitName,
  546. orderNum: child.childGoodsQty,
  547. childGoodsQty: child.childGoodsQty,
  548. //
  549. persistStatus: 'new',
  550. mainNumUnit: child.childGoodsUnitName,
  551. }
  552. return translate
  553. })
  554. return reqOrderItemBoms
  555. }
  556. // 订单提交暂存
  557. async editFinish(ident) {
  558. let isReturnTab = false,
  559. result = [],
  560. flag = false,
  561. errReturn = false,
  562. editSubmlitData =
  563. this.props.navigation.state.params.comefrom == 'temporarily'
  564. ? this.getOrderFromList()
  565. : this.getOrderData()
  566. //运输方式为必选项
  567. if(!editSubmlitData.transportModeId) {
  568. this.toast = Toast.show("请选择一种运输方式",{position : toastHeight});
  569. return;
  570. }
  571. editSubmlitData = this.fillGoodsBomInfo(editSubmlitData)
  572. if (this.props.creditData && this.props.creditData.length > 0) {
  573. let alertText = []
  574. this.props.creditData.map(item => {
  575. if (item.thisProdLineAmount > item.creditBalance) {
  576. alertText.push(item.productLineName)
  577. flag = true
  578. }
  579. })
  580. if (flag) {
  581. this.toast = Toast.show(`${alertText.join(',')}金额超过信用余额`, {
  582. position: toastHeight,
  583. })
  584. }
  585. }
  586. if (ident === 'Temporary') {
  587. // 暂存提交
  588. this.setState({ temporaryLoading: true })
  589. result = await authService.temporaryOrder(editSubmlitData).catch(err => {
  590. this.setState({ temporaryLoading: false })
  591. errReturn = true
  592. if (this.toast) {
  593. Toast.hide(this.toast)
  594. }
  595. this.toast = Toast.show(err.message, { position: toastHeight })
  596. console.log(
  597. err,
  598. '-----订单编辑-暂存订单报错的完整信息' +
  599. '\n' +
  600. '具体错误显示--->' +
  601. err.response.data.message
  602. )
  603. })
  604. this.setState({ temporaryLoading: false })
  605. } else if (ident === 'Submit') {
  606. //补充商品行
  607. editSubmlitData = this.transportPromData(editSubmlitData)
  608. if (this.state.payWayDef.code == 'PayFirst') {
  609. // 在线支付 需要把errReturn设置成false
  610. this.setState({ temporaryLoading: true })
  611. result = await authService
  612. .temporaryOrder(editSubmlitData)
  613. .catch(err => {
  614. this.setState({ temporaryLoading: false })
  615. errReturn = false
  616. this.toast = Toast.show(err.message, { position: toastHeight })
  617. console.log(
  618. err,
  619. '-----订单编辑-暂存订单报错的完整信息' +
  620. '\n' +
  621. '具体错误显示--->' +
  622. err.response.data.message
  623. )
  624. })
  625. this.setState({ temporaryLoading: false })
  626. this.props.dispatch(
  627. NavigationActions.navigate({
  628. routeName: 'OrderPay',
  629. params: {
  630. submitData: { id: result.data.id },
  631. totalAmount: result.data.totalDealAmount,
  632. callBack: () => {
  633. this.props.dispatch(
  634. NavigationActions.navigate({
  635. routeName: 'OrderHome',
  636. })
  637. )
  638. },
  639. },
  640. })
  641. )
  642. } else {
  643. this.setState({ submitLoading: true })
  644. result = await authService.postOrder(editSubmlitData).catch(err => {
  645. this.setState({ submitLoading: false })
  646. errReturn = true
  647. this.toast = Toast.show(err.response.data.message, { position: toastHeight })
  648. console.log(
  649. err,
  650. '-----订单编辑-提交订单报错的完整信息' +
  651. '\n' +
  652. '具体错误显示||--->:' +
  653. err.response.data.message
  654. )
  655. })
  656. this.setState({ submitLoading: false })
  657. }
  658. }
  659. // 请求数据报错,则不进行下一步
  660. if (!errReturn) {
  661. if (result.data && Object.keys(result.data).length > 0) {
  662. isReturnTab = true
  663. }
  664. if (isReturnTab) {
  665. if (
  666. this.props.navigation.state.params.cartId &&
  667. this.props.navigation.state.params.cartId.length > 0
  668. ) {
  669. this.props.navigation.state.params.cartId.forEach(item => {
  670. this.props.dispatch(
  671. createAction('shoppingcart/deleteShop')({
  672. params: {
  673. id: item,
  674. customer: CUSTOMERINFO.id,
  675. },
  676. })
  677. )
  678. })
  679. }
  680. // 返回OrderHome
  681. this.props.dispatch(
  682. NavigationActions.navigate({
  683. routeName: 'OrderHome',
  684. action: NavigationActions.navigate({ routeName: 'OrderHome' }),
  685. })
  686. )
  687. }
  688. }
  689. }
  690. // 头部
  691. header() {
  692. return (
  693. <View
  694. style={{
  695. height: HEADERSTYLE.height,
  696. paddingTop: HEADERSTYLE.paddingTop + 5,
  697. backgroundColor: '#fff',
  698. borderBottomColor: '#eee',
  699. borderBottomWidth: 1 / PixelRatio.get(),
  700. }}
  701. >
  702. <View
  703. style={{
  704. flex: 1,
  705. justifyContent: 'center',
  706. }}
  707. >
  708. <TouchableOpacity
  709. style={{ position: 'absolute', left: 10, flexDirection: 'row' }}
  710. onPress={() => this.props.dispatch(NavigationActions.back())}
  711. >
  712. <Icon
  713. name="icon-icon-fanhui"
  714. size={20}
  715. color={'#666'}
  716. style={{ marginTop: 4 }}
  717. />
  718. <Text
  719. style={{
  720. fontSize: 14,
  721. lineHeight: 20,
  722. color: '#666',
  723. alignSelf: 'center',
  724. }}
  725. >
  726. 返回
  727. </Text>
  728. </TouchableOpacity>
  729. <Text
  730. style={{
  731. alignSelf: 'center',
  732. fontSize: 18,
  733. lineHeight: 25,
  734. letterSpacing: 0.19,
  735. color: '#333',
  736. }}
  737. >
  738. 订单编辑
  739. </Text>
  740. <TouchableOpacity
  741. style={{ position: 'absolute', right: 10 }}
  742. onPress={
  743. () =>
  744. this.setState({
  745. activeAllCollaps: !this.state.activeAllCollaps,
  746. })
  747. // this._info.setActive()
  748. }
  749. >
  750. <Text
  751. style={{
  752. fontSize: 14,
  753. lineHeight: 20,
  754. letterSpacing: 0.17,
  755. color: '#666',
  756. }}
  757. >
  758. 折叠
  759. </Text>
  760. </TouchableOpacity>
  761. </View>
  762. </View>
  763. )
  764. }
  765. // 供应商
  766. supplier(supplierDefault) {
  767. return (
  768. <View
  769. style={{
  770. backgroundColor: '#FFF',
  771. padding: 10,
  772. flexDirection: 'row',
  773. borderBottomColor: '#eee',
  774. borderBottomWidth: 1,
  775. }}
  776. >
  777. <Text
  778. style={{
  779. fontSize: 14,
  780. lineHeight: 20,
  781. letterSpacing: 0.17,
  782. color: '#333',
  783. fontWeight: '600',
  784. }}
  785. >
  786. {supplierDefault.SaleOrSupplierName}
  787. </Text>
  788. </View>
  789. )
  790. }
  791. // 底部按钮
  792. bottomTouch() {
  793. let touchArr = [],
  794. touchAtt = [
  795. {
  796. touchName: '暂存',
  797. background: '#FFF',
  798. textColor: '#666',
  799. loading: this.state.temporaryLoading,
  800. itemonpress: () => {
  801. this.editFinish('Temporary')
  802. },
  803. },
  804. {
  805. touchName: '提交',
  806. background: '#E70013',
  807. textColor: '#FFF',
  808. loading: this.state.submitLoading,
  809. itemonpress: () => {
  810. this.editFinish('Submit')
  811. },
  812. },
  813. ]
  814. for (let i = 0; i < touchAtt.length; i++) {
  815. if (touchAtt[i].loading) {
  816. touchArr.push(
  817. <View
  818. onPress={() => touchAtt[i].itemonpress()}
  819. key={i}
  820. style={{
  821. flex: 1,
  822. backgroundColor: touchAtt[i].background,
  823. justifyContent: 'center',
  824. borderRightColor: '#eee',
  825. borderRightWidth: 1 / PixelRatio.get(),
  826. }}
  827. >
  828. <ActivityIndicator />
  829. </View>
  830. )
  831. } else {
  832. touchArr.push(
  833. <TouchableOpacity
  834. disabled={
  835. this.state.temporaryLoading || this.state.submitLoading
  836. ? true
  837. : false
  838. }
  839. onPress={() => touchAtt[i].itemonpress()}
  840. key={i}
  841. style={{
  842. flex: 1,
  843. backgroundColor: touchAtt[i].background,
  844. justifyContent: 'center',
  845. borderRightColor: '#eee',
  846. borderRightWidth: 1 / PixelRatio.get(),
  847. }}
  848. >
  849. <Text
  850. style={{
  851. fontSize: 14,
  852. lineHeight: 20,
  853. color: touchAtt[i].textColor,
  854. alignSelf: 'center',
  855. }}
  856. >
  857. {touchAtt[i].touchName}
  858. </Text>
  859. </TouchableOpacity>
  860. )
  861. }
  862. }
  863. return touchArr
  864. }
  865. // 运输方式、结算方式等
  866. viewRender(data, inputTextLOck) {
  867. let viewRen = [],
  868. size = 16
  869. for (let i = 0; i < data.length; i++) {
  870. if (data[i].iconName == 'icon-icon-jianjinzhishiqi') {
  871. size = 24
  872. }
  873. viewRen.push(
  874. <View key={i}>
  875. <TouchableOpacity
  876. onPress={() => data[i].onPress()}
  877. style={{
  878. paddingVertical: 10,
  879. paddingLeft: 10,
  880. paddingRight:
  881. data[i].iconName == 'icon-icon-jianjinzhishiqi' ? 3 : 10,
  882. flexDirection: 'row',
  883. justifyContent: 'space-between',
  884. borderBottomColor: '#EEE',
  885. borderBottomWidth: 1 / PixelRatio.get(),
  886. }}
  887. >
  888. <Text style={styles.text333}>{data[i].viewName}</Text>
  889. <View style={{ flexDirection: 'row' }}>
  890. <Text
  891. style={{
  892. fontSize: 14,
  893. lineHeight: 20,
  894. color: '#666',
  895. marginRight: 10,
  896. }}
  897. >
  898. {data[i].rightName}
  899. </Text>
  900. <Icon name={data[i].iconName} size={size} color={'#ccc'} />
  901. </View>
  902. </TouchableOpacity>
  903. {/* 折叠 */}
  904. <Collapsible collapsed={i !== this.state.activeMethod}>
  905. {data[i].dataArr &&
  906. (data[i].dataArr || []).map((item, key) => (
  907. <TouchableOpacity
  908. onPress={() => {
  909. if (data[i].viewName == '运输方式') {
  910. this.props.dispatch(
  911. createAction('mine/TransportSetstate')(item)
  912. )
  913. this.setState({ transportSel: item.name })
  914. // this.setState({ transportVal: item });
  915. } else if (data[i].viewName == '结算方式') {
  916. this.props.dispatch(
  917. createAction('mine/BillwaySetstate')(item)
  918. )
  919. this.setState({ billWaySel: item.name })
  920. // this.setState({ billWay: item });
  921. } else if (data[i].viewName == '支付方式') {
  922. this.setState({ payWayDef: item, paySel: item.name })
  923. }
  924. // 继续写发票和发货日期的更新值
  925. // else if(){}
  926. // 收起折叠板
  927. this.setState({ activeMethod: 'fjidos' })
  928. }}
  929. key={key}
  930. style={{
  931. flexDirection: 'row',
  932. justifyContent: 'space-between',
  933. padding: 10,
  934. }}
  935. >
  936. <Text
  937. style={{
  938. fontSize: 14,
  939. lineHeight: 20,
  940. color: '#666',
  941. }}
  942. >
  943. {item.name || ''}
  944. </Text>
  945. {data[i].viewName == '支付方式' ? (
  946. this.state.paySel ==
  947. (this.state.paySel == 0 ? key : item.name) ? (
  948. <Icon
  949. name={'icon-icon-duigou'}
  950. size={16}
  951. color={'#E14C46'}
  952. style={{ marginRight: 30 }}
  953. />
  954. ) : null
  955. ) : data[i].viewName == '运输方式' ? (
  956. this.state.transportSel ==
  957. (this.state.transportSel == 0 ? key : item.name) ? (
  958. <Icon
  959. name={'icon-icon-duigou'}
  960. size={16}
  961. color={'#E14C46'}
  962. style={{ marginRight: 30 }}
  963. />
  964. ) : null
  965. ) : this.state.billWaySel ==
  966. (this.state.billWaySel == 0 ? key : item.name) ? (
  967. <Icon
  968. name={'icon-icon-duigou'}
  969. size={16}
  970. color={'#E14C46'}
  971. style={{ marginRight: 30 }}
  972. />
  973. ) : null}
  974. </TouchableOpacity>
  975. ))}
  976. </Collapsible>
  977. {!inputTextLOck ? null : (
  978. <View
  979. style={{
  980. paddingHorizontal: 10,
  981. paddingBottom: 3,
  982. flexDirection: 'row',
  983. }}
  984. >
  985. <Text style={[styles.text333, { alignSelf: 'center' }]}>
  986. {data[i].inputName}
  987. </Text>
  988. <Input
  989. style={{
  990. marginTop: 4,
  991. width: width / 1.15,
  992. }}
  993. isICon={false}
  994. blurOnSubmit={true}
  995. textInputBacg={'#FFF'}
  996. placeholder={data[i].inputDefault}
  997. placeholderTextColor={'#CCC'}
  998. onchangeFn={e => {
  999. this.setState({ remark: e })
  1000. }}
  1001. />
  1002. </View>
  1003. )}
  1004. </View>
  1005. )
  1006. }
  1007. return viewRen
  1008. }
  1009. // 地址回调
  1010. callback(e) {
  1011. this.props.dispatch(createAction('mine/AdressSetstate')(e.item))
  1012. // this.setState({ addressDefault: e.item });
  1013. }
  1014. // 发票回调
  1015. invoiceCallback(e) {
  1016. this.props.dispatch(createAction('mine/InvoiceSetstate')(e))
  1017. }
  1018. async TimeAndroid() {
  1019. const { action, year, month, day } = await DatePickerAndroid.open({
  1020. date: new Date(),
  1021. minDate: new Date(),
  1022. mode: 'spinner',
  1023. })
  1024. if (action !== DatePickerAndroid.dismissedAction) {
  1025. this.setState({
  1026. deliveryTime: moment(
  1027. `${year}-${month + 1}-${day}`,
  1028. 'YYYY-MM-DD'
  1029. ).format('YYYY-MM-DD'),
  1030. })
  1031. // 这里开始可以处理用户选好的年月日三个参数:year, month (0-11), day
  1032. }
  1033. }
  1034. // 清除费用冲抵 输入框
  1035. ClearOffset() {
  1036. //this.AverageRef.setClear()
  1037. this.setState({ giftSelected: [] })
  1038. }
  1039. async combinedFn(init, item, nv) {
  1040. this.ClearOffset()
  1041. if (!init) {
  1042. this.state.EditPromData[item].orderNum = nv
  1043. this.state.EditPromData[item].mainNum = accMul(
  1044. this.state.EditPromData[item].orderNum,
  1045. this.state.EditPromData[item].conversionRate
  1046. )
  1047. this.setState({ Loading: true })
  1048. // await this.promDispatch(this.state.EditPromData);
  1049. await this.props.dispatch(
  1050. createAction('orderedit/getProm')({
  1051. promInfo: {
  1052. customerId: CUSTOMERINFO.id,
  1053. saleOrgId: this.props.navigation.state.params.SaleOrSupplier
  1054. .SaleOrSupplierId,
  1055. isPrimaryChannel: this.props.navigation.state.params.SaleOrSupplier
  1056. .isPrimaryChannel,
  1057. reqOrderItems: this.state.EditPromData,
  1058. },
  1059. })
  1060. )
  1061. // this.creditCheck(
  1062. // this.props.promData.reqOrderItems || this.state.EditPromData
  1063. // )
  1064. // this.creditCheck(this.props.promData.reqOrderItems);
  1065. }
  1066. this.setState({ Loading: false })
  1067. this.CountNumFn(
  1068. init,
  1069. item,
  1070. nv,
  1071. this.props.promData.reqOrderItems || this.state.EditPromData
  1072. )
  1073. // this.CountNumFn(init, item, nv, this.props.promData.reqOrderItems);
  1074. }
  1075. CountNumFn(init, item, nv, EditPromData) {
  1076. // this.ClearOffset();
  1077. init ? null : (EditPromData[item].orderNum = nv)
  1078. // init ? null : (item.orderNum = nv);
  1079. let amount = 0,
  1080. totalnum = 0,
  1081. totoalvolume = 0,
  1082. totalweight = 0,
  1083. totalProm = 0
  1084. ;(EditPromData || []).map(val => {
  1085. val.dealPrice = val.promPrice
  1086. val.offsetAmount = 0
  1087. val.mainNum = accMul(val.orderNum, val.conversionRate)
  1088. // 金额
  1089. amount = accAdd(
  1090. accMul(val.salePrice || val.basePrice, val.mainNum),
  1091. amount
  1092. )
  1093. // 商品行总促销金额 = 促销价格*主数量
  1094. totalProm = accAdd(
  1095. accSub(accMul(val.promPrice, val.mainNum), val.promAmount || 0),
  1096. totalProm
  1097. )
  1098. totalnum = accAdd(val.orderNum, totalnum)
  1099. totoalvolume = accAdd(val.volume, totoalvolume)
  1100. totalweight += accMul(val.weight, val.mainNum)
  1101. val.dealAmount = accMul(val.dealPrice, val.mainNum)
  1102. val.amount = accMul(val.salePrice || val.basePrice, val.mainNum)
  1103. })
  1104. this.setState({
  1105. totalAmount: accSub(amount, accSub(amount, totalProm)),
  1106. totalAmountCopy: accSub(amount, accSub(amount, totalProm)),
  1107. goodsAmount: amount,
  1108. totalNum: totalnum,
  1109. // 促销金额 = 总金额 - 商品行总促销金额
  1110. totalPromAmt: accSub(amount, totalProm),
  1111. totoalVolume: totoalvolume,
  1112. totalWeight: totalweight,
  1113. // 每次增加商品行数量 对冲抵总金额初始化
  1114. offsetAmount: 0,
  1115. EditPromData: EditPromData,
  1116. })
  1117. this.addBoomToData()
  1118. }
  1119. // 当促7销输入数字后对每行商品进行均摊
  1120. AverageBooth(e, MaxOffset) {
  1121. e = parseFloat(e)
  1122. let ToffsetAmount = 0,
  1123. EditPromData = this.state.EditPromData
  1124. // 冲抵输入框的值大于0,则进行--均摊计算---
  1125. if (e > 0 && MaxOffset > 0) {
  1126. // 计算最大可冲抵金额
  1127. if (e >= MaxOffset) {
  1128. ToffsetAmount = MaxOffset
  1129. } else {
  1130. ToffsetAmount = e
  1131. }
  1132. if (ToffsetAmount > this.state.totalAmountCopy) {
  1133. ToffsetAmount = this.state.totalAmountCopy
  1134. }
  1135. // 大于1行的商品,遍历n-1个商品,最后一个商品用总冲抵金额减去除最后一行冲抵金额
  1136. if (EditPromData.length > 1) {
  1137. // 商品除最后一行分摊总金额
  1138. let subOffset = 0,
  1139. rowPromAmt = 0
  1140. for (let i = 0; i < EditPromData.length - 1; i++) {
  1141. // 行促销金额存在rowPromAmt中
  1142. rowPromAmt = accSub(
  1143. accMul(EditPromData[i].promPrice, EditPromData[i].mainNum),
  1144. EditPromData[i].promAmount || 0
  1145. )
  1146. // 行分摊金额
  1147. EditPromData[i].offsetAmount = ScaleUtil(
  1148. accMul(
  1149. accDiv(rowPromAmt, this.state.totalAmountCopy),
  1150. ToffsetAmount
  1151. )
  1152. )
  1153. // 计算除最后一行分摊总金额
  1154. subOffset = accAdd(EditPromData[i].offsetAmount, subOffset)
  1155. // 分摊后成交金额
  1156. EditPromData[i].dealAmount = ScaleUtil(
  1157. accSub(rowPromAmt, EditPromData[i].offsetAmount)
  1158. )
  1159. // 根据分摊后成交金额反算成交价格
  1160. EditPromData[i].dealPrice = ScaleUtil(
  1161. accDiv(EditPromData[i].dealAmount, EditPromData[i].mainNum)
  1162. )
  1163. }
  1164. // 商品最后一行处理
  1165. EditPromData[EditPromData.length - 1].offsetAmount = ScaleUtil(
  1166. accSub(ToffsetAmount, subOffset)
  1167. )
  1168. // 促销金额-冲抵金额 (行)
  1169. EditPromData[EditPromData.length - 1].dealAmount = ScaleUtil(
  1170. accSub(
  1171. accSub(
  1172. accMul(
  1173. EditPromData[EditPromData.length - 1].promPrice,
  1174. EditPromData[EditPromData.length - 1].mainNum
  1175. ),
  1176. EditPromData[EditPromData.length - 1].promAmount || 0
  1177. ),
  1178. EditPromData[EditPromData.length - 1].offsetAmount
  1179. )
  1180. )
  1181. EditPromData[EditPromData.length - 1].dealPrice = ScaleUtil(
  1182. accDiv(
  1183. EditPromData[EditPromData.length - 1].dealAmount,
  1184. EditPromData[EditPromData.length - 1].mainNum
  1185. )
  1186. )
  1187. } else {
  1188. // 如果只有一行数据
  1189. // 则直接进行处理
  1190. EditPromData[0].offsetAmount = ToffsetAmount
  1191. EditPromData[0].dealAmount = ScaleUtil(
  1192. accSub(
  1193. accSub(
  1194. accMul(EditPromData[0].promPrice, EditPromData[0].mainNum),
  1195. EditPromData[0].promAmount || 0
  1196. ),
  1197. EditPromData[0].offsetAmount
  1198. )
  1199. )
  1200. EditPromData[0].dealPrice = ScaleUtil(
  1201. accDiv(EditPromData[0].dealAmount, EditPromData[0].mainNum)
  1202. )
  1203. }
  1204. this.setState({
  1205. totalAmount: accSub(
  1206. accSub(this.state.goodsAmount, this.state.totalPromAmt),
  1207. ToffsetAmount
  1208. ),
  1209. offsetAmount: ToffsetAmount,
  1210. EditPromData: EditPromData,
  1211. })
  1212. } else {
  1213. // 冲抵输入框为0或者输入框为空
  1214. // 则还原各行成交价格/金额 为 销售价格/金额,以及冲抵分摊金额还原为0
  1215. ;(EditPromData || []).forEach(val => {
  1216. val.dealAmount = val.amount
  1217. val.dealPrice = val.promPrice
  1218. val.offsetAmount = 0
  1219. })
  1220. this.setState({
  1221. totalAmount: accSub(this.state.goodsAmount, this.state.totalPromAmt),
  1222. offsetAmount: 0,
  1223. EditPromData: EditPromData,
  1224. })
  1225. }
  1226. this.addBoomToData()
  1227. }
  1228. //控制弹出层隐藏显示
  1229. modalVisible(index) {
  1230. this.setState({
  1231. modalVisible : true,
  1232. index : index,
  1233. num : ""
  1234. })
  1235. }
  1236. //弹出框点击确定
  1237. onModalOk() {
  1238. const {num,index} = this.state;
  1239. if(!(/(^[1-9]\d*$)/.test(num))) {
  1240. Toast.show("请输入正确的数量",{position : toastHeight});
  1241. return;
  1242. }
  1243. this.combinedFn(false,index,num);
  1244. this.setState({
  1245. modalVisible : false
  1246. })
  1247. }
  1248. promInfo(item) {
  1249. let promWay = item.promWay == 1 ? '买赠' : '降价'
  1250. return (
  1251. <View>
  1252. <View style={{ flex: 1, flexDirection: 'row', marginTop: 10 }}>
  1253. <View
  1254. style={{
  1255. paddingHorizontal: 4,
  1256. paddingVertical: 2,
  1257. borderRadius: 100,
  1258. backgroundColor: '#E70013',
  1259. marginRight: 14,
  1260. alignSelf: 'center',
  1261. }}
  1262. >
  1263. <Text style={{ fontSize: 12, lineHeight: 14, color: '#FFF' }}>
  1264. {promWay}
  1265. </Text>
  1266. </View>
  1267. <Text
  1268. numberOfLines={3}
  1269. style={{ flex: 1, fontSize: 12, lineHeight: 17, color: '#333' }}
  1270. >
  1271. {item.description}
  1272. </Text>
  1273. </View>
  1274. </View>
  1275. )
  1276. }
  1277. goodsInfo(item, indexParent) {
  1278. // let optFlag = true,
  1279. let optFlag = false,
  1280. isOptArrs = []
  1281. if (item.isOptional) {
  1282. isOptArrs.push(item.isOptional)
  1283. } else if (item.reqOrderItemBoms && item.reqOrderItemBoms.length > 0) {
  1284. item.reqOrderItemBoms.forEach(data => {
  1285. isOptArrs.push(data.isOptional)
  1286. })
  1287. }
  1288. if (isOptArrs.some(smdata => smdata == 1)) {
  1289. optFlag = true
  1290. }
  1291. return (
  1292. <View>
  1293. <View style={{ padding: 10, marginTop: 10, backgroundColor: '#FFF' }}>
  1294. {/* 满减/买赠 */}
  1295. <View style={{ paddingBottom: 10 }}>
  1296. <FlatList
  1297. keyExtractor={item => item.ruleId}
  1298. data={item.reqOrderPromRels || []}
  1299. extraData={this.state}
  1300. renderItem={({ item, index }) => this.promInfo(item, index)}
  1301. />
  1302. </View>
  1303. {/* 商品行 */}
  1304. <View style={{ flexDirection: 'row' }}>
  1305. <Image
  1306. source={{ uri: ImageBaseUrl + item.goodsImg } || png}
  1307. style={{ width: 80, height: 80 }}
  1308. />
  1309. <View style={{ marginLeft: 10, flex: 1 }}>
  1310. <View style={{flexDirection:'row'}}>
  1311. <Text style={{ fontSize: 13, lineHeight: 18, color: '#333',width:'90%' }}>
  1312. {item.goodsDisplayName}
  1313. </Text>
  1314. <TouchableOpacity onPress={() =>this.deleteGoodsFn(indexParent)}>
  1315. <Image
  1316. source={deletePng}
  1317. style={{ width: 20, height: 20}}
  1318. />
  1319. </TouchableOpacity>
  1320. </View>
  1321. <View
  1322. style={{
  1323. flexDirection: 'row',
  1324. justifyContent: 'space-between',
  1325. marginTop: 10,
  1326. }}
  1327. >
  1328. <Text style={{ fontSize: 12, lineHeight: 17, color: '#666' }}>
  1329. 型号:{item.model?(item.model.length>10?item.model.substr(0,10):item.model):""}
  1330. </Text>
  1331. </View>
  1332. <View
  1333. style={{
  1334. flexDirection: 'row',
  1335. justifyContent: 'space-between',
  1336. marginTop: 10,
  1337. }}
  1338. >
  1339. <Text style={{ fontSize: 12, lineHeight: 17, color: '#666' }}>
  1340. 规格:{item.specification?(item.specification.split("/")[0]+'/'+item.mainNumUnitName):""}
  1341. </Text>
  1342. </View>
  1343. <View
  1344. style={{
  1345. flexDirection: 'row',
  1346. justifyContent: 'space-between',
  1347. marginTop: 7,
  1348. }}
  1349. >
  1350. {/* <CountNum
  1351. defaultValue={item.orderNum}
  1352. size={25}
  1353. callback={nv => {
  1354. this.combinedFn(false, indexParent, nv)
  1355. }}
  1356. /> */}
  1357. <Text style={{ fontSize: 12, lineHeight: 17, color: '#666' }}>
  1358. 数量:{item.mainNum} {item.mainNumUnitName}
  1359. </Text>
  1360. <Text style={{ fontSize: 12, lineHeight: 17, color: '#666' }}>
  1361. 重量:{item.weight*item.mainNum}{'KG'}
  1362. </Text>
  1363. </View>
  1364. <View style={{
  1365. flexDirection: 'row',
  1366. justifyContent: 'space-between',
  1367. marginTop: 7,
  1368. }}>
  1369. <TouchableOpacity
  1370. style={{
  1371. backgroundColor : '#E70013',
  1372. borderRadius : 100,
  1373. }}
  1374. onPress={() =>this.modalVisible(indexParent)}
  1375. >
  1376. <Text style={{fontSize:12,color:'#fff',padding:5}}>修改数量</Text>
  1377. </TouchableOpacity>
  1378. </View>
  1379. </View>
  1380. </View>
  1381. <View
  1382. style={{
  1383. flexDirection: 'row',
  1384. justifyContent: 'space-between',
  1385. marginTop: 10,
  1386. }}
  1387. >
  1388. <Text style={{ fontSize: 12, lineHeight: 17, color: '#666' }}>
  1389. 成交价:<Text
  1390. style={{ fontSize: 14, lineHeight: 17, color: '#E14C46' }}
  1391. >
  1392. {CURRENCY.currencySign}
  1393. {ScaleUtil(
  1394. item.dealPrice || item.basePrice,
  1395. CURRENCY.currencyPriceScale
  1396. )}
  1397. </Text>
  1398. </Text>
  1399. <Text style={{ fontSize: 12, lineHeight: 17, color: '#666' }}>
  1400. 成交金额:<Text
  1401. style={{ fontSize: 14, lineHeight: 17, color: '#E14C46' }}
  1402. >
  1403. {CURRENCY.currencySign}
  1404. {ScaleUtil(item.dealAmount, CURRENCY.currencyAmountScale)}
  1405. </Text>
  1406. </Text>
  1407. </View>
  1408. </View>
  1409. {/* 选配列表 */}
  1410. {optFlag ? (
  1411. <View
  1412. style={{
  1413. backgroundColor: '#FFF',
  1414. borderTopColor: '#EEE',
  1415. borderTopWidth: 1 / PixelRatio.get(),
  1416. }}
  1417. >
  1418. {this.optView(item, indexParent, true)}
  1419. <FlatList
  1420. keyExtractor={item => item.id}
  1421. data={item.reqOrderItemBoms || []}
  1422. extraData={this.state}
  1423. renderItem={itemSec =>
  1424. this.reqItemBoms(itemSec.item, itemSec.index, item)
  1425. }
  1426. />
  1427. <Collapsible collapsed={this.state.optCollapse != indexParent}>
  1428. <FlatList
  1429. keyExtractor={item => item.id}
  1430. data={item.reqOrderItemBoms || []}
  1431. extraData={this.state}
  1432. renderItem={itemSec =>
  1433. this.reqItemBoms(itemSec.item, itemSec.index, item)
  1434. }
  1435. />
  1436. </Collapsible>
  1437. </View>
  1438. ) : null}
  1439. {/* 重量等信息 */}
  1440. <Collapsible collapsed={this.state.activeAllCollaps}>
  1441. <View style={{ padding: 10, backgroundColor: '#FAFAFA' }}>
  1442. <View
  1443. style={{ flexDirection: 'row', justifyContent: 'space-between' }}
  1444. >
  1445. <Text style={styles.text666}>
  1446. 单价:{CURRENCY.currencySign}
  1447. {item.salePrice}
  1448. </Text>
  1449. <Text style={styles.text666}>
  1450. 金额:{CURRENCY.currencySign}
  1451. {accMul(item.salePrice || item.basePrice, item.mainNum)}
  1452. </Text>
  1453. </View>
  1454. <View
  1455. style={{
  1456. flexDirection: 'row',
  1457. justifyContent: 'space-between',
  1458. marginTop: 3,
  1459. }}
  1460. >
  1461. <Text style={styles.text666}>
  1462. 重量:{item.weight}
  1463. {item.weightUnit}
  1464. </Text>
  1465. <Text style={styles.text666}>
  1466. 体积:{item.volume}
  1467. {item.volumeUnit}
  1468. </Text>
  1469. </View>
  1470. </View>
  1471. </Collapsible>
  1472. </View>
  1473. )
  1474. }
  1475. optView(item, indexParent, collaseFlag, isOptional) {
  1476. const reqBomText = []
  1477. if (item.reqOrderItemBoms && item.reqOrderItemBoms.length > 0) {
  1478. item.reqOrderItemBoms.forEach((data, key) => {
  1479. reqBomText.push(`子件${NumberTranslate(key)}`)
  1480. })
  1481. }
  1482. if (collaseFlag || isOptional) {
  1483. return (
  1484. <View
  1485. style={{
  1486. padding: 10,
  1487. flexDirection: 'row',
  1488. justifyContent: 'space-between',
  1489. }}
  1490. >
  1491. <View style={{ flexDirection: 'row' }}>
  1492. <Text style={{ fontSize: 12, lineHeight: 17, color: '#333' }}>
  1493. {reqBomText && reqBomText.length > 0 ? '选配项:' : '选 配:'}
  1494. </Text>
  1495. <Text
  1496. numberOfLines={1}
  1497. style={{
  1498. width:
  1499. reqBomText && reqBomText.length > 0
  1500. ? width * 0.4
  1501. : width * 0.75,
  1502. fontSize: 12,
  1503. lineHeight: 17,
  1504. color: '#666',
  1505. }}
  1506. >
  1507. {collaseFlag
  1508. ? reqBomText && reqBomText.length > 0
  1509. ? reqBomText.join()
  1510. : item.baseGoodsOptValue
  1511. : item.baseGoodsOptValue}
  1512. </Text>
  1513. </View>
  1514. {collaseFlag ? (
  1515. <View style={{ flexDirection: 'row' }}>
  1516. {/* <TouchableOpacity
  1517. onPress={() => {
  1518. item.reqOrderItemBoms && item.reqOrderItemBoms.length > 0
  1519. ? this.state.optCollapse == indexParent
  1520. ? this.setState({ optCollapse: 'shouqi' })
  1521. : this.setState({ optCollapse: indexParent })
  1522. : this.optional._openModal(JSON.parse(JSON.stringify(item)))
  1523. }}
  1524. style={{ alignSelf: 'center' }}
  1525. >
  1526. {item.reqOrderItemBoms && item.reqOrderItemBoms.length > 0 ? (
  1527. this.state.optCollapse == indexParent ? (
  1528. <Text
  1529. style={{ fontSize: 12, lineHeight: 17, color: '#333' }}
  1530. >
  1531. 收起
  1532. </Text>
  1533. ) : (
  1534. <Text
  1535. style={{ fontSize: 12, lineHeight: 17, color: '#333' }}
  1536. >
  1537. 展开
  1538. </Text>
  1539. )
  1540. ) : (
  1541. <Image source={moreDian} style={{ width: 24, height: 5 }} />
  1542. )}
  1543. </TouchableOpacity> */}
  1544. {item.reqOrderItemBoms && item.reqOrderItemBoms.length > 0 ? (
  1545. <View style={{ flexDirection: 'row' }}>
  1546. <Text
  1547. style={{ marginLeft: 8, marginRight: 8, color: '#DDD' }}
  1548. >
  1549. |
  1550. </Text>
  1551. <TouchableOpacity
  1552. onPress={() => {
  1553. this.optional._openModal(
  1554. JSON.parse(JSON.stringify(item)),
  1555. true
  1556. )
  1557. }}
  1558. >
  1559. <Text
  1560. style={{ fontSize: 12, lineHeight: 17, color: '#333' }}
  1561. >
  1562. 选配
  1563. {/* 批量选配 */}
  1564. </Text>
  1565. </TouchableOpacity>
  1566. </View>
  1567. ) : null}
  1568. </View>
  1569. ) : null
  1570. // <TouchableOpacity
  1571. // onPress={() => {
  1572. // this.optional._openModal(JSON.parse(JSON.stringify(item)));
  1573. // }}
  1574. // style={{ alignSelf: "center", paddingRight: 5 }}
  1575. // >
  1576. // <Image source={moreDian} style={{ width: 24, height: 5 }} />
  1577. // </TouchableOpacity>
  1578. }
  1579. </View>
  1580. )
  1581. }
  1582. }
  1583. reqItemBoms(item, index, parentItem) {
  1584. return (
  1585. <View>
  1586. <View
  1587. style={{
  1588. paddingTop: 10,
  1589. paddingHorizontal: 10,
  1590. paddingBottom: item.isOptional ? 0 : 10,
  1591. borderTopColor: '#EEE',
  1592. borderTopWidth: 1 / PixelRatio.get(),
  1593. }}
  1594. >
  1595. <View style={{ flexDirection: 'row' }}>
  1596. <View>
  1597. <Text style={styles.bomTitle}>{`子件${NumberTranslate(
  1598. index
  1599. )}:`}</Text>
  1600. </View>
  1601. <View style={{ flex: 1 }}>
  1602. <Text style={styles.bomTitle}>{item.childGoodsName}</Text>
  1603. <View style={{ flexDirection: 'row', marginTop: 10 }}>
  1604. <Text style={styles.bomText}>编码:{item.childGoodsCode}</Text>
  1605. <Text style={[styles.bomText, { marginLeft: 10 }]}>
  1606. {'v' + item.childGoodsVersion}
  1607. </Text>
  1608. </View>
  1609. <View
  1610. style={{
  1611. flexDirection: 'row',
  1612. justifyContent: 'space-between',
  1613. marginTop: 1,
  1614. }}
  1615. >
  1616. <Text style={styles.bomText}>
  1617. 数量:{accMul(
  1618. accMul(parentItem.conversionRate, parentItem.orderNum),
  1619. item.childGoodsQty
  1620. )}
  1621. {' ' + item.childGoodsUnitName}
  1622. </Text>
  1623. <Text style={styles.bomText}>
  1624. 单价:<Text style={{ color: '#E70013' }}>
  1625. {CURRENCY.currencySign +
  1626. accMul(
  1627. accMul(parentItem.conversionRate, parentItem.orderNum),
  1628. parentItem.basePrice
  1629. )}
  1630. </Text>
  1631. </Text>
  1632. </View>
  1633. </View>
  1634. </View>
  1635. </View>
  1636. <View>{this.optView(item, index, false, item.isOptional)}</View>
  1637. </View>
  1638. )
  1639. }
  1640. promInfoFilter(mutualRelationShip) {
  1641. let result = []
  1642. const basePromInfo = [
  1643. { number: 1, name: '买赠-基于商品' },
  1644. { number: 2, name: '降价-基于商品' },
  1645. { number: 3, name: '买赠-基于订单' },
  1646. { number: 4, name: '降价-基于订单' },
  1647. ]
  1648. for (let i = 0; i < mutualRelationShip.length; i++) {
  1649. let groupArr = []
  1650. ;(mutualRelationShip[i] || []).map(valsec => {
  1651. groupArr = groupArr.concat(
  1652. basePromInfo.filter(item => item.number == valsec)
  1653. )
  1654. })
  1655. result.push(groupArr)
  1656. }
  1657. return result
  1658. }
  1659. baseOnPromTouch(item) {
  1660. let Arr = []
  1661. ;(item || []).map(val => Arr.push(val.number))
  1662. this.props.dispatch(
  1663. createAction('orderedit/getProm')({
  1664. promInfo: {
  1665. customerId: CUSTOMERINFO.id,
  1666. promotionStyle: Arr,
  1667. saleOrgId: this.props.navigation.state.params.SaleOrSupplier
  1668. .SaleOrSupplierId,
  1669. isPrimaryChannel: this.props.navigation.state.params.SaleOrSupplier
  1670. .isPrimaryChannel,
  1671. reqOrderItems: this.state.EditPromData,
  1672. },
  1673. })
  1674. )
  1675. this.combinedFn(true)
  1676. }
  1677. // 赠品回调
  1678. giftCb(e, ids) {
  1679. const {EditPromData} = this.state;
  1680. let totalWeight = 0;
  1681. if(EditPromData && EditPromData.length) {
  1682. EditPromData.map(data => {
  1683. totalWeight += data.mainNum*data.weight;
  1684. })
  1685. }
  1686. if(e && e.length) {
  1687. e.map(data => {
  1688. totalWeight += data.mainNum*data.weight
  1689. })
  1690. }
  1691. this.setState({ giftSelected: e,totalWeight })
  1692. }
  1693. baseOnProm(mutualRelationShip) {
  1694. if (mutualRelationShip) {
  1695. this.RelationShipCopy = mutualRelationShip
  1696. } else {
  1697. mutualRelationShip = this.RelationShipCopy
  1698. }
  1699. let basePromInfo = this.promInfoFilter(mutualRelationShip)
  1700. let basePromData = []
  1701. for (let i = 0; i < basePromInfo.length; i++) {
  1702. ;(basePromInfo[i] || []).map((data, index) =>
  1703. basePromData.push(
  1704. <TouchableOpacity
  1705. key={index + data.name ? data.name : ''}
  1706. style={{ flexDirection: 'row', width: width / 2 - 10 }}
  1707. onPress={() => {
  1708. this.state.baseIndex == i ? {} : this.setState({ baseIndex: i })
  1709. this.baseOnPromTouch(basePromInfo[i])
  1710. }}
  1711. >
  1712. <Icon
  1713. name={
  1714. this.state.baseIndex == i
  1715. ? 'icon-icon-danxuankuang-xuanzhong'
  1716. : 'icon-icon-danxuankuang-weixuanzhong'
  1717. }
  1718. size={26}
  1719. color={this.state.baseIndex == i ? '#E14C46' : '#CCC'}
  1720. />
  1721. <Text
  1722. style={{
  1723. marginLeft: 5,
  1724. fontSize: 13,
  1725. lineHeight: 17,
  1726. color: '#333',
  1727. alignSelf: 'center',
  1728. marginBottom: 1,
  1729. }}
  1730. >
  1731. {data.name || ''}
  1732. </Text>
  1733. </TouchableOpacity>
  1734. )
  1735. )
  1736. }
  1737. return (
  1738. <View
  1739. style={{
  1740. backgroundColor: '#FFF',
  1741. marginTop: 10,
  1742. paddingVertical: 7,
  1743. paddingHorizontal: 10,
  1744. flexDirection: 'row',
  1745. flexWrap: 'wrap',
  1746. }}
  1747. >
  1748. {basePromData}
  1749. </View>
  1750. )
  1751. }
  1752. checkCast(castRateData) {
  1753. let financeOrgIds = [],
  1754. flag = true,
  1755. productLineIds = Array.from(new Set(this.state.productLineIds)),
  1756. returnData = {}
  1757. productLineIds.forEach(lineId => {
  1758. castRateData.forEach(castitem => {
  1759. if (
  1760. castitem.productLineIds.length == 1 &&
  1761. !castitem.productLineIds[0]
  1762. ) {
  1763. flag = false
  1764. returnData = castitem
  1765. } else if (castitem.productLineIds.indexOf(lineId) != -1) {
  1766. financeOrgIds.push(castitem.financeOrgId)
  1767. }
  1768. })
  1769. })
  1770. if (financeOrgIds.length == 1 && flag) {
  1771. castRateData.forEach(item => {
  1772. if (item.financeOrgId == financeOrgIds[0]) {
  1773. returnData = item
  1774. }
  1775. })
  1776. }
  1777. return returnData
  1778. }
  1779. render() {
  1780. const {
  1781. addressDefault,
  1782. transportData,
  1783. transportDefault,
  1784. billwayData,
  1785. billwayDefault,
  1786. invoiceDefault,
  1787. castRateData,
  1788. promData,
  1789. creditData,
  1790. orderPayStatus,
  1791. } = this.props
  1792. const supplierDefault = this.props.navigation.state.params.SaleOrSupplier
  1793. let MaxOffset = 0,
  1794. castRateDataOnly = { costOffsetRatio: 0, supplyMaxOccupyMny: 0 }
  1795. if (
  1796. castRateData &&
  1797. castRateData.length > 0 &&
  1798. this.state.productLineIds &&
  1799. this.state.productLineIds.length > 0
  1800. ) {
  1801. let checkCastReturn = this.checkCast(castRateData)
  1802. if (Object.keys(checkCastReturn).length > 0) {
  1803. castRateDataOnly = checkCastReturn
  1804. }
  1805. if (
  1806. accMul(this.state.goodsAmount, castRateDataOnly.costOffsetRatio) >=
  1807. castRateDataOnly.supplyMaxOccupyMny
  1808. ) {
  1809. MaxOffset = castRateDataOnly.supplyMaxOccupyMny
  1810. } else {
  1811. MaxOffset = accMul(
  1812. this.state.goodsAmount,
  1813. castRateDataOnly.costOffsetRatio
  1814. )
  1815. }
  1816. if (MaxOffset >= this.state.totalAmountCopy) {
  1817. MaxOffset = this.state.totalAmountCopy
  1818. }
  1819. }
  1820. return (
  1821. <View
  1822. style={[
  1823. styles.container,
  1824. { backgroundColor: '#F7F7F7' },
  1825. // { backgroundColor: appTheme.backgroundColor }
  1826. ]}
  1827. >
  1828. <StatusBar
  1829. animated={true}
  1830. // barStyle={appTheme.barStyle}
  1831. barStyle={'dark-content'}
  1832. backgroundColor={'transparent'}
  1833. translucent={true}
  1834. />
  1835. {/* 头部 */}
  1836. {this.header()}
  1837. <ScrollView
  1838. style={{ flex: 1 }}
  1839. // scrollEventThrottle={200}
  1840. // onScroll={() => {
  1841. // // 判断圆形按钮滑动前后是否变化控制刷新
  1842. // if (this.cicleActive == this.state.cicleActive) {
  1843. // this.setState({ cicleActive: false });
  1844. // this.cicleActive = this.state.cicleActive;
  1845. // }
  1846. // }}
  1847. // onScrollEndDrag={() => this.setState({ cicleActive: true })}
  1848. // onMomentumScrollEnd={() => this.setState({ cicleActive: true })}
  1849. >
  1850. {/* 供应商显示 */}
  1851. {this.supplier(supplierDefault)}
  1852. {/*选项行*/}
  1853. <View>
  1854. <View style={{ backgroundColor: '#FFF', marginTop: 10 }}>
  1855. {this.viewRender([
  1856. {
  1857. viewName: '运输方式',
  1858. rightName:
  1859. (transportDefault && transportDefault.name) || '铁路运输',
  1860. iconName: 'icon-icon-xiala',
  1861. onPress: () => {
  1862. this.state.activeMethod == 0
  1863. ? this.setState({ activeMethod: 'nfjdsjf' })
  1864. : this.setState({ activeMethod: 0 })
  1865. },
  1866. dataArr: transportData || [],
  1867. },
  1868. // {
  1869. // viewName: '结算方式',
  1870. // rightName: (billwayDefault && billwayDefault.name) || '现金',
  1871. // iconName: 'icon-icon-xiala',
  1872. // onPress: () => {
  1873. // this.state.activeMethod == 1
  1874. // ? this.setState({ activeMethod: 'nfjdsjf' })
  1875. // : this.setState({ activeMethod: 1 })
  1876. // },
  1877. // dataArr: billwayData || [],
  1878. // },
  1879. // {
  1880. // viewName: '支付方式',
  1881. // rightName: this.state.payWayDef && this.state.payWayDef.name,
  1882. // iconName: 'icon-icon-xiala',
  1883. // onPress: () => {
  1884. // this.state.activeMethod == 2
  1885. // ? this.setState({ activeMethod: 'nfjdsjf' })
  1886. // : this.setState({ activeMethod: 2 })
  1887. // },
  1888. // dataArr: orderPayStatus || [],
  1889. // },
  1890. ])}
  1891. </View>
  1892. <View style={{ backgroundColor: '#FFF', marginTop: 10 }}>
  1893. {this.viewRender([
  1894. {
  1895. viewName: '发票',
  1896. rightName:
  1897. (invoiceDefault && invoiceDefault.invoiceTitle) || '发票',
  1898. iconName: 'icon-icon-jianjinzhishiqi',
  1899. onPress: () =>
  1900. this.props.dispatch(
  1901. NavigationActions.navigate({
  1902. routeName: 'SelectInvoice',
  1903. params: e => this.invoiceCallback(e),
  1904. })
  1905. ),
  1906. },
  1907. ])}
  1908. </View>
  1909. {/* <View style={{ backgroundColor: '#FFF', marginTop: 10 }}>
  1910. {this.viewRender(
  1911. [
  1912. {
  1913. viewName: '期望到货日期',
  1914. rightName: this.state.deliveryTime,
  1915. iconName: 'icon-icon-xiala',
  1916. onPress: () =>
  1917. Platform.OS == 'ios'
  1918. ? this.showTime._openModal()
  1919. : this.TimeAndroid(),
  1920. inputName: '备注',
  1921. inputDefault: this.state.remark || '备注订单内容',
  1922. inputValue: '',
  1923. },
  1924. ],
  1925. true
  1926. )}
  1927. </View> */}
  1928. </View>
  1929. {/* 选地址 */}
  1930. <TouchableOpacity
  1931. activeOpacity={1}
  1932. onPress={() =>
  1933. this.props.dispatch(
  1934. NavigationActions.navigate({
  1935. routeName: 'SelectAdress',
  1936. params: e => this.callback(e),
  1937. })
  1938. )
  1939. }
  1940. style={{
  1941. backgroundColor: '#FFF',
  1942. marginTop: 10,
  1943. flexDirection: 'row',
  1944. paddingTop: 10,
  1945. paddingBottom: 5,
  1946. }}
  1947. >
  1948. <View style={{ flex: 1, justifyContent: 'flex-end' }}>
  1949. <Icon
  1950. name="icon-icon-dizhi"
  1951. size={24}
  1952. color={'#333'}
  1953. style={{ alignSelf: 'center' }}
  1954. />
  1955. </View>
  1956. <View style={{ flex: 8, paddingBottom: 5 }}>
  1957. <View style={{ flexDirection: 'row' }}>
  1958. <Text style={{ fontSize: 15, lineHeight: 21, color: '#333' }}>
  1959. {addressDefault && addressDefault.receiver}
  1960. </Text>
  1961. <Text style={{ marginLeft: 3, alignSelf: 'center' }}>
  1962. {addressDefault && addressDefault.receiverPhone}
  1963. </Text>
  1964. </View>
  1965. <Text
  1966. style={{
  1967. marginTop: 4,
  1968. fontSize: 13,
  1969. lineHeight: 18,
  1970. color: '#333',
  1971. }}
  1972. >
  1973. {((addressDefault && addressDefault.receiverProvince) || '') +
  1974. ((addressDefault && addressDefault.receiverCity) || '') +
  1975. ((addressDefault && addressDefault.receiverDistrict) || '') +
  1976. ((addressDefault && addressDefault.receiverTown) || '') +
  1977. ((addressDefault && addressDefault.receiverAddress) || '')}
  1978. </Text>
  1979. </View>
  1980. <View
  1981. style={{
  1982. flex: 1,
  1983. justifyContent: 'center',
  1984. }}
  1985. >
  1986. <Icon
  1987. name="icon-icon-jianjinzhishiqi"
  1988. size={24}
  1989. color={'#ccc'}
  1990. style={{ alignSelf: 'center' }}
  1991. />
  1992. </View>
  1993. </TouchableOpacity>
  1994. {/* Image地址下边框 */}
  1995. <Image source={redblue} style={{ height: 2, width: width }} />
  1996. {/* 基于原单或基于商品数量选项 */}
  1997. {promData.mutualRelationShip
  1998. ? this.baseOnProm(promData.mutualRelationShip)
  1999. : null}
  2000. {/* 商品信息 */}
  2001. {this.state.Loading ? (
  2002. <View style={{ marginTop: 10 }}>
  2003. <ActivityIndicator />
  2004. </View>
  2005. ) : (
  2006. <FlatList
  2007. keyExtractor={item => item.goodsId}
  2008. data={this.state.EditPromData}
  2009. extraData={this.state}
  2010. renderItem={({ item, index }) => this.goodsInfo(item, index)}
  2011. />
  2012. )}
  2013. {/* 赠品明细 */}
  2014. {promData && promData.giftProms && promData.giftProms.length > 0 ? (
  2015. <View
  2016. style={{
  2017. backgroundColor: '#FFF',
  2018. paddingHorizontal: 10,
  2019. paddingTop: 10,
  2020. marginTop: 10,
  2021. }}
  2022. >
  2023. <TouchableOpacity
  2024. onPress={() => {
  2025. let NavigateGift =
  2026. JSON.parse(JSON.stringify(promData.giftProms)) || []
  2027. ;(NavigateGift || []).map(item => {
  2028. item.data = item.giftDtos
  2029. delete item.giftDtos
  2030. })
  2031. this.props.dispatch(
  2032. NavigationActions.navigate({
  2033. routeName: 'OrderGifts',
  2034. params: {
  2035. giftProms: NavigateGift,
  2036. giftCb: (e, ids) => this.giftCb(e, ids),
  2037. },
  2038. })
  2039. )
  2040. }}
  2041. style={{
  2042. paddingBottom: 6,
  2043. flexDirection: 'row',
  2044. justifyContent: 'space-between',
  2045. }}
  2046. >
  2047. <Text style={{ fontSize: 14, lineHeight: 20, color: '#333' }}>
  2048. 赠品明细
  2049. </Text>
  2050. <View style={{ flexDirection: 'row' }}>
  2051. <Text style={{ fontSize: 14, lineHeight: 20, color: '#666' }}>
  2052. 选择赠品
  2053. </Text>
  2054. <Icon
  2055. name="icon-icon-jianjinzhishiqi"
  2056. color="#666"
  2057. size={24}
  2058. style={{ alignSelf: 'center' }}
  2059. />
  2060. </View>
  2061. </TouchableOpacity>
  2062. {this.state.giftSelected.length > 0 ? (
  2063. <FlatList
  2064. keyExtractor={(item, index) => index}
  2065. data={this.state.giftSelected}
  2066. extraData={this.state}
  2067. style={{
  2068. paddingBottom: 10,
  2069. borderTopColor: '#EEE',
  2070. borderTopWidth: 1 / PixelRatio.get(),
  2071. }}
  2072. renderItem={({ item, index }) => (
  2073. <View
  2074. style={{
  2075. flexDirection: 'row',
  2076. justifyContent: 'space-between',
  2077. paddingTop: 10,
  2078. }}
  2079. >
  2080. <Text
  2081. numberOfLines={1}
  2082. style={{
  2083. flex: 1,
  2084. fontSize: 12,
  2085. lineHeight: 17,
  2086. color: '#333',
  2087. }}
  2088. >
  2089. {item.goodsDisplayName}
  2090. </Text>
  2091. <View style={{ flexDirection: 'row', marginLeft: 30 }}>
  2092. <Icon
  2093. name="icon-icon-guanbianniu"
  2094. size={20}
  2095. color="#666"
  2096. />
  2097. <Text
  2098. style={{
  2099. fontSize: 12,
  2100. lineHeight: 17,
  2101. color: '#333',
  2102. marginLeft: 5,
  2103. }}
  2104. >
  2105. {item.mainNum || 1}
  2106. </Text>
  2107. </View>
  2108. </View>
  2109. )}
  2110. />
  2111. ) : null}
  2112. </View>
  2113. ) : null}
  2114. {/* 总体积、数量 */}
  2115. <View style={{ marginTop: 10, padding: 10, backgroundColor: '#FFF' }}>
  2116. <View
  2117. style={{
  2118. flexDirection: 'row',
  2119. justifyContent: 'space-between',
  2120. }}
  2121. >
  2122. <Text style={styles.text666}>总重量</Text>
  2123. <Text style={styles.text666}>
  2124. {this.state.totalWeight}{"KG"}
  2125. {/* {this.state.weightUnit} */}
  2126. </Text>
  2127. </View>
  2128. {/* <View
  2129. style={{
  2130. flexDirection: 'row',
  2131. justifyContent: 'space-between',
  2132. }}
  2133. >
  2134. <Text style={styles.text666}>总体积</Text>
  2135. <Text style={styles.text666}>
  2136. {this.state.totoalVolume}
  2137. {this.state.volumeUnit}
  2138. </Text>
  2139. </View> */}
  2140. </View>
  2141. {/* 金额显示 */}
  2142. <View style={{ marginTop: 10, backgroundColor: '#FFF', padding: 10 }}>
  2143. <View
  2144. style={{
  2145. flexDirection: 'row',
  2146. justifyContent: 'space-between',
  2147. }}
  2148. >
  2149. <Text style={styles.text666}>商品金额:</Text>
  2150. <Text style={styles.text666red}>
  2151. {CURRENCY.currencySign}
  2152. {ScaleUtil(
  2153. this.state.goodsAmount,
  2154. CURRENCY.currencyAmountScale
  2155. )}
  2156. </Text>
  2157. </View>
  2158. <View
  2159. style={{
  2160. flexDirection: 'row',
  2161. justifyContent: 'space-between',
  2162. }}
  2163. >
  2164. <Text style={styles.text666}>促销金额:</Text>
  2165. <Text style={styles.text666red}>
  2166. {CURRENCY.currencySign}
  2167. {this.state.totalPromAmt}
  2168. </Text>
  2169. </View>
  2170. {/* <View
  2171. style={{
  2172. flexDirection: 'row',
  2173. justifyContent: 'space-between',
  2174. }}
  2175. >
  2176. <Text style={styles.text666}>费用冲抵:</Text>
  2177. <Input
  2178. style={{
  2179. borderWidth: 1,
  2180. borderColor: '#E6E6E6',
  2181. borderRadius: 2,
  2182. width: width / 2.5,
  2183. height: 24,
  2184. padding: 0,
  2185. alignItems: 'center',
  2186. }}
  2187. ref={AverageRef => (this.AverageRef = AverageRef)}
  2188. keyboardType={'numeric'}
  2189. isICon={false}
  2190. blurOnSubmit={true}
  2191. placeholder={''}
  2192. textInputBacg={'#FFF'}
  2193. placeholderTextColor={'#CCC'}
  2194. onchangeFn={e => this.AverageBooth(e, MaxOffset)}
  2195. maxNum={MaxOffset}
  2196. />
  2197. </View> */}
  2198. {/* <View
  2199. style={{
  2200. flexDirection: 'row',
  2201. justifyContent: 'flex-end',
  2202. marginTop: 5,
  2203. }}
  2204. >
  2205. <Text style={[styles.text999, { marginRight: 10 }]}>
  2206. (本次最高冲抵:<Text style={{ color: '#E14C46' }}>
  2207. {CURRENCY.currencySign}
  2208. {ScaleUtil(MaxOffset, CURRENCY.currencyAmountScale)}
  2209. </Text>
  2210. </Text>
  2211. <Text style={styles.text999}>
  2212. 费用总金额:
  2213. <Text style={{ color: '#E14C46' }}>
  2214. {CURRENCY.currencySign}
  2215. {ScaleUtil(
  2216. castRateDataOnly.supplyMaxOccupyMny || 0,
  2217. CURRENCY.currencyAmountScale
  2218. )}
  2219. </Text>)
  2220. </Text>
  2221. </View> */}
  2222. <View
  2223. style={{
  2224. flexDirection: 'row',
  2225. justifyContent: 'space-between',
  2226. marginTop: 20,
  2227. }}
  2228. >
  2229. {/* <TouchableOpacity
  2230. style={{ flexDirection: 'row' }}
  2231. onPress={() => {
  2232. this.credit._openModal(creditData)
  2233. this.setState({ creditShow: true })
  2234. }}
  2235. >
  2236. <Text style={[styles.text999, { alignSelf: 'center' }]}>
  2237. 信用查询
  2238. </Text>
  2239. <Image
  2240. source={orderCreditPng}
  2241. style={{
  2242. width: 14,
  2243. height: 14,
  2244. alignSelf: 'center',
  2245. marginLeft: 4,
  2246. }}
  2247. />
  2248. </TouchableOpacity> */}
  2249. <Text style={styles.text666}>
  2250. 订单总金额:<Text
  2251. style={{ fontSize: 18, lineHeight: 25, color: '#E14C46' }}
  2252. >
  2253. {CURRENCY.currencySign}{' '}
  2254. {ScaleUtil(
  2255. this.state.totalAmount,
  2256. CURRENCY.currencyAmountScale
  2257. )}
  2258. </Text>
  2259. </Text>
  2260. </View>
  2261. <View style={{ marginTop: 10, backgroundColor: '#FFF' }}>
  2262. <View style={{flexDirection: 'row'}}>
  2263. <Text>备注:</Text>
  2264. <TextInput
  2265. style={{
  2266. fontSize: 12,
  2267. color: '#333333',
  2268. padding: 0,
  2269. backgroundColor: '#FFF',
  2270. height: 25,
  2271. borderWidth: 1,
  2272. borderColor: '#DDDDDD',
  2273. width:'60%'
  2274. }}
  2275. // multiline
  2276. // numberOfLines={4}
  2277. value={this.state.remark}
  2278. onChangeText={text=>this.setState({remark:text})}
  2279. underlineColorAndroid="transparent"
  2280. />
  2281. </View>
  2282. </View>
  2283. </View>
  2284. <Modal
  2285. animationType="slide"
  2286. presentationStyle="formSheet"
  2287. transparent={true}
  2288. visible={this.state.modalVisible}
  2289. onRequestClose={() => {
  2290. console.log('close');
  2291. }}
  2292. >
  2293. <View
  2294. style={{
  2295. backgroundColor:'#f8f8f8',
  2296. marginTop:'50%',
  2297. marginLeft:'15%',
  2298. width:'70%',
  2299. height:'24%',
  2300. alignItems : 'center',
  2301. shadowColor : '#000',
  2302. shadowOffset: {width: 0,height: 2},
  2303. shadowOpacity : 0.25,
  2304. shadowRadius : 3.84,
  2305. elevation : 5,
  2306. //borderRadius : 20
  2307. }}>
  2308. <Text style={{marginTop:10}}>请输入商品数量</Text>
  2309. <TextInput
  2310. style={{width:'50%'}}
  2311. onChangeText={text => this.setState({num:text})}
  2312. value={this.state.num}
  2313. />
  2314. <View style={{width:"100%",flexDirection:'row',position:'absolute',bottom:0}}>
  2315. <TouchableOpacity style={{backgroundColor : '#E70013',width:'50%',alignItems:'center',fontSize:20,padding:5}}
  2316. onPress= {() => this.onModalOk()}
  2317. >
  2318. <Text>确定</Text>
  2319. </TouchableOpacity>
  2320. <TouchableOpacity style={{backgroundColor : '#fff',width:'50%',alignItems:'center',fontSize:20,padding:5}}
  2321. onPress= {() => this.setState({modalVisible:false})}
  2322. >
  2323. <Text>取消</Text>
  2324. </TouchableOpacity>
  2325. </View>
  2326. </View>
  2327. </Modal>
  2328. </ScrollView>
  2329. {/* 信用弹窗 */}
  2330. <OrderCredit
  2331. ref={credit => (this.credit = credit)}
  2332. cb={() => this.setState({ creditShow: false })}
  2333. />
  2334. <OrderOptional
  2335. {...this.props}
  2336. ref={optional => (this.optional = optional)}
  2337. onPressBom={() => {
  2338. this.addBoomToData()
  2339. }}
  2340. // 选配回调处理(将选择的选配结果返回 加到商品行上)
  2341. optCb={data => {
  2342. this.state.EditPromData.forEach(item => {
  2343. let allOptIds = '',
  2344. allOptVals = ''
  2345. if (item.reqOrderItemBoms && item.reqOrderItemBoms.length > 0) {
  2346. item.reqOrderItemBoms.forEach(itemSec => {
  2347. data.forEach(itemTh => {
  2348. if (itemSec.childGoodsId == itemTh.goodsId) {
  2349. itemSec.baseGoodsOptId = itemTh.optIds
  2350. itemSec.baseGoodsOptValue = itemTh.optVals
  2351. if (allOptIds && allOptIds.length > 0) {
  2352. allOptIds = allOptIds.concat(
  2353. ',' + itemSec.baseGoodsOptId
  2354. )
  2355. allOptVals = allOptVals.concat(
  2356. ',' + itemSec.baseGoodsOptValue
  2357. )
  2358. } else {
  2359. allOptIds = itemSec.baseGoodsOptId
  2360. allOptVals = itemSec.baseGoodsOptValue
  2361. }
  2362. }
  2363. })
  2364. })
  2365. } else {
  2366. data.forEach(dataFt => {
  2367. if (dataFt.goodsId == item.goodsId) {
  2368. allOptIds = dataFt.optIds
  2369. allOptVals = dataFt.optVals
  2370. }
  2371. })
  2372. }
  2373. item.baseGoodsOptId = allOptIds
  2374. item.baseGoodsOptValue = allOptVals
  2375. })
  2376. this.addBoomToData()
  2377. this.setState({ EditPromData: this.state.EditPromData })
  2378. }}
  2379. />
  2380. {/* 时间弹窗 */}
  2381. <SelectTime
  2382. ref={showTime => (this.showTime = showTime)}
  2383. cb={date => {
  2384. this.setState({
  2385. deliveryTime: moment(date).format('YYYY-MM-DD'),
  2386. })
  2387. }}
  2388. />
  2389. {/* 底部 */}
  2390. <View
  2391. style={{
  2392. height: 45 + HEADERSTYLE.paddingBottom,
  2393. paddingBottom: HEADERSTYLE.paddingBottom,
  2394. backgroundColor: '#FFF',
  2395. flexDirection: 'row',
  2396. borderTopColor: '#EEE',
  2397. borderTopWidth: 1 / PixelRatio.get(),
  2398. }}
  2399. >
  2400. {this.bottomTouch()}
  2401. </View>
  2402. {/* 信用弹窗毛玻璃效果 */}
  2403. {/* {this.state.creditShow ? (
  2404. <View
  2405. style={{
  2406. position: "absolute",
  2407. width: width,
  2408. height: height,
  2409. backgroundColor: "#000",
  2410. opacity: 0.5
  2411. }}
  2412. />
  2413. ) : null} */}
  2414. </View>
  2415. )
  2416. }
  2417. }
  2418. const styles = StyleSheet.create({
  2419. container: {
  2420. flex: 1,
  2421. },
  2422. text333: {
  2423. fontSize: 14,
  2424. lineHeight: 20,
  2425. letterSpacing: 0.17,
  2426. color: '#333',
  2427. },
  2428. text666: {
  2429. fontSize: 13,
  2430. lineHeight: 18,
  2431. color: '#666',
  2432. },
  2433. text666red: {
  2434. fontSize: 14,
  2435. lineHeight: 25,
  2436. color: '#E14C46',
  2437. },
  2438. text999: {
  2439. fontSize: 12,
  2440. lineHeight: 17,
  2441. color: '#999',
  2442. },
  2443. bomTitle: {
  2444. fontSize: 13,
  2445. lineHeight: 18,
  2446. color: '#333',
  2447. },
  2448. bomText: {
  2449. fontSize: 12,
  2450. lineHeight: 17,
  2451. color: '#666',
  2452. },
  2453. modalStyle: {
  2454. }
  2455. })
  2456. export default OrderEdit