detail.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. const _Http = getApp().globalData.http;
  2. let figure = null; //免运费额度
  3. import currency from "../../utils/currency";
  4. Page({
  5. data: {
  6. hidePrice: wx.getStorageSync('hidePrice'),
  7. loading: true,
  8. sa_orderid: null,
  9. tabsActive: 0,
  10. tabsList: [{
  11. label: "产品明细",
  12. icon: "icon-tabchanpin",
  13. model: "#Product"
  14. }, {
  15. label: "附件",
  16. icon: "icon-tabfujian1",
  17. model: "#Yl_Attachment"
  18. }, {
  19. label: "订单进度",
  20. icon: "icon-tabcaozuojilu1",
  21. model: "#Progress"
  22. }]
  23. },
  24. onLoad(options) {
  25. this.setData({
  26. options: wx.getStorageSync('auth').worderform.options,
  27. sa_orderid: options.id,
  28. order_rebate_used: wx.getStorageSync('siteP').order_rebate_used,
  29. userrole: wx.getStorageSync('userrole')
  30. });
  31. this.getDetail(true);
  32. },
  33. /* 获取详情 */
  34. getDetail(init = false, show = true) {
  35. _Http.basic({
  36. "id": 20221108151302,
  37. "content": {
  38. nocache: true,
  39. "sa_orderid": this.data.sa_orderid
  40. }
  41. }, show).then(res => {
  42. console.log("订单详情", res)
  43. if (res.msg != '成功') return wx.showToast({
  44. title: res.msg,
  45. icon: "none"
  46. });
  47. let CNY = value => currency(value, {
  48. symbol: "¥",
  49. precision: 2
  50. }).format();
  51. res.data.sa_accountclassinfos = res.data.sa_accountclassinfos.map(v => {
  52. v.amount = CNY(v.amount)
  53. v.text = `\n(余额:${CNY(v.balance)},信用额度:${CNY(v.creditquota)})`
  54. return v
  55. })
  56. this.setData({
  57. detail: res.data,
  58. loading: false,
  59. amount: CNY(res.data.amount)
  60. });
  61. if (init) {
  62. this.partialRenewal(true)
  63. let content = wx.getStorageSync('userrole') == '业务员' ? {
  64. sys_enterpriseid: this.data.detail.sys_enterpriseid
  65. } : {};
  66. //业务员根据指定经销商的免运费
  67. _Http.basic({
  68. "id": 20220920084001,
  69. content
  70. }, false).then(res => {
  71. console.log("查询企业档案获取企业免邮额度", res)
  72. if (res.msg != '成功') return wx.showToast({
  73. title: res.msg,
  74. icon: "none"
  75. })
  76. figure = res.data.freefreightamount;
  77. this.setLogisticsMsg();
  78. })
  79. } else {
  80. this.setLogisticsMsg();
  81. }
  82. })
  83. },
  84. /* 免运费信息 */
  85. setLogisticsMsg() {
  86. let logistics = null;
  87. if (figure == -1) {
  88. logistics = '到付'
  89. } else if (figure == 0) {
  90. logistics = '预付'
  91. } else {
  92. let amount = this.data.detail.amount;
  93. logistics = amount >= figure ? '免运费' : '差' + currency(figure).subtract(amount).value + '元免运费';
  94. }
  95. this.setData({
  96. logistics
  97. })
  98. },
  99. /* 选择结算人 */
  100. selectAgent() {
  101. if (this.isEdit()) return;
  102. if (this.data.detail.type == '项目订单') return;
  103. wx.navigateTo({
  104. url: `/select/agent/index?params=${JSON.stringify({
  105. "id":20230104103702,
  106. "content": {
  107. "pageNumber": 1,
  108. "pageTotal": 1,
  109. "pageSize": 20,
  110. "where": {
  111. "condition": "",
  112. },
  113. }
  114. })}&radio=true`,
  115. });
  116. getApp().globalData.handleSelect = this.setAgeant.bind(this);
  117. },
  118. /* 设置结算人 */
  119. setAgeant({
  120. item
  121. }) {
  122. let that = this;
  123. console.log("选择经销商", item)
  124. wx.showModal({
  125. title: '提示',
  126. content: `是否确认设置"${item.enterprisename}"为结算人?`,
  127. complete: (res) => {
  128. if (res.confirm) {
  129. let pay_enterpriseid = that.data.detail.pay_enterpriseid,
  130. sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid,
  131. sa_accountclassid = that.data.detail.accountclass.sa_accountclassid;
  132. that.setData({
  133. "detail.pay_enterpriseid": item.sys_enterpriseid,
  134. "detail.sys_enterprise_financeid": item.finance[0] ? item.finance[0].sys_enterprise_financeid : 0,
  135. "detail.accountclass.sa_accountclassid": item.accounts[0] ? item.accounts[0].sa_accountclassid : 0,
  136. });
  137. that.changeDetail().then(s => {
  138. if (s.msg == '成功') {
  139. wx.showToast({
  140. title: '设置成功',
  141. icon: "none"
  142. });
  143. setTimeout(() => {
  144. wx.navigateBack();
  145. that.getDetail();
  146. }, 500)
  147. } else {
  148. that.setData({
  149. "detail.pay_enterpriseid": pay_enterpriseid,
  150. "detail.sys_enterprise_financeid": sys_enterprise_financeid,
  151. "detail.sa_accountclassid": sa_accountclassid
  152. });
  153. }
  154. })
  155. }
  156. }
  157. })
  158. },
  159. /* 选择财务信息 */
  160. selectFinance() {
  161. if (this.isEdit()) return;
  162. wx.navigateTo({
  163. url: `/select/finance/index?params=${JSON.stringify({
  164. "id":20221013160602,
  165. "content": {
  166. nocache:true,
  167. sys_enterpriseid:this.data.detail.sys_enterpriseid,
  168. "pageNumber": 1,
  169. "pageTotal": 1,
  170. "pageSize": 20,
  171. "where": {
  172. "condition": "",
  173. },
  174. }
  175. })}&radio=true`,
  176. });
  177. getApp().globalData.handleSelect = this.setFinance.bind(this);
  178. },
  179. /* 设置财务信息 */
  180. setFinance({
  181. item
  182. }) {
  183. let that = this;
  184. console.log("设置财务信息", item)
  185. wx.showModal({
  186. title: '提示',
  187. content: `是否确认设置"${item.enterprisename}"为开票单位?`,
  188. complete: (res) => {
  189. if (res.confirm) {
  190. let sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid;
  191. that.setData({
  192. "detail.sys_enterprise_financeid": item.sys_enterprise_financeid
  193. });
  194. that.changeDetail().then(s => {
  195. if (s.msg == '成功') {
  196. wx.showToast({
  197. title: '设置成功',
  198. icon: "none"
  199. });
  200. setTimeout(() => {
  201. wx.navigateBack();
  202. that.getDetail();
  203. }, 500)
  204. } else {
  205. that.setData({
  206. "detail.sys_enterprise_financeid": sys_enterprise_financeid
  207. });
  208. }
  209. })
  210. }
  211. }
  212. })
  213. },
  214. //tabs 切换
  215. tabsChange({
  216. detail
  217. }) {
  218. this.setData({
  219. tabsActive: detail
  220. });
  221. this.partialRenewal();
  222. },
  223. //局部数据更新 tabs
  224. partialRenewal(init = false) {
  225. let model = this.data.tabsList[this.data.tabsActive].model;
  226. if (model) {
  227. let Component = this.selectComponent(model),
  228. {
  229. total,
  230. pageNumber,
  231. pageTotal
  232. } = Component.data.content,
  233. id = this.data.detail.sa_orderid;
  234. if (total == null || init) {
  235. Component.getList(id, init);
  236. } else if (pageNumber <= pageTotal) {
  237. Component.getList(id, false);
  238. }
  239. }
  240. },
  241. onReachBottom() {
  242. this.partialRenewal();
  243. },
  244. /* 更新数据 */
  245. changeDetail() {
  246. let data = this.data.detail,
  247. content = {
  248. "sa_orderid": data.sa_orderid,
  249. "sys_enterpriseid": data.sys_enterpriseid, //订货企业id
  250. "sa_accountclassid": data.sa_accountclassid || 0, //营销账户类型ID
  251. "sa_brandid": data.sa_brandid, //品牌ID
  252. "sys_enterprise_financeid": data.sys_enterprise_financeid || 0, //合作企业财务信息ID(开票信息)
  253. //"sa_logiscompid": data.logiscomp.sa_logiscompid || 0, 物流公司档案ID
  254. "rec_contactsid": data.rec_contactsid || 0, //合作企业联系人表ID(收货信息)
  255. "type": data.type, //订单类型
  256. "typemx": data.typemx, // 明细分类,可选
  257. "remarks": data.remarks,
  258. "saler_hrid": data.saler_hrid, //销售人员hrid,业务员hrid
  259. "tradefield": data.tradefield, //必选
  260. "pay_enterpriseid": data.pay_enterpriseid, //结算单位
  261. "rebate_userate": data.accountclass.rebate_userate, //返利金使用比例
  262. };
  263. return new Promise((resolve, reject) => {
  264. _Http.basic({
  265. "id": 20221108111402,
  266. content
  267. }).then(res => {
  268. console.log("修改订单数据", res);
  269. if (res.msg != '成功') wx.showToast({
  270. title: res.msg,
  271. icon: "none"
  272. });
  273. resolve(res)
  274. })
  275. })
  276. },
  277. /* 修改订单备注 */
  278. changeRemarks(e) {
  279. let value = e.detail.value,
  280. remarks = this.data.detail.remarks,
  281. that = this;
  282. if (value == this.data.detail.remarks) return;
  283. wx.showModal({
  284. title: '提示',
  285. content: '是否确定修改订单备注?',
  286. complete: async (res) => {
  287. if (res.cancel) that.setData({
  288. "detail.remarks": remarks
  289. })
  290. if (res.confirm) {
  291. this.data.detail.remarks = value;
  292. let res = await that.changeDetail();
  293. that.setData({
  294. "detail.remarks": res.msg == '成功' ? value : remarks
  295. })
  296. }
  297. }
  298. })
  299. },
  300. /* 设置是否使用返利金 */
  301. changeRebateUsed() {
  302. if (this.isEdit()) return this.setData({
  303. detail: this.data.detail
  304. })
  305. let amount = (this.data.detail.order_rebate_userate * this.data.detail.amount).toFixed(2); //最大可用金额
  306. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  307. _Http.basic({
  308. "id": 20230218225002,
  309. "content": {
  310. "sa_orderid": this.data.sa_orderid, //订单金额
  311. "isused": this.data.detail.rebate_used == 1 ? 0 : 1, //是否使用
  312. "rebateamount": rebatebalance > amount ? amount : rebatebalance //返利金使用金额
  313. }
  314. }, false).then(res => {
  315. console.log('设置启用返利金', res)
  316. if (res.msg != '成功') {
  317. wx.showToast({
  318. title: res.msg,
  319. icon: "none"
  320. });
  321. this.setData({
  322. "detail.rebate_used": this.data.detail.rebate_used
  323. })
  324. return;
  325. }
  326. this.getDetail(true, false)
  327. })
  328. },
  329. /* 修改返利金 */
  330. setRebate_amount(e = 0) {
  331. let value = e.detail.value;
  332. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  333. value = value > rebatebalance ? rebatebalance : value;
  334. let amount = (this.data.detail.order_rebate_userate * this.data.detail.amount).toFixed(2); //最大可用金额
  335. _Http.basic({
  336. "id": 20230218225002,
  337. "content": {
  338. "sa_orderid": this.data.sa_orderid, //订单金额
  339. "isused": 1, //是否使用
  340. "rebateamount": value > amount ? amount : value
  341. }
  342. }, false).then(res => {
  343. console.log('设置返利金', res)
  344. if (res.msg != '成功') {
  345. wx.showToast({
  346. title: res.msg,
  347. icon: "none",
  348. mask: true
  349. });
  350. this.setData({
  351. "detail.accountclass.rebate_amount": this.data.detail.accountclass.rebate_amount
  352. })
  353. } else {
  354. this.setData({
  355. "detail.accountclass.rebate_amount": value
  356. })
  357. if (value > amount || amount == 0) wx.showToast({
  358. title: "返利金最大可使用" + amount + "元",
  359. icon: "none"
  360. })
  361. this.getDetail(true, false)
  362. }
  363. })
  364. },
  365. /* 删除订单 */
  366. deleteItem() {
  367. let that = this;
  368. wx.showModal({
  369. title: '提示',
  370. content: '是否确认删除订单?',
  371. complete: (res) => {
  372. if (res.confirm) _Http.basic({
  373. "id": 20221108152102,
  374. "content": {
  375. "sa_orderids": [
  376. that.data.sa_orderid
  377. ]
  378. }
  379. }).then(s => {
  380. console.log("删除订单", s)
  381. if (s.msg != '成功') return wx.showToast({
  382. title: s.msg,
  383. icon: "none"
  384. });
  385. wx.showToast({
  386. title: `成功删除${that.data.detail.sonum}订单`,
  387. icon: "none"
  388. });
  389. setTimeout(() => {
  390. wx.navigateBack()
  391. }, 500)
  392. })
  393. }
  394. })
  395. },
  396. /* 特殊订单预提交 */
  397. presubmission(e) {
  398. let that = this;
  399. let isrecheck = e.currentTarget.dataset.isrecheck == 1;
  400. wx.showModal({
  401. title: '提示',
  402. content: `是否确认${isrecheck?'预提交订单':'撤回预提交'}?`,
  403. complete: (res) => {
  404. if (res.confirm) _Http.basic({
  405. "id": 20230331152503,
  406. "content": {
  407. isrecheck,
  408. sa_orderid: that.data.sa_orderid
  409. },
  410. }).then(s => {
  411. console.log("预提交订单", s)
  412. wx.showToast({
  413. title: s.msg != '成功' ? s.msg : isrecheck ? '预提交成功' : '撤回预提交成功',
  414. icon: "none"
  415. });
  416. if (s.msg == '成功') that.setData({
  417. "detail.status": isrecheck ? "预提交" : '新建'
  418. })
  419. })
  420. }
  421. })
  422. },
  423. /* 提交订单 */
  424. submit() {
  425. let that = this;
  426. wx.showModal({
  427. title: '提示',
  428. content: '是否确认提交订单?',
  429. complete: (res) => {
  430. if (res.confirm) _Http.basic({
  431. "id": 20221108153402,
  432. "content": {
  433. sa_orderid: that.data.sa_orderid
  434. },
  435. }).then(s => {
  436. console.log("提交订单", s)
  437. wx.showToast({
  438. title: s.msg != '成功' ? s.msg : '提交成功',
  439. icon: "none"
  440. });
  441. if (s.msg == '成功') that.setData({
  442. "detail.status": "提交"
  443. })
  444. })
  445. }
  446. })
  447. },
  448. /* 判断是否可以编辑 */
  449. isEdit() {
  450. if (this.data.detail.status != '新建') wx.showToast({
  451. title: '当前订单状态不可设置!',
  452. icon: "none"
  453. });
  454. return this.data.detail.status != '新建' || this.data.detail.type == '特殊订单';
  455. },
  456. /* 拷贝订单 */
  457. copyItem() {
  458. let item = this.data.detail;
  459. wx.showModal({
  460. title: '提示',
  461. content: `是否确认复制${item.type}“${item.sonum}”`,
  462. complete: (res) => {
  463. if (res.confirm) _Http.basic({
  464. "id": 20230102144502,
  465. "content": {
  466. "sa_orderid": item.sa_orderid
  467. }
  468. }).then(res => {
  469. console.log("复制订单", res)
  470. if (res.msg != '成功') return wx.showToast({
  471. title: res.msg,
  472. icon: "none"
  473. });
  474. wx.showModal({
  475. title: '提示',
  476. content: `${item.type}复制成功 是否立即前往`,
  477. complete: (s) => {
  478. if (s.confirm) wx.redirectTo({
  479. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  480. })
  481. }
  482. })
  483. })
  484. }
  485. })
  486. },
  487. /* 设置项目订单品牌领域 */
  488. setBraned() {
  489. wx.navigateTo({
  490. url: './modules/setBrand/index?id=' + this.data.sa_orderid,
  491. })
  492. },
  493. onUnload() {
  494. let page = getCurrentPages().find(v => v.__route__ == "packageA/orderForm/index")
  495. if (page) page.updateList && page.updateList()
  496. }
  497. })