create.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. import {
  2. set
  3. } from "lodash";
  4. // pages/order/create/create.js
  5. var app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. loading: true,
  12. addr: {},
  13. ecc: {},
  14. eccName: '',
  15. goodsList: [],
  16. checkPrice: 0,
  17. logisticsList: [],
  18. auditUserList: [],
  19. bxdCustomTypeList: [],
  20. bxdEccList: [],
  21. projectThemeList: [{
  22. id: 1,
  23. name: '会销'
  24. },
  25. {
  26. id: 2,
  27. name: '科室会'
  28. },
  29. {
  30. id: 3,
  31. name: '患教活动'
  32. },
  33. {
  34. id: 4,
  35. name: '日常拜访'
  36. },
  37. {
  38. id: 5,
  39. name: '展会'
  40. },
  41. {
  42. id: 6,
  43. name: '品牌路演'
  44. },
  45. {
  46. id: 7,
  47. name: '公司内部活动'
  48. },
  49. {
  50. id: 8,
  51. name: '授牌权益'
  52. },
  53. ],
  54. userInfo: wx.getStorageSync('userInfo'),
  55. company: wx.getStorageSync('company'),
  56. isSales: false,
  57. isStraumann: false,
  58. order: {
  59. logisticsName: '',
  60. logisticsCode: '',
  61. checkUserName: '',
  62. checkUserId: '',
  63. totalAmount: '',
  64. bxdOrderList: [{
  65. companyId: wx.getStorageSync('companyId'),
  66. companyName: wx.getStorageSync('companyName'),
  67. eccCode: '',
  68. eccName: '',
  69. customerName: '', //eccName
  70. typeName: '',
  71. remark: '',
  72. publicRemark: '',
  73. activityName: '',
  74. projectTheme: '',
  75. }]
  76. },
  77. errShow: false,
  78. errMsg: '',
  79. },
  80. /**
  81. * 生命周期函数--监听页面加载
  82. */
  83. async onLoad(options) {
  84. let that = this;
  85. const eventChannel = that.getOpenerEventChannel()
  86. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  87. eventChannel.on('acceptDataFromOpenerPage', function (data) {
  88. that.setData({
  89. goodsList: data.goodsList,
  90. ["order.bxdOrderList[0].bxdOrderItem"]: data.goodsList.map(v => {
  91. v['prodCount'] = v.qty;
  92. v['prodName'] = v.picTitle;
  93. v['priceTotal'] = app.currency(0).add(app.currency(v.price).multiply(v.qty).value);
  94. v['productTotalAmount'] = v.priceTotal;
  95. return v;
  96. }),
  97. ["order.bxdOrderList[0].totalAmount"]: data.checkPrice,
  98. ["order.bxdOrderList[0].productNums"]: data.goodsList.filter((item => item.check)).reduce((qty, item1) => app.currency(qty).add(item1.qty).value, 0),
  99. ["order.totalAmount"]: data.checkPrice,
  100. checkPrice: data.checkPrice,
  101. });
  102. });
  103. await app.getUserInfo(this);
  104. await this.getAddr();
  105. let company = this.data.company;
  106. this.setData({
  107. isStraumann: company && company.corporationCode == 'straumann'
  108. });
  109. // let {
  110. // data: check
  111. // } = await app.ajax.gets('/admin/address/check');
  112. // let isSales = false;
  113. // if (check.code == 0) {
  114. // if (check.data == 2004) {
  115. // isSales = false
  116. // } else if (check.data == 2005) {
  117. // isSales = true
  118. // }
  119. // }
  120. // this.setData({
  121. // isSales
  122. // });
  123. // if (company && company.corporationCode == 'straumann') {
  124. // let {
  125. // data: data1
  126. // } = await app.ajax.gets('/admin/bxdecc/page?current=1&size=10');
  127. // this.setData({
  128. // bxdEccList: data1.data.records.map(v => {
  129. // return {
  130. // ...v,
  131. // name: v.eccName
  132. // }
  133. // })
  134. // });
  135. // }
  136. if (this.data.userInfo.auditSwitch === '1' && this.data.userInfo.auditUsers) {
  137. let {
  138. data
  139. } = await app.ajax.gets(`/admin/user/getUsersByIds?userIds=${this.data.userInfo.auditUsers.split(',')}`);
  140. this.setData({
  141. auditUserList: data.data.map(v => {
  142. return {
  143. id: v.userId,
  144. name: v.fullname
  145. }
  146. })
  147. });
  148. }
  149. this.getLogisticsList();
  150. this.setData({
  151. loading: false
  152. });
  153. },
  154. async getAddr() {
  155. let {
  156. data
  157. } = await app.ajax.gets("/admin/bxdClientAddress/default");
  158. if (data.data) {
  159. this.setData({
  160. addr: data.data,
  161. ["order.bxdOrderList[0]"]: {
  162. ...this.data.order.bxdOrderList[0],
  163. ...data.data,
  164. addrId: `clientAddrId_${data.data.addrId}`,
  165. receiverName: data.data.receiver,
  166. address: data.data.addr,
  167. remarks: data.data.remark,
  168. }
  169. })
  170. }
  171. },
  172. bindOrderRemark(e) {
  173. this.setData({
  174. ["order.bxdOrderList[0].publicRemark"]: e.detail.value
  175. })
  176. },
  177. /**
  178. * 生命周期函数--监听页面初次渲染完成
  179. */
  180. onReady() {
  181. },
  182. /**
  183. * 生命周期函数--监听页面显示
  184. */
  185. onShow() {
  186. },
  187. // chooseAddr() {
  188. // let that = this;
  189. // wx.navigateTo({
  190. // url: '/pages/order/create/create',
  191. // success: function (res) {
  192. // // 通过eventChannel向被打开页面传送数据
  193. // res.eventChannel.emit('acceptDataFromOpenerPage', {
  194. // goodsList: cartList.filter((item => item.check)),
  195. // checkPrice: cartList.filter((item => item.check)).reduce((price, item1) => app.currency(price).add(item1.price).multiply(item1.qty).value, 0),
  196. // })
  197. // }
  198. // })
  199. // },
  200. chooseAddr: function () {
  201. let that = this;
  202. wx.navigateTo({
  203. url: '/pages/user/address/list/list',
  204. events: {
  205. // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
  206. acceptDataFromOpenerPage: function (data) {
  207. that.setData({
  208. addr: data.addr,
  209. ["order.bxdOrderList[0]"]: {
  210. ...that.data.order.bxdOrderList[0],
  211. ...data.addr,
  212. addrId: `clientAddrId_${data.addr.addrId}`,
  213. receiverName: data.addr.receiver,
  214. address: data.addr.addr,
  215. remarks: data.addr.remark,
  216. }
  217. })
  218. },
  219. },
  220. success: function (res) {
  221. // 通过eventChannel向被打开页面传送数据
  222. res.eventChannel.emit('acceptDataFromOpenerPage', {
  223. check: true,
  224. addr: that.data.addr
  225. })
  226. }
  227. })
  228. },
  229. chooseEcc: function () {
  230. let that = this;
  231. wx.navigateTo({
  232. url: '/pages/user/ecc/ecc',
  233. events: {
  234. // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
  235. acceptDataFromOpenerPage: function (data) {
  236. that.setData({
  237. ecc: data.ecc,
  238. eccName: data.eccName,
  239. ["order.bxdOrderList[0].eccCode"]: data.ecc.eccCode,
  240. ["order.bxdOrderList[0].eccName"]: data.ecc.eccName,
  241. ["order.bxdOrderList[0].typeName"]: data.ecc.customTypeName,
  242. })
  243. },
  244. },
  245. success: function (res) {
  246. // 通过eventChannel向被打开页面传送数据
  247. res.eventChannel.emit('acceptDataFromOpenerPage', {
  248. ecc: that.data.ecc,
  249. eccName: that.data.eccName
  250. })
  251. }
  252. })
  253. },
  254. async getLogisticsList() {
  255. let {
  256. data
  257. } = await app.ajax.gets("/admin/dict/getSysDictListByType?type=logisticsCode");
  258. let company = wx.getStorageSync('company')
  259. this.setData({
  260. logisticsList: data.data.filter(v => {
  261. //console.log(v.value, company.logisticsCode.split(",").indexOf(v.value))
  262. return company.logisticsCode.split(",").indexOf(v.value) != -1;
  263. }).map(v => {
  264. return {
  265. id: v.value,
  266. name: v.label
  267. }
  268. })
  269. });
  270. let onlyLogisticsCode = wx.getStorageSync('company').onlyLogisticsCode || '';
  271. let onlyLogisticsCodeIndex = 0;
  272. try {
  273. onlyLogisticsCodeIndex = this.data.logisticsList.findIndex(v => v.id == onlyLogisticsCode) > 0 ? this.data.logisticsList.findIndex(v => v.id == onlyLogisticsCode) : 0;
  274. } catch (e) { }
  275. this.setData({
  276. logisticsCodeValue: onlyLogisticsCodeIndex,
  277. ['order.logisticsName']: this.data.logisticsList[onlyLogisticsCodeIndex].name,
  278. ['order.logisticsCode']: this.data.logisticsList[onlyLogisticsCodeIndex].id,
  279. ["order.bxdOrderList[0].logisticsCode"]: this.data.logisticsList[onlyLogisticsCodeIndex].id,
  280. })
  281. },
  282. bindLogisticsCode(e) {
  283. this.setData({
  284. logisticsCodeValue: Number(e.detail.value),
  285. ['order.logisticsName']: this.data.logisticsList[Number(e.detail.value)].name,
  286. ['order.logisticsCode']: this.data.logisticsList[Number(e.detail.value)].id,
  287. ["order.bxdOrderList[0].logisticsCode"]: this.data.logisticsList[Number(e.detail.value)].id,
  288. })
  289. },
  290. bindCheckUser(e) {
  291. this.setData({
  292. ['order.checkUserName']: this.data.auditUserList[Number(e.detail.value)].name,
  293. ['order.checkUserId']: this.data.auditUserList[Number(e.detail.value)].id,
  294. })
  295. },
  296. bindEccUser(e) {
  297. this.setData({
  298. ['order.bxdOrderList[0].eccName']: this.data.bxdEccList[Number(e.detail.value)].name,
  299. ['order.bxdOrderList[0].eccCode']: this.data.bxdEccList[Number(e.detail.value)].eccCode,
  300. ['order.bxdOrderList[0].typeName']: this.data.bxdEccList[Number(e.detail.value)].customTypeName,
  301. })
  302. },
  303. bindActivityName(e) {
  304. this.setData({
  305. ['order.bxdOrderList[0].activityName']: e.detail.value
  306. })
  307. },
  308. bindProjectTheme(e) {
  309. this.setData({
  310. ['order.bxdOrderList[0].projectTheme']: this.data.projectThemeList[Number(e.detail.value)].name
  311. })
  312. },
  313. async submit() {
  314. let that = this;
  315. this.setData({
  316. ['order.shenhe']: "",
  317. ['order.fahuo']: "",
  318. ['order.qianshou']: "",
  319. });
  320. wx.requestSubscribeMessage({
  321. tmplIds: ['X3m1gQyKyTBIvEAZO7FgPcOmF-ibwXck1-acj9St0LE', '6Lc7eHUHQeqzxNFB3kioZCZjInjLJ5lMZOTcf7635OQ', 'AEJCSo1FZ12WNgJd7XUQCSzhF_pF4Sz64Cmt5074tEg'],
  322. success(res) {
  323. if (res.errMsg == "requestSubscribeMessage:ok") {
  324. if (res["X3m1gQyKyTBIvEAZO7FgPcOmF-ibwXck1-acj9St0LE"] == "accept") {
  325. that.setData({
  326. ['order.shenhe']: 'X3m1gQyKyTBIvEAZO7FgPcOmF-ibwXck1-acj9St0LE'
  327. })
  328. }
  329. if (res["6Lc7eHUHQeqzxNFB3kioZCZjInjLJ5lMZOTcf7635OQ"] == "accept") {
  330. that.setData({
  331. ['order.fahuo']: '6Lc7eHUHQeqzxNFB3kioZCZjInjLJ5lMZOTcf7635OQ'
  332. })
  333. }
  334. if (res["AEJCSo1FZ12WNgJd7XUQCSzhF_pF4Sz64Cmt5074tEg"] == "accept") {
  335. that.setData({
  336. ['order.qianshou']: 'AEJCSo1FZ12WNgJd7XUQCSzhF_pF4Sz64Cmt5074tEg'
  337. })
  338. }
  339. }
  340. },
  341. fail(res) { },
  342. complete(res) {
  343. that.submit1();
  344. }
  345. })
  346. },
  347. async submit1() {
  348. let goodsList = this.data.goodsList;
  349. let addr = this.data.addr;
  350. let order = this.data.order;
  351. let userInfo = this.data.userInfo;
  352. if (!goodsList || goodsList.length == 0) {
  353. wx.showToast({
  354. title: '请选择商品',
  355. icon: 'error'
  356. });
  357. return;
  358. }
  359. if (!addr || !addr.addrId) {
  360. wx.showToast({
  361. title: '请选择地址',
  362. icon: 'error'
  363. });
  364. return;
  365. }
  366. if (!order.logisticsCode) {
  367. wx.showToast({
  368. title: '请选择快递公司',
  369. icon: 'error'
  370. });
  371. return;
  372. }
  373. if (userInfo.auditSwitch === '1' && !order.checkUserId && !this.data.isStraumann) {
  374. wx.showToast({
  375. title: '请选择审核用户',
  376. icon: 'error'
  377. });
  378. return;
  379. }
  380. if (this.data.isStraumann && !order.bxdOrderList[0].eccName) {
  381. wx.showToast({
  382. title: '请选择客户编码',
  383. icon: 'error'
  384. });
  385. return;
  386. }
  387. if (this.data.isStraumann && !order.bxdOrderList[0].typeName) {
  388. wx.showToast({
  389. title: '暂无客户类型请先维护',
  390. icon: 'none'
  391. });
  392. return;
  393. }
  394. if (this.data.isStraumann && !order.bxdOrderList[0].activityName) {
  395. wx.showToast({
  396. title: '请输入活动名称',
  397. icon: 'error'
  398. });
  399. return;
  400. }
  401. if (this.data.isStraumann && !order.bxdOrderList[0].projectTheme) {
  402. wx.showToast({
  403. title: '请选择活动类型',
  404. icon: 'error'
  405. });
  406. return;
  407. }
  408. let {
  409. data: res
  410. } = await app.ajax.post({
  411. url: "/admin/bxdorder/commitOrder",
  412. data: order
  413. });
  414. if (res.code == 401) {
  415. wx.showToast({
  416. title: '下单失败',
  417. icon: 'error',
  418. duration: 2000
  419. });
  420. return;
  421. } else if (res.code == 4000) {
  422. this.setData({
  423. errShow: true,
  424. errMsg: `下单失败:${res.data ? '收货人公司【' + res.data + '】,' : ''}下单额度不足,请联系部门负责人`,
  425. })
  426. // this.errClose();
  427. } else {
  428. wx.showToast({
  429. title: '提交订单成功!',
  430. });
  431. let status = true ? '' : this.data.isStraumann ? 1 : userInfo.auditSwitch === '0' ? 1 : '0';
  432. setTimeout(() => {
  433. wx.redirectTo({
  434. url: `/pages/order/user/list/list?status=${status}`,
  435. })
  436. }, 1000);
  437. }
  438. },
  439. errClose() {
  440. this.setData({
  441. errShow: false,
  442. errMsg: ''
  443. })
  444. },
  445. /**
  446. * 生命周期函数--监听页面隐藏
  447. */
  448. onHide() {
  449. },
  450. /**
  451. * 生命周期函数--监听页面卸载
  452. */
  453. onUnload() {
  454. },
  455. /**
  456. * 页面相关事件处理函数--监听用户下拉动作
  457. */
  458. onPullDownRefresh() {
  459. },
  460. /**
  461. * 页面上拉触底事件的处理函数
  462. */
  463. onReachBottom() {
  464. },
  465. /**
  466. * 用户点击右上角分享
  467. */
  468. onShareAppMessage() {
  469. }
  470. })