newSupplier.js 28 KB

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