modify.jsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import React, { Component } from "react";
  2. import {
  3. AtCalendar,
  4. AtModal,
  5. AtModalAction,
  6. AtModalContent,
  7. AtButton,
  8. isPublicity,
  9. } from "taro-ui";
  10. import { Button, View } from "@tarojs/components";
  11. import Enterprise from "./enterprise";
  12. import PublicContent from "./publicContent";
  13. import { getNewList } from "../../utils/tools";
  14. import {
  15. getRestrictProjectUser
  16. } from "../../utils/servers/servers";
  17. import "taro-ui/dist/style/components/modal.scss";
  18. import Taro from "@tarojs/taro";
  19. class Modify extends Component {
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. data: {},
  24. dtails: props.dtails,
  25. userList: props.userList,
  26. modifyType: 2,
  27. // colors: "primary",
  28. // color: "secondary",
  29. type: 0,
  30. visibles: true,
  31. // newList: getNewList(props.dtails.uids, props.dtails.userNames),
  32. newList: [],
  33. jsList: [],
  34. };
  35. this.submit = this.submit.bind(this);
  36. this.onChange = this.onChange.bind(this);
  37. this.onVisible = this.onVisible.bind(this);
  38. this.onListChange = this.onListChange.bind(this);
  39. this.getValue = this.getValue.bind(this);
  40. }
  41. getValue(arr, key) {
  42. return arr.map(obj => { return obj[key]; }).join(",")
  43. }
  44. getRestrictProjectUser() {
  45. getRestrictProjectUser({
  46. ids: this.getValue(this.state.newList, "id"),
  47. })
  48. .then((v) => {
  49. if (v.error.length === 0) {
  50. this.setState({
  51. userList: v.data
  52. })
  53. } else {
  54. Taro.showToast({
  55. title: v.error[0].message,
  56. icon: "none",
  57. });
  58. }
  59. })
  60. .catch((err) => {
  61. });
  62. }
  63. submit() {
  64. // if (this.state.type == 1) {
  65. // Taro.showToast({ title: "技术公出请直接点击公出企业", icon: "none" });
  66. // return;
  67. // } else if (this.state.length == 0) {
  68. // Taro.showToast({ title: "请先选择公出的企业", icon: "none" });
  69. // return;
  70. // }
  71. // if (Object.keys(this.state.data).length === 0) {
  72. // Taro.showToast({ title: "请先选择公出的企业", icon: "none" });
  73. // return;
  74. // } else if (this.state.type == 1) {
  75. // Taro.showToast({ title: "技术公出请直接点击公出企业", icon: "none" });
  76. // return;
  77. // }
  78. let obj = {}
  79. if (this.state.type != 1) {
  80. if (this.state.newList.length == 0) {
  81. Taro.showToast({
  82. title: "请先选择公出企业",
  83. icon: 'none'
  84. })
  85. return
  86. }
  87. this.getRestrictProjectUser()
  88. obj = {
  89. uids: this.getValue(this.state.newList, "id"),
  90. userNames: this.getValue(this.state.newList, "name"),
  91. type: this.state.type,
  92. newList: this.state.newList
  93. }
  94. } else {
  95. let contractNo = ""
  96. let orderNo = ""
  97. for (var i = 0; i < this.state.jsList.length; i++) {
  98. if (!!this.state.jsList[i].contractNo) {
  99. contractNo = this.state.jsList[i].contractNo
  100. orderNo = this.state.jsList[i].orderNo
  101. }
  102. }
  103. if (this.state.jsList.length == 0) {
  104. Taro.showToast({
  105. title: "必须选择一个派单编号",
  106. icon: 'none'
  107. })
  108. return
  109. }
  110. obj = {
  111. uids: this.getValue(this.state.jsList, "id"),
  112. userNames: this.getValue(this.state.jsList, "name"),
  113. type: this.state.type,
  114. contractNo,
  115. orderNo,
  116. newList: this.state.newList
  117. }
  118. }
  119. this.setState({
  120. dtails: {
  121. ...this.state.dtails,
  122. ...obj,
  123. },
  124. data: obj,
  125. })
  126. this.setState({
  127. modifyType: 2,
  128. });
  129. }
  130. onVisible() {
  131. this.setState({
  132. visibles: false,
  133. });
  134. }
  135. componentWillUnmount() {
  136. this.setState({
  137. data: {},
  138. });
  139. }
  140. onListChange(list) {
  141. this.setState({
  142. newList: list
  143. })
  144. }
  145. onChange(value, visi) {
  146. value.type = this.state.type;
  147. this.setState({
  148. dtails: {
  149. ...this.state.dtails,
  150. ...value,
  151. },
  152. data: value,
  153. modifyType: 2,
  154. });
  155. // if (visi == 0) {
  156. // this.setState({
  157. // dtails: {
  158. // ...this.state.dtails,
  159. // ...value,
  160. // },
  161. // data: value,
  162. // });
  163. // } else {
  164. // value.type = this.state.type;
  165. // this.setState({
  166. // dtails: {
  167. // ...this.state.dtails,
  168. // ...value,
  169. // },
  170. // data: value,
  171. // modifyType: 2,
  172. // });
  173. // }
  174. }
  175. render() {
  176. let userInfor = Taro.getStorageSync('userInfor');
  177. return (
  178. <AtModal isOpened={this.props.isOpened} onClose={this.props.onModalClose}>
  179. {this.state.modifyType === 1 ? (
  180. <View
  181. style={{ display: "flex", margin: "10px 0 0 0", padding: "0 5px" }}
  182. >
  183. {[
  184. { type: 0, title: "业务公出" },
  185. { type: 1, title: "技术公出" },
  186. { type: 2, title: "行政公出" },
  187. ].map((item) => (
  188. <View style={{ margin: "0 5px" }} key={item.type}>
  189. <AtButton
  190. circle
  191. size="small"
  192. disabled={item.type === 1 && userInfor.type !== 3}
  193. type={this.state.type == item.type ? "primary" : "secondary"}
  194. onClick={() => {
  195. this.setState({
  196. type: item.type,
  197. });
  198. item.type != 1 &&
  199. this.setState({
  200. visibles: true,
  201. });
  202. }}
  203. >
  204. {item.title}
  205. </AtButton>
  206. </View>
  207. ))}
  208. <View style={{ flex: "1" }}></View>
  209. </View>
  210. ) : (
  211. ""
  212. )}
  213. <AtModalContent>
  214. {this.state.modifyType === 1 ? (
  215. <Enterprise
  216. type={this.state.type}
  217. isOpened={this.props.isOpened}
  218. isVerify={this.props.isVerify} //判断是否在审核中修改
  219. onChange={this.onChange}
  220. newList={this.state.newList}
  221. jsList={this.state.jsList}
  222. onListChange={this.onListChange}
  223. />
  224. ) : (
  225. <PublicContent
  226. permission={this.props.permission}
  227. index={this.props.index}
  228. type={this.state.type}
  229. onClose={() => {
  230. this.props.onClose();
  231. }}
  232. locationInfor={this.props.locationInfor}
  233. dtails={this.state.dtails}
  234. userList={this.state.userList}
  235. isOpened={this.props.isOpened}
  236. isVerify={this.props.isVerify}
  237. reason={this.props.reason}//修改原因
  238. onChange={this.onChange}
  239. onBack={() => {
  240. this.setState({
  241. modifyType: 1,
  242. });
  243. }}
  244. />
  245. )}
  246. </AtModalContent>
  247. {this.state.modifyType === 1 ? (
  248. <AtModalAction>
  249. <Button
  250. onClick={() => {
  251. this.props.onClose();
  252. }}
  253. >
  254. 取消
  255. </Button>
  256. <Button onClick={this.submit}>下一步</Button>
  257. </AtModalAction>
  258. ) : null}
  259. </AtModal>
  260. );
  261. }
  262. }
  263. export default Modify;