detail.js 17 KB

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