/** * 统一选择组件 */ import React, { Component } from "react"; import { connect } from "dva"; import { Form, Select, InputNumber, Row, Col, Button } from "antd"; import "../../meeting.less"; import { formatCurrency } from "../../../../utils/utils"; const { Option } = Select; const productBuyMode = [ { label: "按月", value: "1" }, { label: "按年", value: "2" }, { label: "一次性", value: "3" } ]; //月份 const month = [ { label: "1月", value: 1 }, { label: "2月", value: 2 }, { label: "3月", value: 3 }, { label: "4月", value: 4 }, { label: "5月", value: 5 }, { label: "6月", value: 6 }, { label: "7月", value: 7 }, { label: "8月", value: 8 }, { label: "9月", value: 9 } ]; //年份 const year = [ { label: "1年", value: 1 }, { label: "2年", value: 2 }, { label: "3年", value: 3 } ]; @connect(state => ({ comName: state.global.companyInfo.comName, mobilePhone: state.user.currentUser.mobilePhone })) @Form.create() export default class StandardComponent extends Component { constructor(props, context) { super(props, context); this.state = { itemData: props.itemData, buyList: props.buyList, //拼合成的购买列表 show: false //大于两个的时候,是否显示 }; } componentDidMount() { // console.log(this.props); } componentWillReceiveProps(nextProps) { this.setState({ buyList: nextProps.buyList }); } //购买方式发生改变 _changeBuyMeans(modeList, selectValue, index, productBuyModeId) { modeList.forEach(item => { if (item.productBuyMode === selectValue) { const buyList = JSON.parse(JSON.stringify(this.state.buyList)); buyList.productInfoList[index].eachAmount = item.amount; buyList.productInfoList[index].unit = item.unit; buyList.productInfoList[index].productBuyMode = selectValue; buyList.productInfoList[index].productBuyModeId = productBuyModeId; this.setState({ buyList }, () => { /** * 购买方式发生改变,会引发时长的改变 * 默认时长的初始值是1个月或者1年,所以参数值都是1 */ this._changeDuration("1", index); }); } }); } //数量发生改变 _changeNum(num, index) { const buyList = JSON.parse(JSON.stringify(this.state.buyList)); buyList.productInfoList[index].num = num; this.setState({ buyList }, () => { this._changeTotal(index); }); } //时长发生改变 _changeDuration(selectValue, index) { const buyList = JSON.parse(JSON.stringify(this.state.buyList)); buyList.productInfoList[index].duration = selectValue; this.setState({ buyList }, () => { this._changeTotal(index); }); } //该条信息总金额发生改变 _changeTotal(index) { const buyList = JSON.parse(JSON.stringify(this.state.buyList)); buyList.productInfoList[index].amount = buyList.productInfoList[index].eachAmount * buyList.productInfoList[index].duration * buyList.productInfoList[index].num; this.setState({ buyList }); this.props.changeBuyList(buyList); } //渲染时长选择框 _renderDuration(data, index) { return ( 时长: ); } // _renderView(infoList, buyList, index) { return (
{infoList.productUrl && (
)}

{infoList.name}

{infoList.remark}
购买方式: 单价: {formatCurrency(buyList.productInfoList[index].eachAmount)} {buyList.productInfoList[index].unit} {buyList.productInfoList[index].productBuyMode === "1" && this._renderDuration(month, index)} {buyList.productInfoList[index].productBuyMode === "2" && this._renderDuration(year, index)} {/* */} 数量: { this._changeNum(value, index); }} />
); } render() { const { itemData, buyList } = this.state; return (
{itemData.productTypeUrl && (
)}

{itemData.name}

{itemData.remark}
{itemData.productInfoList.length > 0 && buyList && itemData.productInfoList.map((infoList, index) => { if (index === 2) { return this.state.show ? ( itemData.productInfoList.map((infoList2, index2) => { if (index2 > 1) { return (
{this._renderView(infoList2, buyList, index2)}
); } }) ) : ( { this.setState({ show: !this.state.show }); }} style={{ color: "#0F71FF" }} key={index} > +展开其他规格产品 ); } else if (index > 2) { return ""; } else { return this._renderView(infoList, buyList, index); } })}
); } }