updatesales.jsx 8.7 KB

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