newSupplier.js 24 KB

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