detail.js 20 KB

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