detail.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../utils/currency"),
  3. CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. isLeader: false, //是否为负责人
  10. tabsActive: 0, //tabs 选中项
  11. sa_contractid: "",
  12. tabsList: [{
  13. label: "详细信息",
  14. icon: "icon-tabxiangxixinxi1"
  15. }],
  16. tabbarList: [],
  17. loading: true
  18. },
  19. onLoad(options) {
  20. const appAuth = wx.getStorageSync('auth').wcontract;
  21. this.setData({
  22. sa_contractid: options.id,
  23. isAdmin: appAuth.options.some(v => v == "admin"), //是否具有管理权限
  24. options: appAuth.options, //权限列表
  25. istask: appAuth.istask
  26. })
  27. this.getDetail(true);
  28. },
  29. getDetail() {
  30. _Http.basic({
  31. "id": 20221121195102,
  32. "content": {
  33. nocache: true,
  34. "sa_contractid": this.data.sa_contractid
  35. },
  36. }).then(res => {
  37. console.log("合同详情", res)
  38. if (res.msg != '成功') return wx.showToast({
  39. title: res.msg,
  40. icon: "none"
  41. });
  42. let data = res.data,
  43. tabsList = this.data.tabsList,
  44. tabsActive = 0;
  45. this.getTags();
  46. this.getGroup();
  47. this.setTabbar(data.status, res.data.leader.some(some => some.userid == wx.getStorageSync('userMsg').userid));
  48. switch (data.type) {
  49. case "框架":
  50. data.type = '经销商合作协议'
  51. tabsList = tabsList.concat([{
  52. label: "产品明细折扣",
  53. icon: "icon-tabchanpin",
  54. model: '#PiscountProduct'
  55. }, {
  56. label: "产品类别折扣",
  57. icon: "icon-tabchanpinleibie",
  58. model: '#PiscountType'
  59. }, {
  60. label: "业绩目标",
  61. icon: "icon-tabrenwu",
  62. model: '#Objective'
  63. }, {
  64. label: "跟进动态",
  65. icon: "icon-tabgenjindongtai1",
  66. model: '#Trace'
  67. }]);
  68. tabsActive = 1;
  69. break;
  70. case "工具借用":
  71. data.type = '工具使用(借用)协议'
  72. tabsList = tabsList.concat([{
  73. label: "工具清单",
  74. icon: "icon-tabgongjuqingdan",
  75. model: '#Product'
  76. }, {
  77. label: "跟进动态",
  78. icon: "icon-tabgenjindongtai1",
  79. model: '#Trace'
  80. }])
  81. tabsActive = 1;
  82. break;
  83. case "居间":
  84. data.type = '居间协议'
  85. break;
  86. case "项目":
  87. /* {
  88. label: "合同条款",
  89. num: 132
  90. }, */
  91. data.type = data.typemx + '项目协议'
  92. tabsList = tabsList.concat([{
  93. label: "产品明细折扣",
  94. icon: "icon-tabchanpin",
  95. model: '#Product'
  96. }, {
  97. label: "产品类别折扣",
  98. icon: "icon-tabchanpinleibie",
  99. model: '#PiscountType'
  100. }, {
  101. label: "跟进动态",
  102. icon: "icon-tabgenjindongtai1"
  103. }]);
  104. tabsActive = 1;
  105. break;
  106. };
  107. if (this.data.istask) tabsList.push({
  108. label: "任务",
  109. icon: "icon-tabrenwu",
  110. model: "#Work"
  111. })
  112. this.setData({
  113. detail: data,
  114. loading: false,
  115. list2: [{
  116. label: "创建人",
  117. value: data.createby
  118. }, {
  119. label: "创建时间",
  120. value: data.createdate
  121. }, {
  122. label: "最近编辑人",
  123. value: data.changeby
  124. }, {
  125. label: "最近编辑时间",
  126. value: data.changedate
  127. }, {
  128. label: "提交人",
  129. value: data.submitby
  130. }, {
  131. label: "提交时间",
  132. value: data.submitdate
  133. }, {
  134. label: "审核人",
  135. value: data.checkby
  136. }, {
  137. label: "审核时间",
  138. value: data.checkdate
  139. }, {
  140. label: "作废原因",
  141. value: data.leader.deletereason
  142. }, {
  143. label: "转手次数",
  144. value: data.leader[0].leadernum
  145. }],
  146. tabsList,
  147. tabsActive,
  148. });
  149. this.setDetail(data);
  150. this.partialRenewal();
  151. })
  152. },
  153. /* 设置tabbar */
  154. async setTabbar(status, Leader) {
  155. let isLeader = Leader,
  156. isAdmin = this.data.isAdmin,
  157. editdataleader = true,
  158. tabbarList = [{
  159. icon: "icon-genjin",
  160. label: "跟进"
  161. }];
  162. if (!isLeader) {
  163. let s = await getApp().agentOrNot("sa_contract", this.data.sa_contractid);
  164. isLeader = s.data.editable == 1;
  165. editdataleader = s.data.editdataleader == 1;
  166. }
  167. if (status != '已终止' && status != '已过期') {
  168. if (isAdmin) tabbarList = [{
  169. icon: "icon-genjin",
  170. label: "审核"
  171. }, {
  172. icon: "icon-genjin",
  173. label: "反审核"
  174. }].concat(tabbarList);
  175. if (isLeader || isAdmin) {
  176. if (editdataleader) tabbarList.unshift({
  177. icon: "icon-zhuanyi",
  178. label: "更换负责人"
  179. });
  180. tabbarList = [{
  181. icon: "icon-shanchu",
  182. label: "作废"
  183. }].concat(tabbarList)
  184. if (status == '新建') {
  185. tabbarList.push({
  186. icon: "icon-bianji",
  187. label: "编辑"
  188. })
  189. tabbarList.unshift({
  190. icon: "icon-genjin",
  191. label: '提交'
  192. })
  193. } else if (status == '已提交') {
  194. tabbarList.unshift({
  195. icon: "icon-genjin",
  196. label: '撤回'
  197. })
  198. } else if (status == '审核') {
  199. tabbarList.unshift({
  200. icon: "icon-genjin",
  201. label: "终止"
  202. })
  203. }
  204. };
  205. } else {
  206. tabbarList = [{
  207. icon: "icon-shanchu",
  208. label: "作废"
  209. }];
  210. }
  211. this.setData({
  212. isLeader,
  213. tabbarList,
  214. editdataleader
  215. });
  216. },
  217. /* 设置详情信息 */
  218. setDetail(data) {
  219. let briefs = [{
  220. label: "合同编号",
  221. value: data.billno
  222. }, {
  223. label: "合同类型",
  224. value: data.type
  225. }, {
  226. label: "经销商",
  227. value: data.enterprisename
  228. }, {
  229. label: "整体折扣",
  230. value: data.discountrate * 100 + "%"
  231. }, {
  232. label: "签约日期",
  233. value: data.signdate
  234. }, {
  235. label: "状态",
  236. value: data.status
  237. }],
  238. list1 = [{
  239. label: "合同标题",
  240. value: data.title
  241. }, {
  242. label: "合同编号",
  243. value: data.billno
  244. }, {
  245. label: "合同类型",
  246. value: data.type
  247. }, {
  248. label: "签约日期",
  249. value: data.signdate
  250. }, {
  251. label: "合同有效期",
  252. value: data.begdate + ' 至 ' + data.enddate
  253. }, {
  254. label: "合同模板",
  255. value: data.type
  256. }, {
  257. label: "合同描述",
  258. value: data.remarks
  259. }, {
  260. label: "负责人",
  261. value: data.leader[0].name
  262. }, {
  263. label: "状态",
  264. value: data.status
  265. }];
  266. if (data.typemx) {
  267. console.log(data)
  268. briefs.splice(3, 0, {
  269. label: "项目",
  270. value: data.projectname
  271. })
  272. briefs.splice(4, 0, {
  273. label: "项目编号",
  274. value: data.projectnum
  275. })
  276. briefs.splice(5, 0, {
  277. label: "有效期",
  278. value: data.begdate + ' 至 ' + data.enddate
  279. })
  280. briefs.splice(6, 1)
  281. briefs.splice(7, 0, {
  282. label: "签约金额(元)",
  283. value: CNY(data.signamount)
  284. })
  285. briefs.splice(7, 0, {
  286. label: "折扣(%)",
  287. value: data.discountrate * 100 + "%"
  288. })
  289. list1.splice(3, 0, {
  290. label: data.typemx == '直销' ? '客户' : "经销商",
  291. value: data.enterprisename
  292. })
  293. list1.splice(4, 0, {
  294. label: "项目",
  295. value: data.projectname
  296. })
  297. list1.splice(5, 0, {
  298. label: "品牌",
  299. value: data.brandname
  300. })
  301. list1.splice(6, 0, {
  302. label: "领域",
  303. value: data.tradefields
  304. })
  305. list1.splice(7, 0, {
  306. label: "项目编号",
  307. value: data.projectnum
  308. })
  309. list1.splice(8, 0, {
  310. label: "项目地址",
  311. value: data.address
  312. })
  313. list1.splice(9, 0, {
  314. label: "收货人",
  315. value: data.name
  316. })
  317. list1.splice(10, 0, {
  318. label: "收货人电话",
  319. value: data.phonenumber
  320. })
  321. list1.splice(11, 0, {
  322. label: "业务员",
  323. value: data.salername
  324. })
  325. list1.splice(12, 0, {
  326. label: "签约金额",
  327. value: CNY(data.signamount)
  328. })
  329. list1.splice(13, 0, {
  330. label: "折扣(%)",
  331. value: data.discountrate * 100 + "%"
  332. })
  333. if (data.typemx == '直销') briefs[2].label = '客户';
  334. } else {
  335. switch (data.type) {
  336. case "居间协议":
  337. briefs.splice(2, 1, {
  338. label: "居间服务商",
  339. value: data.enterprisename
  340. })
  341. briefs.splice(3, 0, {
  342. label: "项目",
  343. value: data.projectname
  344. })
  345. briefs.splice(4, 0, {
  346. label: "项目编号",
  347. value: data.projectnum
  348. })
  349. briefs.splice(5, 1, {
  350. label: data.calculatemodel == 1 ? '订单金额比例' : '产品折扣',
  351. value: data.calculatemodel == 1 ? data.orderratio * 100 + '%' : data.productdiscount * 100 + '%'
  352. })
  353. briefs.splice(3, 0, {
  354. label: "项目合同",
  355. value: data.ascription_title
  356. })
  357. briefs.splice(7, 0, {
  358. label: "合同有效期",
  359. value: data.begdate + "-" + data.enddate
  360. })
  361. list1.splice(3, 0, {
  362. label: "居间服务商",
  363. value: data.enterprisename
  364. })
  365. list1.splice(4, 0, {
  366. label: "项目合同",
  367. value: data.ascription_title
  368. })
  369. list1.splice(5, 0, {
  370. label: "项目",
  371. value: data.projectname
  372. })
  373. list1.splice(6, 0, {
  374. label: "项目编号",
  375. value: data.projectnum
  376. })
  377. list1.splice(8, 0, {
  378. label: data.calculatemodel == 1 ? '订单金额比例' : '居间产品折扣',
  379. value: data.calculatemodel == 1 ? data.orderratio * 100 + '%' : data.productdiscount * 100 + '%'
  380. })
  381. break;
  382. case "工具使用(借用)协议":
  383. briefs.splice(2, 1, {
  384. label: "客户",
  385. value: data.enterprisename
  386. })
  387. briefs.splice(3, 1, {
  388. label: "单套价格",
  389. value: data.signamount
  390. })
  391. briefs.splice(5, 0, {
  392. label: "合同有效期",
  393. value: data.begdate + ' 至 ' + data.enddate
  394. })
  395. list1.splice(3, 0, {
  396. label: "客户",
  397. value: data.enterprisename
  398. })
  399. list1.splice(4, 0, {
  400. label: "单套价格",
  401. value: data.signamount
  402. })
  403. break;
  404. case "经销商合作协议":
  405. briefs[3].label = '折扣(%)';
  406. briefs.splice(3, 0, {
  407. label: "签约金额(元)",
  408. value: CNY(data.signamount)
  409. })
  410. list1.splice(3, 0, {
  411. label: "经销商",
  412. value: data.enterprisename
  413. })
  414. list1.splice(4, 0, {
  415. label: "签约金额(元)",
  416. value: CNY(data.signamount)
  417. })
  418. list1.splice(5, 0, {
  419. label: "折扣(%)",
  420. value: data.discountrate * 100 + "%"
  421. })
  422. list1.splice(6, 0, {
  423. label: "品牌",
  424. value: data.brandname
  425. })
  426. list1.splice(7, 0, {
  427. label: "领域",
  428. value: data.tradefields
  429. })
  430. break;
  431. }
  432. }
  433. this.setData({
  434. briefs,
  435. list1
  436. })
  437. },
  438. //tabs 切换
  439. tabsChange({
  440. detail
  441. }) {
  442. this.setData({
  443. tabsActive: detail
  444. });
  445. this.partialRenewal();
  446. },
  447. //更新标签
  448. getTags() {
  449. this.selectComponent("#Tags").getTags();
  450. },
  451. //更新团队成员
  452. getGroup() {
  453. this.selectComponent("#Group").getList();
  454. },
  455. //局部数据更新 tabs
  456. partialRenewal(init = false) {
  457. let model = this.data.tabsList[this.data.tabsActive].model;
  458. if (model) {
  459. let Component = this.selectComponent(model),
  460. {
  461. total,
  462. pageNumber,
  463. pageTotal
  464. } = Component.data.content,
  465. id = this.data.sa_contractid;
  466. if (total == null || init) {
  467. Component.getList(id, init);
  468. } else if (pageNumber <= pageTotal) {
  469. Component.getList(id, false);
  470. }
  471. }
  472. },
  473. onReachBottom() {
  474. this.partialRenewal();
  475. },
  476. //详情按钮回调
  477. tabbarOnClick({
  478. detail
  479. }) {
  480. let data = this.data.detail,
  481. that = this;
  482. switch (detail.label) {
  483. case "终止":
  484. wx.showModal({
  485. title: '提示',
  486. content: `是否确定终止当前协议`,
  487. complete: (res) => {
  488. if (res.confirm) _Http.basic({
  489. "id": 20221212102802,
  490. "content": {
  491. "sa_contractid": that.data.sa_contractid
  492. }
  493. }).then(res => {
  494. console.log("提交报价单", res)
  495. wx.showToast({
  496. title: res.msg == '成功' ? "已终止" : res.msg,
  497. icon: "none"
  498. })
  499. if (res.msg == '成功') setTimeout(() => {
  500. that.getDetail();
  501. }, 300)
  502. })
  503. }
  504. })
  505. break;
  506. case "提交":
  507. if (data.status != '新建') return wx.showToast({
  508. title: '当前状态不可提交!',
  509. icon: "none"
  510. })
  511. wx.showModal({
  512. title: '提示',
  513. content: `是否确定提交当前协议,提交后禁止使用部分功能`,
  514. complete: (res) => {
  515. if (res.confirm) _Http.basic({
  516. "id": 20221121202802,
  517. "content": {
  518. "sa_contractids": [that.data.sa_contractid]
  519. }
  520. }).then(res => {
  521. console.log("提交报价单", res)
  522. wx.showToast({
  523. title: res.msg == '成功' ? "提交成功" : res.msg,
  524. icon: "none"
  525. })
  526. if (res.msg == '成功') setTimeout(() => {
  527. that.getDetail();
  528. }, 300)
  529. })
  530. }
  531. })
  532. break;
  533. case "审核":
  534. if (data.status != '已提交') return wx.showToast({
  535. title: '当前状态不可审核!',
  536. icon: "none"
  537. })
  538. wx.showModal({
  539. title: '提示',
  540. content: `是否通过当前协议`,
  541. complete: (res) => {
  542. if (res.confirm) _Http.basic({
  543. "id": 20221121203102,
  544. "version": 1,
  545. "content": {
  546. "type": 1, //0:不通过,1:通过
  547. "sa_contractids": [that.data.sa_contractid]
  548. }
  549. }).then(res => {
  550. console.log("审核合同", res)
  551. wx.showToast({
  552. title: res.msg == '成功' ? "审核成功" : res.msg,
  553. icon: "none"
  554. })
  555. if (res.msg == '成功') setTimeout(() => {
  556. that.getDetail();
  557. }, 300)
  558. })
  559. }
  560. })
  561. break;
  562. case "撤回":
  563. if (data.status != '已提交') return wx.showToast({
  564. title: '当前状态不可撤回!',
  565. icon: "none"
  566. })
  567. wx.showModal({
  568. title: '提示',
  569. content: `是否撤回审核当前协议`,
  570. complete: (res) => {
  571. if (res.confirm) _Http.basic({
  572. "id": 20230130091502,
  573. "content": {
  574. "sa_contractid": that.data.sa_contractid,
  575. }
  576. }).then(res => {
  577. console.log("撤回审核合同", res)
  578. wx.showToast({
  579. title: res.msg == '成功' ? "撤回审核成功" : res.msg,
  580. icon: "none"
  581. })
  582. if (res.msg == '成功') setTimeout(() => {
  583. that.getDetail();
  584. }, 300)
  585. })
  586. }
  587. })
  588. break;
  589. case "反审核":
  590. if (data.status == '新建') return wx.showToast({
  591. title: '当前状态不可反审核!',
  592. icon: "none"
  593. })
  594. wx.showModal({
  595. title: '提示',
  596. content: `是否反审核当前协议`,
  597. complete: (res) => {
  598. if (res.confirm) _Http.basic({
  599. "id": 20221212135402,
  600. "content": {
  601. "sa_contractid": that.data.sa_contractid,
  602. }
  603. }).then(res => {
  604. console.log("反审核合同", res)
  605. wx.showToast({
  606. title: res.msg == '成功' ? "反审核成功" : res.msg,
  607. icon: "none"
  608. })
  609. if (res.msg == '成功') setTimeout(() => {
  610. that.getDetail();
  611. }, 300)
  612. })
  613. }
  614. })
  615. break;
  616. case "跟进":
  617. wx.navigateTo({
  618. url: `/packageA/setclient/modules/trace/add/index?ownertable=sa_contract&ownerid=${data.sa_contractid}`,
  619. })
  620. break;
  621. case "作废":
  622. wx.showModal({
  623. title: '提示',
  624. content: '是否确认作废该协议?',
  625. complete: ({
  626. confirm
  627. }) => {
  628. if (confirm) _Http.basic({
  629. "id": 20221121202502,
  630. "version": 1,
  631. "content": {
  632. "sa_contractids": [this.data.detail.sa_contractid]
  633. }
  634. }).then(res => {
  635. wx.showToast({
  636. title: res.msg == '成功' ? '已作废协议' : res.msg,
  637. icon: "none"
  638. });
  639. if (res.msg == '成功') {
  640. setTimeout(() => {
  641. getCurrentPages().forEach(v => {
  642. if (v.__route__ == 'packageA/contract/index') {
  643. v.setData({
  644. list: v.data.list.filter(value => value.sa_contractid != this.data.detail.sa_contractid),
  645. 'content.total': v.data.content.total - 1
  646. })
  647. }
  648. })
  649. wx.navigateBack();
  650. }, 300)
  651. }
  652. })
  653. }
  654. })
  655. break;
  656. case "编辑":
  657. this.toEdit();
  658. break;
  659. case "更换负责人":
  660. wx.navigateTo({
  661. url: `/pages/group/select?data=${JSON.stringify({
  662. ownertable:"sa_contract",
  663. ownerid:data.sa_contractid,
  664. })}&radio=true&principal=true`,
  665. })
  666. break;
  667. }
  668. },
  669. toEdit() {
  670. let data = this.data.detail,
  671. type = null;
  672. data.invaliddate = [data.begdate, data.enddate]
  673. data.sys_enterpriseid = [data.enterprisename, [data.sys_enterpriseid]];
  674. data.sa_projectid = [data.projectname, [data.sa_projectid]];
  675. switch (data.type) {
  676. case "经销商合作协议":
  677. type = "type1"
  678. break;
  679. case "经销项目协议":
  680. type = "type2"
  681. break;
  682. case "直销项目协议":
  683. type = "type3"
  684. break;
  685. case "居间协议":
  686. data.ascription_contractid = [data.ascription_title, [data.ascription_contractid]];
  687. data.radios = data.calculatemodel + "";
  688. type = "type4"
  689. break;
  690. case "工具使用(借用)协议":
  691. type = "type5"
  692. break;
  693. };
  694. if (type) wx.navigateTo({
  695. url: `/packageA/contract/add/${type}/index?data=${JSON.stringify(data)}`,
  696. })
  697. },
  698. /* 更换负责人 */
  699. handelSubmit(arr) {
  700. const that = this;
  701. wx.showModal({
  702. title: '提示',
  703. content: '是否确认更换负责人',
  704. complete: ({
  705. confirm
  706. }) => {
  707. if (confirm) _Http.basic({
  708. "id": 20220930103701,
  709. "content": {
  710. ownertable: "sa_contract",
  711. ownerid: that.data.detail.sa_contractid,
  712. userid: arr[0]
  713. }
  714. }).then(res => {
  715. console.log("更换负责人", res)
  716. if (res.msg != '成功') return wx.showToast({
  717. title: res.data,
  718. icon: "none"
  719. });
  720. wx.showToast({
  721. title: '更换成功!',
  722. icon: "none"
  723. });
  724. setTimeout(() => {
  725. that.getDetail();
  726. wx.navigateBack();
  727. }, 300)
  728. })
  729. }
  730. })
  731. },
  732. onUnload() {
  733. let page = getCurrentPages().find(v => v.__route__ == 'packageA/contract/index');
  734. if (!page) return;
  735. let content = JSON.parse(JSON.stringify(page.data.content));
  736. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  737. content.pageNumber = 1;
  738. _Http.basic({
  739. id: 20221121201502,
  740. content
  741. }).then(res => {
  742. console.log("更新合同列表", res);
  743. if (res.msg == '成功') page.setData({
  744. list: res.data,
  745. "content.total": res.total
  746. })
  747. })
  748. }
  749. })