import React, { Component } from "react";
import { AutoComplete, Button, Form, Input, message, Modal, Select, Spin, Tag, Radio, DatePicker } from "antd";
import $ from "jquery";
import moment from "moment";
import ImgList from "../../common/imgList";
import { splitUrl } from "../../tools";
import { vipYear } from "../../dataDic";
const FormItem = Form.Item;
const Option = Select.Option;
const RadioGroup = Radio.Group;
const formItemLayout = {
labelCol: { span: 8 },
wrapperCol: { span: 14 },
};
const PicturesWall = React.createClass({
getInitialState() {
return {
previewVisible: false,
previewImage: "",
fileList: this.props.pictureUrl,
};
},
getDefaultProps() {
return {
changeClick: this.modifyChange,
};
},
handleCancel() {
this.setState({ previewVisible: false });
},
handlePreview(file) {
this.setState({
previewImage: file.url || file.thumbUrl,
previewVisible: true,
});
},
handleChange(info) {
let fileList = info.fileList;
this.setState({ fileList });
this.props.fileList(fileList);
},
componentWillReceiveProps(nextProps) {
this.state.fileList = nextProps.pictureUrl;
},
render() {
const { fileList } = this.state;
return (
{
this.handleChange(infor);
}}
fileList={fileList}
/>
);
},
});
class ProjectOperationVip extends Component {
constructor(props) {
super(props);
this.state = {
commodityName: undefined,
commodityQuantity: 1,
patentType: 0,
officialCost: '',
costReduction: '',
commodityPrice: '',
main: '',
taskComment: '',
declarationBatch: '',
ifCertificationFee: '',
displayFees: "none",
customerArr: [],
patentTypeList: [],
loading: false,
patentTransfer: props.dataInfor ? props.dataInfor.patentTransfer : 0, //收否为专利转让 0 否 1 是
orgCodeUrl: [],
serviceLife: [],
histYear: [], //已派年份
serviceYear: undefined, //本次派单
isEdit: false,//是否可编辑
contractTerm: [],//合同期
addyear: undefined,//
isGive: undefined,//是否赠送
cPeriod: false, // 合同期是否可编辑
}
this.onSubmit = this.onSubmit.bind(this);
this.httpChange = this.httpChange.bind(this);
this.selectAuto = this.selectAuto.bind(this);
this.setValue = this.setValue.bind(this);
this.getOrgCodeUrl = this.getOrgCodeUrl.bind(this);
}
componentDidMount() {
this.setValue();
}
setValue() {
const { dataInfor } = this.props;
if (!(dataInfor && Object.keys(dataInfor).length > 0)) {
} else {
this.setState({
fid: dataInfor.id,
commodityId: dataInfor.commodityId, //项目ID
commodityName: dataInfor.commodityName, //项目名称
commodityQuantity: dataInfor.commodityQuantity, // 数量
memberType: dataInfor.memberType.toString(),// 付款情况
taskComment: dataInfor.taskComment, // 备注
orgCodeUrl: dataInfor.pictureUrl ? splitUrl(dataInfor.pictureUrl, ",", globalConfig.avatarHost + "/upload") : [],// 附件
yearSum: dataInfor.yearSum && dataInfor.yearSum.toString() || undefined,//会员总服务年限
serviceLife: JSON.parse(dataInfor.serviceLife) || [],//会员服务年限
serviceYear: dataInfor.serviceYear || undefined,//本次派单
contractTerm: (!dataInfor.contractTerm || (dataInfor.contractTerm.indexOf("-") == -1)) ? [] : JSON.parse(dataInfor.contractTerm),//合同期
});
}
}
//
getOrgCodeUrl(e) {
this.setState({ orgCodeUrl: e });
}
// 新建会员项目
onSubmit() {
let pictureUrl = [];
if (this.state.orgCodeUrl.length) {
let picArr = [];
this.state.orgCodeUrl.map(function (item) {
if (
item.response &&
item.response.data &&
item.response.data.length
) {
picArr.push(item.response.data);
}
});
pictureUrl = picArr.join(",");
}
if (this.state.commodityId === undefined || !this.state.commodityId) {
message.warning("服务名称不匹配!");
return
}
let reg = /^([0]|[1-9][0-9]*)$/;
if (
!this.state.commodityQuantity ||
!reg.test(this.state.commodityQuantity)
) {
message.warning("请输入正确商品数量!");
return
}
if (this.state.memberType === undefined) {
message.warning("请选择付款情况!");
return
}
if (this.state.yearSum === undefined) {
message.warning("请选择会员总服务年限!");
return
}
if (this.state.serviceLife.length === 0) {
message.warning("请添加会员服务年限!");
return
}
if (this.state.serviceLife.length != this.state.yearSum) {
message.warning("会员服务年限与总年限不符合!");
return
}
if (this.state.serviceYear === undefined) {
message.warning("请选择本次派单年份!");
return
}
if (this.state.contractTerm.length === 0) {
message.warning("请添加合同期!");
return
}
if (this.state.memberType == "1" || this.state.memberType == "2") {
if (typeof pictureUrl !== "string") {
message.warning("请上传附件!");
return
}
}
this.setState({
loading: true,
});
let infor = {
orderNo: this.props.orderNo, //订单编号
commodityId: this.state.commodityId, //项目编号
commodityName: this.state.commodityName, //项目名称
commodityQuantity: this.state.commodityQuantity, //商品数量
commodityPrice: 0, //签单总价
taskComment: this.state.taskComment, //服务说明
memberType: this.state.memberType,//会员付款状态
yearSum: this.state.yearSum,//会员总服务年限
serviceLife: JSON.stringify(this.state.serviceLife),//会员服务年限
serviceYear: this.state.serviceYear,//本次派单
contractTerm: JSON.stringify(this.state.contractTerm),//合同期
pictureUrl: pictureUrl.length ? pictureUrl : "",//附件
}
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/orderProject/addMemberProject",
data: infor,
}).done(
function (data) {
this.setState({
loading: false,
});
if (!data.error.length) {
Modal.success({
title: '保存成功!',
content: (
已提出会员项目申请!请在
“订单管理-我的会员项目“
跟进查看会员项目的审核状态,审核通过,即表示添加会员项目完成!!!
),
});
this.props.onCancel();
} else {
message.warning(data.error[0].message);
}
}.bind(this)
);
}
// 修改会员项目
onChange() {
let pictureUrl = [];
if (this.state.orgCodeUrl.length) {
let picArr = [];
this.state.orgCodeUrl.map(function (item) {
if (
item.response &&
item.response.data &&
item.response.data.length
) {
picArr.push(item.response.data);
}
});
pictureUrl = picArr.join(",");
}
if (this.state.commodityId === undefined || !this.state.commodityId) {
message.warning("服务名称不匹配!");
return
}
let reg = /^([0]|[1-9][0-9]*)$/;
if (
!this.state.commodityQuantity ||
!reg.test(this.state.commodityQuantity)
) {
message.warning("请输入正确商品数量!");
return false;
}
if (this.state.memberType === undefined) {
message.warning("请选择付款情况!");
return
}
if (this.state.yearSum === undefined) {
message.warning("请选择会员总服务年限!");
return
}
if (this.state.serviceLife.length === 0) {
message.warning("请添加会员服务年限!");
return
}
if (this.state.serviceLife.length != this.state.yearSum) {
message.warning("会员服务年限与总年限不符合!");
return
}
if (this.state.serviceYear === undefined) {
message.warning("请选择本次派单年份!");
return
}
if (this.state.contractTerm.length === 0) {
message.warning("请添加合同期!");
return
}
if (this.state.memberType == "1" || this.state.memberType == "2") {
if (typeof pictureUrl !== "string") {
message.warning("请上传附件!");
return
}
}
this.setState({
loading: true,
});
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/orderProject/updateMemberProject",
data: {
id: this.state.fid, //任务ID
commodityId: this.state.commodityId, //项目ID
commodityName: this.state.commodityName, //项目名称
orderNo: this.props.orderNo, //订单编号
commodityQuantity: this.state.commodityQuantity, //数量
taskComment: this.state.taskComment, //备注
memberType: this.state.memberType,//会员付款状态
yearSum: this.state.yearSum,//会员总服务年限
serviceLife: JSON.stringify(this.state.serviceLife),//会员服务年限
serviceYear: this.state.serviceYear,//本次派单
contractTerm: JSON.stringify(this.state.contractTerm),//合同期
pictureUrl: pictureUrl.length ? pictureUrl : "",//附件
},
}).done(
function (data) {
this.setState({
loading: false,
});
if (!data.error.length) {
message.success("保存成功!");
this.props.onCancel();
} else {
message.warning(data.error[0].message);
}
}.bind(this)
);
}
//
httpChange(e) {
this.setState({
commodityName: e,
});
if (e.length >= 1) {
this.supervisor(e);
}
}
//加载(自动补全)
supervisor(e) {
//服务名称自动补全
let api = "/api/admin/order/getBusinessProjectByName";
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + api,
data: {
businessName: e,
cname: "高新会员服务",
},
success: function (data) {
let thedata = data.data;
if (!thedata) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
}
thedata = {};
}
this.setState({
customerArr: thedata,
});
}.bind(this),
}).always(
function () {
}.bind(this)
);
}
//
selectAuto(value) {
const { customerArr } = this.state;
const { newData } = this.props
const newdataSources = JSON.stringify(customerArr) == "{}" ? [] : customerArr;
let cid = newdataSources.find((item) => item.bname == value).commodityId
this.setState({
commodityName: value,
commodityId: cid,
histYear: [],
});
if (newData && newData.length > 0) {
let llist = []
for (var i = 0; i < newData.length; i++) {
if (newData[i].commodityId == cid) {
llist.push(newData[i].serviceYear)
}
}
this.setState({
histYear: llist
})
for (var i = newData.length - 1; i >= 0; i--) {
if (newData[i].commodityId == cid) {
this.setState({
yearSum: newData[i].yearSum.toString(), // 会员总服务年限
serviceLife: JSON.parse(newData[i].serviceLife) || [], // 会员服务年限
isEdit: true, // 不可编辑
cPeriod: !newData[i].contractTerm ? false : true, //合同期编辑
})
} else {
this.setState({
yearSum: undefined,
serviceLife: [],
isEdit: false, // 可编辑
cPeriod: false,
})
}
return
}
}
}
handleClose(removedTag) {
let serviceLife = this.state.serviceLife.filter(tag => { return tag !== removedTag });
this.setState({
serviceLife,
// commodityQuantity: serviceLife.length == 0 ? undefined : serviceLife.length,
yearSum: serviceLife.length == 0 ? undefined : serviceLife.length.toString(),
serviceYear: undefined
});
}
render() {
let options = this.state.customerArr.map((group, index) => (
{group.bname}
));
// let contList = vipYear.map(its => (
//
// ));
const { readOnly } = this.props;
const { histYear, isEdit, cPeriod } = this.state
const { RangePicker } = DatePicker;
return (
{
this.state.addYears &&
{
if (!this.state.addyear) {
message.warn("请选择年份!")
return
}
if (this.state.isGive == undefined) {
message.warn("请选择是否赠送!")
return
}
let slist = this.state.serviceLife
if (this.state.isGive == 0) {
slist.push(this.state.addyear)
} else if (this.state.isGive == 1) {
let newYear = this.state.addyear + "(赠)"
slist.push(newYear)
}
this.setState({
serviceLife: slist,
yearSum: slist.length.toString(),
addYears: false
})
}}
onCancel={() => {
this.setState({
addYears: false
})
}}
>
{
this.setState({
isGive: e.target.value
})
}}
value={this.state.isGive}
>
非赠送
赠送
}
)
}
}
export default ProjectOperationVip;