operationPayNode.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. import React,{Component} from 'react';
  2. import {Button, DatePicker, Form, Input, message, Modal, Select, Spin, InputNumber} from "antd";
  3. import { cuiJieDian } from '@/dataDic.js'
  4. import PropTypes from 'prop-types';
  5. import $ from "jquery";
  6. import moment from "moment";
  7. const formItemLayout = {
  8. labelCol: { span: 8 },
  9. wrapperCol: { span: 14 },
  10. }
  11. class OperationPayNode extends Component{
  12. constructor(props) {
  13. super(props);
  14. this.state={
  15. loading: false,
  16. thirdCompanyName: props.payNodeInfor.companyName, //供应商名称
  17. paySubject: [],
  18. paySubjectName: props.payNodeInfor.dunType, //可简化
  19. thirdUnitPrice: props.thirdUnitPrice, //单价
  20. }
  21. this.savePayNode = this.savePayNode.bind(this);
  22. this.payNodeCalculatedAmount = this.payNodeCalculatedAmount.bind(this);
  23. }
  24. componentDidMount() {
  25. this.getCsortData()
  26. }
  27. //保存付款节点
  28. savePayNode(e) {
  29. e.preventDefault();
  30. this.props.form.validateFields((err, values) => {
  31. if (err) {
  32. return;
  33. }
  34. let api
  35. if (this.props.thirdId) {
  36. //修改
  37. api = '/api/admin/company/updatePaymentNode'
  38. } else {
  39. //新增
  40. api = '/api/admin/company/addPaymentNode'
  41. }
  42. let customerId=0;
  43. this.props.supplierList.some((value)=>{
  44. if(value.companyName === values.companyName){
  45. customerId = value.id
  46. return true;
  47. }
  48. });
  49. if(!values.companyName){
  50. message.error('请选择供应商名称');
  51. return;
  52. }
  53. if(!values.dunType){
  54. message.error('请选择付款科目');
  55. return;
  56. }
  57. if(!values.quantity){
  58. message.error('请输入数量');
  59. return;
  60. }
  61. let data = {
  62. id: this.props.thirdId, //id
  63. tid: this.props.tid, //订单编号
  64. cid: customerId,//对应的第三方信息
  65. companyName: values.companyName.split('-')[0], //第三方名称
  66. quantity: values.quantity, //数量
  67. dunType: values.dunType, //催款节点
  68. projectType: this.props.cSort, //项目分类
  69. }
  70. if(values.dunType === '0'){
  71. if(!values.partyTimes.format('YYYY-MM-DD HH:mm:ss')){
  72. message.error('请选择付款时间');
  73. return;
  74. }
  75. data.partyTimes = values.partyTimes.format('YYYY-MM-DD') //付款时间
  76. }
  77. if(this.props.projectType !== 2){ //其他类型 0正常 1专利 2软著 3审计
  78. data.totalAmount = values.totalAmount //总价
  79. data.unitPrice = this.state.thirdUnitPrice //单价
  80. }
  81. this.setState({
  82. loading: true,
  83. })
  84. $.ajax({
  85. url: globalConfig.context + api,
  86. method: 'post',
  87. dataType: 'json',
  88. crossDomain: false,
  89. data: data,
  90. }).done(
  91. function (data) {
  92. this.setState({
  93. loading: false,
  94. })
  95. if (!data.error.length) {
  96. message.success('保存成功!');
  97. this.props.onCancel();
  98. } else {
  99. message.warning(data.error[0].message)
  100. }
  101. }.bind(this)
  102. )
  103. })
  104. }
  105. // 付款节点自动计算总金额
  106. payNodeCalculatedAmount(num) {
  107. let currentTotalPrice,quantity,unitPrice;
  108. //获取当前供应商名称对应的单价并更新
  109. this.props.thirdInfoList.forEach((item) => {
  110. if (item.companyName === this.state.thirdCompanyName) {
  111. currentTotalPrice = num ? item.unitPrice * num : item.quantity * item.unitPrice;
  112. currentTotalPrice = currentTotalPrice.toFixed(6);
  113. quantity = num ? num : item.quantity;
  114. unitPrice = item.unitPrice;
  115. }
  116. })
  117. this.props.form.setFieldsValue({
  118. quantity :num ? num : quantity
  119. })
  120. if(this.props.projectType !== 2){
  121. this.props.form.setFieldsValue({
  122. totalAmount: parseFloat(currentTotalPrice)
  123. })
  124. this.setState({
  125. thirdUnitPrice: unitPrice
  126. })
  127. }
  128. }
  129. // 获取csort下的数据
  130. getCsortData() {
  131. cuiJieDian.map((item) => {
  132. if (item.value == this.props.cSort) {
  133. this.setState({
  134. paySubject: item.children,
  135. })
  136. }
  137. })
  138. }
  139. render() {
  140. const { getFieldDecorator } = this.props.form;
  141. const { payNodeInfor } = this.props;
  142. return (
  143. <Modal
  144. maskClosable={false}
  145. visible={this.props.visible}
  146. onCancel={this.props.onCancel}
  147. width={800}
  148. title={this.props.thirdId ? "修改付款节点" : "新增付款节点"}
  149. footer=""
  150. className="admin-desc-content"
  151. >
  152. <Form
  153. layout="horizontal"
  154. onSubmit={this.savePayNode}
  155. style={{ paddingBottom: '40px' }}
  156. >
  157. <Spin spinning={this.state.loading}>
  158. <div className="clearfix">
  159. <div className="clearfix">
  160. <Form.Item {...formItemLayout} label="供应商名称">
  161. {getFieldDecorator('companyName', {
  162. initialValue: payNodeInfor.companyName,
  163. rules: [{ required: true, message: '请选择供应商' }],
  164. })(
  165. <Select
  166. onChange={(val) => {
  167. this.setState(
  168. {
  169. thirdCompanyName: val,
  170. },
  171. () => this.payNodeCalculatedAmount()
  172. ) //更新完state调用
  173. }}
  174. defaultValue="请选择供应商"
  175. style={{ width: 220 }}
  176. >
  177. {this.props.supplierList.map((item, index) => (
  178. <Select.Option value={item.companyName} key={index}>
  179. {item.companyName}
  180. </Select.Option>
  181. ))}
  182. </Select>
  183. )}
  184. </Form.Item>
  185. </div>
  186. <div className="clearfix">
  187. <Form.Item {...formItemLayout} label="付款科目">
  188. {getFieldDecorator('dunType', {
  189. initialValue: payNodeInfor.dunType,
  190. rules: [{ required: true, message: '请选择付款科目' }],
  191. })(
  192. <Select
  193. onChange={(val) => {
  194. this.setState({
  195. paySubjectName: val,
  196. dunType: val,
  197. })
  198. }}
  199. defaultValue="请选择付款科目"
  200. style={{ width: 220 }}
  201. >
  202. {this.state.paySubject.map((item, index) => (
  203. <Select.Option value={item.value} key={index}>
  204. {item.key}
  205. </Select.Option>
  206. ))}
  207. <Select.Option key={0} value={'0'}>
  208. 自定义
  209. </Select.Option>
  210. </Select>)}
  211. </Form.Item>
  212. </div>
  213. <div className="clearfix">
  214. {this.state.paySubjectName === '0'? <Form.Item {...formItemLayout} label="付款时间">
  215. {getFieldDecorator('partyTimes', {
  216. initialValue: payNodeInfor.partyTimes ? moment(payNodeInfor.partyTimes) : moment(),
  217. rules: [{ required: true, message: '请选择付款时间' }],
  218. })(
  219. <DatePicker showTime format="YYYY-MM-DD" style={{ width: '220px' }}/>
  220. )}
  221. </Form.Item> : <div/>}
  222. </div>
  223. <div className="clearfix">
  224. <Form.Item {...formItemLayout} label="数量">
  225. {getFieldDecorator('quantity', {
  226. initialValue: payNodeInfor.quantity,
  227. rules: [{ required: true, message: '请输入数量' }],
  228. })(
  229. <InputNumber
  230. min={1}
  231. precision={0}
  232. // disabled={payNodeInfor.quantity <= 1}
  233. placeholder="请输入数量"
  234. onChange={(e) => {
  235. this.payNodeCalculatedAmount(e)
  236. }}
  237. style={{ width: '220px' }}
  238. />
  239. )}
  240. </Form.Item>
  241. </div>
  242. {this.props.projectType !== 2 ? <div className="clearfix">
  243. <Form.Item {...formItemLayout} label="总价(万元)">
  244. {getFieldDecorator('totalAmount', {
  245. initialValue: isNaN(parseFloat(payNodeInfor.totalAmount)) ? payNodeInfor.totalAmount : parseFloat(payNodeInfor.totalAmount),
  246. rules: [{ required: true, message: '请输入总价' }],
  247. })(
  248. <Input
  249. type={'number'}
  250. placeholder="请输入总价"
  251. style={{ width: '220px' }}
  252. />
  253. )}
  254. </Form.Item>
  255. </div> : <div/>}
  256. <div className="clearfix">
  257. <div className="addSave" style={{ marginTop: '15px' }}>
  258. <Button
  259. className="cancel"
  260. type="primary"
  261. style={{ marginLeft: '300px' }}
  262. htmlType="submit"
  263. >
  264. 保存
  265. </Button>
  266. <Button
  267. className="cancel"
  268. type="ghost"
  269. onClick={this.props.onCancel}
  270. style={{ marginLeft: '50px' }}
  271. >
  272. 取消
  273. </Button>
  274. </div>
  275. </div>
  276. </div>
  277. </Spin>
  278. </Form>
  279. </Modal>
  280. )
  281. }
  282. }
  283. OperationPayNode.propTypes = {
  284. visible : PropTypes.bool.isRequired, //控制组件是否显示
  285. onCancel : PropTypes.func.isRequired, //取消方法
  286. thirdId : PropTypes.number.isRequired, //供应商ID
  287. thirdInfoList: PropTypes.array.isRequired, //第三方信息列表
  288. supplierList: PropTypes.array.isRequired, //第三方信息列表已存在的供应商名字和id信息 用于添加付款节点时的选择对应供应商
  289. payNodeInfor: PropTypes.object.isRequired, //选择的支付节点信息(来自支付节点列表)
  290. projectType: PropTypes.number.isRequired, //项目类型 0正常 1专利 2软著 3审计
  291. tid: PropTypes.number.isRequired, //订单编号
  292. cSort: PropTypes.number.isRequired, //项目分类
  293. thirdUnitPrice: PropTypes.number.isRequired //所选信息单价
  294. }
  295. OperationPayNode.defaultProps = {
  296. visible : false,
  297. onCancel: ()=>{},
  298. thirdInfoList: [],
  299. supplierList: [],
  300. payNodeInfor: {},
  301. }
  302. const WrappedNormalLoginForm = Form.create()(OperationPayNode);
  303. export default WrappedNormalLoginForm;