newSupplier.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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.payNodeTable();
  224. this.props.onCancel();
  225. } else {
  226. message.warning(data.error[0].message)
  227. }
  228. }.bind(this)
  229. )
  230. }
  231. render() {
  232. return (
  233. <Modal
  234. maskClosable={false}
  235. visible={this.props.visible}
  236. onCancel={this.props.onCancel}
  237. width={800}
  238. title={this.props.ThirdId ? "修改第三方信息" : "新增第三方信息"}
  239. footer=""
  240. className="admin-desc-content"
  241. >
  242. <Form
  243. layout="horizontal"
  244. style={{ paddingBottom: '40px' }}
  245. >
  246. <Spin spinning={this.state.loading}>
  247. <div className="clearfix">
  248. <div className="clearfix">
  249. {/*
  250. projectType 0正常 1专利 2软著 3审计
  251. patentType 0:专利申请/变更/转让 1:专利买卖
  252. */}
  253. <Form.Item
  254. {...formItemLayout}
  255. label="供应商名称"
  256. help={
  257. this.props.projectType === 2 ||
  258. (this.props.projectType === 1 &&
  259. this.props.patentType === 0) ? '输入供应商关键字,并选择系统后台已有供应商,如“长沙科明”' : ''
  260. }
  261. >
  262. <AutoComplete
  263. className="certain-category-search"
  264. dropdownClassName="certain-category-search-dropdown"
  265. dropdownMatchSelectWidth={false}
  266. dropdownStyle={{ width: 220 }}
  267. style={{ width: '220px' }}
  268. dataSource={(this.state.customerArr || []).map((group) => (
  269. <Select.Option key={group.id} value={group.companyName}>
  270. {group.companyName}
  271. </Select.Option>
  272. ))}
  273. placeholder="请输入供应商名称"
  274. value={this.state.thirdCompanyName}
  275. onChange={(e) => {
  276. this.httpChange(e)
  277. }}
  278. filterOption={true}
  279. required="required"
  280. />
  281. <span className="mandatory">*</span>
  282. </Form.Item>
  283. </div>
  284. {/*projectType 0正常 1专利 2软著 3审计*/}
  285. {this.props.projectType !== 2 && !(this.props.projectType === 1 && this.props.patentType === 0) ? <div className="clearfix">
  286. <Form.Item {...formItemLayout} label="单价(万元)">
  287. <InputNumber
  288. min={0}
  289. value={this.state.thirdUnitPrice}
  290. placeholder="请输入单价(必填项)"
  291. required="required"
  292. onBlur={this.calculatedAmount}
  293. onChange={(value) => {
  294. this.setState({
  295. thirdUnitPrice: value,
  296. })
  297. }}
  298. dropdownStyle={{ width: 220 }}
  299. style={{
  300. width: '220px',
  301. }}
  302. />
  303. <span className="mandatory" style={{
  304. marginLeft: '-2px',
  305. }}>
  306. *
  307. </span>
  308. </Form.Item>
  309. </div> : <div />}
  310. <div className="clearfix">
  311. <Form.Item {...formItemLayout} label="数量">
  312. <InputNumber
  313. min={0}
  314. value={this.state.thirdQuantity}
  315. placeholder="请输入数量(必填项)"
  316. onBlur={this.calculatedAmount}
  317. precision={0}
  318. onChange={(value) => {
  319. this.setState({
  320. thirdQuantity: value,
  321. })
  322. }}
  323. style={{ width: '220px' }}
  324. />
  325. <span className="mandatory" style={{
  326. marginLeft: '-2px',
  327. }}>
  328. *
  329. </span>
  330. </Form.Item>
  331. </div>
  332. {/*专利 的专利申请 和 软著没有总价*/}
  333. {this.props.projectType !== 2 && this.props.patentType !== 0 ? <div className="clearfix">
  334. <Form.Item {...formItemLayout} label="总价(万元)">
  335. <span>
  336. {
  337. ((this.state.thirdQuantity || 0) * 1000000) *
  338. ((this.state.thirdUnitPrice || 0) * 1000000) / 1000000 / 1000000
  339. }
  340. </span>
  341. </Form.Item>
  342. </div> : <div />}
  343. {this.props.projectType === 2 ? <div>
  344. <div className="clearfix">
  345. <Form.Item {...formItemLayout} label="材料">
  346. <Select
  347. value={this.state.thirdMaterial}
  348. onChange={(val) => {
  349. this.setState({
  350. thirdMaterial: val,
  351. })
  352. this.props.otherOperations && this.props.otherOperations({
  353. thirdMaterial: val,
  354. thirdUrgent: this.state.thirdUrgent,
  355. customerArr: this.state.customerArr,
  356. thirdCompanyName: this.state.thirdCompanyName,
  357. });
  358. }}
  359. style={{ width: '220px' }}
  360. defaultValue="0"
  361. >
  362. <Option value={0}>无材料</Option>
  363. <Option value={1}>有材料</Option>
  364. </Select>
  365. <span className="mandatory">*</span>
  366. </Form.Item>
  367. </div>
  368. <div className="clearfix">
  369. <Form.Item {...formItemLayout} label="加急">
  370. <Select
  371. value={getUrgentStatus(this.state.thirdUrgent)}
  372. onChange={(val) => {
  373. this.setState({
  374. thirdUrgent: val,
  375. })
  376. this.props.otherOperations && this.props.otherOperations({
  377. thirdMaterial: this.state.thirdMaterial,
  378. thirdUrgent: val,
  379. customerArr: this.state.customerArr,
  380. thirdCompanyName: this.state.thirdCompanyName
  381. });
  382. }}
  383. style={{ width: '220px' }}
  384. defaultValue="0"
  385. >
  386. <Option value="0">无加急</Option>
  387. <Option value="1">加急3-5个工作日</Option>
  388. <Option value="2">加急6-10个工作日</Option>
  389. <Option value="3">加急11-15个工作日</Option>
  390. <Option value="4">加急16-20个工作日</Option>
  391. <Option value="5">加急21-25个工作日</Option>
  392. <Option value="6">加急26-30个工作日</Option>
  393. </Select>
  394. <span className="mandatory">*</span>
  395. </Form.Item>
  396. </div>
  397. </div> : <div />}
  398. {/*{*/}
  399. {/* this.props.patentType === 0 ? <div>*/}
  400. {/* <div className="clearfix">*/}
  401. {/* <Form.Item*/}
  402. {/* {...formItemLayout}*/}
  403. {/* label="官费:"*/}
  404. {/* >*/}
  405. {/* <span style={{ color: "red", marginRight: "27px" }}>*/}
  406. {/* **/}
  407. {/* </span>*/}
  408. {/* <Radio.Group*/}
  409. {/* value={this.state.officialCost}*/}
  410. {/* onChange={(e) => {*/}
  411. {/* this.setState({ officialCost: e.target.value });*/}
  412. {/* }}*/}
  413. {/* >*/}
  414. {/* <Radio value={1}>含官费</Radio>*/}
  415. {/* <Radio value={0}>不含官费</Radio>*/}
  416. {/* </Radio.Group>*/}
  417. {/* </Form.Item>*/}
  418. {/* </div>*/}
  419. {/* <div className="clearfix">*/}
  420. {/* <Form.Item*/}
  421. {/* {...formItemLayout}*/}
  422. {/* label="费减:"*/}
  423. {/* >*/}
  424. {/* <span style={{ color: "red", marginRight: "27px" }}>*/}
  425. {/* **/}
  426. {/* </span>*/}
  427. {/* <Radio.Group*/}
  428. {/* value={this.state.costReduction}*/}
  429. {/* onChange={(e) => {*/}
  430. {/* this.setState({ costReduction: e.target.value });*/}
  431. {/* }}*/}
  432. {/* >*/}
  433. {/* <Radio value={1}>有费减</Radio>*/}
  434. {/* <Radio value={0}>无费减</Radio>*/}
  435. {/* </Radio.Group>*/}
  436. {/* </Form.Item>*/}
  437. {/* </div>*/}
  438. {/* </div> : <div/>*/}
  439. {/*}*/}
  440. {
  441. this.props.projectType === 3 ? <div>
  442. <div className="clearfix">
  443. <Form.Item {...formItemLayout} label="审计">
  444. <Select
  445. value={this.state.audit}
  446. onChange={(val) => {
  447. this.setState({
  448. audit: val,
  449. })
  450. }}
  451. style={{ width: '220px' }}
  452. defaultValue="0"
  453. >
  454. {/*0无审计 1年审 2专审*/}
  455. <Option value={1}>年审</Option>
  456. <Option value={2}>专审</Option>
  457. </Select>
  458. <span className="mandatory">*</span>
  459. </Form.Item>
  460. </div>
  461. <div className="clearfix">
  462. <Form.Item {...formItemLayout} label="公司资产(万元)">
  463. <InputNumber
  464. min={0}
  465. value={this.state.assets}
  466. placeholder="请输入公司资产"
  467. required="required"
  468. onChange={(value) => {
  469. this.setState({
  470. assets: value,
  471. })
  472. }}
  473. style={{ width: '220px' }}
  474. />
  475. <span className="mandatory">*</span>
  476. </Form.Item>
  477. </div>
  478. <div className="clearfix">
  479. <Form.Item {...formItemLayout} label="收入(万元)">
  480. <InputNumber
  481. min={0}
  482. value={this.state.income}
  483. placeholder="请输入收入"
  484. required="required"
  485. onChange={(value) => {
  486. this.setState({
  487. income: value,
  488. })
  489. }}
  490. style={{ width: '220px' }}
  491. />
  492. <span className="mandatory">*</span>
  493. </Form.Item>
  494. </div>
  495. </div> : <div />
  496. }
  497. <div className="clearfix">
  498. <Form.Item
  499. style={{ height: 'auto' }}
  500. labelCol={{ span: 4 }}
  501. wrapperCol={{ span: 18 }}
  502. label="备注"
  503. >
  504. <TextArea
  505. rows={4}
  506. placeholder="请输入备注"
  507. ref="signTotalAmount"
  508. style={{ width: '95%' }}
  509. value={this.state.thirdRemarks}
  510. onChange={(e) => {
  511. this.setState({
  512. thirdRemarks: e.target.value,
  513. })
  514. }}
  515. />
  516. </Form.Item>
  517. </div>
  518. <div className="clearfix">
  519. <div className="addSave" style={{ marginTop: '15px' }}>
  520. <Button
  521. className="cancel"
  522. type="primary"
  523. onClick={() => {
  524. this.handleCancelq();
  525. }}
  526. style={{ marginLeft: '300px' }}
  527. htmlType="submit"
  528. >
  529. 保存
  530. </Button>
  531. <Button
  532. className="cancel"
  533. type="ghost"
  534. onClick={this.props.onCancel}
  535. style={{ marginLeft: '50px' }}
  536. >
  537. 取消
  538. </Button>
  539. </div>
  540. </div>
  541. </div>
  542. </Spin>
  543. </Form>
  544. </Modal>
  545. )
  546. }
  547. }
  548. export default NewSupplier;