enterprise.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. import React, { Component } from "react";
  2. import { View, Text, Icon } from "@tarojs/components";
  3. import {
  4. getUserByName,
  5. getOrderByUid,
  6. getRestrictProjectUser,
  7. checkUserArchives,
  8. } from "../../utils/servers/servers";
  9. import { AtSearchBar, AtListItem, AtButton, AtIcon } from "taro-ui";
  10. import "taro-ui/dist/style/components/search-bar.scss";
  11. import "taro-ui/dist/style/components/button.scss";
  12. import "taro-ui/dist/style/components/icon.scss";
  13. import "taro-ui/dist/style/components/list.scss";
  14. import "taro-ui/dist/style/components/icon.scss";
  15. import ListBottomStart from "../../components/common/listBottomStart";
  16. import "./enterprise.less";
  17. import Taro from "@tarojs/taro";
  18. class Enterprise extends Component {
  19. constructor(props) {
  20. super(props);
  21. this.state = {
  22. value: "",
  23. list: [],
  24. listState: "NO_DATA",
  25. pageNo: 1,
  26. listVisible: false,
  27. listValue: {},
  28. orderNo: [],
  29. newList: [],
  30. jsList: [],
  31. userList: [],
  32. };
  33. this.onChange = this.onChange.bind(this);
  34. this.getList = this.getList.bind(this);
  35. }
  36. componentDidMount() {
  37. Taro.eventCenter.on("result", () => {
  38. this.setState({
  39. value: "",
  40. list: [],
  41. newList: [],
  42. listState: "NO_DATA",
  43. pageNo: 1,
  44. });
  45. });
  46. Taro.eventCenter.on("applyDepartSearchList", () => {
  47. this.getList(this.state.value, this.state.pageNo + 1);
  48. });
  49. }
  50. componentDidUpdate(props) {
  51. if (props.type !== this.props.type) {
  52. this.setState({
  53. newList: []
  54. })
  55. }
  56. }
  57. getRestrictProjectUser() {
  58. getRestrictProjectUser({
  59. ids: this.state.newList.map(obj => { return obj.id; }).join(","),
  60. })
  61. .then((v) => {
  62. if (v.error.length === 0) {
  63. Taro.eventCenter.trigger("enterprise",
  64. {
  65. id: this.state.newList.map(obj => { return obj.id; }).join(","),
  66. name: this.state.newList.map(obj => { return obj.name; }).join(","),
  67. list: this.state.newList,
  68. userList: v.data,
  69. }
  70. );
  71. } else {
  72. Taro.showToast({
  73. title: v.error[0].message,
  74. icon: "none",
  75. });
  76. }
  77. })
  78. .catch((err) => {
  79. });
  80. }
  81. onChange(value, lv = true) {
  82. this.setState({
  83. value,
  84. });
  85. if (value.length < 2 && !lv) {
  86. Taro.showToast({ title: "最少输入两个字符", icon: "none" });
  87. return;
  88. }
  89. if (value.length < 4 && lv) {
  90. return;
  91. }
  92. this.getList(value);
  93. }
  94. getByUid(val) {
  95. this.setState({
  96. listState: "LOADING",
  97. });
  98. getOrderByUid({
  99. uid: val.id,
  100. }).then((msg) => {
  101. if (msg.error.length === 0) {
  102. let data = msg.data;
  103. this.setState({
  104. listState: "NO_MORE_DATA",
  105. orderNo: data,
  106. });
  107. } else {
  108. Taro.showToast({ title: msg.error[0].message, icon: "none" });
  109. this.setState({
  110. listState: msg.error[0].field === "403" ? "NO_DATA" : "RELOAD",
  111. });
  112. }
  113. });
  114. }
  115. getList(value = this.state.value, pageNo = 1) {
  116. this.setState({
  117. listState: "LOADING",
  118. });
  119. getUserByName({
  120. name: value,
  121. type: 1,
  122. pageNo: pageNo,
  123. pageSize: 10,
  124. })
  125. .then((msg) => {
  126. if (msg.error.length === 0) {
  127. if (msg.data.totalCount === 0) {
  128. this.setState({
  129. listState: "NO_DATA",
  130. });
  131. } else if (
  132. msg.data.totalCount === this.state.list.length &&
  133. pageNo !== 1
  134. ) {
  135. Taro.showToast({ title: "没有更多数据了", icon: "none" });
  136. this.setState({
  137. listState: "NO_MORE_DATA",
  138. });
  139. } else {
  140. if (
  141. msg.data.totalCount ===
  142. (pageNo === 1
  143. ? msg.data.list
  144. : this.state.list.concat(msg.data.list)
  145. ).length
  146. ) {
  147. this.setState({
  148. listState: "NO_MORE_DATA",
  149. });
  150. }
  151. }
  152. this.setState({
  153. list:
  154. pageNo === 1
  155. ? msg.data.list
  156. : this.state.list.concat(msg.data.list),
  157. pageNo: msg.data.pageNo,
  158. });
  159. } else {
  160. Taro.showToast({ title: msg.error[0].message, icon: "none" });
  161. this.setState({
  162. listState: msg.error[0].field === "403" ? "NO_DATA" : "RELOAD",
  163. });
  164. }
  165. })
  166. .catch(() => {
  167. this.setState({
  168. listState: "RELOAD",
  169. });
  170. });
  171. }
  172. checkUserArchives(v) {
  173. if (v.status == 2 && this.props.type == 0) {
  174. Taro.showToast({
  175. title: "请在“单位公共客户”中领取后,再次发起公出!",
  176. icon: 'none'
  177. })
  178. return
  179. }
  180. let list = this.state.newList
  181. for (var i = 0; i < list.length; i++) {
  182. if (list[i].id == v.id) {
  183. Taro.showToast({
  184. title: "该企业已在公出列表中",
  185. icon: 'none'
  186. })
  187. return
  188. }
  189. }
  190. if (this.props.type == 1 || this.props.type == 2) {
  191. list.push(v)
  192. this.setState({
  193. newList: list
  194. })
  195. return
  196. }
  197. checkUserArchives({
  198. uid: v.id
  199. })
  200. .then((msg) => {
  201. if (msg.error.length === 0) {
  202. // if (msg.data) {
  203. list.push(v)
  204. this.setState({
  205. newList: list
  206. })
  207. // } else {
  208. // Taro.showToast({
  209. // title: "请先完善客户档案,才可发起公出",
  210. // icon: 'none'
  211. // })
  212. // }
  213. } else {
  214. Taro.showToast({
  215. title: msg.error[0].message,
  216. icon: "none",
  217. });
  218. }
  219. })
  220. .catch(() => {
  221. this.setState({
  222. listState: "RELOAD",
  223. });
  224. });
  225. }
  226. render() {
  227. return (
  228. <>
  229. <AtSearchBar
  230. placeholder="请输入企业/渠道"
  231. showActionButton
  232. value={this.state.value}
  233. onChange={this.onChange}
  234. onActionClick={() => {
  235. this.setState({
  236. listVisible: false,
  237. });
  238. this.onChange(this.state.value, false);
  239. }}
  240. onConfirm={() => {
  241. this.onChange(this.state.value, false);
  242. }}
  243. onClear={() => {
  244. this.setState({
  245. value: "",
  246. list: [],
  247. listState: "NO_DATA",
  248. pageNo: 1,
  249. listVisible: false,
  250. });
  251. }}
  252. />
  253. {/* 业务行政公出 */}
  254. {
  255. this.state.newList.length > 0 && this.props.type != 1 &&
  256. <View className="slist">
  257. <View style={{ fontSize: "30rpx" }}>本次公出列表</View>
  258. {
  259. this.state.newList.map((item, index) =>
  260. <View className="slitems" key={index}>
  261. <Text>{index + 1}、{item.name}</Text>
  262. <AtIcon value='close' size='18'
  263. onClick={() => {
  264. let list = this.state.newList
  265. for (var i = 0; i < list.length; i++) {
  266. if (list[i].id == item.id) {
  267. list.splice(i, 1)
  268. this.setState({
  269. newList: list
  270. })
  271. }
  272. }
  273. }}
  274. />
  275. </View>
  276. )
  277. }
  278. <View className="slbt">
  279. <AtButton size="small" type='primary'
  280. onClick={() => {
  281. this.getRestrictProjectUser()
  282. }}
  283. >确定公出列表</AtButton>
  284. </View>
  285. <View className="cltips">增加企业:搜索增加更多企业,删除企业:点击“X”删除公出列表</View>
  286. </View>
  287. }
  288. {/* 技术公出 */}
  289. {
  290. this.state.jsList.length > 0 && this.props.type == 1 &&
  291. <View className="slist">
  292. <View style={{ fontSize: "30rpx" }}>本次公出列表</View>
  293. {
  294. this.state.jsList.map((item, index) =>
  295. <View className="slitems" key={index}>
  296. <Text>{index + 1}、{item.name}{!!item.contractNo && `(${item.contractNo})`}</Text>
  297. <AtIcon value='close' size='18'
  298. onClick={() => {
  299. let list = this.state.jsList
  300. for (var i = 0; i < list.length; i++) {
  301. if (list[i].id == item.id) {
  302. list.splice(i, 1)
  303. this.setState({
  304. jsList: list
  305. })
  306. }
  307. }
  308. }}
  309. />
  310. </View>
  311. )
  312. }
  313. <View className="slbt">
  314. <AtButton size="small" type='primary'
  315. onClick={() => {
  316. let contractNo = ""
  317. let orderNo = ""
  318. let select = 0
  319. for (var i = 0; i < this.state.jsList.length; i++) {
  320. if (!!this.state.jsList[i].contractNo) {
  321. contractNo = this.state.jsList[i].contractNo
  322. orderNo = this.state.jsList[i].orderNo
  323. select = 1
  324. }
  325. }
  326. if (select == 0) {
  327. Taro.showToast({
  328. title: "必须选择一个派单编号",
  329. icon: 'none'
  330. })
  331. return
  332. }
  333. Taro.eventCenter.trigger("enterprise",
  334. {
  335. id: this.state.jsList.map(obj => { return obj.id; }).join(","),
  336. name: this.state.jsList.map(obj => { return obj.name; }).join(","),
  337. list: this.state.jsList,
  338. contractNo,
  339. orderNo,
  340. }
  341. );
  342. }}
  343. >确定公出列表</AtButton>
  344. </View>
  345. <View className="cltips">增加企业:搜索增加更多企业,删除企业:点击“X”删除公出列表</View>
  346. </View>
  347. }
  348. <View>
  349. {[0, 2, 5].indexOf(this.props.type) > -1 ? this.state.list.map((v, k) => (
  350. <View key={k}>
  351. <AtListItem
  352. title={v.name}
  353. arrow="right"
  354. iconInfo={{ size: 25, color: "#000000", value: "bookmark" }}
  355. onClick={() => {
  356. this.checkUserArchives(v)
  357. // Taro.eventCenter.trigger("enterprise", v);
  358. }}
  359. />
  360. </View>
  361. ))
  362. : !this.state.listVisible
  363. ? this.state.list.map((v, k) => (
  364. <View key={k}>
  365. <AtListItem
  366. title={v.name}
  367. arrow="right"
  368. iconInfo={{ size: 25, color: "#000000", value: "bookmark" }}
  369. onClick={() => {
  370. let select = 0
  371. if (this.state.jsList.length == 0) {
  372. select = 0
  373. }
  374. for (var i = 0; i < this.state.jsList.length; i++) {
  375. if (!!this.state.jsList[i].contractNo) {
  376. select = 1
  377. }
  378. }
  379. if (select == 0) {
  380. this.setState({
  381. listVisible: true,
  382. listValue: v,
  383. });
  384. this.getByUid(v);
  385. } else {
  386. let list = this.state.jsList
  387. for (var i = 0; i < list.length; i++) {
  388. if (list[i].id == v.id) {
  389. Taro.showToast({
  390. title: "该企业已在公出列表中",
  391. icon: 'none'
  392. })
  393. return
  394. }
  395. }
  396. list.push(v)
  397. this.setState({
  398. jsList: list
  399. })
  400. }
  401. }}
  402. />
  403. </View>
  404. ))
  405. : ""}
  406. {this.state.listVisible && this.props.type == 1 ? (
  407. <View>
  408. <AtListItem
  409. title={this.state.listValue.name}
  410. arrow="right"
  411. iconInfo={{ size: 25, color: "#000000", value: "bookmark" }}
  412. />
  413. {
  414. this.state.listState == "NO_MORE_DATA" &&
  415. <View style={{ marginTop: "10px" }}>
  416. {this.state.orderNo.length > 0 ? (
  417. <View>
  418. {this.state.orderNo.map((v, k) => (
  419. <View
  420. key={k}
  421. style={{
  422. display: "flex",
  423. justifyContent: " center",
  424. marginBottom: "20px",
  425. }}
  426. >
  427. 编号:<View>{v.contractNo}</View>
  428. <View
  429. style={{
  430. width: "60px",
  431. height: "24px",
  432. backgroundColor: "#5599FF",
  433. borderRadius: "15px",
  434. textAlign: "center",
  435. lineHeight: "24px",
  436. marginLeft: "20px",
  437. color: "white",
  438. }}
  439. circle
  440. onClick={() => {
  441. this.setState({
  442. listVisible: false,
  443. });
  444. v.name = this.state.listValue.name;
  445. v.id = this.state.listValue.id;
  446. v.aname = this.state.listValue.aname;
  447. v.aid = this.state.listValue.aid;
  448. v.status = this.state.listValue.status;
  449. let list = this.state.jsList
  450. list.push(v)
  451. this.setState({
  452. jsList: list
  453. })
  454. // Taro.eventCenter.trigger("enterprise", v);
  455. }}
  456. >
  457. 选择
  458. </View>
  459. </View>
  460. ))}{" "}
  461. <View style={{ color: "red", width: "260px", margin: "0 auto" }}>
  462. 注:请选择正确的派单编号!公出信息将统计至对应的订单中。
  463. </View>
  464. </View>
  465. ) :
  466. <View style={{ color: "red", width: "260px", margin: "0 auto" }}>
  467. 该企业暂无订单,无法技术公出!请联系营销员查询派单情况
  468. </View>}
  469. </View>
  470. }
  471. </View>
  472. ) : (
  473. ""
  474. )}
  475. <ListBottomStart
  476. state={this.state.listState}
  477. reload={() => {
  478. this.onChange(this.state.value);
  479. }}
  480. />
  481. </View>
  482. </>
  483. );
  484. }
  485. }
  486. export default Enterprise;