enterprise.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. {this.props.type == 0 || this.props.type == 2
  350. ? this.state.list.map((v, k) => (
  351. <View key={k}>
  352. <AtListItem
  353. title={v.name}
  354. arrow="right"
  355. iconInfo={{ size: 25, color: "#000000", value: "bookmark" }}
  356. onClick={() => {
  357. this.checkUserArchives(v)
  358. // Taro.eventCenter.trigger("enterprise", v);
  359. }}
  360. />
  361. </View>
  362. ))
  363. : !this.state.listVisible
  364. ? this.state.list.map((v, k) => (
  365. <View key={k}>
  366. <AtListItem
  367. title={v.name}
  368. arrow="right"
  369. iconInfo={{ size: 25, color: "#000000", value: "bookmark" }}
  370. onClick={() => {
  371. let select = 0
  372. if (this.state.jsList.length == 0) {
  373. select = 0
  374. }
  375. for (var i = 0; i < this.state.jsList.length; i++) {
  376. if (!!this.state.jsList[i].contractNo) {
  377. select = 1
  378. }
  379. }
  380. if (select == 0) {
  381. this.setState({
  382. listVisible: true,
  383. listValue: v,
  384. });
  385. this.getByUid(v);
  386. } else {
  387. let list = this.state.jsList
  388. for (var i = 0; i < list.length; i++) {
  389. if (list[i].id == v.id) {
  390. Taro.showToast({
  391. title: "该企业已在公出列表中",
  392. icon: 'none'
  393. })
  394. return
  395. }
  396. }
  397. list.push(v)
  398. this.setState({
  399. jsList: list
  400. })
  401. }
  402. }}
  403. />
  404. </View>
  405. ))
  406. : ""}
  407. {this.state.listVisible && this.props.type == 1 ? (
  408. <View>
  409. <AtListItem
  410. title={this.state.listValue.name}
  411. arrow="right"
  412. iconInfo={{ size: 25, color: "#000000", value: "bookmark" }}
  413. />
  414. {
  415. this.state.listState == "NO_MORE_DATA" &&
  416. <View style={{ marginTop: "10px" }}>
  417. {this.state.orderNo.length > 0 ? (
  418. <View>
  419. {this.state.orderNo.map((v, k) => (
  420. <View
  421. key={k}
  422. style={{
  423. display: "flex",
  424. justifyContent: " center",
  425. marginBottom: "20px",
  426. }}
  427. >
  428. 编号:<View>{v.contractNo}</View>
  429. <View
  430. style={{
  431. width: "60px",
  432. height: "24px",
  433. backgroundColor: "#5599FF",
  434. borderRadius: "15px",
  435. textAlign: "center",
  436. lineHeight: "24px",
  437. marginLeft: "20px",
  438. color: "white",
  439. }}
  440. circle
  441. onClick={() => {
  442. this.setState({
  443. listVisible: false,
  444. });
  445. v.name = this.state.listValue.name;
  446. v.id = this.state.listValue.id;
  447. v.aname = this.state.listValue.aname;
  448. v.aid = this.state.listValue.aid;
  449. v.status = this.state.listValue.status;
  450. let list = this.state.jsList
  451. list.push(v)
  452. this.setState({
  453. jsList: list
  454. })
  455. // Taro.eventCenter.trigger("enterprise", v);
  456. }}
  457. >
  458. 选择
  459. </View>
  460. </View>
  461. ))}{" "}
  462. <View style={{ color: "red", width: "260px", margin: "0 auto" }}>
  463. 注:请选择正确的派单编号!公出信息将统计至对应的订单中。
  464. </View>
  465. </View>
  466. ) :
  467. <View style={{ color: "red", width: "260px", margin: "0 auto" }}>
  468. 该企业暂无订单,无法技术公出!请联系营销员查询派单情况
  469. </View>}
  470. </View>
  471. }
  472. </View>
  473. ) : (
  474. ""
  475. )}
  476. <ListBottomStart
  477. state={this.state.listState}
  478. reload={() => {
  479. this.onChange(this.state.value);
  480. }}
  481. />
  482. </View>
  483. </>
  484. );
  485. }
  486. }
  487. export default Enterprise;