newSupplier.js 25 KB

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