newSupplier.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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.assets){
  168. message.warning("请选择审计!");
  169. return false;
  170. }
  171. if(!this.state.assets){
  172. message.warning("请输入公司资产!");
  173. return false;
  174. }
  175. if(!this.state.assets){
  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. value={this.state.thirdUnitPrice}
  281. placeholder="请输入单价(必填项)"
  282. required="required"
  283. onBlur={this.calculatedAmount}
  284. onChange={(value) => {
  285. this.setState({
  286. thirdUnitPrice: value,
  287. })
  288. }}
  289. dropdownStyle={{ width: 220 }}
  290. style={{
  291. width: '220px',
  292. }}
  293. />
  294. <span className="mandatory" style={{
  295. marginLeft: '-2px',
  296. }}>
  297. *
  298. </span>
  299. </Form.Item>
  300. </div> : <div/>}
  301. <div className="clearfix">
  302. <Form.Item {...formItemLayout} label="数量">
  303. <InputNumber
  304. value={this.state.thirdQuantity}
  305. placeholder="请输入数量(必填项)"
  306. onBlur={this.calculatedAmount}
  307. precision={0}
  308. onChange={(value) => {
  309. this.setState({
  310. thirdQuantity: value,
  311. })
  312. }}
  313. style={{ width: '220px' }}
  314. />
  315. <span className="mandatory" style={{
  316. marginLeft: '-2px',
  317. }}>
  318. *
  319. </span>
  320. </Form.Item>
  321. </div>
  322. {/*专利 的专利申请 和 软著没有总价*/}
  323. {this.props.projectType !== 2 && this.props.patentType !==0 ?<div className="clearfix">
  324. <Form.Item {...formItemLayout} label="总价(万元)">
  325. <span>
  326. {
  327. ((this.state.thirdQuantity || 0) * 1000000) *
  328. ((this.state.thirdUnitPrice || 0) * 1000000) / 1000000 / 1000000
  329. }
  330. </span>
  331. </Form.Item>
  332. </div> : <div/>}
  333. {this.props.projectType === 2 ? <div>
  334. <div className="clearfix">
  335. <Form.Item {...formItemLayout} label="材料">
  336. <Select
  337. value={this.state.thirdMaterial}
  338. onChange={(val) => {
  339. this.setState({
  340. thirdMaterial: val,
  341. })
  342. this.props.otherOperations && this.props.otherOperations({
  343. thirdMaterial: val,
  344. thirdUrgent: this.state.thirdUrgent,
  345. customerArr: this.state.customerArr,
  346. thirdCompanyName: this.state.thirdCompanyName,
  347. });
  348. }}
  349. style={{ width: '220px' }}
  350. defaultValue="0"
  351. >
  352. <Option value={0}>无材料</Option>
  353. <Option value={1}>有材料</Option>
  354. </Select>
  355. <span className="mandatory">*</span>
  356. </Form.Item>
  357. </div>
  358. <div className="clearfix">
  359. <Form.Item {...formItemLayout} label="加急">
  360. <Select
  361. value={getUrgentStatus(this.state.thirdUrgent)}
  362. onChange={(val) => {
  363. this.setState({
  364. thirdUrgent: val,
  365. })
  366. this.props.otherOperations && this.props.otherOperations({
  367. thirdMaterial: this.state.thirdMaterial,
  368. thirdUrgent: val,
  369. customerArr: this.state.customerArr,
  370. thirdCompanyName: this.state.thirdCompanyName
  371. });
  372. }}
  373. style={{ width: '220px' }}
  374. defaultValue="0"
  375. >
  376. <Option value="0">无加急</Option>
  377. <Option value="1">加急3天</Option>
  378. <Option value="2">加急4天</Option>
  379. <Option value="3">加急5-10天</Option>
  380. <Option value="4">加急11-15天</Option>
  381. <Option value="5">加急16-20天</Option>
  382. <Option value="6">加急21-25天</Option>
  383. <Option value="7">加急26-30天</Option>
  384. </Select>
  385. <span className="mandatory">*</span>
  386. </Form.Item>
  387. </div>
  388. </div>:<div/>}
  389. {/*{*/}
  390. {/* this.props.patentType === 0 ? <div>*/}
  391. {/* <div className="clearfix">*/}
  392. {/* <Form.Item*/}
  393. {/* {...formItemLayout}*/}
  394. {/* label="官费:"*/}
  395. {/* >*/}
  396. {/* <span style={{ color: "red", marginRight: "27px" }}>*/}
  397. {/* **/}
  398. {/* </span>*/}
  399. {/* <Radio.Group*/}
  400. {/* value={this.state.officialCost}*/}
  401. {/* onChange={(e) => {*/}
  402. {/* this.setState({ officialCost: e.target.value });*/}
  403. {/* }}*/}
  404. {/* >*/}
  405. {/* <Radio value={1}>含官费</Radio>*/}
  406. {/* <Radio value={0}>不含官费</Radio>*/}
  407. {/* </Radio.Group>*/}
  408. {/* </Form.Item>*/}
  409. {/* </div>*/}
  410. {/* <div className="clearfix">*/}
  411. {/* <Form.Item*/}
  412. {/* {...formItemLayout}*/}
  413. {/* label="费减:"*/}
  414. {/* >*/}
  415. {/* <span style={{ color: "red", marginRight: "27px" }}>*/}
  416. {/* **/}
  417. {/* </span>*/}
  418. {/* <Radio.Group*/}
  419. {/* value={this.state.costReduction}*/}
  420. {/* onChange={(e) => {*/}
  421. {/* this.setState({ costReduction: e.target.value });*/}
  422. {/* }}*/}
  423. {/* >*/}
  424. {/* <Radio value={1}>有费减</Radio>*/}
  425. {/* <Radio value={0}>无费减</Radio>*/}
  426. {/* </Radio.Group>*/}
  427. {/* </Form.Item>*/}
  428. {/* </div>*/}
  429. {/* </div> : <div/>*/}
  430. {/*}*/}
  431. {
  432. this.props.projectType === 3 ? <div>
  433. <div className="clearfix">
  434. <Form.Item {...formItemLayout} label="审计">
  435. <Select
  436. value={this.state.audit}
  437. onChange={(val) => {
  438. this.setState({
  439. audit: val,
  440. })
  441. }}
  442. style={{ width: '220px' }}
  443. defaultValue="0"
  444. >
  445. {/*0无审计 1年审 2专审*/}
  446. <Option value={1}>年审</Option>
  447. <Option value={2}>专审</Option>
  448. </Select>
  449. <span className="mandatory">*</span>
  450. </Form.Item>
  451. </div>
  452. <div className="clearfix">
  453. <Form.Item {...formItemLayout} label="公司资产(万元)">
  454. <InputNumber
  455. value={this.state.assets}
  456. placeholder="请输入公司资产"
  457. required="required"
  458. onChange={(value) => {
  459. this.setState({
  460. assets: value,
  461. })
  462. }}
  463. style={{ width: '220px' }}
  464. />
  465. <span className="mandatory">*</span>
  466. </Form.Item>
  467. </div>
  468. <div className="clearfix">
  469. <Form.Item {...formItemLayout} label="收入(万元)">
  470. <InputNumber
  471. value={this.state.income}
  472. placeholder="请输入收入"
  473. required="required"
  474. onChange={(value) => {
  475. this.setState({
  476. income: value,
  477. })
  478. }}
  479. style={{ width: '220px' }}
  480. />
  481. <span className="mandatory">*</span>
  482. </Form.Item>
  483. </div>
  484. </div> : <div/>
  485. }
  486. <div className="clearfix">
  487. <Form.Item
  488. style={{ height: 'auto' }}
  489. labelCol={{ span: 4 }}
  490. wrapperCol={{ span: 18 }}
  491. label="备注"
  492. >
  493. <TextArea
  494. rows={4}
  495. placeholder="请输入备注"
  496. ref="signTotalAmount"
  497. style={{ width: '95%' }}
  498. value={this.state.thirdRemarks}
  499. onChange={(e) => {
  500. this.setState({
  501. thirdRemarks: e.target.value,
  502. })
  503. }}
  504. />
  505. </Form.Item>
  506. </div>
  507. <div className="clearfix">
  508. <div className="addSave" style={{ marginTop: '15px' }}>
  509. <Button
  510. className="cancel"
  511. type="primary"
  512. onClick={()=>{
  513. this.handleCancelq();
  514. }}
  515. style={{ marginLeft: '300px' }}
  516. htmlType="submit"
  517. >
  518. 保存
  519. </Button>
  520. <Button
  521. className="cancel"
  522. type="ghost"
  523. onClick={this.props.onCancel}
  524. style={{ marginLeft: '50px' }}
  525. >
  526. 取消
  527. </Button>
  528. </div>
  529. </div>
  530. </div>
  531. </Spin>
  532. </Form>
  533. </Modal>
  534. )
  535. }
  536. }
  537. export default NewSupplier;