detail.js 19 KB

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