newSupplier.js 25 KB

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