create.js 13 KB

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