newSupplier.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. import React,{Component} from 'react';
  2. import {AutoComplete, Button, Form, Input, message, Modal, 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. customerArr: [],
  25. loading: false,
  26. }
  27. }
  28. componentDidMount() {
  29. if(this.props.ThirdId){
  30. this.supervisor(this.state.thirdCompanyName)
  31. }
  32. }
  33. //服务值改变时请求供应商名称
  34. httpChange(e) {
  35. if (e.length >= 1) {
  36. this.supervisor(e)
  37. }
  38. this.props.otherOperations && this.props.otherOperations({
  39. thirdMaterial: this.state.thirdMaterial,
  40. thirdUrgent: this.state.thirdUrgent,
  41. customerArr: this.state.customerArr,
  42. thirdCompanyName: e,
  43. });
  44. this.setState({
  45. thirdCompanyName: e,
  46. })
  47. }
  48. //加载(自动补全)
  49. supervisor(e) {
  50. $.ajax({
  51. method: 'get',
  52. dataType: 'json',
  53. crossDomain: false,
  54. url: globalConfig.context + '/api/admin/company/selectVague',
  55. data: {
  56. name: e,
  57. type: this.props.projectType === 2 ? 0 : 1
  58. },
  59. success: function (data) {
  60. let thedata = data.data
  61. if (!thedata) {
  62. if (data.error && data.error.length) {
  63. message.warning(data.error[0].message)
  64. }
  65. thedata = {}
  66. }
  67. this.setState({
  68. customerArr: thedata,
  69. })
  70. this.props.otherOperations && this.props.otherOperations({
  71. thirdMaterial: this.state.thirdMaterial,
  72. thirdUrgent: this.state.thirdUrgent,
  73. customerArr: thedata,
  74. thirdCompanyName: this.state.thirdCompanyName,
  75. });
  76. }.bind(this),
  77. }).always(
  78. function () {
  79. this.setState({
  80. loading: false,
  81. })
  82. }.bind(this)
  83. )
  84. }
  85. // 第三方信息自动计算总金额
  86. calculatedAmount() {
  87. let currentTotalPrice
  88. currentTotalPrice = this.state.thirdUnitPrice * this.state.thirdQuantity
  89. currentTotalPrice = currentTotalPrice.toFixed(4)
  90. this.setState({
  91. currentTotalPrice: currentTotalPrice,
  92. })
  93. }
  94. // 保存供应商信息
  95. handleCancelq() {
  96. let api
  97. if (this.props.ThirdId) {
  98. //修改
  99. api = '/api/admin/company/updateCompany'
  100. } else {
  101. //新增
  102. api = '/api/admin/company/addCompany'
  103. }
  104. let customerId = 0;
  105. let isHave =this.state.customerArr.some((value)=>{
  106. if(value.companyName === this.state.thirdCompanyName){
  107. customerId = value.id
  108. return true;
  109. }
  110. });
  111. //软著 必须要使用查询出来第三方名称和对应id
  112. if(!isHave && this.props.projectType === 2){ //projectType 0正常 1专利 2软著
  113. message.warning('请输入正确的供应商名称')
  114. return;
  115. }
  116. this.setState({
  117. loading: true,
  118. })
  119. // material: this.state.thirdMaterial, //材料
  120. // urgent: this.state.thirdUrgent, //加急
  121. // unitPrice: this.state.thirdUnitPrice, //单价
  122. let data = {
  123. id: this.props.ThirdId, //id
  124. tid: this.props.tid, //订单编号
  125. companyName: this.state.thirdCompanyName, //第三方名称
  126. quantity: this.state.thirdQuantity, //数量
  127. remarks: this.state.thirdRemarks, //备注
  128. unitPrice: this.state.thirdUnitPrice, //单价
  129. }
  130. if(isHave){
  131. data.cid = customerId //公司id 只有软著类要传cid,其他类型都是非必填的
  132. }
  133. if(this.props.projectType === 2){
  134. data.material = this.state.thirdMaterial //材料
  135. data.urgent = this.state.thirdUrgent //加急
  136. data.calculation = 1; //0 其他 1软著
  137. }else{ //非软著类需要传总金额
  138. data.totalAmount = this.state.thirdQuantity * this.state.thirdUnitPrice;
  139. }
  140. $.ajax({
  141. url: globalConfig.context + api,
  142. method: 'post',
  143. dataType: 'json',
  144. crossDomain: false,
  145. data: data,
  146. }).done(
  147. function (data) {
  148. this.setState({
  149. loading: false,
  150. })
  151. if (!data.error.length) {
  152. message.success('保存成功!')
  153. this.setState({
  154. thirdCompanyName: '', //第三方名称
  155. thirdUnitPrice: '', //单价
  156. thirdQuantity: '', //数量
  157. currentTotalPrice: '', //总价
  158. thirdRemarks: '',
  159. thirdUrgent: 0,
  160. })
  161. this.props.onCancel();
  162. } else {
  163. message.warning(data.error[0].message)
  164. }
  165. }.bind(this)
  166. )
  167. }
  168. render() {
  169. return(
  170. <Modal
  171. visible={this.props.visible}
  172. onCancel={this.props.onCancel}
  173. width={800}
  174. title={this.props.ThirdId ? "修改供应商" : "新增供应商"}
  175. footer=""
  176. className="admin-desc-content"
  177. >
  178. <Form
  179. layout="horizontal"
  180. style={{ paddingBottom: '40px' }}
  181. >
  182. <Spin spinning={this.state.loading}>
  183. <div className="clearfix">
  184. <div className="clearfix">
  185. <Form.Item {...formItemLayout} label="供应商名称">
  186. <AutoComplete
  187. className="certain-category-search"
  188. dropdownClassName="certain-category-search-dropdown"
  189. dropdownMatchSelectWidth={false}
  190. dropdownStyle={{ width: 220 }}
  191. style={{ width: '220px' }}
  192. dataSource={(this.state.customerArr || []).map((group) => (
  193. <Select.Option key={group.id} value={group.companyName}>
  194. {group.companyName}
  195. </Select.Option>
  196. ))}
  197. placeholder="请输入供应商名称"
  198. value={this.state.thirdCompanyName}
  199. onChange={(e)=>{
  200. this.httpChange(e)
  201. }}
  202. filterOption={true}
  203. required="required"
  204. />
  205. <span className="mandatory">*</span>
  206. </Form.Item>
  207. </div>
  208. {this.props.projectType !== 2 ?<div className="clearfix">
  209. <Form.Item {...formItemLayout} label="单价(万元)">
  210. <Input
  211. value={this.state.thirdUnitPrice}
  212. placeholder="请输入金额(必填项)"
  213. required="required"
  214. type={'number'}
  215. onBlur={this.calculatedAmount}
  216. onChange={(e) => {
  217. this.setState({
  218. thirdUnitPrice: e.target.value,
  219. })
  220. }}
  221. style={{ width: '220px' }}
  222. />
  223. <span className="mandatory">*</span>
  224. </Form.Item>
  225. </div> : <div/>}
  226. <div className="clearfix">
  227. <Form.Item {...formItemLayout} label="数量">
  228. <Input
  229. value={this.state.thirdQuantity}
  230. placeholder="请输入数量(必填项)"
  231. required="required"
  232. onBlur={this.calculatedAmount}
  233. type={'number'}
  234. onChange={(e) => {
  235. this.setState({
  236. thirdQuantity: e.target.value,
  237. })
  238. }}
  239. style={{ width: '220px' }}
  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. <span>{this.state.thirdQuantity * this.state.thirdUnitPrice}</span>
  247. </Form.Item>
  248. </div> : <div/>}
  249. {this.props.projectType === 2 ? <div>
  250. <div className="clearfix">
  251. <Form.Item {...formItemLayout} label="材料">
  252. <Select
  253. value={getMaterialStatus(this.state.thirdMaterial)}
  254. onChange={(val) => {
  255. this.setState({
  256. thirdMaterial: val,
  257. })
  258. this.props.otherOperations && this.props.otherOperations({
  259. thirdMaterial: val,
  260. thirdUrgent: this.state.thirdUrgent,
  261. customerArr: this.state.customerArr,
  262. thirdCompanyName: this.state.thirdCompanyName,
  263. });
  264. }}
  265. style={{ width: '220px' }}
  266. defaultValue="0"
  267. >
  268. <Option value="1">有材料</Option>
  269. <Option value="0">无材料</Option>
  270. </Select>
  271. <span className="mandatory">*</span>
  272. </Form.Item>
  273. </div>
  274. <div className="clearfix">
  275. <Form.Item {...formItemLayout} label="加急">
  276. <Select
  277. value={getUrgentStatus(this.state.thirdUrgent)}
  278. onChange={(val) => {
  279. this.setState({
  280. thirdUrgent: val,
  281. })
  282. this.props.otherOperations && this.props.otherOperations({
  283. thirdMaterial: this.state.thirdMaterial,
  284. thirdUrgent: val,
  285. customerArr: this.state.customerArr,
  286. thirdCompanyName: this.state.thirdCompanyName
  287. });
  288. }}
  289. style={{ width: '220px' }}
  290. defaultValue="0"
  291. >
  292. <Option value="0">无加急</Option>
  293. <Option value="1">加急3天</Option>
  294. <Option value="2">加急4天</Option>
  295. <Option value="3">加急5-10天</Option>
  296. <Option value="4">加急11-15天</Option>
  297. <Option value="5">加急16-20天</Option>
  298. <Option value="6">加急21-25天</Option>
  299. <Option value="7">加急26-30天</Option>
  300. </Select>
  301. <span className="mandatory">*</span>
  302. </Form.Item>
  303. </div>
  304. </div>:<div/>}
  305. <div className="clearfix">
  306. <Form.Item
  307. style={{ height: 'auto' }}
  308. labelCol={{ span: 4 }}
  309. wrapperCol={{ span: 18 }}
  310. label="备注"
  311. >
  312. <TextArea
  313. rows={4}
  314. placeholder="请输入备注"
  315. ref="signTotalAmount"
  316. style={{ width: '95%' }}
  317. value={this.state.thirdRemarks}
  318. onChange={(e) => {
  319. this.setState({
  320. thirdRemarks: e.target.value,
  321. })
  322. }}
  323. />
  324. </Form.Item>
  325. </div>
  326. <div className="clearfix">
  327. <div className="addSave" style={{ marginTop: '15px' }}>
  328. <Button
  329. className="cancel"
  330. type="primary"
  331. onClick={()=>{
  332. this.handleCancelq();
  333. }}
  334. style={{ marginLeft: '300px' }}
  335. htmlType="submit"
  336. >
  337. 保存
  338. </Button>
  339. <Button
  340. className="cancel"
  341. type="ghost"
  342. onClick={this.props.onCancel}
  343. style={{ marginLeft: '50px' }}
  344. >
  345. 取消
  346. </Button>
  347. </div>
  348. </div>
  349. </div>
  350. </Spin>
  351. </Form>
  352. </Modal>
  353. )
  354. }
  355. }
  356. export default NewSupplier;