detail.js 13 KB

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