newSupplier.js 28 KB

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