enterprise.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. import React, { Component } from "react";
  2. import { View, Text, Icon } from "@tarojs/components";
  3. import { getUserByName, getOrderByUid } from "../../utils/servers/servers";
  4. import { AtSearchBar, AtPagination, AtListItem, AtIcon, AtButton } from "taro-ui";
  5. import "taro-ui/dist/style/components/search-bar.scss";
  6. import "taro-ui/dist/style/components/button.scss";
  7. import "taro-ui/dist/style/components/list.scss";
  8. import "taro-ui/dist/style/components/icon.scss";
  9. import "taro-ui/dist/style/components/pagination.scss";
  10. import "./index.less";
  11. import ListBottomStart from "../../components/common/listBottomStart";
  12. import Taro from "@tarojs/taro";
  13. class Enterprise extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. value: "",
  18. list: [],
  19. listState: "NO_DATA",
  20. selectId: 0,
  21. pageNo: 1,
  22. listVisible: false,
  23. listValue: {},
  24. orderNo: [],
  25. visibles: true,
  26. };
  27. this.onChange = this.onChange.bind(this);
  28. }
  29. onChange(value, lv = true) {
  30. this.setState({
  31. value,
  32. });
  33. if (value.length < 2 && !lv) {
  34. Taro.showToast({ title: "最少输入两个字符", icon: "none" });
  35. return;
  36. }
  37. if (value.length < 4 && lv) {
  38. return;
  39. }
  40. this.getList(value);
  41. }
  42. componentWillUnmount() {
  43. this.setState({
  44. value: "",
  45. list: [],
  46. listState: "NO_DATA",
  47. selectId: 0,
  48. pageNo: 1,
  49. totalCount: 0,
  50. });
  51. }
  52. getByUid(val) {
  53. this.setState({
  54. listState: "LOADING",
  55. });
  56. getOrderByUid({
  57. uid: val.id,
  58. }).then((msg) => {
  59. if (msg.error.length === 0) {
  60. let data = msg.data;
  61. this.setState({
  62. listState: "NO_MORE_DATA",
  63. orderNo: data,
  64. });
  65. } else {
  66. Taro.showToast({ title: msg.error[0].message, icon: "none" });
  67. this.setState({
  68. listState: msg.error[0].field === "403" ? "NO_DATA" : "RELOAD",
  69. });
  70. }
  71. });
  72. }
  73. getList(value = this.state.value, pageNo = 1) {
  74. Taro.showLoading({ title: "加载中..." });
  75. this.setState({
  76. listState: "LOADING",
  77. });
  78. getUserByName({
  79. name: value,
  80. pageNo: pageNo,
  81. pageSize: 10,
  82. })
  83. .then((msg) => {
  84. Taro.hideLoading();
  85. if (msg.error.length === 0) {
  86. if (msg.data.totalCount === 0) {
  87. this.setState({
  88. listState: "NO_DATA",
  89. });
  90. } else if (
  91. msg.data.totalCount === this.state.list.length &&
  92. pageNo !== 1
  93. ) {
  94. Taro.showToast({ title: "没有更多数据了", icon: "none" });
  95. this.setState({
  96. listState: "NO_MORE_DATA",
  97. });
  98. } else {
  99. if (
  100. msg.data.totalCount ===
  101. (pageNo === 1
  102. ? msg.data.list
  103. : this.state.list.concat(msg.data.list)
  104. ).length
  105. ) {
  106. this.setState({
  107. listState: "NO_MORE_DATA",
  108. });
  109. }
  110. }
  111. this.setState({
  112. list: msg.data.list,
  113. pageNo: msg.data.pageNo,
  114. totalCount: msg.data.totalCount,
  115. });
  116. } else {
  117. Taro.showToast({ title: msg.error[0].message, icon: "none" });
  118. this.setState({
  119. listState: msg.error[0].field === "403" ? "NO_DATA" : "RELOAD",
  120. });
  121. }
  122. })
  123. .catch(() => {
  124. Taro.hideLoading();
  125. this.setState({
  126. listState: "RELOAD",
  127. });
  128. });
  129. }
  130. render() {
  131. return (
  132. <>
  133. <AtSearchBar
  134. showActionButton
  135. value={this.state.value}
  136. placeholder="请输入公出企业名称"
  137. onChange={this.onChange}
  138. onActionClick={() => {
  139. this.onChange(this.state.value, false);
  140. }}
  141. onConfirm={() => {
  142. this.onChange(this.state.value, false);
  143. }}
  144. onClear={() => {
  145. this.setState(
  146. {
  147. value: "",
  148. list: [],
  149. orderNo: [],
  150. listValue: {},
  151. listVisible: false,
  152. listState: "NO_DATA",
  153. selectId: 0,
  154. pageNo: 1,
  155. totalCount: 0,
  156. },
  157. () => {
  158. this.props.onChange({}, 0);
  159. }
  160. );
  161. }}
  162. />
  163. {
  164. this.props.newList.length > 0 && this.props.type != 1 &&
  165. <View className="slist">
  166. <View style={{ fontSize: "30rpx" }}>本次公出列表</View>
  167. {
  168. this.props.newList.map((item, index) =>
  169. <View className="slitems" key={index}>
  170. <Text>{index + 1}、{item.name}</Text>
  171. <AtIcon value='close' size='18'
  172. onClick={() => {
  173. let list = this.props.newList
  174. for (var i = 0; i < list.length; i++) {
  175. if (list[i].id == item.id) {
  176. list.splice(i, 1)
  177. this.setState({
  178. newList: list
  179. })
  180. }
  181. }
  182. }}
  183. />
  184. </View>
  185. )
  186. }
  187. <View className="cltips">增加企业:搜索增加更多企业</View>
  188. <View className="cltips">删除企业:点击“X”删除公出列表</View>
  189. </View>
  190. }
  191. <View>
  192. {this.props.type == 0 || this.props.type == 2 ? (
  193. <View>
  194. {" "}
  195. {this.state.list.map((v, k) => (
  196. <View
  197. style={{
  198. padding: "10px",
  199. display: "flex",
  200. flexFlow: "row",
  201. alignItems: "center",
  202. justifyContent: "space-between",
  203. borderBottom: "1px #ece6e6 solid",
  204. }}
  205. key={k}
  206. onClick={() => {
  207. let list = this.props.newList
  208. for (var i = 0; i < list.length; i++) {
  209. if (list[i].id == v.id) {
  210. Taro.showToast({
  211. title: "该企业已在公出列表中",
  212. icon: 'none'
  213. })
  214. return
  215. }
  216. }
  217. list.push(v)
  218. this.setState({
  219. newList: list
  220. })
  221. // this.setState({
  222. // selectId: v.id,
  223. // });
  224. // this.getByUid(v)
  225. // this.props.onChange({ uid: v.id, nickname: v.name }, 0);
  226. }}
  227. >
  228. <View style={{ fontSize: "15px" }}>{v.name}</View>
  229. {this.state.selectId === v.id ? (
  230. <Icon size="20" type="success_no_circle" />
  231. ) : null}
  232. </View>
  233. ))}{" "}
  234. <ListBottomStart
  235. type="pagination"
  236. pageSize={10}
  237. state={this.state.listState}
  238. total={this.state.totalCount}
  239. current={this.state.pageNo}
  240. onPageChange={(type, current) => {
  241. this.getList(this.state.value, current);
  242. }}
  243. reload={() => {
  244. this.getList(this.state.value);
  245. }}
  246. />{" "}
  247. </View>
  248. ) : !this.state.listVisible ? (
  249. <View>
  250. {this.state.list.map((v, k) => (
  251. <View
  252. style={{
  253. padding: "10px",
  254. display: "flex",
  255. flexFlow: "row",
  256. alignItems: "center",
  257. justifyContent: "space-between",
  258. borderBottom: "1px #ece6e6 solid",
  259. }}
  260. key={k}
  261. onClick={() => {
  262. this.setState({
  263. // selectId:v.id
  264. listValue: v,
  265. listVisible: true,
  266. });
  267. this.getByUid(v);
  268. // this.props.onVisible()
  269. // this.props.onChange({uid:v.id,nickname:v.name});
  270. }}
  271. >
  272. <View style={{ fontSize: "15px" }}>{v.name}</View>
  273. {this.state.selectId === v.id ? (
  274. <Icon size="20" type="success_no_circle" />
  275. ) : null}
  276. </View>
  277. ))}{" "}
  278. <ListBottomStart
  279. type="pagination"
  280. pageSize={10}
  281. state={this.state.listState}
  282. total={this.state.totalCount}
  283. current={this.state.pageNo}
  284. onPageChange={(type, current) => {
  285. this.getList(this.state.value, current);
  286. }}
  287. reload={() => {
  288. this.getList(this.state.value);
  289. }}
  290. />{" "}
  291. </View>
  292. ) : (
  293. ""
  294. )}
  295. {this.state.listVisible && this.props.type == 1 ? (
  296. <View>
  297. <AtListItem
  298. title={this.state.listValue.name}
  299. arrow="right"
  300. iconInfo={{ size: 25, color: "#000000", value: "bookmark" }}
  301. />
  302. <View>
  303. {this.state.orderNo.length > 0 ? (
  304. <View>
  305. {" "}
  306. {this.state.orderNo.map((v, k) => (
  307. <View
  308. key={k}
  309. style={{
  310. display: "flex",
  311. justifyContent: " center",
  312. marginBottom: "20px",
  313. }}
  314. >
  315. 编号:<View>{v.contractNo}</View>
  316. <View
  317. style={{
  318. width: "60px",
  319. height: "24px",
  320. backgroundColor: "#5599FF",
  321. borderRadius: "15px",
  322. textAlign: "center",
  323. lineHeight: "24px",
  324. marginLeft: "20px",
  325. color: "white",
  326. }}
  327. circle
  328. onClick={() => {
  329. this.setState({
  330. listVisible: false,
  331. });
  332. v.id = this.state.listValue.id;
  333. v.name = this.state.listValue.name;
  334. this.props.onChange(
  335. {
  336. uids: v.id,
  337. userNames: v.name,
  338. orderNo: v.orderNo,
  339. contractNo: v.contractNo,
  340. },
  341. 1
  342. );
  343. // Taro.eventCenter.trigger('enterprise', v)
  344. }}
  345. >
  346. 选择
  347. </View>
  348. </View>
  349. ))}
  350. <View
  351. style={{ color: "red", width: "260px", margin: "0 auto" }}
  352. >
  353. 注:请选择正确的派单编号!公出信息将统计至对应的订单中。
  354. </View>
  355. </View>
  356. ) : (
  357. <View style={{ color: "red" }}>
  358. 该企业暂无订单,无法技术公出!请联系营销员查询派单情况
  359. </View>
  360. )}
  361. </View>
  362. </View>
  363. ) : (
  364. ""
  365. )}
  366. </View>
  367. </>
  368. );
  369. }
  370. }
  371. export default Enterprise;