refund.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. reasonData: [],
  6. current: 1,
  7. imgPath: util.config.imgPath,
  8. datas: {},
  9. reason: '',
  10. showtext: false,
  11. mask: false,
  12. refundBack: '',
  13. refundpwd: '',
  14. orderid: '',
  15. status: '',
  16. groupId: '',
  17. reasonList: [],
  18. reasonIndex: 0,
  19. default: "请选择 >",
  20. // 控制sku
  21. showSku: false,
  22. refundShow: false,
  23. oid: "",
  24. orderInfo: {},
  25. codeShow: false,
  26. query: {
  27. orderid: '',
  28. otype: 0,
  29. presellStatus: 0
  30. },
  31. showGoodsRecom: false,
  32. index: 0,
  33. changeMeal_oid: "",
  34. type: 0,
  35. // 支付宝户号绑定内容
  36. AlipayNum: "",
  37. // 支付宝账号绑定内容
  38. accountNum: "",
  39. // 银行卡户名
  40. carName: "",
  41. // 银行名称
  42. bankName: "",
  43. // 银行卡号
  44. BankcardNo: "",
  45. // 银行开户行
  46. Bankofdeposit: "",
  47. password:''
  48. },
  49. isOK() {
  50. this.setData({
  51. codeShow: false
  52. })
  53. },
  54. // 二维码弹框
  55. showCode() {
  56. console.log("执行");
  57. this.setData({
  58. showSku: false,
  59. codeShow: true
  60. })
  61. },
  62. // 换场次中点击退款条例
  63. showFund() {
  64. this.setData({
  65. showSku: false,
  66. refundShow: true,
  67. type: this.data.orderInfo.refundRule
  68. })
  69. },
  70. changedeposit(e) {
  71. this.setData({
  72. Bankofdeposit: e.detail.value
  73. })
  74. },
  75. ChangeBankcardNo(e) {
  76. this.setData({
  77. BankcardNo: e.detail.value
  78. })
  79. },
  80. closeRefund() {
  81. this.setData({
  82. refundShow: false
  83. })
  84. },
  85. changeName(e) {
  86. this.setData({
  87. bankName: e.detail.value
  88. })
  89. },
  90. changebankName(e) {
  91. this.setData({
  92. carName: e.detail.value
  93. })
  94. },
  95. changeaccount(e) {
  96. this.setData({
  97. accountNum: e.detail.value
  98. })
  99. },
  100. changeAlipay(e) {
  101. // console.log(e.detail.value);
  102. this.setData({
  103. AlipayNum: e.detail.value
  104. })
  105. },
  106. showProp() {
  107. // if(this.data.orderInfo.refundRule==1){
  108. // this.data.type=this.data.orderInfo.refundRule
  109. // }
  110. // console.log(this.data.orderInfo);
  111. console.log(this.data.orderInfo.refundRule);
  112. this.setData({
  113. refundShow: true,
  114. type: this.data.orderInfo.refundRule
  115. // type:3
  116. })
  117. },
  118. // 关闭弹框
  119. closeSku() {
  120. this.setData({
  121. showSku: false,
  122. changeMeal_oid: ''
  123. });
  124. },
  125. // 点击换场次
  126. confirmChange(e) {
  127. console.log(this.data.orderInfo);
  128. let that = this,
  129. data = {};
  130. data.newAlipayId = e.detail ? e.detail : '';
  131. data.oid = that.data.changeMeal_oid;
  132. console.log(data);
  133. util.ajax({
  134. func: "v2/order/getRefundPriceByOid",
  135. data: {
  136. oid: that.data.info.subOrders[that.data.index].oid,
  137. }
  138. }, function (res) {
  139. data.priceInfo = that.data.orderInfo
  140. data.password = that.data.password
  141. console.log(data);
  142. if (res.code == 0) {
  143. util.ajax({
  144. func: "v2/order/change/audit",
  145. data,
  146. method: 'POST',
  147. load: false
  148. }, function (res) {
  149. if (res.code == 0) {
  150. util.showTips('已发起申请,请耐心等待宝大大审核~');
  151. that.setData({
  152. showSku: false,
  153. changeMeal_oid: ''
  154. })
  155. that.getData1();
  156. } else {
  157. console.log(data);
  158. util.showTips(res.reason);
  159. }
  160. })
  161. } else if (res.code == -10) {
  162. util.showTips('不满足更换场次要求,请联系宝大大处理');
  163. } else {
  164. console.log(data);
  165. util.showTips(res.reason);
  166. }
  167. })
  168. },
  169. // 退款换场次
  170. changeMeals(e) {
  171. console.log(this.data.info.subOrders[this.data.index]);
  172. let status = this.data.info.subOrders[this.data.index].changeStatus,
  173. oid = this.data.info.subOrders[this.data.index].oid;
  174. if (status == 1) {
  175. util.showTips('已提交申请,请耐心等待宝大大审核~');
  176. return false;
  177. } else {
  178. let that = this
  179. this.OrderInfo(oid)
  180. this.setData({
  181. showSku: true,
  182. changeMeal_oid: oid
  183. });
  184. console.log(this.data.changeMeal_oid);
  185. }
  186. },
  187. // 获取换场次信息
  188. getData1(val) {
  189. let that = this;
  190. let data = {};
  191. if (!util.isEmpty(that.data.orderid)) {
  192. data.orderid = that.data.orderid;
  193. }
  194. if (!util.isEmpty((val || that.data.presellStatus))) {
  195. data.presellStatus = val || that.data.presellStatus
  196. }
  197. if (!util.isEmpty(that.data.otype)) {
  198. data.otype = that.data.otype
  199. }
  200. console.log(data);
  201. util.ajax({
  202. func: "v2/order/detail",
  203. data,
  204. load: false
  205. }, function (res) {
  206. console.log(res);
  207. if (res.code == 0) {
  208. let datas = res.data;
  209. datas.timeContrast = util.timeContrast(datas.stopBuy);
  210. if (!util.isEmpty(datas.mailAddress)) {
  211. var info = datas.mailAddress.split(" ");
  212. datas.mail = {};
  213. datas.mail.name = info[0] || "";
  214. datas.mail.postMobile = info[1] || "";
  215. datas.mail.province = info[2] || "";
  216. datas.mail.address = datas.mail.province.replace("/", "") + info[3];
  217. }
  218. if (datas.comment) {
  219. datas.comment.tag = datas.comment.content.match(/#([^#]+)#/g) ? datas.comment.content.match(/#([^#]+)#/g).join("") : '';
  220. datas.comment.content = datas.comment.content.replace(/#([^#]+)#/g, "").replace(/<br\/>/g, '\n');
  221. if (datas.comment.additionalComment.content) {
  222. datas.comment.additionalComment.content = datas.comment.additionalComment.content.replace(/<br\/>/g, '\n')
  223. }
  224. }
  225. if (datas.saleTime && datas.presellPaymentDeadline) {
  226. datas.startTime = util.formatDate(util.formatUnixtimestamp(datas.saleTime), 'MM月dd日 hh:mm', false);
  227. datas.endTime = util.formatDate(util.formatUnixtimestamp(datas.presellPaymentDeadline), 'MM月dd日 hh:mm', false);
  228. }
  229. let num = 0,
  230. length = (datas.groupinfo.discount && !util.isEmpty(datas.groupinfo.discount.users)) ? datas.groupinfo.discount.users.length : 0;
  231. if (length > 0) {
  232. datas.groupinfo.discount.users.forEach(el => {
  233. num = el.status == 4 ? num++ : num;
  234. if (el.status == 4) {
  235. num++;
  236. }
  237. that.setData({
  238. iconView: num == 0 ? false : true
  239. });
  240. });
  241. }
  242. that.setData({
  243. info: datas
  244. });
  245. // console.log(that.data.info.subOrders[that.data.index].changeStatus);
  246. that.getGoodsRecommend()
  247. if (datas.groupinfo.gstatus == 0 && datas.groupinfo.discount && datas.groupinfo.discount.status == 0 && datas.groupinfo.discount.deadline > 0) {
  248. that.data.info.groupinfo.discount.deadline = that.data.info.groupinfo.discount.deadline - new Date().getTime();
  249. that.updateTime();
  250. }
  251. } else
  252. util.showTips(res.reason);
  253. });
  254. },
  255. getGoodsRecommend() {
  256. let that = this;
  257. util.getGoodsRecommend(this.data.info.aid).then(res => {
  258. that.setData({
  259. showGoodsRecom: res
  260. })
  261. })
  262. },
  263. // 获取订单信息
  264. OrderInfo(oid) {
  265. console.log(this.data.oid);
  266. let that = this
  267. util.ajax({
  268. func: "v2/order/getRefundPriceByOid",
  269. data: {
  270. "oid": that.data.oid
  271. }
  272. }, function (res) {
  273. console.log(res);
  274. if (res.code == 0) {
  275. that.setData({
  276. orderInfo: res.data,
  277. changeMeal_oid: oid
  278. })
  279. } else if (res.code == -10) {
  280. util.showTips('不满足更换场次要求,请联系宝大大处理');
  281. that.setData({
  282. showSku: false,
  283. changeMeal_oid: oid
  284. });
  285. } else {
  286. util.showTips(res.reason)
  287. }
  288. })
  289. },
  290. onLoad(options) {
  291. console.log(options);
  292. this.setData({
  293. index: options.index,
  294. oid: options.oid,
  295. refundpwd: options.refundpwd,
  296. orderid: options.orderid,
  297. status: options.refundStatus,
  298. groupId: options.groupid || '',
  299. password:options.refundpwd
  300. });
  301. if (options.atype != "1") {
  302. this.OrderInfo()
  303. } else {
  304. this.setData({
  305. atype: options.atype
  306. })
  307. }
  308. let reasonData = [],
  309. current = 1;
  310. if (this.data.status == 15) {
  311. current = 4;
  312. }
  313. this.setData({
  314. current
  315. })
  316. this.getData();
  317. },
  318. onShow() {
  319. if (this.data.atype != "1") {
  320. this.OrderInfo()
  321. this.getData1()
  322. }
  323. },
  324. // 切换退款原因
  325. changeReason(e) {
  326. console.log(e.detail.value);
  327. console.log(this.data.reasonData[e.detail.value].type == 0);
  328. if (this.data.reasonData[e.detail.value].type == 0) {
  329. this.setData({
  330. showtext: true
  331. })
  332. } else {
  333. this.setData({
  334. showtext: false
  335. })
  336. }
  337. this.data.reasonIndex = e.detail.value
  338. this.setData({
  339. reasonIndex: this.data.reasonIndex,
  340. default: this.data.reasonList[this.data.reasonIndex]
  341. });
  342. },
  343. getData() {
  344. let that = this;
  345. let current = 0
  346. util.ajax({
  347. func: "v2/order/detail",
  348. data: {
  349. "orderid": that.data.orderid,
  350. "otype": 0,
  351. "password": that.data.refundpwd || "",
  352. }
  353. }, function (res) {
  354. if (res.code == 0) {
  355. let reasonData = [];
  356. if (res.data.atype == '1') { //电商
  357. reasonData = [{
  358. type: 5,
  359. txt: '不喜欢/不想要'
  360. },
  361. {
  362. type: 6,
  363. txt: '质量问题'
  364. },
  365. {
  366. type: 0,
  367. txt: '其他原因'
  368. }
  369. ];
  370. } else {
  371. if (that.data.status == 15) {
  372. reasonData = [{
  373. type: 4,
  374. txt: '候补退款'
  375. }], current = 4;
  376. } else {
  377. reasonData = [{
  378. type: 1,
  379. txt: '行程有变'
  380. },
  381. {
  382. type: 2,
  383. txt: '买多了/买错了'
  384. },
  385. {
  386. type: 3,
  387. txt: '孩子突发身体原因'
  388. },
  389. {
  390. type: 0,
  391. txt: '其他原因'
  392. }
  393. ];
  394. }
  395. }
  396. reasonData.forEach(item => {
  397. console.log(item);
  398. that.data.reasonList.push(item.txt)
  399. })
  400. if (reasonData.length == 1) {
  401. that.data.default = "候补退款"
  402. }
  403. that.setData({
  404. default: that.data.default,
  405. datas: res.data,
  406. reasonData,
  407. current: reasonData[0].type,
  408. reasonList: that.data.reasonList
  409. });
  410. }
  411. })
  412. },
  413. backBtn() {
  414. wx.redirectTo({
  415. url: '/pages/order/index/order?otype=2'
  416. })
  417. },
  418. confirm(e) {
  419. console.log(e);
  420. this.setData({
  421. reason: e.detail.value
  422. });
  423. },
  424. bindreason(e) {
  425. console.log(e);
  426. this.setData({
  427. current: e.currentTarget.dataset.type
  428. });
  429. },
  430. img() {
  431. this.data.datas.logo = '/images/noimg.png';
  432. this.setData({
  433. datas: this.data.datas
  434. });
  435. },
  436. refundRequest() {
  437. let that = this,
  438. reason = this.data.reason,
  439. current = this.data.current;
  440. console.log(current);
  441. let type = 0
  442. if (this.data.default == "行程有变") {
  443. type = 1
  444. } else if (this.data.default == "买多了/买错了") {
  445. type = 2
  446. } else if (this.data.default == "孩子突发身体原因") {
  447. type = 3
  448. } else if (this.data.default == "其他原因") {
  449. type = 0
  450. } else if (this.data.default == "候补退款") {
  451. type = 4
  452. } else if (this.data.default == "质量问题") {
  453. type = 6
  454. } else if (this.data.default == "不喜欢/不想要") {
  455. type = 5
  456. }
  457. if (this.data.default == "请选择 >" || type == -1) {
  458. util.showTips("请选择退款原因")
  459. return false
  460. }
  461. if (this.data.showtext == true && util.isEmpty(reason)) {
  462. util.showTips("请填写退款原因")
  463. return false
  464. }
  465. if (current == 0 && reason == '') {
  466. util.showTips('请输入退款原因。');
  467. return false;
  468. }
  469. if (this.data.dayBeforeStart <= 0) {
  470. util.showTips("活动已开始,无法提交退款申请")
  471. wx.navigateBack({
  472. delta: 1,
  473. })
  474. return
  475. }
  476. if (this.data.current == 1 && this.data.orderInfo.overdue == 1) {
  477. if (util.isEmpty(this.data.AlipayNum)) {
  478. util.showTips("支付宝户号不能为空")
  479. return
  480. }
  481. if (util.isEmpty(this.data.accountNum)) {
  482. util.showTips("支付宝账号不能为空")
  483. return
  484. }
  485. } else if (this.data.current == 2 && this.data.orderInfo.overdue == 1) {
  486. if (util.isEmpty(this.data.carName)) {
  487. util.showTips("卡户名不能为空")
  488. return
  489. }
  490. if (util.isEmpty(this.data.bankName)) {
  491. util.showTips("银行名称不能为空")
  492. return
  493. }
  494. if (util.isEmpty(this.data.BankcardNo)) {
  495. util.showTips("银行卡号不能为空")
  496. return
  497. }
  498. if (util.isEmpty(this.data.Bankofdeposit)) {
  499. util.showTips("开户行不能为空")
  500. return
  501. }
  502. }
  503. let desc = ""
  504. if (this.data.current == 1) {
  505. desc = "支付宝"
  506. } else if (this.data.current == 2) {
  507. desc = "银行卡"
  508. }
  509. console.log(that.data.orderInfo);
  510. util.ajax({
  511. func: "order/commit_refund",
  512. data: {
  513. "reasonType": type,
  514. "reason": reason,
  515. "orderid": that.data.orderid,
  516. "password": that.data.refundpwd || "",
  517. "type": '0',
  518. "priceInfo": that.data.orderInfo,
  519. "receiveAccount": that.data.orderInfo.overdue == 0 ? '' : (that.data.current == 1 ? "支付宝" + " " + that.data.AlipayNum + " " + that.data.accountNum : "银行卡" + " " + that.data.carName + " " + that.data.bankName + " " + that.data.BankcardNo + " " + that.data.Bankofdeposit)
  520. },
  521. method: "POST"
  522. }, function (res) {
  523. console.log(res);
  524. if (res.code == 0) {
  525. wx.setStorageSync('_REFUND_', 'REFUND');
  526. that.setData({
  527. refundBack: res.reason,
  528. mask: true
  529. })
  530. } else if (res.code == -10) {
  531. wx.showModal({
  532. title: "提示",
  533. content: res.reason,
  534. success(res) {
  535. if (res.confirm) {
  536. wx.navigateBack({
  537. delta: 1,
  538. })
  539. } else if (res.cancel) {
  540. console.log('用户点击取消')
  541. }
  542. }
  543. });
  544. } else if (res.code == -11) {
  545. wx.showModal({
  546. title: "提示",
  547. content: res.reason,
  548. showCancel: false,
  549. success: function (res) {
  550. if (res.confirm) {
  551. that.onLoad({
  552. index: that.data.index,
  553. oid: that.data.oid,
  554. refundpwd: that.data.refundpwd,
  555. orderid: that.data.orderid,
  556. status: that.data.refundStatus,
  557. groupId: that.data.groupid || ''
  558. })
  559. // that.onReady()
  560. }
  561. }
  562. });
  563. } else {
  564. wx.showModal({
  565. title: "提示",
  566. content: res.reason,
  567. showCancel: false,
  568. success: function (res) {
  569. if (res.confirm) {
  570. wx.navigateBack({
  571. delta: 1,
  572. })
  573. }
  574. }
  575. });
  576. }
  577. });
  578. },
  579. onReady() {
  580. }
  581. })