addPeoplePlan.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. import React from 'react';
  2. import { BirdGrid } from 'components/Grid';
  3. import { BirdForm } from 'components/Form';
  4. import { config, request, util } from 'utils'
  5. const { WXAPIV5 } = config;
  6. import { connect } from "dva";
  7. import { Modal, Row, Col, Button, Icon, Upload, Model, message, Input } from 'antd';
  8. class addPeoplePlan extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. fileList: [], // 上传的文件
  13. file: null,// 上传的文件
  14. fileUrl: null,// 上传的文件路径
  15. addVisible: false,// 创建按钮弹窗
  16. userVisible: false,// 选择客服弹窗
  17. selectUserName: "",// 选择客服的名字
  18. selectUserId: null// 选择客服的ID
  19. }
  20. }
  21. // 选择客服显示
  22. showUserVisible = () => {
  23. this.setState({
  24. userVisible: true
  25. })
  26. }
  27. // 选择客服关闭
  28. closeUserVisible = () => {
  29. this.setState({
  30. userVisible: false
  31. })
  32. }
  33. // 选择客服
  34. selectUser = (data) => {
  35. let userName = data.name;
  36. let userId = data.id;
  37. this.setState({
  38. selectUserName: userName,
  39. selectUserId: userId,
  40. userVisible: false
  41. })
  42. }
  43. // 创建任务显示
  44. showAddVisible = () => {
  45. this.setState({
  46. addVisible: true
  47. })
  48. }
  49. // 创建任务关闭
  50. closeAddVisible = () => {
  51. this.setState({
  52. addVisible: false
  53. })
  54. }
  55. // 创建任务
  56. createPlanClick = () => {
  57. console.log(this.refs.addForm);
  58. let fieldArr = this.refs.addForm.props.fields;
  59. let falg = this.dataVerify(fieldArr)
  60. if(!falg){
  61. return;
  62. }
  63. let json = {
  64. planName: fieldArr[0].value,
  65. planCentent: fieldArr[1].value,
  66. planPeopleCount: fieldArr[3].value,
  67. userId: this.state.selectUserId,
  68. planFileUrl: this.state.fileUrl
  69. }
  70. request({
  71. url: WXAPIV5 + "/plan/" + this.props.corpid + "/create",
  72. method: "post",
  73. data: json,
  74. }).then(result => {
  75. console.log(result);
  76. if(result.success==1){
  77. message.success(result.message);
  78. }else {
  79. message.error(result.message);
  80. }
  81. this.setState({
  82. selectUserName: "",
  83. selectUserId: null,
  84. file: null,
  85. fileList: [],
  86. fileUrl: null,
  87. addVisible: false
  88. })
  89. this.refs.addForm.setState({
  90. initValue: {}
  91. })
  92. this.refs.grid.reload();
  93. })
  94. }
  95. // 创建任务数据校验
  96. dataVerify = (fieldArr) => {
  97. let planName = fieldArr[0].value;
  98. let planCentent = fieldArr[1].value;
  99. let planPeopleCount = fieldArr[3].value;
  100. let userId = this.state.selectUserId;
  101. let fileUrl = this.state.fileUrl;
  102. if(planName==null || planName===""){
  103. message.warn("请填写任务名称!")
  104. return false;
  105. }
  106. if(planCentent==null || planCentent===""){
  107. message.warn("请填写任务内容!")
  108. return false;
  109. }
  110. if(planPeopleCount==null || planPeopleCount==0){
  111. message.warn("请填写任务添加人数!")
  112. return false;
  113. }
  114. if(userId==null){
  115. message.warn("请选择客服!")
  116. return false;
  117. }
  118. if(fileUrl==null){
  119. message.warn("请上传Excel文件!")
  120. return false;
  121. }
  122. return true;
  123. }
  124. // 截断文件
  125. truncateFile = (file) => {
  126. let fileArr = this.state.fileList;
  127. if (fileArr.length > 0) {
  128. message.warn("只能上传一个文件!");
  129. this.setState({
  130. fileList: fileArr
  131. })
  132. return false;
  133. }
  134. fileArr.push(file);
  135. this.setState({
  136. fileList: fileArr,
  137. file: file
  138. });
  139. return true;
  140. }
  141. // 移除文件
  142. removeFile = (file) => {
  143. this.setState(state => {
  144. const index = state.fileList.indexOf(file);
  145. const newFileList = state.fileList.slice();
  146. newFileList.splice(index, 1);
  147. return {
  148. fileList: newFileList,
  149. fileUrl: null,
  150. file: null
  151. };
  152. });
  153. }
  154. // 文件变化
  155. fileChange = (e) => {
  156. // console.log(e);
  157. if (e.file != null && e.file.response != null) {
  158. this.setState({
  159. fileUrl: e.file.response
  160. })
  161. }
  162. }
  163. render() {
  164. var { corpid } = this.props;
  165. let token = util.auth.getToken();
  166. let self = this;
  167. // 任务列表
  168. let gridOption = {
  169. title: "应用管理",
  170. url: {
  171. read: WXAPIV5 + "/plan/" + corpid + "/query",
  172. // add: WXAPIV5 + "/plan/"+corpid+"/create",
  173. },
  174. actions: [],// 新增
  175. columns: [
  176. { title: "任务ID", data: "planId", type: "text", hide: true },
  177. { title: "企业微信cropid", data: "cropid", type: "text", hide: true },
  178. { title: "任务名称", data: "planName", type: "text", query: true },
  179. { title: "任务内容", data: "planCentent", type: "text" },
  180. { title: "所属客服", data: "userName", type: "text" },
  181. { title: "所属客服ID", data: "userId", type: "text", hide: true },
  182. { title: "任务添加人数", data: "planPeopleCount", type: "number" },
  183. { title: "任务添加时间", data: "dateFormat", type: "text" },
  184. { title: "任务添加时间", data: "planCreateTime", type: "datetime", hide: true },
  185. { title: "状态", data: "state", type: "text" },
  186. { title: "状态", data: "planState", type: "text", hide: true },
  187. { title: "文件路径", data: "planFileUrl", type: "text", hide: true},
  188. {
  189. title: "操作选项", type: "command",
  190. actions: []
  191. }
  192. ],
  193. actions: [
  194. {
  195. name: "创建任务",
  196. onClick: () => self.showAddVisible()
  197. }
  198. ]
  199. };
  200. let uploadProps = {
  201. accept: '.xls,.xlsx',
  202. beforeUpload: (file, fileList) => self.truncateFile(file, fileList),
  203. onRemove: (file) => self.removeFile(file),
  204. fileList: self.state.fileList,
  205. action: WXAPIV5 + "/plan/" + corpid + "/upload",
  206. onChange: (e) => self.fileChange(e),
  207. headers: {
  208. "Sso-Token": token
  209. }
  210. }
  211. // 添加任务表单
  212. let addFields = [
  213. {
  214. name: "任务名称",
  215. key: "planName",
  216. fieldType: "text",
  217. isRequired: true,
  218. },
  219. {
  220. name: "任务内容",
  221. key: "planCentent",
  222. fieldType: "text",
  223. isRequired: true,
  224. },
  225. {
  226. name: "选择客服",
  227. fieldType: "command",
  228. isRequired: true,
  229. render: () => {
  230. return (
  231. <Row>
  232. <Col span={17}>
  233. <Input ref="userInput" value={self.state.selectUserName}/>
  234. </Col>
  235. <Col span={6} offset={1}>
  236. <Button onClick={$ => self.showUserVisible()}>添加</Button>
  237. </Col>
  238. </Row>
  239. )
  240. }
  241. },
  242. {
  243. name: "添加人数",
  244. key: "planPeopleCount",
  245. fieldType: "number",
  246. defaultValue: 0,
  247. isRequired: true,
  248. },
  249. {
  250. name: "上传Excel文件",
  251. fieldType: "command",
  252. isRequired: true,
  253. render: () => {
  254. return (
  255. <Upload {...uploadProps}>
  256. <Button><Icon type="upload" />选择文件</Button>
  257. </Upload>
  258. )
  259. }
  260. }
  261. ];
  262. // 选择客服列表
  263. let selectUserGrid = {
  264. title: "客服列表",
  265. url: {
  266. read: WXAPIV5 + "/users/" + corpid + "/getUsersList"
  267. },
  268. actions: [
  269. ],
  270. columns: [
  271. { title: "客服名称", data: "name", type: "text", query: true },
  272. { title: "所属部门", data: "departmentName", type: "text", hide: true },
  273. { title: "手机", data: "mobile", type: "text", query: true },
  274. {
  275. title: "选择客服", type: "command",
  276. actions: [
  277. {
  278. name: "选择客服",
  279. onClick: (data) => self.selectUser(data),
  280. }
  281. ]
  282. }
  283. ]
  284. }
  285. return (
  286. <div>
  287. <BirdGrid gridOption={gridOption} ref="grid"></BirdGrid>
  288. {/* 创建任务弹窗 */}
  289. <Modal title="创建任务"
  290. visible={self.state.addVisible}
  291. onOk={$ => self.createPlanClick()}
  292. onCancel={$ => self.closeAddVisible()}
  293. >
  294. <BirdForm
  295. fields={addFields}
  296. ref="addForm"
  297. />
  298. </Modal>
  299. {/* 选择客服弹窗 */}
  300. <Modal title="选择客服"
  301. visible={self.state.userVisible}
  302. onOk={$ => self.selectUser()}
  303. onCancel={$ => self.closeUserVisible()}
  304. footer={null}
  305. width={920}
  306. >
  307. <BirdGrid gridOption={selectUserGrid} ref="selectGrid"></BirdGrid>
  308. </Modal>
  309. </div>
  310. );
  311. }
  312. }
  313. //字面意思就是,把models的state变成组件的props
  314. function mapStateToProps(state) {
  315. const { corpid } = state.sellmanage // test就是models命名空间名字
  316. return { corpid }; // 在这return,上面才能获取到
  317. }
  318. export default connect(mapStateToProps)(addPeoplePlan);