index.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import React, { Component } from "react";
  2. import Taro, { getCurrentInstance } from "@tarojs/taro";
  3. import { connect } from "react-redux";
  4. import { View, Text, } from "@tarojs/components";
  5. import { AtInput, AtButton, AtRadio } from "taro-ui";
  6. import "taro-ui/dist/style/components/button.scss";
  7. import "taro-ui/dist/style/components/radio.scss";
  8. import "taro-ui/dist/style/components/input.scss";
  9. import "taro-ui/dist/style/components/icon.scss";
  10. import { creatOrder } from '../../utils/servers/servers';
  11. import { accountList } from '../../utils/tools/config';
  12. import "./index.less";
  13. class applyReimbursement extends Component {
  14. $instance = getCurrentInstance();
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. type: -1,
  19. other: "",
  20. };
  21. }
  22. handleChange(e) {
  23. this.setState({
  24. type: e
  25. })
  26. }
  27. onInputChange(e) {
  28. this.setState({
  29. other: e
  30. })
  31. }
  32. componentDidShow() {
  33. }
  34. componentDidMount() {
  35. }
  36. // 不需要prid绑定,直接发起
  37. creatOrder() {
  38. const { type, other, } = this.state
  39. Taro.showLoading({ title: '处理中...' });
  40. creatOrder({
  41. type,
  42. typeOther: other,
  43. }).then(v => {
  44. Taro.hideLoading()
  45. if (v.error.length === 0) {
  46. Taro.redirectTo({
  47. url: '/pages/drafts/index?id=' + v.data
  48. })
  49. } else {
  50. Taro.showToast({ title: v.error[0].message, icon: 'none' })
  51. }
  52. }).catch(() => {
  53. Taro.showToast({
  54. title: '系统错误,请稍后再试',
  55. icon: 'none'
  56. })
  57. })
  58. }
  59. render() {
  60. const { type, other } = this.state
  61. return (
  62. <View className="reimbursement">
  63. <View>
  64. <View className="rtit">请选择报销费用类型</View>
  65. <View className="rlist">
  66. <AtRadio
  67. options={accountList}
  68. value={type}
  69. onClick={this.handleChange.bind(this)}
  70. />
  71. {type == 0 &&
  72. <AtInput
  73. name='other'
  74. type='text'
  75. placeholder='请填写明细'
  76. value={other}
  77. onChange={this.onInputChange.bind(this)}
  78. />}
  79. <View className="rlbuttom">
  80. <AtButton
  81. type="primary"
  82. circle
  83. onClick={() => {
  84. if (type == -1) {
  85. Taro.showToast({
  86. title: '请选择报销费用类型',
  87. icon: 'none'
  88. })
  89. } else if (type == 0 && !other) {
  90. Taro.showToast({
  91. title: '请填写其他明细',
  92. icon: 'none'
  93. })
  94. } else {
  95. this.creatOrder()
  96. }
  97. }}
  98. >
  99. 确定
  100. </AtButton>
  101. </View>
  102. </View>
  103. </View>
  104. </View>
  105. );
  106. }
  107. }
  108. export default applyReimbursement;