newSupplier.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. import React,{Component} from 'react';
  2. import {AutoComplete, Button, Form, Input, message, Modal, InputNumber, Select, Spin} from "antd";
  3. import {
  4. getMaterialStatus,
  5. getUrgentStatus,
  6. } from '@/tools'
  7. import $ from "jquery";
  8. const { Option } = Select
  9. const { TextArea } = Input
  10. const formItemLayout = {
  11. labelCol: { span: 8 },
  12. wrapperCol: { span: 14 },
  13. }
  14. class NewSupplier extends Component{
  15. constructor(props) {
  16. super(props);
  17. this.state={
  18. thirdCompanyName: props.thirdCompanyName && props.thirdCompanyName.split('-')[0],
  19. thirdUnitPrice: props.thirdUnitPrice || 0,
  20. thirdQuantity: props.thirdQuantity || 0,
  21. thirdRemarks: props.thirdRemarks,
  22. thirdMaterial: props.thirdMaterial,
  23. thirdUrgent: props.thirdUrgent,
  24. patentType: props.patentType,
  25. audit: props.audit,
  26. assets: props.assets,
  27. income: props.income,
  28. customerArr: [],
  29. loading: false,
  30. officialCost: "", //是否有官费
  31. costReduction: "", //是否有费减
  32. }
  33. this.calculatedAmount = this.calculatedAmount.bind(this);
  34. }
  35. componentDidMount() {
  36. if(this.props.ThirdId){
  37. this.supervisor(this.state.thirdCompanyName)
  38. }
  39. }
  40. //服务值改变时请求供应商名称
  41. httpChange(e) {
  42. if (e.length >= 1) {
  43. this.supervisor(e)
  44. }
  45. this.props.otherOperations && this.props.otherOperations({
  46. thirdMaterial: this.state.thirdMaterial,
  47. thirdUrgent: this.state.thirdUrgent,
  48. customerArr: this.state.customerArr,
  49. thirdCompanyName: e,
  50. });
  51. this.setState({
  52. thirdCompanyName: e,
  53. })
  54. }
  55. //加载(自动补全)
  56. supervisor(e) {
  57. $.ajax({
  58. method: 'get',
  59. dataType: 'json',
  60. crossDomain: false,
  61. url: globalConfig.context + '/api/admin/company/selectVague',
  62. data: {
  63. name: e,
  64. //0软著用 1其他用 2专利申请用
  65. type:
  66. this.props.projectType === 2 ?
  67. 0 :
  68. (this.props.projectType === 1 && this.props.patentType === 0) ? 2 : 1 //this.props.projectType 0正常 1专利 2软著 3审计 this.props.patentType 0:专利申请/变更/转让 1:专利买卖
  69. },
  70. success: function (data) {
  71. let thedata = data.data
  72. if (!thedata) {
  73. if (data.error && data.error.length) {
  74. message.warning(data.error[0].message)
  75. }
  76. thedata = {}
  77. }
  78. this.setState({
  79. customerArr: thedata,
  80. })
  81. this.props.otherOperations && this.props.otherOperations({
  82. thirdMaterial: this.state.thirdMaterial,
  83. thirdUrgent: this.state.thirdUrgent,
  84. customerArr: thedata,
  85. thirdCompanyName: this.state.thirdCompanyName,
  86. });
  87. }.bind(this),
  88. }).always(
  89. function () {
  90. this.setState({
  91. loading: false,
  92. })
  93. }.bind(this)
  94. )
  95. }
  96. // 第三方信息自动计算总金额
  97. calculatedAmount() {
  98. let currentTotalPrice
  99. currentTotalPrice = (this.state.thirdQuantity * 1000000) * (this.state.thirdUnitPrice * 1000000) / 1000000 / 1000000
  100. currentTotalPrice = currentTotalPrice.toFixed(4)
  101. this.setState({
  102. currentTotalPrice: currentTotalPrice,
  103. })
  104. }
  105. // 保存供应商信息
  106. handleCancelq() {
  107. let api
  108. if (this.props.ThirdId) {
  109. //修改
  110. api = '/api/admin/company/updateCompany'
  111. } else {
  112. //新增
  113. api = '/api/admin/company/addCompany'
  114. }
  115. if(!this.state.thirdCompanyName){
  116. message.warning('请输入供应商名称')
  117. return;
  118. }
  119. if(!this.state.thirdUnitPrice && this.props.projectType !== 2 && !(this.props.projectType === 1 && this.props.patentType ===0)){
  120. message.warning('请输入正确的单价')
  121. return;
  122. }
  123. if(!this.state.thirdQuantity){
  124. message.warning('请输入数量')
  125. return;
  126. }
  127. let customerId = 0;
  128. let isHave =this.state.customerArr.some((value)=>{
  129. if(value.companyName === this.state.thirdCompanyName){
  130. customerId = value.id
  131. return true;
  132. }
  133. });
  134. //软著 必须要使用查询出来第三方名称和对应id
  135. if(!isHave && this.props.projectType === 2){ //projectType 0正常 1专利 2软著 3审计
  136. message.warning('请输入正确的供应商名称')
  137. return;
  138. }
  139. //专利 必须要使用查询出来第三方名称和对应id
  140. if(!isHave && this.props.projectType === 1 && this.props.patentType === 0){ //projectType 0正常 1专利 2软著 3审计 patentType 0:专利申请/变更/转让 1:专利买卖
  141. message.warning('请输入正确的供应商名称')
  142. return;
  143. }
  144. let data = {
  145. id: this.props.ThirdId, //id
  146. tid: this.props.tid, //订单编号
  147. companyName: this.state.thirdCompanyName, //第三方名称
  148. quantity: this.state.thirdQuantity, //数量
  149. remarks: this.state.thirdRemarks, //备注
  150. }
  151. if(isHave){
  152. data.cid = customerId //公司id 只有软著类要传cid,其他类型都是非必填的
  153. }
  154. if(this.props.projectType === 2){
  155. data.material = this.state.thirdMaterial; //材料
  156. data.urgent = this.state.thirdUrgent; //加急
  157. data.calculation = 1; //0 其他 1软著 2专利
  158. }else{ //非软著类需要传总金额
  159. data.totalAmount = (this.state.thirdQuantity * 1000000) * (this.state.thirdUnitPrice * 1000000) / 1000000 / 1000000;
  160. data.calculation = 0; //0 其他 1软著 2专利
  161. }
  162. if(this.props.projectType === 1 && this.props.patentType === 0){
  163. data.calculation = 2; //0 其他 1软著 2专利
  164. }
  165. // data.type = this.props.realProjectType === 1 ? (this.props.patentType === 0 ? 1 : 2) : 0 //0其他 1专利申请 2专利买卖
  166. if(this.props.realProjectType === 1){ //专利
  167. data.patentType = this.props.patentType === 0 ? 0 : 1; //专利类型
  168. data.patentNameType =this.props.patentNameType; //专利名称
  169. }
  170. data.startType = this.props.startType; //项目类型 0外包 1供应商
  171. if(this.props.projectType === 3){
  172. if(!this.state.audit){
  173. message.warning("请选择审计!");
  174. return false;
  175. }
  176. if(!this.state.assets){
  177. message.warning("请输入公司资产!");
  178. return false;
  179. }
  180. if(!this.state.income){
  181. message.warning("请输入收入!");
  182. return false;
  183. }
  184. }
  185. //projectType 0正常 1专利 2软著 3审计
  186. //软著不需要传 单价
  187. if(this.props.projectType !== 2){
  188. data.unitPrice = this.state.thirdUnitPrice; //单价
  189. }
  190. if(this.props.projectType === 3){ //审计
  191. data.assets = this.state.assets; //资产
  192. data.audit = this.state.audit; //0无审计 1年审 2专审
  193. data.income = this.state.income; //收入
  194. }
  195. //已经发起的供应商项目新增第三方时需要传type=1
  196. if(this.props.isLaunch && !this.props.ThirdId && this.props.startType === 1){
  197. data.type = 1; //在发起供应商后,新增第三方需要加上type=1,因为在发起供应商会计算成本,这个新增的需要单独去计算
  198. }
  199. this.setState({
  200. loading: true,
  201. })
  202. $.ajax({
  203. url: globalConfig.context + api,
  204. method: 'post',
  205. dataType: 'json',
  206. crossDomain: false,
  207. data: data,
  208. }).done(
  209. function (data) {
  210. this.setState({
  211. loading: false,
  212. })
  213. if (!data.error.length) {
  214. message.success('保存成功!')
  215. this.setState({
  216. thirdCompanyName: '', //第三方名称
  217. thirdUnitPrice: 0, //单价
  218. thirdQuantity: 0, //数量
  219. currentTotalPrice: 0, //总价
  220. thirdRemarks: '',
  221. thirdUrgent: 0,
  222. })
  223. this.props.onCancel();
  224. } else {
  225. message.warning(data.error[0].message)
  226. }
  227. }.bind(this)
  228. )
  229. }
  230. render() {
  231. return(
  232. <Modal
  233. maskClosable={false}
  234. visible={this.props.visible}
  235. onCancel={this.props.onCancel}
  236. width={800}
  237. title={this.props.ThirdId ? "修改第三方信息" : "新增第三方信息"}
  238. footer=""
  239. className="admin-desc-content"
  240. >
  241. <Form
  242. layout="horizontal"
  243. style={{ paddingBottom: '40px' }}
  244. >
  245. <Spin spinning={this.state.loading}>
  246. <div className="clearfix">
  247. <div className="clearfix">
  248. {/*
  249. projectType 0正常 1专利 2软著 3审计
  250. patentType 0:专利申请/变更/转让 1:专利买卖
  251. */}
  252. <Form.Item
  253. {...formItemLayout}
  254. label="供应商名称"
  255. help={
  256. this.props.projectType === 2 ||
  257. (this.props.projectType === 1 &&
  258. this.props.patentType === 0) ? '输入供应商关键字,并选择系统后台已有供应商,如“长沙科明”' : ''
  259. }
  260. >
  261. <AutoComplete
  262. className="certain-category-search"
  263. dropdownClassName="certain-category-search-dropdown"
  264. dropdownMatchSelectWidth={false}
  265. dropdownStyle={{ width: 220 }}
  266. style={{ width: '220px' }}
  267. dataSource={(this.state.customerArr || []).map((group) => (
  268. <Select.Option key={group.id} value={group.companyName}>
  269. {group.companyName}
  270. </Select.Option>
  271. ))}
  272. placeholder="请输入供应商名称"
  273. value={this.state.thirdCompanyName}
  274. onChange={(e)=>{
  275. this.httpChange(e)
  276. }}
  277. filterOption={true}
  278. required="required"
  279. />
  280. <span className="mandatory">*</span>
  281. </Form.Item>
  282. </div>
  283. {/*projectType 0正常 1专利 2软著 3审计*/}
  284. {this.props.projectType !== 2 && !(this.props.projectType === 1 && this.props.patentType ===0) ?<div className="clearfix">
  285. <Form.Item {...formItemLayout} label="单价(万元)">
  286. <InputNumber
  287. min={0}
  288. value={this.state.thirdUnitPrice}
  289. placeholder="请输入单价(必填项)"
  290. required="required"
  291. onBlur={this.calculatedAmount}
  292. onChange={(value) => {
  293. this.setState({
  294. thirdUnitPrice: value,
  295. })
  296. }}
  297. dropdownStyle={{ width: 220 }}
  298. style={{
  299. width: '220px',
  300. }}
  301. />
  302. <span className="mandatory" style={{
  303. marginLeft: '-2px',
  304. }}>
  305. *
  306. </span>
  307. </Form.Item>
  308. </div> : <div/>}
  309. <div className="clearfix">
  310. <Form.Item {...formItemLayout} label="数量">
  311. <InputNumber
  312. min={0}
  313. value={this.state.thirdQuantity}
  314. placeholder="请输入数量(必填项)"
  315. onBlur={this.calculatedAmount}
  316. precision={0}
  317. onChange={(value) => {
  318. this.setState({
  319. thirdQuantity: value,
  320. })
  321. }}
  322. style={{ width: '220px' }}
  323. />
  324. <span className="mandatory" style={{
  325. marginLeft: '-2px',
  326. }}>
  327. *
  328. </span>
  329. </Form.Item>
  330. </div>
  331. {/*专利 的专利申请 和 软著没有总价*/}
  332. {this.props.projectType !== 2 && this.props.patentType !==0 ?<div className="clearfix">
  333. <Form.Item {...formItemLayout} label="总价(万元)">
  334. <span>
  335. {
  336. ((this.state.thirdQuantity || 0) * 1000000) *
  337. ((this.state.thirdUnitPrice || 0) * 1000000) / 1000000 / 1000000
  338. }
  339. </span>
  340. </Form.Item>
  341. </div> : <div/>}
  342. {this.props.projectType === 2 ? <div>
  343. <div className="clearfix">
  344. <Form.Item {...formItemLayout} label="材料">
  345. <Select
  346. value={this.state.thirdMaterial}
  347. onChange={(val) => {
  348. this.setState({
  349. thirdMaterial: val,
  350. })
  351. this.props.otherOperations && this.props.otherOperations({
  352. thirdMaterial: val,
  353. thirdUrgent: this.state.thirdUrgent,
  354. customerArr: this.state.customerArr,
  355. thirdCompanyName: this.state.thirdCompanyName,
  356. });
  357. }}
  358. style={{ width: '220px' }}
  359. defaultValue="0"
  360. >
  361. <Option value={0}>无材料</Option>
  362. <Option value={1}>有材料</Option>
  363. </Select>
  364. <span className="mandatory">*</span>
  365. </Form.Item>
  366. </div>
  367. <div className="clearfix">
  368. <Form.Item {...formItemLayout} label="加急">
  369. <Select
  370. value={getUrgentStatus(this.state.thirdUrgent)}
  371. onChange={(val) => {
  372. this.setState({
  373. thirdUrgent: val,
  374. })
  375. this.props.otherOperations && this.props.otherOperations({
  376. thirdMaterial: this.state.thirdMaterial,
  377. thirdUrgent: val,
  378. customerArr: this.state.customerArr,
  379. thirdCompanyName: this.state.thirdCompanyName
  380. });
  381. }}
  382. style={{ width: '220px' }}
  383. defaultValue="0"
  384. >
  385. <Option value="0">无加急</Option>
  386. <Option value="1">加急3-5个工作日</Option>
  387. <Option value="2">加急6-10个工作日</Option>
  388. <Option value="3">加急11-15个工作日</Option>
  389. <Option value="4">加急16-20个工作日</Option>
  390. <Option value="5">加急21-25个工作日</Option>
  391. <Option value="6">加急26-30个工作日</Option>
  392. </Select>
  393. <span className="mandatory">*</span>
  394. </Form.Item>
  395. </div>
  396. </div>:<div/>}
  397. {/*{*/}
  398. {/* this.props.patentType === 0 ? <div>*/}
  399. {/* <div className="clearfix">*/}
  400. {/* <Form.Item*/}
  401. {/* {...formItemLayout}*/}
  402. {/* label="官费:"*/}
  403. {/* >*/}
  404. {/* <span style={{ color: "red", marginRight: "27px" }}>*/}
  405. {/* **/}
  406. {/* </span>*/}
  407. {/* <Radio.Group*/}
  408. {/* value={this.state.officialCost}*/}
  409. {/* onChange={(e) => {*/}
  410. {/* this.setState({ officialCost: e.target.value });*/}
  411. {/* }}*/}
  412. {/* >*/}
  413. {/* <Radio value={1}>含官费</Radio>*/}
  414. {/* <Radio value={0}>不含官费</Radio>*/}
  415. {/* </Radio.Group>*/}
  416. {/* </Form.Item>*/}
  417. {/* </div>*/}
  418. {/* <div className="clearfix">*/}
  419. {/* <Form.Item*/}
  420. {/* {...formItemLayout}*/}
  421. {/* label="费减:"*/}
  422. {/* >*/}
  423. {/* <span style={{ color: "red", marginRight: "27px" }}>*/}
  424. {/* **/}
  425. {/* </span>*/}
  426. {/* <Radio.Group*/}
  427. {/* value={this.state.costReduction}*/}
  428. {/* onChange={(e) => {*/}
  429. {/* this.setState({ costReduction: e.target.value });*/}
  430. {/* }}*/}
  431. {/* >*/}
  432. {/* <Radio value={1}>有费减</Radio>*/}
  433. {/* <Radio value={0}>无费减</Radio>*/}
  434. {/* </Radio.Group>*/}
  435. {/* </Form.Item>*/}
  436. {/* </div>*/}
  437. {/* </div> : <div/>*/}
  438. {/*}*/}
  439. {
  440. this.props.projectType === 3 ? <div>
  441. <div className="clearfix">
  442. <Form.Item {...formItemLayout} label="审计">
  443. <Select
  444. value={this.state.audit}
  445. onChange={(val) => {
  446. this.setState({
  447. audit: val,
  448. })
  449. }}
  450. style={{ width: '220px' }}
  451. defaultValue="0"
  452. >
  453. {/*0无审计 1年审 2专审*/}
  454. <Option value={1}>年审</Option>
  455. <Option value={2}>专审</Option>
  456. </Select>
  457. <span className="mandatory">*</span>
  458. </Form.Item>
  459. </div>
  460. <div className="clearfix">
  461. <Form.Item {...formItemLayout} label="公司资产(万元)">
  462. <InputNumber
  463. min={0}
  464. value={this.state.assets}
  465. placeholder="请输入公司资产"
  466. required="required"
  467. onChange={(value) => {
  468. this.setState({
  469. assets: value,
  470. })
  471. }}
  472. style={{ width: '220px' }}
  473. />
  474. <span className="mandatory">*</span>
  475. </Form.Item>
  476. </div>
  477. <div className="clearfix">
  478. <Form.Item {...formItemLayout} label="收入(万元)">
  479. <InputNumber
  480. min={0}
  481. value={this.state.income}
  482. placeholder="请输入收入"
  483. required="required"
  484. onChange={(value) => {
  485. this.setState({
  486. income: value,
  487. })
  488. }}
  489. style={{ width: '220px' }}
  490. />
  491. <span className="mandatory">*</span>
  492. </Form.Item>
  493. </div>
  494. </div> : <div/>
  495. }
  496. <div className="clearfix">
  497. <Form.Item
  498. style={{ height: 'auto' }}
  499. labelCol={{ span: 4 }}
  500. wrapperCol={{ span: 18 }}
  501. label="备注"
  502. >
  503. <TextArea
  504. rows={4}
  505. placeholder="请输入备注"
  506. ref="signTotalAmount"
  507. style={{ width: '95%' }}
  508. value={this.state.thirdRemarks}
  509. onChange={(e) => {
  510. this.setState({
  511. thirdRemarks: e.target.value,
  512. })
  513. }}
  514. />
  515. </Form.Item>
  516. </div>
  517. <div className="clearfix">
  518. <div className="addSave" style={{ marginTop: '15px' }}>
  519. <Button
  520. className="cancel"
  521. type="primary"
  522. onClick={()=>{
  523. this.handleCancelq();
  524. }}
  525. style={{ marginLeft: '300px' }}
  526. htmlType="submit"
  527. >
  528. 保存
  529. </Button>
  530. <Button
  531. className="cancel"
  532. type="ghost"
  533. onClick={this.props.onCancel}
  534. style={{ marginLeft: '50px' }}
  535. >
  536. 取消
  537. </Button>
  538. </div>
  539. </div>
  540. </div>
  541. </Spin>
  542. </Form>
  543. </Modal>
  544. )
  545. }
  546. }
  547. export default NewSupplier;