newSupplier.js 27 KB

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