123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- import React,{Component} from 'react';
- import {AutoComplete, Button, Form, Input, message, Modal, Radio, Select, Spin} from "antd";
- import {
- getMaterialStatus,
- getUrgentStatus,
- } from '@/tools'
- import $ from "jquery";
- const { Option } = Select
- const { TextArea } = Input
- const formItemLayout = {
- labelCol: { span: 8 },
- wrapperCol: { span: 14 },
- }
- class NewSupplier extends Component{
- constructor(props) {
- super(props);
- this.state={
- thirdCompanyName: props.thirdCompanyName && props.thirdCompanyName.split('-')[0],
- thirdUnitPrice: props.thirdUnitPrice,
- thirdQuantity: props.thirdQuantity,
- thirdRemarks: props.thirdRemarks,
- thirdMaterial: props.thirdMaterial,
- thirdUrgent: props.thirdUrgent,
- patentType: props.patentType,
- customerArr: [],
- loading: false,
- officialCost: "", //是否有官费
- costReduction: "", //是否有费减
- }
- }
- componentDidMount() {
- if(this.props.ThirdId){
- this.supervisor(this.state.thirdCompanyName)
- }
- }
- //服务值改变时请求供应商名称
- httpChange(e) {
- if (e.length >= 1) {
- this.supervisor(e)
- }
- this.props.otherOperations && this.props.otherOperations({
- thirdMaterial: this.state.thirdMaterial,
- thirdUrgent: this.state.thirdUrgent,
- customerArr: this.state.customerArr,
- thirdCompanyName: e,
- });
- this.setState({
- thirdCompanyName: e,
- })
- }
- //加载(自动补全)
- supervisor(e) {
- $.ajax({
- method: 'get',
- dataType: 'json',
- crossDomain: false,
- url: globalConfig.context + '/api/admin/company/selectVague',
- data: {
- name: e,
- type: this.props.projectType === 2 ? 0 :
- (this.props.projectType === 1 && this.props.patentType === 0) ? 2 : 1 //this.props.projectType 0正常 1专利 2软著 3审计 this.props.patentType 0:专利申请/变更/转让 1:专利买卖
- },
- 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,
- })
- this.props.otherOperations && this.props.otherOperations({
- thirdMaterial: this.state.thirdMaterial,
- thirdUrgent: this.state.thirdUrgent,
- customerArr: thedata,
- thirdCompanyName: this.state.thirdCompanyName,
- });
- }.bind(this),
- }).always(
- function () {
- this.setState({
- loading: false,
- })
- }.bind(this)
- )
- }
- // 第三方信息自动计算总金额
- calculatedAmount() {
- let currentTotalPrice
- currentTotalPrice = this.state.thirdUnitPrice * this.state.thirdQuantity
- currentTotalPrice = currentTotalPrice.toFixed(4)
- this.setState({
- currentTotalPrice: currentTotalPrice,
- })
- }
- // 保存供应商信息
- handleCancelq() {
- let api
- if (this.props.ThirdId) {
- //修改
- api = '/api/admin/company/updateCompany'
- } else {
- //新增
- api = '/api/admin/company/addCompany'
- }
- if(!this.state.thirdCompanyName){
- message.warning('请输入供应商名称')
- return;
- }
- if(!this.state.thirdUnitPrice && this.props.projectType !== 2 && !(this.props.projectType === 1 && this.props.patentType ===0)){
- message.warning('请输入正确的单价')
- return;
- }
- if(!this.state.thirdQuantity){
- message.warning('请输入数量')
- return;
- }
- let customerId = 0;
- let isHave =this.state.customerArr.some((value)=>{
- if(value.companyName === this.state.thirdCompanyName){
- customerId = value.id
- return true;
- }
- });
- //软著 必须要使用查询出来第三方名称和对应id
- if(!isHave && this.props.projectType === 2){ //projectType 0正常 1专利 2软著 3审计
- message.warning('请输入正确的供应商名称')
- return;
- }
- //专利 必须要使用查询出来第三方名称和对应id
- if(!isHave && this.props.projectType === 1 && this.props.patentType === 0){ //projectType 0正常 1专利 2软著 3审计 patentType 0:专利申请/变更/转让 1:专利买卖
- message.warning('请输入正确的供应商名称')
- return;
- }
- let data = {
- id: this.props.ThirdId, //id
- tid: this.props.tid, //订单编号
- companyName: this.state.thirdCompanyName, //第三方名称
- quantity: this.state.thirdQuantity, //数量
- remarks: this.state.thirdRemarks, //备注
- unitPrice: this.state.thirdUnitPrice, //单价
- }
- if(isHave){
- data.cid = customerId //公司id 只有软著类要传cid,其他类型都是非必填的
- }
- if(this.props.projectType === 2){
- data.material = this.state.thirdMaterial; //材料
- data.urgent = this.state.thirdUrgent; //加急
- data.calculation = 1; //0 其他 1软著 2专利
- }else{ //非软著类需要传总金额
- data.totalAmount = this.state.thirdQuantity * this.state.thirdUnitPrice;
- data.calculation = 0; //0 其他 1软著 2专利
- }
- if(this.props.projectType === 1 && this.props.patentType === 0){
- data.calculation = 2; //0 其他 1软著 2专利
- }
- data.type = this.props.projectType === 1 ? (this.props.patentType === 0 ? 1 : 2) : 0 //0其他 1专利申请 2专利买卖
- if(this.props.projectType === 3){
- if(!this.state.assets){
- message.warning("请选择审计!");
- return false;
- }
- if(!this.state.assets){
- message.warning("请输入公司资产!");
- return false;
- }
- if(!this.state.assets){
- message.warning("请输入收入!");
- return false;
- }
- }
- if(this.props.projectType === 3){ //审计
- data.assets = this.state.assets; //资产
- data.audit = this.state.audit; //0无审计 1年审 2专审
- data.income = this.state.income; //收入
- }
- if(this.props.projectType === 1){ //专利
- data.patentType = this.props.patentNameType //专利名称
- }
- this.setState({
- loading: true,
- })
- $.ajax({
- url: globalConfig.context + api,
- method: 'post',
- dataType: 'json',
- crossDomain: false,
- data: data,
- }).done(
- function (data) {
- this.setState({
- loading: false,
- })
- if (!data.error.length) {
- message.success('保存成功!')
- this.setState({
- thirdCompanyName: '', //第三方名称
- thirdUnitPrice: '', //单价
- thirdQuantity: '', //数量
- currentTotalPrice: '', //总价
- thirdRemarks: '',
- thirdUrgent: 0,
- })
- this.props.onCancel();
- } else {
- message.warning(data.error[0].message)
- }
- }.bind(this)
- )
- }
- render() {
- return(
- <Modal
- visible={this.props.visible}
- onCancel={this.props.onCancel}
- width={800}
- title={this.props.ThirdId ? "修改供应商" : "新增供应商"}
- footer=""
- className="admin-desc-content"
- >
- <Form
- layout="horizontal"
- style={{ paddingBottom: '40px' }}
- >
- <Spin spinning={this.state.loading}>
- <div className="clearfix">
- <div className="clearfix">
- <Form.Item {...formItemLayout} label="供应商名称">
- <AutoComplete
- className="certain-category-search"
- dropdownClassName="certain-category-search-dropdown"
- dropdownMatchSelectWidth={false}
- dropdownStyle={{ width: 220 }}
- style={{ width: '220px' }}
- dataSource={(this.state.customerArr || []).map((group) => (
- <Select.Option key={group.id} value={group.companyName}>
- {group.companyName}
- </Select.Option>
- ))}
- placeholder="请输入供应商名称"
- value={this.state.thirdCompanyName}
- onChange={(e)=>{
- this.httpChange(e)
- }}
- filterOption={true}
- required="required"
- />
- <span className="mandatory">*</span>
- </Form.Item>
- </div>
- {/*projectType 0正常 1专利 2软著 3审计*/}
- {this.props.projectType !== 2 && !(this.props.projectType === 1 && this.props.patentType ===0) ?<div className="clearfix">
- <Form.Item {...formItemLayout} label="单价(万元)">
- <Input
- value={this.state.thirdUnitPrice}
- placeholder="请输入金额(必填项)"
- required="required"
- type={'number'}
- onBlur={this.calculatedAmount}
- onChange={(e) => {
- this.setState({
- thirdUnitPrice: e.target.value,
- })
- }}
- style={{ width: '220px' }}
- />
- <span className="mandatory">*</span>
- </Form.Item>
- </div> : <div/>}
- <div className="clearfix">
- <Form.Item {...formItemLayout} label="数量">
- <Input
- value={this.state.thirdQuantity}
- placeholder="请输入数量(必填项)"
- onBlur={this.calculatedAmount}
- type={'number'}
- onChange={(e) => {
- this.setState({
- thirdQuantity: e.target.value,
- })
- }}
- style={{ width: '220px' }}
- />
- <span className="mandatory">*</span>
- </Form.Item>
- </div>
- {/*专利 的专利申请 和 软著没有总价*/}
- {this.props.projectType !== 2 && this.props.patentType !==0 ?<div className="clearfix">
- <Form.Item {...formItemLayout} label="总价(万元)">
- <span>{this.state.thirdQuantity * this.state.thirdUnitPrice}</span>
- </Form.Item>
- </div> : <div/>}
- {this.props.projectType === 2 ? <div>
- <div className="clearfix">
- <Form.Item {...formItemLayout} label="材料">
- <Select
- value={getMaterialStatus(this.state.thirdMaterial)}
- onChange={(val) => {
- this.setState({
- thirdMaterial: val,
- })
- this.props.otherOperations && this.props.otherOperations({
- thirdMaterial: val,
- thirdUrgent: this.state.thirdUrgent,
- customerArr: this.state.customerArr,
- thirdCompanyName: this.state.thirdCompanyName,
- });
- }}
- style={{ width: '220px' }}
- defaultValue="0"
- >
- <Option value="0">无材料</Option>
- <Option value="1">有材料</Option>
- </Select>
- <span className="mandatory">*</span>
- </Form.Item>
- </div>
- <div className="clearfix">
- <Form.Item {...formItemLayout} label="加急">
- <Select
- value={getUrgentStatus(this.state.thirdUrgent)}
- onChange={(val) => {
- this.setState({
- thirdUrgent: val,
- })
- this.props.otherOperations && this.props.otherOperations({
- thirdMaterial: this.state.thirdMaterial,
- thirdUrgent: val,
- customerArr: this.state.customerArr,
- thirdCompanyName: this.state.thirdCompanyName
- });
- }}
- style={{ width: '220px' }}
- defaultValue="0"
- >
- <Option value="0">无加急</Option>
- <Option value="1">加急3天</Option>
- <Option value="2">加急4天</Option>
- <Option value="3">加急5-10天</Option>
- <Option value="4">加急11-15天</Option>
- <Option value="5">加急16-20天</Option>
- <Option value="6">加急21-25天</Option>
- <Option value="7">加急26-30天</Option>
- </Select>
- <span className="mandatory">*</span>
- </Form.Item>
- </div>
- </div>:<div/>}
- {/*{*/}
- {/* this.props.patentType === 0 ? <div>*/}
- {/* <div className="clearfix">*/}
- {/* <Form.Item*/}
- {/* {...formItemLayout}*/}
- {/* label="官费:"*/}
- {/* >*/}
- {/* <span style={{ color: "red", marginRight: "27px" }}>*/}
- {/* **/}
- {/* </span>*/}
- {/* <Radio.Group*/}
- {/* value={this.state.officialCost}*/}
- {/* onChange={(e) => {*/}
- {/* this.setState({ officialCost: e.target.value });*/}
- {/* }}*/}
- {/* >*/}
- {/* <Radio value={1}>含官费</Radio>*/}
- {/* <Radio value={0}>不含官费</Radio>*/}
- {/* </Radio.Group>*/}
- {/* </Form.Item>*/}
- {/* </div>*/}
- {/* <div className="clearfix">*/}
- {/* <Form.Item*/}
- {/* {...formItemLayout}*/}
- {/* label="费减:"*/}
- {/* >*/}
- {/* <span style={{ color: "red", marginRight: "27px" }}>*/}
- {/* **/}
- {/* </span>*/}
- {/* <Radio.Group*/}
- {/* value={this.state.costReduction}*/}
- {/* onChange={(e) => {*/}
- {/* this.setState({ costReduction: e.target.value });*/}
- {/* }}*/}
- {/* >*/}
- {/* <Radio value={1}>有费减</Radio>*/}
- {/* <Radio value={0}>无费减</Radio>*/}
- {/* </Radio.Group>*/}
- {/* </Form.Item>*/}
- {/* </div>*/}
- {/* </div> : <div/>*/}
- {/*}*/}
- {
- this.props.projectType === 3 ? <div>
- <div className="clearfix">
- <Form.Item {...formItemLayout} label="审计">
- <Select
- value={this.state.audit}
- onChange={(val) => {
- this.setState({
- audit: val,
- })
- }}
- style={{ width: '220px' }}
- defaultValue="0"
- >
- {/*0无审计 1年审 2专审*/}
- <Option value={0}>无审计</Option>
- <Option value={1}>年审</Option>
- <Option value={2}>专审</Option>
- </Select>
- <span className="mandatory">*</span>
- </Form.Item>
- </div>
- <div className="clearfix">
- <Form.Item {...formItemLayout} label="公司资产(万元)">
- <Input
- value={this.state.assets}
- placeholder="请输入公司资产"
- required="required"
- type={'number'}
- onChange={(e) => {
- this.setState({
- assets: e.target.value,
- })
- }}
- style={{ width: '220px' }}
- />
- <span className="mandatory">*</span>
- </Form.Item>
- </div>
- <div className="clearfix">
- <Form.Item {...formItemLayout} label="收入(万元)">
- <Input
- value={this.state.income}
- placeholder="请输入收入"
- required="required"
- type={'number'}
- onChange={(e) => {
- this.setState({
- income: e.target.value,
- })
- }}
- style={{ width: '220px' }}
- />
- <span className="mandatory">*</span>
- </Form.Item>
- </div>
- </div> : <div/>
- }
- <div className="clearfix">
- <Form.Item
- style={{ height: 'auto' }}
- labelCol={{ span: 4 }}
- wrapperCol={{ span: 18 }}
- label="备注"
- >
- <TextArea
- rows={4}
- placeholder="请输入备注"
- ref="signTotalAmount"
- style={{ width: '95%' }}
- value={this.state.thirdRemarks}
- onChange={(e) => {
- this.setState({
- thirdRemarks: e.target.value,
- })
- }}
- />
- </Form.Item>
- </div>
- <div className="clearfix">
- <div className="addSave" style={{ marginTop: '15px' }}>
- <Button
- className="cancel"
- type="primary"
- onClick={()=>{
- this.handleCancelq();
- }}
- style={{ marginLeft: '300px' }}
- htmlType="submit"
- >
- 保存
- </Button>
- <Button
- className="cancel"
- type="ghost"
- onClick={this.props.onCancel}
- style={{ marginLeft: '50px' }}
- >
- 取消
- </Button>
- </div>
- </div>
- </div>
- </Spin>
- </Form>
- </Modal>
- )
- }
- }
- export default NewSupplier;
|