index.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import React, { Component } from "react";
  2. import { View, Button, Text } from "@tarojs/components";
  3. import { AtModal, AtModalContent, AtSearchBar, AtList, AtListItem } from "taro-ui";
  4. import { getadminByName } from "../../../utils/servers/servers";
  5. import { isOneself } from "../../../utils/tools"
  6. import './index.less';
  7. import "taro-ui/dist/style/components/modal.scss";
  8. import Taro from "@tarojs/taro";
  9. class UserQuery extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. value: "",
  14. list: [],
  15. listState: "NO_DATA",
  16. pageNo: 1,
  17. listVisible: false,
  18. listValue: {},
  19. };
  20. this.onChange = this.onChange.bind(this);
  21. }
  22. onChange(value, lv = true) {
  23. this.setState({
  24. value,
  25. });
  26. if (value.length < 2 && !lv) {
  27. Taro.showToast({ title: "最少输入两个字符", icon: "none" });
  28. return;
  29. }
  30. if (value.length < 4 && lv) {
  31. return;
  32. }
  33. this.getList(value);
  34. }
  35. getList(value = this.state.value, pageNo = 1) {
  36. this.setState({
  37. listState: "LOADING",
  38. });
  39. getadminByName({
  40. adminName: value,
  41. pageNo: pageNo,
  42. pageSize: 10,
  43. })
  44. .then((msg) => {
  45. if (msg.error.length === 0) {
  46. this.setState({
  47. list: msg.data
  48. })
  49. } else {
  50. Taro.showToast({ title: msg.error[0].message, icon: "none" });
  51. this.setState({
  52. listState: msg.error[0].field === "403" ? "NO_DATA" : "RELOAD",
  53. });
  54. }
  55. })
  56. .catch(() => {
  57. this.setState({
  58. listState: "RELOAD",
  59. });
  60. });
  61. }
  62. render() {
  63. const { coorderList, cList } = this.props
  64. return (
  65. <AtModal
  66. isOpened={this.props.isOpened}
  67. onClose={this.props.onDesc}
  68. >
  69. <AtModalContent>
  70. <AtSearchBar
  71. placeholder="请输入协单人姓名"
  72. showActionButton
  73. value={this.state.value}
  74. onChange={this.onChange}
  75. onActionClick={() => {
  76. this.onChange(this.state.value, false);
  77. }}
  78. onConfirm={() => {
  79. this.onChange(this.state.value, false);
  80. }}
  81. onClear={() => {
  82. this.setState({
  83. value: "",
  84. list: [],
  85. listState: "NO_DATA",
  86. pageNo: 1,
  87. listVisible: false,
  88. });
  89. }}
  90. />
  91. <AtList>
  92. {
  93. this.state.list.map(v =>
  94. <View key={v.id}>
  95. <AtListItem
  96. title={v.name}
  97. onClick={() => {
  98. if (coorderList.includes(v.id)) {
  99. Taro.showToast({ title: "你已经邀请过Ta了~", icon: "none" });
  100. return
  101. } else if (isOneself(v.id)) {
  102. Taro.showToast({ title: "你不能邀请自己哦~", icon: "none" });
  103. return
  104. } else {
  105. coorderList.push(v.id);
  106. cList.push(v);
  107. this.props.setList(cList, coorderList);
  108. this.props.onDesc();
  109. }
  110. }}
  111. />
  112. </View>
  113. )
  114. }
  115. </AtList>
  116. <View
  117. style={{ color: "red", margin: "20px auto 0", textAlign: "center" }}
  118. onClick={this.props.onDesc}
  119. >点击关闭弹窗</View>
  120. </AtModalContent>
  121. </AtModal>
  122. );
  123. }
  124. }
  125. export default UserQuery;