select.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import React, { Component } from "react";
  2. import Taro from "@tarojs/taro";
  3. import { View, Button, } from '@tarojs/components'
  4. import { AtRadio, AtInput, AtModal, AtModalHeader, AtModalContent, AtModalAction } from "taro-ui";
  5. import { accountList } from '../../utils/tools/config';
  6. import { creatOrder } from '../../utils/servers/servers';
  7. import './index.less';
  8. import "taro-ui/dist/style/components/icon.scss";
  9. import "taro-ui/dist/style/components/button.scss";
  10. import "taro-ui/dist/style/components/radio.scss";
  11. class Select extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. type: -1,
  16. other: "",
  17. };
  18. }
  19. componentDidMount() {
  20. const { type, other } = this.props
  21. this.setState({
  22. type,
  23. other
  24. })
  25. }
  26. handleChange(e) {
  27. this.setState({
  28. type: e
  29. })
  30. }
  31. onInputChange(e) {
  32. this.setState({
  33. other: e
  34. })
  35. }
  36. creatOrder() {
  37. const { prid, onClose } = this.props
  38. const { type, other, } = this.state
  39. creatOrder({
  40. prid,
  41. type,
  42. typeOther: other,
  43. }).then(v => {
  44. if (v.error.length === 0) {
  45. onClose()
  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 { visible = "", onClose, noPost = false, onOk } = this.props
  61. const { type, other } = this.state
  62. return (
  63. <AtModal
  64. isOpened={visible != ""}
  65. closeOnClickOverlay={false}
  66. >
  67. <AtModalHeader>请选择报销类型</AtModalHeader>
  68. <AtModalContent>
  69. <View className="rlist">
  70. <AtRadio
  71. options={accountList}
  72. value={type}
  73. onClick={this.handleChange.bind(this)}
  74. />
  75. {type == 0 &&
  76. <AtInput
  77. name='other'
  78. type='text'
  79. placeholder='请填写明细'
  80. value={other}
  81. onChange={this.onInputChange.bind(this)}
  82. />}
  83. </View>
  84. </AtModalContent>
  85. <AtModalAction>
  86. <Button onClick={onClose}>取消</Button>
  87. <Button onClick={() => {
  88. if (type == -1) {
  89. Taro.showToast({
  90. title: '请选择报销费用类型',
  91. icon: 'none'
  92. })
  93. } else if (type == 0 && !other) {
  94. Taro.showToast({
  95. title: '请填写其他明细',
  96. icon: 'none'
  97. })
  98. } else {
  99. noPost
  100. ? this.creatOrder()
  101. : onOk(type, other)
  102. }
  103. }}>确定</Button>
  104. </AtModalAction>
  105. </AtModal>
  106. )
  107. }
  108. }
  109. export default Select;