newSupplier.js 26 KB

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