refund.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. defaultText: "请选择 >",
  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. that.nps();
  226. if (datas.saleTime && datas.presellPaymentDeadline) {
  227. datas.startTime = util.formatDate(util.formatUnixtimestamp(datas.saleTime), 'MM月dd日 hh:mm', false);
  228. datas.endTime = util.formatDate(util.formatUnixtimestamp(datas.presellPaymentDeadline), 'MM月dd日 hh:mm', false);
  229. }
  230. let num = 0,
  231. length = datas.groupinfo.discount && !util.isEmpty(datas.groupinfo.discount.users) ? datas.groupinfo.discount.users.length : 0;
  232. if (length > 0) {
  233. datas.groupinfo.discount.users.forEach((el) => {
  234. num = el.status == 4 ? num++ : num;
  235. if (el.status == 4) {
  236. num++;
  237. }
  238. that.setData({
  239. iconView: num == 0 ? false : true
  240. });
  241. });
  242. }
  243. that.setData({
  244. info: datas
  245. });
  246. // console.log(that.data.info.subOrders[that.data.index].changeStatus);
  247. that.getGoodsRecommend();
  248. if (datas.groupinfo.gstatus == 0 && datas.groupinfo.discount && datas.groupinfo.discount.status == 0 && datas.groupinfo.discount.deadline > 0) {
  249. that.data.info.groupinfo.discount.deadline = that.data.info.groupinfo.discount.deadline - new Date().getTime();
  250. that.updateTime();
  251. }
  252. } else
  253. util.showTips(res.reason);
  254. });
  255. },
  256. // 默认评价弹窗
  257. nps() {
  258. let that = this,
  259. newDate = util.getNowFormatDate('yyyy-MM-dd hh:mm:ss');
  260. let npsData = tt.getStorageSync("nps") || {
  261. num: 0,
  262. oldDate: newDate,
  263. timesSec: newDate
  264. };
  265. if (npsData.num < util.config.npsNum && util.datedifference(newDate, npsData.timesSec, true) > 3600 || util.isObjEmpty(npsData)) {
  266. util.ajax({
  267. func: "v2/order/reviews/one",
  268. load: false
  269. }, function (res) {
  270. if (res.code == 0 && !util.isObjEmpty(res.data)) {
  271. that.setData({
  272. npsOptons: res.data,
  273. npsStatus: true
  274. });
  275. npsData.num += 1;
  276. npsData.timesSec = newDate;
  277. tt.setStorageSync("nps", npsData);
  278. }
  279. });
  280. }
  281. },
  282. getGoodsRecommend() {
  283. let that = this;
  284. util.getGoodsRecommend(this.data.info.aid).then((res) => {
  285. that.setData({
  286. showGoodsRecom: res
  287. });
  288. });
  289. },
  290. // 获取订单信息
  291. OrderInfo(oid) {
  292. console.log(this.data.oid);
  293. let that = this;
  294. util.ajax({
  295. func: "v2/order/getRefundPriceByOid",
  296. data: {
  297. "oid": that.data.oid
  298. }
  299. }, function (res) {
  300. console.log(res);
  301. if (res.code == 0) {
  302. that.setData({
  303. orderInfo: res.data,
  304. changeMeal_oid: oid
  305. });
  306. } else if (res.code == -10) {
  307. util.showTips('不满足更换场次要求,请联系宝大大处理');
  308. that.setData({
  309. showSku: false,
  310. changeMeal_oid: oid
  311. });
  312. } else {
  313. util.showTips(res.reason);
  314. }
  315. });
  316. },
  317. onLoad(options) {
  318. console.log(options);
  319. this.setData({
  320. index: options.index,
  321. oid: options.oid,
  322. refundpwd: options.refundpwd,
  323. orderid: options.orderid,
  324. status: options.refundStatus,
  325. groupId: options.groupid || '',
  326. password: options.refundpwd
  327. });
  328. if (options.atype != "1") {
  329. this.OrderInfo();
  330. } else {
  331. this.setData({
  332. atype: options.atype
  333. });
  334. }
  335. let reasonData = [],
  336. current = 1;
  337. if (this.data.status == 15) {
  338. current = 4;
  339. }
  340. this.setData({
  341. current
  342. });
  343. this.getData();
  344. },
  345. onShow() {},
  346. // 切换退款原因
  347. changeReason(e) {
  348. console.log(e.detail.value);
  349. console.log(this.data.reasonData[e.detail.value].type == 0);
  350. if (this.data.reasonData[e.detail.value].type == 0) {
  351. this.setData({
  352. showtext: true
  353. });
  354. } else {
  355. this.setData({
  356. showtext: false
  357. });
  358. }
  359. this.data.reasonIndex = e.detail.value;
  360. this.setData({
  361. reasonIndex: this.data.reasonIndex,
  362. defaultText: this.data.reasonList[this.data.reasonIndex]
  363. });
  364. },
  365. getData() {
  366. let that = this;
  367. let current = 0;
  368. util.ajax({
  369. func: "v2/order/detail",
  370. data: {
  371. "orderid": that.data.orderid,
  372. "otype": 0,
  373. "password": that.data.refundpwd || ""
  374. }
  375. }, function (res) {
  376. if (res.code == 0) {
  377. let reasonData = [];
  378. if (res.data.atype == '1') { //电商
  379. reasonData = [{
  380. type: 5,
  381. txt: '不喜欢/不想要'
  382. },
  383. {
  384. type: 6,
  385. txt: '质量问题'
  386. },
  387. {
  388. type: 0,
  389. txt: '其他原因'
  390. }
  391. ];
  392. } else {
  393. if (that.data.status == 15) {
  394. reasonData = [{
  395. type: 4,
  396. txt: '候补退款'
  397. }], current = 4;
  398. } else {
  399. reasonData = [{
  400. type: 1,
  401. txt: '行程有变'
  402. },
  403. {
  404. type: 2,
  405. txt: '买多了/买错了'
  406. },
  407. {
  408. type: 3,
  409. txt: '孩子突发身体原因'
  410. },
  411. {
  412. type: 0,
  413. txt: '其他原因'
  414. }
  415. ];
  416. }
  417. }
  418. reasonData.forEach((item) => {
  419. console.log(item);
  420. that.data.reasonList.push(item.txt);
  421. });
  422. that.setData({
  423. datas: res.data,
  424. reasonData,
  425. current: reasonData[0].type,
  426. reasonList: that.data.reasonList
  427. });
  428. console.log(that.data.defaultText, 7)
  429. }
  430. });
  431. },
  432. backBtn() {
  433. tt.redirectTo({
  434. url: '/pages/order/index/order?otype=2'
  435. });
  436. },
  437. confirm(e) {
  438. console.log(e);
  439. this.setData({
  440. reason: e.detail.value
  441. });
  442. },
  443. bindreason(e) {
  444. console.log(e);
  445. this.setData({
  446. current: e.currentTarget.dataset.type
  447. });
  448. },
  449. img() {
  450. this.data.datas.logo = '/images/noimg.png';
  451. this.setData({
  452. datas: this.data.datas
  453. });
  454. },
  455. refundRequest() {
  456. let that = this,
  457. current = this.data.current;
  458. console.log(current, 78787);
  459. if (this.data.defaultText == "请选择 >") {
  460. util.showTips("请选择退款原因");
  461. return false;
  462. }
  463. if (this.data.showtext == true && util.isEmpty(this.data.reason)) {
  464. util.showTips("请填写退款原因");
  465. return false;
  466. }
  467. util.ajax({
  468. func: "tiktok/order/preRefund/detail",
  469. data: {
  470. "oid": that.data.oid
  471. }
  472. }, function (res) {
  473. if (res.code == 0) {
  474. tt.applyRefund({
  475. refundInfo: {
  476. reason: [that.data.defaultText], // 退款理由 必填
  477. note: that.data.reason, // 备注 非必填
  478. },
  479. outOrderNo: that.data.datas.outTradeNo, // 外部订单号 必填
  480. itemOrderList: [{
  481. itemOrderId: res.data.itemOrderList[0].itemOrderId
  482. }, ],
  483. callbackData: {
  484. reason_type: that.data.reasonIndex,
  485. reason: that.data.reason ? that.data.reason : that.data.defaultText,
  486. oid: that.data.oid,
  487. }, // 透传数据,开发者自定义字段 非必传
  488. success: successRes => {
  489. that.setData({
  490. mask: true
  491. });
  492. console.log('申请退款成功', successRes, '参数',
  493. 'itemOrderId:', res.data.itemOrderList[0].itemOrderId,
  494. 'reason:', that.data.defaultText
  495. );
  496. },
  497. fail: errRes => {
  498. const {
  499. errNo,
  500. errMsg,
  501. errLogId
  502. } = errRes;
  503. util.showTips(errMsg);
  504. console.log('申请失败', errNo, errMsg, errLogId, '参数',
  505. 'itemOrderId:', res.data.itemOrderList[0].itemOrderId, 'reason:', that.data.defaultText);
  506. },
  507. });
  508. } else {
  509. util.showTips(res.reason);
  510. }
  511. });
  512. },
  513. onReady() {
  514. }
  515. });