updatesales.jsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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();
  82. this.close();
  83. } else {
  84. message.warning(data.error[0].message);
  85. }
  86. }.bind(this)
  87. );
  88. }
  89. goSelect(value) {
  90. let channelid;
  91. let fwList = this.state.channelArr;
  92. fwList.map(function (item) {
  93. if (value == item.name) {
  94. channelid = item.id;
  95. }
  96. });
  97. this.setState({
  98. channelname: value,
  99. channelid: channelid,
  100. });
  101. }
  102. //渠道名称自动补全
  103. channelChange(e) {
  104. this.setState({
  105. channelName: e
  106. })
  107. if (e.length >= 2) {
  108. this.selectChannel(e);
  109. }
  110. }
  111. // 渠道查询
  112. selectChannel(e) {
  113. $.ajax({
  114. method: "get",
  115. dataType: "json",
  116. crossDomain: false,
  117. url: globalConfig.context + "/api/admin/customer/selectChannelUserList",
  118. data: {
  119. name: e,
  120. },
  121. success: function (data) {
  122. let thedata = data.data;
  123. if (!thedata) {
  124. if (data.error && data.error.length) {
  125. message.warning(data.error[0].message);
  126. }
  127. thedata = {};
  128. }
  129. this.setState({
  130. channelArr: thedata,
  131. });
  132. }.bind(this),
  133. }).always(
  134. function () {
  135. this.setState({
  136. loading: false,
  137. });
  138. }.bind(this)
  139. );
  140. }
  141. // 是否在数组中存在
  142. isArray(arr, value, title) {
  143. for (var i = 0; i < arr.length; i++) {
  144. if (value == arr[i][title]) {
  145. return true
  146. }
  147. }
  148. return false
  149. }
  150. //
  151. update() {
  152. const { updatas } = this.props;
  153. let defaults = JSON.parse(JSON.stringify(updatas));
  154. if (updatas.userType == null && updatas.salesType == null) {//无客户所属类型 无销售类型则可选取所有销售类型
  155. defaults.userType = 2
  156. } else {
  157. if (updatas.salesType != null) {
  158. this.isArray(ssalesType, updatas.salesType, "value") && (defaults.userType = 0);//有销售类型(私有客户)
  159. this.isArray(qsalesType, updatas.salesType, "value") && (defaults.userType = 1);//有销售类型(以签单客户)
  160. }
  161. }
  162. this.setState({
  163. datas: defaults,
  164. channelName: defaults.salesType == "3" ? defaults.other : "",//销售类型为渠道的时候给编辑出的渠道名称赋值
  165. upsalesType: true,
  166. })
  167. }
  168. render() {
  169. const { datas } = this.state;
  170. let cdataSources = this.state.channelArr || [];
  171. let channeloptions = cdataSources.map((group) => (
  172. <Select.Option key={group.id} value={group.name}>
  173. {group.name}
  174. </Select.Option>
  175. ));
  176. return (
  177. <span style={{ marginLeft: 10 }}>
  178. <Button
  179. type="primary"
  180. onClick={this.update.bind(this)}
  181. >修改</Button>
  182. {
  183. this.state.upsalesType &&
  184. <Modal
  185. title="修改"
  186. visible={this.state.upsalesType}
  187. width="600px"
  188. onOk={this.updateSalesType.bind(this)}
  189. onCancel={this.close.bind(this)}
  190. >
  191. <Form>
  192. {
  193. datas.userType != null &&
  194. <FormItem {...formItemLayout} label="客户所属类型">
  195. <Select
  196. placeholder="请选择客户所属类型"
  197. style={{ width: "200px" }}
  198. value={datas.userType.toString()}
  199. disabled={true}
  200. >
  201. {customerType.map(function (item) {
  202. return (
  203. <Select.Option key={item.value}>
  204. {item.key}
  205. </Select.Option>
  206. );
  207. })}
  208. </Select>
  209. </FormItem>
  210. }
  211. <FormItem {...formItemLayout} label="销售类型">
  212. <Select
  213. placeholder="请选择销售类型"
  214. style={{ width: "200px" }}
  215. value={datas.salesType == null ? undefined : datas.salesType.toString()}
  216. onChange={(e) => {
  217. this.setState({
  218. datas: Object.assign(datas, {
  219. salesType: e,
  220. }),
  221. });
  222. }}
  223. >
  224. {(datas.userType == "0"
  225. ? ssalesType : datas.userType == "1"
  226. ? qsalesType : datas.userType == "2"
  227. ? [...ssalesType, ...qsalesType] : []).map(function (item) {
  228. return (
  229. <Select.Option key={item.value}>
  230. {item.key}
  231. </Select.Option>
  232. );
  233. })}
  234. </Select>
  235. </FormItem>
  236. {
  237. (datas.salesType == "4" || datas.salesType == "5") &&
  238. <FormItem {...formItemLayout} label="描述">
  239. <TextArea
  240. placeholder="请填写描述"
  241. style={{ width: 300, height: 80 }}
  242. value={datas.other}
  243. onChange={(e) => {
  244. this.setState({
  245. datas: Object.assign(datas, {
  246. other: e.target.value,
  247. }),
  248. });
  249. }}
  250. />
  251. </FormItem>
  252. }
  253. {
  254. datas.salesType == "3" &&
  255. <div className="clearfix">
  256. <FormItem {...formItemLayout} label="渠道名称">
  257. <AutoComplete
  258. className="certain-category-search"
  259. dropdownClassName="certain-category-search-dropdown"
  260. dropdownMatchSelectWidth={false}
  261. dropdownStyle={{ width: 200 }}
  262. size="large"
  263. style={{ width: "200px" }}
  264. dataSource={channeloptions}
  265. placeholder="请输入渠道关键字"
  266. value={this.state.channelName}
  267. onChange={this.channelChange.bind(this)}
  268. filterOption={true}
  269. onSelect={this.goSelect.bind(this)}
  270. >
  271. <Input />
  272. </AutoComplete>
  273. <span className="mandatory">*</span>
  274. </FormItem>
  275. </div>
  276. }
  277. </Form>
  278. </Modal>
  279. }
  280. </span>
  281. )
  282. }
  283. }
  284. export default UpdateSales;