newSupplier.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. $.ajax({
  159. url: globalConfig.context + api,
  160. method: 'post',
  161. dataType: 'json',
  162. crossDomain: false,
  163. data: data,
  164. }).done(
  165. function (data) {
  166. this.setState({
  167. loading: false,
  168. })
  169. if (!data.error.length) {
  170. message.success('保存成功!')
  171. this.setState({
  172. thirdCompanyName: '', //第三方名称
  173. thirdUnitPrice: '', //单价
  174. thirdQuantity: '', //数量
  175. currentTotalPrice: '', //总价
  176. thirdRemarks: '',
  177. thirdUrgent: 0,
  178. })
  179. this.props.onCancel();
  180. } else {
  181. message.warning(data.error[0].message)
  182. }
  183. }.bind(this)
  184. )
  185. }
  186. render() {
  187. return(
  188. <Modal
  189. visible={this.props.visible}
  190. onCancel={this.props.onCancel}
  191. width={800}
  192. title={this.props.ThirdId ? "修改供应商" : "新增供应商"}
  193. footer=""
  194. className="admin-desc-content"
  195. >
  196. <Form
  197. layout="horizontal"
  198. style={{ paddingBottom: '40px' }}
  199. >
  200. <Spin spinning={this.state.loading}>
  201. <div className="clearfix">
  202. <div className="clearfix">
  203. <Form.Item {...formItemLayout} label="供应商名称">
  204. <AutoComplete
  205. className="certain-category-search"
  206. dropdownClassName="certain-category-search-dropdown"
  207. dropdownMatchSelectWidth={false}
  208. dropdownStyle={{ width: 220 }}
  209. style={{ width: '220px' }}
  210. dataSource={(this.state.customerArr || []).map((group) => (
  211. <Select.Option key={group.id} value={group.companyName}>
  212. {group.companyName}
  213. </Select.Option>
  214. ))}
  215. placeholder="请输入供应商名称"
  216. value={this.state.thirdCompanyName}
  217. onChange={(e)=>{
  218. this.httpChange(e)
  219. }}
  220. filterOption={true}
  221. required="required"
  222. />
  223. <span className="mandatory">*</span>
  224. </Form.Item>
  225. </div>
  226. {this.props.projectType !== 2 ?<div className="clearfix">
  227. <Form.Item {...formItemLayout} label="单价(万元)">
  228. <Input
  229. value={this.state.thirdUnitPrice}
  230. placeholder="请输入金额(必填项)"
  231. required="required"
  232. type={'number'}
  233. onBlur={this.calculatedAmount}
  234. onChange={(e) => {
  235. this.setState({
  236. thirdUnitPrice: e.target.value,
  237. })
  238. }}
  239. style={{ width: '220px' }}
  240. />
  241. <span className="mandatory">*</span>
  242. </Form.Item>
  243. </div> : <div/>}
  244. <div className="clearfix">
  245. <Form.Item {...formItemLayout} label="数量">
  246. <Input
  247. value={this.state.thirdQuantity}
  248. placeholder="请输入数量(必填项)"
  249. required="required"
  250. onBlur={this.calculatedAmount}
  251. type={'number'}
  252. onChange={(e) => {
  253. this.setState({
  254. thirdQuantity: e.target.value,
  255. })
  256. }}
  257. style={{ width: '220px' }}
  258. />
  259. <span className="mandatory">*</span>
  260. </Form.Item>
  261. </div>
  262. {this.props.projectType !== 2 ?<div className="clearfix">
  263. <Form.Item {...formItemLayout} label="总价(万元)">
  264. <span>{this.state.thirdQuantity * this.state.thirdUnitPrice}</span>
  265. </Form.Item>
  266. </div> : <div/>}
  267. {this.props.projectType === 2 ? <div>
  268. <div className="clearfix">
  269. <Form.Item {...formItemLayout} label="材料">
  270. <Select
  271. value={getMaterialStatus(this.state.thirdMaterial)}
  272. onChange={(val) => {
  273. this.setState({
  274. thirdMaterial: val,
  275. })
  276. this.props.otherOperations && this.props.otherOperations({
  277. thirdMaterial: val,
  278. thirdUrgent: this.state.thirdUrgent,
  279. customerArr: this.state.customerArr,
  280. thirdCompanyName: this.state.thirdCompanyName,
  281. });
  282. }}
  283. style={{ width: '220px' }}
  284. defaultValue="0"
  285. >
  286. <Option value="1">有材料</Option>
  287. <Option value="0">无材料</Option>
  288. </Select>
  289. <span className="mandatory">*</span>
  290. </Form.Item>
  291. </div>
  292. <div className="clearfix">
  293. <Form.Item {...formItemLayout} label="加急">
  294. <Select
  295. value={getUrgentStatus(this.state.thirdUrgent)}
  296. onChange={(val) => {
  297. this.setState({
  298. thirdUrgent: val,
  299. })
  300. this.props.otherOperations && this.props.otherOperations({
  301. thirdMaterial: this.state.thirdMaterial,
  302. thirdUrgent: val,
  303. customerArr: this.state.customerArr,
  304. thirdCompanyName: this.state.thirdCompanyName
  305. });
  306. }}
  307. style={{ width: '220px' }}
  308. defaultValue="0"
  309. >
  310. <Option value="0">无加急</Option>
  311. <Option value="1">加急3天</Option>
  312. <Option value="2">加急4天</Option>
  313. <Option value="3">加急5-10天</Option>
  314. <Option value="4">加急11-15天</Option>
  315. <Option value="5">加急16-20天</Option>
  316. <Option value="6">加急21-25天</Option>
  317. <Option value="7">加急26-30天</Option>
  318. </Select>
  319. <span className="mandatory">*</span>
  320. </Form.Item>
  321. </div>
  322. </div>:<div/>}
  323. {/*{*/}
  324. {/* this.props.patentType === 0 ? <div>*/}
  325. {/* <div className="clearfix">*/}
  326. {/* <Form.Item*/}
  327. {/* {...formItemLayout}*/}
  328. {/* label="官费:"*/}
  329. {/* >*/}
  330. {/* <span style={{ color: "red", marginRight: "27px" }}>*/}
  331. {/* **/}
  332. {/* </span>*/}
  333. {/* <Radio.Group*/}
  334. {/* value={this.state.officialCost}*/}
  335. {/* onChange={(e) => {*/}
  336. {/* this.setState({ officialCost: e.target.value });*/}
  337. {/* }}*/}
  338. {/* >*/}
  339. {/* <Radio value={1}>含官费</Radio>*/}
  340. {/* <Radio value={0}>不含官费</Radio>*/}
  341. {/* </Radio.Group>*/}
  342. {/* </Form.Item>*/}
  343. {/* </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.costReduction}*/}
  354. {/* onChange={(e) => {*/}
  355. {/* this.setState({ costReduction: 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> : <div/>*/}
  364. {/*}*/}
  365. <div className="clearfix">
  366. <Form.Item
  367. style={{ height: 'auto' }}
  368. labelCol={{ span: 4 }}
  369. wrapperCol={{ span: 18 }}
  370. label="备注"
  371. >
  372. <TextArea
  373. rows={4}
  374. placeholder="请输入备注"
  375. ref="signTotalAmount"
  376. style={{ width: '95%' }}
  377. value={this.state.thirdRemarks}
  378. onChange={(e) => {
  379. this.setState({
  380. thirdRemarks: e.target.value,
  381. })
  382. }}
  383. />
  384. </Form.Item>
  385. </div>
  386. <div className="clearfix">
  387. <div className="addSave" style={{ marginTop: '15px' }}>
  388. <Button
  389. className="cancel"
  390. type="primary"
  391. onClick={()=>{
  392. this.handleCancelq();
  393. }}
  394. style={{ marginLeft: '300px' }}
  395. htmlType="submit"
  396. >
  397. 保存
  398. </Button>
  399. <Button
  400. className="cancel"
  401. type="ghost"
  402. onClick={this.props.onCancel}
  403. style={{ marginLeft: '50px' }}
  404. >
  405. 取消
  406. </Button>
  407. </div>
  408. </div>
  409. </div>
  410. </Spin>
  411. </Form>
  412. </Modal>
  413. )
  414. }
  415. }
  416. export default NewSupplier;