updatesales.jsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. import React, { Component } from 'react';
  2. import {
  3. Modal,
  4. message,
  5. Input,
  6. Select,
  7. Button,
  8. Form,
  9. AutoComplete,
  10. } from "antd";
  11. import $ from 'jquery/src/ajax';
  12. import {
  13. customerType,
  14. ssalesType,
  15. qsalesType,
  16. wsalesType,
  17. } from "@/dataDic.js";
  18. const FormItem = Form.Item;
  19. const { TextArea } = Input;
  20. const formItemLayout = {
  21. labelCol: { span: 8 },
  22. wrapperCol: { span: 14 },
  23. };
  24. class UpdateSales extends Component {
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. loading: false,
  29. channelArr: [],
  30. upsalesType: false,//修改销售类型弹窗
  31. channelName: "",
  32. datas: {},
  33. channelid: '',
  34. channelname: '',
  35. }
  36. }
  37. // 关闭弹窗
  38. close() {
  39. this.setState({
  40. upsalesType: false,
  41. datas: {},
  42. channelid: '',
  43. channelname: '',
  44. })
  45. }
  46. // 修改订单销售类型提交
  47. updateSalesType() {
  48. const { channelid, channelname, channelName, datas } = this.state;
  49. const { orderNo, onRefresh = () => { } } = this.props;
  50. if (datas.salesType == "3" && channelid == "" && !!channelName) {//渠道类型时--如果打开弹窗无更改将直接关闭不调接口
  51. this.close();
  52. return
  53. }
  54. this.setState({
  55. loading: true,
  56. });
  57. let post = {
  58. orderNo: orderNo,
  59. salesType: datas.salesType,//销售类型
  60. };
  61. if (datas.salesType == "3") { //传渠道编号 other里面传渠道名称
  62. post = Object.assign(post, {
  63. channelId: channelid,
  64. other: channelname,
  65. })
  66. } else if (datas.salesType == "4" || datas.salesType == "5") { //4,5要传描述
  67. post = Object.assign(post, {
  68. other: datas.other,
  69. })
  70. }
  71. $.ajax({
  72. url: globalConfig.context + "/api/admin/newOrder/updateSalesType",
  73. method: "post",
  74. data: post,
  75. }).done(
  76. function (data) {
  77. this.setState({
  78. loading: false,
  79. });
  80. if (!data.error.length) {
  81. message.success("修改成功!");
  82. onRefresh(post);
  83. this.close();
  84. } else {
  85. message.warning(data.error[0].message);
  86. }
  87. }.bind(this)
  88. );
  89. }
  90. // 选中回调
  91. goSelect(value) {
  92. let channelid;
  93. let fwList = this.state.channelArr;
  94. fwList.map(function (item) {
  95. if (value == item.name) {
  96. channelid = item.id;
  97. }
  98. });
  99. this.setState({
  100. channelname: value,
  101. channelid: channelid,
  102. });
  103. }
  104. // 渠道名称自动补全
  105. channelChange(e) {
  106. this.setState({
  107. channelName: e
  108. })
  109. if (e.length >= 2) {
  110. this.selectChannel(e);
  111. }
  112. }
  113. // 渠道查询
  114. selectChannel(e) {
  115. $.ajax({
  116. method: "get",
  117. dataType: "json",
  118. crossDomain: false,
  119. url: globalConfig.context + "/api/admin/customer/selectChannelUserList",
  120. data: {
  121. name: e,
  122. },
  123. success: function (data) {
  124. let thedata = data.data;
  125. if (!thedata) {
  126. if (data.error && data.error.length) {
  127. message.warning(data.error[0].message);
  128. }
  129. thedata = {};
  130. }
  131. this.setState({
  132. channelArr: thedata,
  133. });
  134. }.bind(this),
  135. }).always(
  136. function () {
  137. this.setState({
  138. loading: false,
  139. });
  140. }.bind(this)
  141. );
  142. }
  143. // 是否在数组中存在
  144. isArray(arr, value, title) {
  145. for (var i = 0; i < arr.length; i++) {
  146. if (value == arr[i][title]) {
  147. return true
  148. }
  149. }
  150. return false
  151. }
  152. // 点击修改处理
  153. update() {
  154. const { updatas } = this.props;
  155. let defaults = JSON.parse(JSON.stringify(updatas));
  156. // if (updatas.userType == null && updatas.salesType == null) {//无客户所属类型 无销售类型则可选取所有销售类型
  157. // defaults.userType = 2
  158. // } else {
  159. // if (updatas.salesType != null) {
  160. // this.isArray(ssalesType, updatas.salesType, "value") && (defaults.userType = 0);//有销售类型(私有客户)
  161. // this.isArray(qsalesType, updatas.salesType, "value") && (defaults.userType = 1);//有销售类型(以签单客户)
  162. // }
  163. // }
  164. // if (updatas.userType == null) {//无客户所属类型时--可让其选择所有销售类型
  165. // defaults.userType = 2
  166. // }
  167. this.setState({
  168. datas: defaults,
  169. channelName: defaults.salesType == "3" ? defaults.other : "",//销售类型为渠道的时候给编辑出的渠道名称赋值
  170. upsalesType: true,
  171. })
  172. }
  173. render() {
  174. const { datas } = this.state;
  175. let cdataSources = this.state.channelArr || [];
  176. let channeloptions = cdataSources.map((group) => (
  177. <Select.Option key={group.id} value={group.name}>
  178. {group.name}
  179. </Select.Option>
  180. ));
  181. return (
  182. <span style={{ marginLeft: 10 }}>
  183. <Button
  184. type="primary"
  185. onClick={this.update.bind(this)}
  186. >修改</Button>
  187. {
  188. this.state.upsalesType &&
  189. <Modal
  190. title="修改"
  191. visible={this.state.upsalesType}
  192. width="600px"
  193. onOk={this.updateSalesType.bind(this)}
  194. onCancel={this.close.bind(this)}
  195. >
  196. <Form>
  197. {
  198. (datas.userType != null && datas.userType != 2) &&
  199. <FormItem {...formItemLayout} label="客户所属类型">
  200. <Select
  201. placeholder="请选择客户所属类型"
  202. style={{ width: "200px" }}
  203. value={datas.userType.toString()}
  204. disabled={true}
  205. >
  206. {customerType.map(function (item) {
  207. return (
  208. <Select.Option key={item.value}>
  209. {item.key}
  210. </Select.Option>
  211. );
  212. })}
  213. </Select>
  214. </FormItem>
  215. }
  216. {
  217. console.log("====", datas.userType)
  218. }
  219. <FormItem {...formItemLayout} label="销售类型">
  220. <Select
  221. placeholder="请选择销售类型"
  222. style={{ width: "200px" }}
  223. value={datas.salesType == null ? undefined : datas.salesType.toString()}
  224. onChange={(e) => {
  225. this.setState({
  226. datas: Object.assign(datas, {
  227. salesType: e,
  228. other: "",
  229. channelName: "",
  230. }),
  231. });
  232. }}
  233. >
  234. {(datas.userType == "0"
  235. ? ssalesType : datas.userType == "1"
  236. ? qsalesType : datas.userType == "2"
  237. ? wsalesType : datas.userType == "3"
  238. ? qsalesType : []).map(function (item) {
  239. return (
  240. <Select.Option key={item.value} disabled={item.value == "5"}>
  241. {item.key}
  242. </Select.Option>
  243. );
  244. })}
  245. </Select>
  246. </FormItem>
  247. {
  248. (datas.salesType == "4" || datas.salesType == "5") &&
  249. <FormItem {...formItemLayout} label="描述">
  250. <TextArea
  251. placeholder="请填写描述"
  252. style={{ width: 300, height: 80 }}
  253. value={datas.other}
  254. onChange={(e) => {
  255. this.setState({
  256. datas: Object.assign(datas, {
  257. other: e.target.value,
  258. }),
  259. });
  260. }}
  261. />
  262. </FormItem>
  263. }
  264. {
  265. datas.salesType == "3" &&
  266. <div className="clearfix">
  267. <FormItem {...formItemLayout} label="渠道名称">
  268. <AutoComplete
  269. className="certain-category-search"
  270. dropdownClassName="certain-category-search-dropdown"
  271. dropdownMatchSelectWidth={false}
  272. dropdownStyle={{ width: 200 }}
  273. size="large"
  274. style={{ width: "200px" }}
  275. dataSource={channeloptions}
  276. placeholder="请输入渠道关键字"
  277. value={this.state.channelName}
  278. onChange={this.channelChange.bind(this)}
  279. filterOption={true}
  280. onSelect={this.goSelect.bind(this)}
  281. >
  282. <Input />
  283. </AutoComplete>
  284. <span className="mandatory">*</span>
  285. </FormItem>
  286. </div>
  287. }
  288. </Form>
  289. </Modal>
  290. }
  291. </span>
  292. )
  293. }
  294. }
  295. export default UpdateSales;