抖音c端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  2. var config = require("../../../config/config.js");
  3. var app = getApp();
  4. const Http = require("../../../utils/HttpBasics");
  5. const util = require("../../../utils/util");
  6. const imgurl = require("../../../utils/imgurl");
  7. Page({
  8. data: {
  9. couponIds: "",
  10. showPhoem: false,
  11. couponChannelId: "",
  12. showPage: false,
  13. data: {},
  14. spuIdObj: {},
  15. priceAndStockObj: {},
  16. mallTenantId: ''
  17. },
  18. onLoad: function (options) {
  19. console.log(options, 'options');
  20. if (options.mallTenantId) {
  21. this.setData({
  22. mallTenantId: options.mallTenantId,
  23. })
  24. } else {
  25. this.setData({
  26. mallTenantId: tt.getStorageSync('mallTenantId'),
  27. })
  28. }
  29. console.log(this.data.mallTenantId, 'mallTenantId');
  30. tt.showLoading({
  31. title: "加载中..."
  32. });
  33. let that = this
  34. if (app.globalData.token) {
  35. if (options && options.couponChannelId) {
  36. that.setData({
  37. couponChannelId: options.couponChannelId
  38. })
  39. that.getDetail(options.couponChannelId, 'notendclock');
  40. }
  41. } else {
  42. app.tokenCallback = token => {
  43. that.setData({
  44. couponChannelId: options.couponChannelId
  45. })
  46. if (options && options.couponChannelId) {
  47. that.getDetail(options.couponChannelId, 'notendclock');
  48. }
  49. }
  50. }
  51. },
  52. goInstructions() {
  53. tt.navigateTo({
  54. url: '/pages/coupon/instructions/instructions?couponChannelId=' + this.data.couponChannelId,
  55. success: (res) => {
  56. },
  57. fail: (res) => {
  58. },
  59. });
  60. },
  61. getSupId(id) {
  62. Http.get({
  63. url: config.api.getSpuid,
  64. data: {
  65. id: id
  66. }
  67. }).then(res => {
  68. if (res.data) {
  69. this.setData({
  70. spuIdObj: res.data
  71. })
  72. }
  73. }).catch(err => {
  74. // tt.showToast({
  75. // title: err.message,
  76. // icon: 'none',
  77. // duration: 2000,
  78. // mask: false
  79. // });
  80. })
  81. },
  82. setPhone(paramData) {
  83. //子组件调用这个方法说明手机号已经授权成功
  84. this.setData({
  85. showPhoem: paramData.detail,
  86. })
  87. tt.showToast({
  88. title: '授权成功', // 内容
  89. icon: 'none', // 图标
  90. success: (res) => {
  91. },
  92. fail: (res) => {
  93. },
  94. });
  95. },
  96. setBox(paramData) {
  97. this.setData({
  98. showPhoem: paramData.detail
  99. })
  100. tt.showToast({
  101. title: '取消授权', // 内容
  102. icon: 'none', // 图标
  103. success: (res) => {
  104. tt.reLaunch({
  105. url: "/index/index",
  106. success(res) {
  107. console.log(`${res}`);
  108. app.globalData.selected = 0
  109. },
  110. fail(err) {
  111. console.log(`navigateTo调用失败`, err);
  112. },
  113. });
  114. },
  115. fail: (res) => {
  116. },
  117. });
  118. },
  119. getCouponPriceAndStock(couponChannelId) { //获取券价格与库存
  120. Http.get({
  121. url: config.api.couponPriceAndStock,
  122. data: {
  123. couponChannelId,
  124. mallTenantId: this.data.mallTenantId || ''
  125. }
  126. }).then(res => {
  127. let tempBoj = JSON.parse(res.data)
  128. console.log(tempBoj, "$");
  129. this.setData({
  130. priceAndStockObj: tempBoj
  131. })
  132. })
  133. },
  134. getDetail: function (couponChannelId, flag) {
  135. let that = this;
  136. let data = {};
  137. that.getCouponPriceAndStock(couponChannelId); //获取券价格和库存
  138. if (that.data.couponIds) {
  139. data.couponId = couponChannelId
  140. } else {
  141. data.couponChannelId = couponChannelId
  142. }
  143. var parmer = {
  144. url: config.api.newCouponDetail,
  145. data: data
  146. };
  147. Http.get(parmer).then(res => {
  148. that.setData({
  149. couponId: res.data.couponId
  150. })
  151. /**
  152. * activityStatus==0 活动未开始
  153. * activityStatus==1 活动已开始
  154. * flag == endclock 说明倒计时已经结束
  155. */
  156. if (res.data.endTime && res.data.beginTime) {
  157. that.setData({
  158. begin_time: res.data.beginTime,
  159. end_time: res.data.endTime,
  160. activityStatus: res.data.actStatus ? res.data.actStatus : ''
  161. })
  162. if (res.data.actStatus == 0 && flag != 'endclock') {
  163. that.countdown(res.data.beginTime);
  164. } else if (res.data.actStatus != 0 && flag != 'endclock') {
  165. that.countdown(res.data.endTime);
  166. } else {
  167. clearInterval(that.data.setInterval)
  168. }
  169. if (res.data.actStatus == 0) {
  170. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  171. if (util.timechuo(beginTime).indexOf('-') == 0) {
  172. that.setData({
  173. beginTime: "活动已结束",
  174. });
  175. } else {
  176. that.setData({
  177. beginTime: util.timechuo(beginTime)
  178. });
  179. }
  180. } else {
  181. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  182. if (util.timechuo(endTime).indexOf('-') == 0) {
  183. that.setData({
  184. endtime: "活动已结束",
  185. });
  186. } else {
  187. that.setData({
  188. endtime: util.timechuo(endTime)
  189. });
  190. }
  191. }
  192. }
  193. tt.hideLoading();
  194. that.setData({
  195. data: res.data,
  196. });
  197. if (res.data.type == 10) {
  198. that.setData({
  199. salePriceStr: res.data.salePriceStr,
  200. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  201. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  202. priceStr: res.data.priceStr,
  203. tailPriceStr: res.data.tailPriceStr,
  204. origPriceStr: res.data.origPriceStr
  205. })
  206. }
  207. if (res.data.validType == 1) {
  208. that.setData({
  209. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  210. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  211. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  212. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  213. });
  214. } else {
  215. if (res.data.validDays) {
  216. that.setData({
  217. validDays: res.data.validDays
  218. });
  219. }
  220. }
  221. if (res.data.itemGroup) {
  222. let tempObj = this.data.data
  223. tempObj.itemGroup = JSON.parse(tempObj.itemGroup)
  224. this.setData({
  225. data: tempObj
  226. })
  227. console.log(this.data.data, "data");
  228. }
  229. if (res.data.productAttrs && res.data.skuAttrs) {
  230. let tempObj = this.data.data
  231. tempObj.productAttrs = JSON.parse(tempObj.productAttrs)
  232. tempObj.skuAttrs = JSON.parse(tempObj.skuAttrs)
  233. tempObj.productAttrs.map(item => {
  234. if (item.key == "Notification") {
  235. if (item.data != '') {
  236. tempObj.curLsit = JSON.parse(item.data)
  237. }
  238. }
  239. if (item.key == "bring_out_meal") {
  240. tempObj.besides = item.data
  241. }
  242. if (item.key == "free_pack") {
  243. tempObj.pack = item.data
  244. }
  245. if (item.key == "superimposed_discounts") {
  246. tempObj.superimposed_discounts = item.data
  247. }
  248. if (item.key == "private_room") {
  249. tempObj.private_room = item.data
  250. }
  251. if (item.key == "rec_person_num_max") {
  252. tempObj.rec_person_num_max = item.data
  253. }
  254. if (item.key == 'Description') {
  255. tempObj.Description = JSON.parse(item.data)
  256. }
  257. if (item.key == "can_no_use_date") {
  258. tempObj.can_no_use_date = JSON.parse(item.data)
  259. }
  260. })
  261. tempObj.skuAttrs.map(item => {
  262. if (item.key == "commodity") {
  263. if (item.data != '') {
  264. tempObj.itemGroup = JSON.parse(item.data)
  265. }
  266. }
  267. })
  268. this.setData({
  269. data: tempObj
  270. })
  271. console.log(this.data.data, "data");
  272. }
  273. }).catch(err => {
  274. tt.showToast({
  275. title: err.message,
  276. icon: 'none',
  277. duration: 2000,
  278. mask: false
  279. });
  280. })
  281. },
  282. /**
  283. * 支付订单更新
  284. */
  285. payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType) {
  286. let that = this;
  287. console.log(orderId, 'orderId');
  288. // 支付成功
  289. Http.post({
  290. url: config.api.payOrderUpdate,
  291. data: {
  292. payOrderId: payOrderId,
  293. composeOrderId: orderId,
  294. status: status,
  295. reason: reason,
  296. mallTenantId: that.data.mallTenantId
  297. }
  298. })
  299. .then(res => {
  300. tt.hideLoading()
  301. // 有价券
  302. if (!type && type != 'free') {
  303. setTimeout(() => {
  304. let url = ""
  305. if (_this.data.orderFlag) {
  306. tt.redirectTo({
  307. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order&mallTenantId=${that.data.mallTenantId}`
  308. });
  309. } else {
  310. tt.redirectTo({
  311. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  312. });
  313. }
  314. }, 1600);
  315. } else if (type == 'free') {
  316. tt.navigateTo({
  317. url: `/pages/order/detail/index?orderId=${orderId
  318. }&mallTenantId=${that.data.mallTenantId}`
  319. });
  320. }
  321. })
  322. .catch(err => {
  323. console.log(err);
  324. if (!type) {
  325. setTimeout(function () {
  326. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  327. }, 2000)
  328. }
  329. })
  330. },
  331. // 获得未支付的订单
  332. getUnPaidOrder(couponId) {
  333. let that = this;
  334. Http.get({
  335. url: config.api.getUnPaidOrder,
  336. data: {
  337. couponId: couponId,
  338. mallTenantId: this.data.mallTenantId || ''
  339. }
  340. }).then(res => {
  341. that.setData({
  342. disOrderNumber: res.data.orderNumber,
  343. composeOrderType: res.data.composeOrderType
  344. })
  345. if (res.data && res.data.pressEndDate) {
  346. that.setData({
  347. dispressEndDate: true
  348. })
  349. } else {
  350. that.setData({
  351. dispressEndDate: false
  352. })
  353. }
  354. if (that.data.dispressEndDate) {
  355. tt.showModal({
  356. title: '提示',
  357. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  358. confirmText: "我的砍价",
  359. success: function (res) {
  360. if (res.confirm) {
  361. tt.navigateTo({
  362. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}&composeOrderType=${that.data.composeOrderType}`,
  363. })
  364. }
  365. }
  366. })
  367. } else {
  368. tt.showModal({
  369. title: '提示',
  370. content: '您有未支付订单,请先进行支付',
  371. confirmText: "去支付",
  372. success: function (res1) {
  373. if (res1.confirm) {
  374. if (that.data.composeOrderType > 0) { //券包
  375. tt.navigateTo({
  376. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&mallTenantId=${that.data.mallTenantId}`,
  377. })
  378. } else {
  379. tt.navigateTo({
  380. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&mallTenantId=${that.data.mallTenantId}`,
  381. })
  382. }
  383. }
  384. }
  385. })
  386. }
  387. }).catch(error => {
  388. tt.showToast({
  389. title: error.message,
  390. icon: "none",
  391. duration: 3000
  392. })
  393. })
  394. },
  395. /**
  396. * 发起支付
  397. */
  398. orderFunc(discount) {
  399. if (this.data.showbutton) return;
  400. let that = this;
  401. tt.showLoading({
  402. title: "加载中..."
  403. });
  404. that.setData({
  405. showbutton: true,
  406. })
  407. Http.get({
  408. url: config.api.checkUserStatus,
  409. data: {
  410. token: app.globalData.token,
  411. }
  412. }).then(res => {
  413. Http.get({
  414. url: config.api.checkPhoneStatus,
  415. data: {}
  416. }).then(res => {
  417. //
  418. // if (!tt.canIUse('createOrder') || that.data.data.type == 50 || that.data.priceAndStockObj.salePrice == 0) {
  419. //积分券和免费券
  420. // 发起砍价
  421. if (discount == 'discount') {
  422. var data = {
  423. couponChannelId: "" + that.data.couponChannelId,
  424. couponId: "" + that.data.couponId,
  425. formId: "" + that.data.formId,
  426. press: true
  427. }
  428. } else if (discount == 'discount1') {
  429. var data = {
  430. couponChannelId: "" + that.data.couponChannelId,
  431. couponId: "" + that.data.couponId,
  432. formId: "" + that.data.formId,
  433. press: false
  434. }
  435. } else if (that.data.couponChannelId == null) {
  436. var data = {
  437. couponId: "" + that.data.couponId,
  438. formId: "" + that.data.formId,
  439. };
  440. } else {
  441. var data = {
  442. couponChannelId: "" + that.data.couponChannelId,
  443. couponId: "" + that.data.couponId,
  444. formId: "" + that.data.formId,
  445. }
  446. }
  447. console.log(data, "data")
  448. let url = ""
  449. let tempObj;
  450. let tempArr = []
  451. if (that.data.data.type == 12) {
  452. url = config.api.couponPackageSave
  453. tempObj = {
  454. signleOrder: {
  455. couponChannelId: "" + that.data.couponChannelId,
  456. couponId: "" + that.data.couponId,
  457. formId: "" + that.data.formId,
  458. },
  459. count: "1"
  460. }
  461. tempArr.push(tempObj)
  462. } else {
  463. url = config.api.orderSave
  464. data.mallTenantId = that.data.mallTenantId || ''
  465. }
  466. /**
  467. * orderSave 下单
  468. */
  469. Http.post({
  470. url: url,
  471. data: that.data.data.type == 12 ? JSON.stringify(tempArr) : data
  472. }).then(res => {
  473. if (discount != 'discount') {
  474. if (typeof (res) != "undefined") {
  475. let orderId = "" + res.data.mainOrderId;
  476. that.setData({
  477. orderId: orderId,
  478. composeOrderType: res.data.composeOrderType
  479. });
  480. if (res.data.payment > 0) {
  481. // 支付金额不为0
  482. if (tt.canIUse('createOrder')) {
  483. Http.post({
  484. url: config.api.payOrderCreate_2,
  485. data: {
  486. orderId: orderId,
  487. composeOrderType: res.data.composeOrderType,
  488. mallTenantId: that.data.mallTenantId
  489. }
  490. }).then(res => {
  491. console.log(res, "789789");
  492. let tempCallbackData = res.data.callbackData
  493. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  494. let options = {
  495. callbackData: tempCallbackData,
  496. goodsList: res.data.goodsList,
  497. payment: res.data.payment,
  498. success: res => {
  499. console.log('save,success!');
  500. tt.hideLoading();
  501. that.setData({
  502. showbutton: false,
  503. })
  504. const {
  505. orderId,
  506. outOrderNo
  507. } = res;
  508. that.setData({
  509. orderId,
  510. outOrderNo
  511. });
  512. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  513. },
  514. fail: res => {
  515. console.log('save,fail!');
  516. const {
  517. orderId,
  518. outOrderNo,
  519. errNo,
  520. errMsg,
  521. errLogId
  522. } = res;
  523. if (errLogId) {
  524. tt.hideLoading();
  525. that.setData({
  526. showbutton: false,
  527. })
  528. console.log('预下单失败', errNo, errMsg, errLogId);
  529. let tempErrmsg = errMsg.split('开发者拒绝交易:');
  530. tt.showToast({
  531. title: tempErrmsg[tempErrmsg.length - 1],
  532. icon: 'none',
  533. duration: 2000,
  534. mask: false
  535. });
  536. }
  537. if (orderId || outOrderNo) {
  538. tt.hideLoading();
  539. that.setData({
  540. showbutton: false,
  541. })
  542. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  543. console.log(that.payOrderUpdate, "payOrderUpdate");
  544. tt.showToast({
  545. title: "取消支付",
  546. icon: 'none',
  547. duration: 2000,
  548. mask: false
  549. });
  550. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  551. }
  552. },
  553. }
  554. console.log(options, "options");
  555. tt.createOrder(options)
  556. })
  557. } else { //不支持2.0支付
  558. /**
  559. * 支付订单创建
  560. */
  561. tt.showToast({
  562. title: '请升级抖音', // 内容
  563. icon: "none"
  564. });
  565. return
  566. Http.post({
  567. url: config.api.payOrderCreate,
  568. data: {
  569. orderId: orderId,
  570. composeOrderType: res.data.composeOrderType
  571. }
  572. }).then(res => {
  573. var payOrderId = "" + res.data.outOrderNo;
  574. tt.hideLoading();
  575. tt.pay({
  576. service: 5,
  577. orderInfo: {
  578. order_id: res.data.payOrderId,
  579. order_token: res.data.payOrderToken,
  580. },
  581. success: res => {
  582. tt.showLoading({
  583. title: '订单正在处理中...',
  584. })
  585. if (res.code === 0) {
  586. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that, that.data.composeOrderType);
  587. if (res.errMsg == "requestPayment:ok") {
  588. /**
  589. * 用户支付成功以后跳转到券包列表
  590. */
  591. if (that.data.cardType == 100) {
  592. tt.setStorage({
  593. key: 'couponNum2',
  594. data: "couponNum2"
  595. })
  596. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  597. tt.setStorage({
  598. key: 'couponNum',
  599. data: "couponNum"
  600. })
  601. }
  602. }
  603. } else if (res.code === 1) {
  604. that.setData({
  605. showbutton: false
  606. })
  607. tt.hideLoading();
  608. tt.showToast({
  609. title: '支付超时', // 内容
  610. icon: "none"
  611. });
  612. } else if (res.code === 2) {
  613. that.setData({
  614. showbutton: false
  615. })
  616. tt.hideLoading();
  617. tt.showToast({
  618. title: '支付失败', // 内容
  619. icon: "none"
  620. });
  621. } else if (res.code === 3) {
  622. that.setData({
  623. showbutton: false
  624. })
  625. tt.hideLoading();
  626. tt.showToast({
  627. title: '支付关闭', // 内容
  628. icon: "none"
  629. });
  630. } else if (res.code === 4) {
  631. that.setData({
  632. showbutton: false
  633. })
  634. tt.hideLoading();
  635. tt.showToast({
  636. title: '支付取消', // 内容
  637. icon: "none"
  638. });
  639. } else if (res.code === 9) {
  640. that.setData({
  641. showbutton: false
  642. })
  643. tt.hideLoading();
  644. tt.showToast({
  645. title: '订单状态开发者自行获取', // 内容
  646. icon: "none"
  647. });
  648. }
  649. },
  650. fail: res => {
  651. tt.hideLoading();
  652. /**
  653. * 支付失败,需要更新订单的状态
  654. */
  655. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that, that.data.composeOrderType);
  656. that.setData({
  657. showbutton: false
  658. })
  659. return;
  660. },
  661. complete: res => {}
  662. });
  663. /// End payment --------
  664. })
  665. .catch(err => {
  666. tt.hideLoading();
  667. tt.showToast({
  668. title: err.message,
  669. icon: 'none',
  670. duration: 2000,
  671. mask: false
  672. });
  673. })
  674. }
  675. } else {
  676. // 免费券
  677. that.payOrderUpdate(orderId, "0", 1, '', 'free', that, that.data.composeOrderType);
  678. if (that.data.cardType == 100) {
  679. tt.setStorage({
  680. key: 'couponNum2',
  681. data: "couponNum2"
  682. })
  683. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  684. tt.setStorage({
  685. key: 'couponNum',
  686. data: "couponNum"
  687. })
  688. }
  689. }
  690. }
  691. } else {
  692. if (res) {
  693. tt.navigateTo({
  694. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.mainOrderId}&composeOrderType=${res.data.composeOrderType}`,
  695. })
  696. }
  697. }
  698. }).catch(err => {
  699. tt.hideLoading();
  700. that.setData({
  701. showbutton: false,
  702. })
  703. if (err.code == 3012) {
  704. that.getUnPaidOrder(that.data.couponId);
  705. } else {
  706. tt.showToast({
  707. title: err.message ? err.message : err.data,
  708. icon: 'none',
  709. duration: 2000,
  710. success(res) {
  711. console.log(res);
  712. },
  713. fail(res) {
  714. console.log("showToast 调用失败", res);
  715. },
  716. });
  717. }
  718. })
  719. // } else {
  720. // //有价券
  721. // console.log(tt.canIUse('createOrder'), "是否支持2.0js-api");
  722. // if (tt.canIUse('createOrder')) {
  723. // //支持 支付2.0 js-api
  724. // let tempCallbackData = {}
  725. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  726. // let options = {
  727. // callbackData: tempCallbackData,
  728. // goodsList: [
  729. // {
  730. // quantity: 1, // 购买数量 必填
  731. // price: that.data.priceAndStockObj.salePrice, // 商品价格 必填
  732. // goodsName: that.data.data.title, // 商品名称 必填
  733. // goodsPhoto: that.data.data.coverImg, // 商品图片链接 必填
  734. // goodsId: that.data.data.couponChannel.ttSpuId, // 商品ID 必填
  735. // goodsType: 1, // 商品类型 必填
  736. // goodsLabels: ['过期退', '随时退', '免预约'], // 商品标签 非必填
  737. // dateRule: '', // 使用规则 非必填
  738. // },
  739. // ],
  740. // payment: {
  741. // totalAmount: that.data.priceAndStockObj.salePrice, // 订单总价 必填
  742. // },
  743. // success: res => {
  744. // tt.hideLoading();
  745. // that.setData({
  746. // showbutton: false,
  747. // })
  748. // const { orderId, outOrderNo } = res;
  749. // that.setData({ orderId, outOrderNo });
  750. // that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  751. // },
  752. // fail: res => {
  753. // const { orderId, outOrderNo, errNo, errMsg, errLogId } = res;
  754. // if (errLogId) {
  755. // tt.hideLoading();
  756. // that.setData({
  757. // showbutton: false,
  758. // })
  759. // console.log('预下单失败', errNo, errMsg, errLogId);
  760. // let tempErrmsg = errMsg.split('开发者拒绝交易:');
  761. // tt.showToast({
  762. // title: tempErrmsg[tempErrmsg.length - 1],
  763. // icon: 'none',
  764. // duration: 2000,
  765. // mask: false
  766. // });
  767. // }
  768. // if (orderId || outOrderNo) {
  769. // tt.hideLoading();
  770. // that.setData({
  771. // showbutton: false,
  772. // })
  773. // console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  774. // console.log(that.payOrderUpdate, "payOrderUpdate");
  775. // tt.showToast({
  776. // title: "取消支付",
  777. // icon: 'none',
  778. // duration: 2000,
  779. // mask: false
  780. // });
  781. // that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  782. // }
  783. // },
  784. // }
  785. // console.log(options, "options");
  786. // tt.createOrder(options)
  787. // } else {
  788. // //不支持 支付2.0 js -api
  789. // }
  790. // }
  791. }).catch(err => {
  792. tt.hideLoading()
  793. that.setData({
  794. showbutton: false,
  795. })
  796. if (err.code == 2011) {
  797. tt.showToast({
  798. title: "商户信息没找到",
  799. image: './../../../assets/images/fail.png',
  800. duration: 2000,
  801. mask: false
  802. });
  803. } else if (err.code == 2013) {
  804. tt.showToast({
  805. title: "商户信息禁用",
  806. image: './../../../assets/images/fail.png',
  807. duration: 2000,
  808. mask: false
  809. });
  810. } else if (err.code == 3000) {
  811. tt.showToast({
  812. title: "库存不足",
  813. image: './../../../assets/images/fail.png',
  814. duration: 2000,
  815. mask: false
  816. });
  817. } else if (err.code == 3001) {
  818. tt.showToast({
  819. title: "您已超过限购",
  820. image: './../../../assets/images/fail.png',
  821. duration: 2000,
  822. mask: false
  823. });
  824. } else if (err.code == 3002) {
  825. tt.showToast({
  826. title: "订单失败",
  827. image: './../../../assets/images/fail.png',
  828. duration: 2000,
  829. mask: false
  830. });
  831. } else if (err.code == 3003) {
  832. tt.showToast({
  833. title: "订单不存在",
  834. image: './../../../assets/images/fail.png',
  835. duration: 2000,
  836. mask: false
  837. });
  838. } else if (err.code == 3004) {
  839. tt.showToast({
  840. title: "订单不存在",
  841. image: './../../../assets/images/fail.png',
  842. duration: 2000,
  843. mask: false
  844. });
  845. } else if (err.code == 4003) {
  846. tt.showToast({
  847. title: "卡券已作废",
  848. image: './../../../assets/images/fail.png',
  849. duration: 2000,
  850. mask: false
  851. });
  852. } else if (err.code == 3012) {
  853. that.getUnPaidOrder(that.data.couponId);
  854. } else if (err.code == 11005) {
  855. /**
  856. * 将值传到用户手机号授权的页面
  857. *
  858. */
  859. if (app.globalData.ifCongPh == 1) {
  860. tt.navigateTo({
  861. url: `/pages/getPhone/getPhone?couponChannelId=${that.data.couponChannelId}&mallTenantId=${that.data.mallTenantId}&path=qr`,
  862. });
  863. } else {
  864. this.setData({
  865. showPhoem: true
  866. })
  867. }
  868. } else if (err.code == 11006) {
  869. // 用户手机已加密
  870. tt.navigateTo({
  871. url: `/pages/getPhone/getPhone?couponChannelId=${that.data.couponChannelId}&mallTenantId=${that.data.mallTenantId}&path=qr`
  872. });
  873. } else {
  874. tt.showToast({
  875. title: err.message,
  876. icon: 'none',
  877. duration: 2000,
  878. mask: false
  879. });
  880. }
  881. })
  882. }).catch(err => {
  883. tt.hideLoading()
  884. that.setData({
  885. showbutton: false,
  886. })
  887. console.log(err)
  888. if (err.code == 11004) {
  889. tt.navigateTo({
  890. url: `/pages/getuserinfo/getuserinfo?fromflag=confirmation&confirmationFlag=${that.data.couponChannelId}`,
  891. })
  892. } else {
  893. tt.showToast({
  894. title: err.message,
  895. icon: "none",
  896. duration: 2500
  897. })
  898. }
  899. })
  900. },
  901. })