newSupplier.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. }
  34. componentDidMount() {
  35. if(this.props.ThirdId){
  36. this.supervisor(this.state.thirdCompanyName)
  37. }
  38. }
  39. //服务值改变时请求供应商名称
  40. httpChange(e) {
  41. if (e.length >= 1) {
  42. this.supervisor(e)
  43. }
  44. this.props.otherOperations && this.props.otherOperations({
  45. thirdMaterial: this.state.thirdMaterial,
  46. thirdUrgent: this.state.thirdUrgent,
  47. customerArr: this.state.customerArr,
  48. thirdCompanyName: e,
  49. });
  50. this.setState({
  51. thirdCompanyName: e,
  52. })
  53. }
  54. //加载(自动补全)
  55. supervisor(e) {
  56. $.ajax({
  57. method: 'get',
  58. dataType: 'json',
  59. crossDomain: false,
  60. url: globalConfig.context + '/api/admin/company/selectVague',
  61. data: {
  62. name: e,
  63. type: this.props.projectType === 2 || (this.props.projectType === 1 && this.props.patentType === 1) ? 0 :
  64. (this.props.projectType === 1 && this.props.patentType === 0) ? 2 : 1 //this.props.projectType 0正常 1专利 2软著 3审计 this.props.patentType 0:专利申请/变更/转让 1:专利买卖
  65. },
  66. success: function (data) {
  67. let thedata = data.data
  68. if (!thedata) {
  69. if (data.error && data.error.length) {
  70. message.warning(data.error[0].message)
  71. }
  72. thedata = {}
  73. }
  74. this.setState({
  75. customerArr: thedata,
  76. })
  77. this.props.otherOperations && this.props.otherOperations({
  78. thirdMaterial: this.state.thirdMaterial,
  79. thirdUrgent: this.state.thirdUrgent,
  80. customerArr: thedata,
  81. thirdCompanyName: this.state.thirdCompanyName,
  82. });
  83. }.bind(this),
  84. }).always(
  85. function () {
  86. this.setState({
  87. loading: false,
  88. })
  89. }.bind(this)
  90. )
  91. }
  92. // 第三方信息自动计算总金额
  93. calculatedAmount() {
  94. let currentTotalPrice
  95. currentTotalPrice = this.state.thirdUnitPrice * this.state.thirdQuantity
  96. currentTotalPrice = currentTotalPrice.toFixed(4)
  97. this.setState({
  98. currentTotalPrice: currentTotalPrice,
  99. })
  100. }
  101. // 保存供应商信息
  102. handleCancelq() {
  103. let api
  104. if (this.props.ThirdId) {
  105. //修改
  106. api = '/api/admin/company/updateCompany'
  107. } else {
  108. //新增
  109. api = '/api/admin/company/addCompany'
  110. }
  111. if(!this.state.thirdCompanyName){
  112. message.warning('请输入供应商名称')
  113. return;
  114. }
  115. if(!this.state.thirdUnitPrice && this.props.projectType !== 2 && !(this.props.projectType === 1 && this.props.patentType ===0)){
  116. message.warning('请输入正确的单价')
  117. return;
  118. }
  119. if(!this.state.thirdQuantity){
  120. message.warning('请输入数量')
  121. return;
  122. }
  123. let customerId = 0;
  124. let isHave =this.state.customerArr.some((value)=>{
  125. if(value.companyName === this.state.thirdCompanyName){
  126. customerId = value.id
  127. return true;
  128. }
  129. });
  130. //软著 必须要使用查询出来第三方名称和对应id
  131. if(!isHave && this.props.projectType === 2){ //projectType 0正常 1专利 2软著 3审计
  132. message.warning('请输入正确的供应商名称')
  133. return;
  134. }
  135. //专利 必须要使用查询出来第三方名称和对应id
  136. if(!isHave && this.props.projectType === 1 && this.props.patentType === 0){ //projectType 0正常 1专利 2软著 3审计 patentType 0:专利申请/变更/转让 1:专利买卖
  137. message.warning('请输入正确的供应商名称')
  138. return;
  139. }
  140. let data = {
  141. id: this.props.ThirdId, //id
  142. tid: this.props.tid, //订单编号
  143. companyName: this.state.thirdCompanyName, //第三方名称
  144. quantity: this.state.thirdQuantity, //数量
  145. remarks: this.state.thirdRemarks, //备注
  146. unitPrice: this.state.thirdUnitPrice, //单价
  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 * this.state.thirdUnitPrice;
  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. if(this.props.projectType === 3){ //审计
  178. data.assets = this.state.assets; //资产
  179. data.audit = this.state.audit; //0无审计 1年审 2专审
  180. data.income = this.state.income; //收入
  181. }
  182. if(this.props.projectType === 1){ //专利
  183. data.patentType = this.props.patentNameType //专利名称
  184. }
  185. this.setState({
  186. loading: true,
  187. })
  188. $.ajax({
  189. url: globalConfig.context + api,
  190. method: 'post',
  191. dataType: 'json',
  192. crossDomain: false,
  193. data: data,
  194. }).done(
  195. function (data) {
  196. this.setState({
  197. loading: false,
  198. })
  199. if (!data.error.length) {
  200. message.success('保存成功!')
  201. this.setState({
  202. thirdCompanyName: '', //第三方名称
  203. thirdUnitPrice: 0, //单价
  204. thirdQuantity: 0, //数量
  205. currentTotalPrice: 0, //总价
  206. thirdRemarks: '',
  207. thirdUrgent: 0,
  208. })
  209. this.props.onCancel();
  210. } else {
  211. message.warning(data.error[0].message)
  212. }
  213. }.bind(this)
  214. )
  215. }
  216. render() {
  217. return(
  218. <Modal
  219. visible={this.props.visible}
  220. onCancel={this.props.onCancel}
  221. width={800}
  222. title={this.props.ThirdId ? "修改供应商" : "新增供应商"}
  223. footer=""
  224. className="admin-desc-content"
  225. >
  226. <Form
  227. layout="horizontal"
  228. style={{ paddingBottom: '40px' }}
  229. >
  230. <Spin spinning={this.state.loading}>
  231. <div className="clearfix">
  232. <div className="clearfix">
  233. {/*
  234. projectType 0正常 1专利 2软著 3审计
  235. patentType 0:专利申请/变更/转让 1:专利买卖
  236. */}
  237. <Form.Item
  238. {...formItemLayout}
  239. label="供应商名称"
  240. help={
  241. this.props.projectType === 2 ||
  242. (this.props.projectType === 1 &&
  243. this.props.patentType === 0) ? '输入供应商关键字,并选择系统后台已有供应商,如“长沙科明”' : ''
  244. }
  245. >
  246. <AutoComplete
  247. className="certain-category-search"
  248. dropdownClassName="certain-category-search-dropdown"
  249. dropdownMatchSelectWidth={false}
  250. dropdownStyle={{ width: 220 }}
  251. style={{ width: '220px' }}
  252. dataSource={(this.state.customerArr || []).map((group) => (
  253. <Select.Option key={group.id} value={group.companyName}>
  254. {group.companyName}
  255. </Select.Option>
  256. ))}
  257. placeholder="请输入供应商名称"
  258. value={this.state.thirdCompanyName}
  259. onChange={(e)=>{
  260. this.httpChange(e)
  261. }}
  262. filterOption={true}
  263. required="required"
  264. />
  265. <span className="mandatory">*</span>
  266. </Form.Item>
  267. </div>
  268. {/*projectType 0正常 1专利 2软著 3审计*/}
  269. {this.props.projectType !== 2 && !(this.props.projectType === 1 && this.props.patentType ===0) ?<div className="clearfix">
  270. <Form.Item {...formItemLayout} label="单价(万元)">
  271. <InputNumber
  272. value={this.state.thirdUnitPrice}
  273. placeholder="请输入单价(必填项)"
  274. required="required"
  275. precision={6}
  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 * this.state.thirdUnitPrice}</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={getMaterialStatus(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={0}>无审计</Option>
  424. <Option value={1}>年审</Option>
  425. <Option value={2}>专审</Option>
  426. </Select>
  427. <span className="mandatory">*</span>
  428. </Form.Item>
  429. </div>
  430. <div className="clearfix">
  431. <Form.Item {...formItemLayout} label="公司资产(万元)">
  432. <InputNumber
  433. value={this.state.assets}
  434. precision={6}
  435. placeholder="请输入公司资产"
  436. required="required"
  437. onChange={(value) => {
  438. this.setState({
  439. assets: value,
  440. })
  441. }}
  442. style={{ width: '220px' }}
  443. />
  444. <span className="mandatory">*</span>
  445. </Form.Item>
  446. </div>
  447. <div className="clearfix">
  448. <Form.Item {...formItemLayout} label="收入(万元)">
  449. <InputNumber
  450. value={this.state.income}
  451. precision={6}
  452. placeholder="请输入收入"
  453. required="required"
  454. onChange={(value) => {
  455. this.setState({
  456. income: value,
  457. })
  458. }}
  459. style={{ width: '220px' }}
  460. />
  461. <span className="mandatory">*</span>
  462. </Form.Item>
  463. </div>
  464. </div> : <div/>
  465. }
  466. <div className="clearfix">
  467. <Form.Item
  468. style={{ height: 'auto' }}
  469. labelCol={{ span: 4 }}
  470. wrapperCol={{ span: 18 }}
  471. label="备注"
  472. >
  473. <TextArea
  474. rows={4}
  475. placeholder="请输入备注"
  476. ref="signTotalAmount"
  477. style={{ width: '95%' }}
  478. value={this.state.thirdRemarks}
  479. onChange={(e) => {
  480. this.setState({
  481. thirdRemarks: e.target.value,
  482. })
  483. }}
  484. />
  485. </Form.Item>
  486. </div>
  487. <div className="clearfix">
  488. <div className="addSave" style={{ marginTop: '15px' }}>
  489. <Button
  490. className="cancel"
  491. type="primary"
  492. onClick={()=>{
  493. this.handleCancelq();
  494. }}
  495. style={{ marginLeft: '300px' }}
  496. htmlType="submit"
  497. >
  498. 保存
  499. </Button>
  500. <Button
  501. className="cancel"
  502. type="ghost"
  503. onClick={this.props.onCancel}
  504. style={{ marginLeft: '50px' }}
  505. >
  506. 取消
  507. </Button>
  508. </div>
  509. </div>
  510. </div>
  511. </Spin>
  512. </Form>
  513. </Modal>
  514. )
  515. }
  516. }
  517. export default NewSupplier;