index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="top_footer">
  3. <template v-if="hasDiscount">
  4. <view class="pay_price">
  5. <!-- <view class='pay_price_y'>优惠价</view> -->
  6. <view class="pay_price_p">¥{{price}}</view>
  7. <view class="pro_tag"><text style="margin: 6rpx 5rpx 0 0;">优惠后:</text><text
  8. class="price">¥{{promotionPrice}}</text></view>
  9. </view>
  10. <view style="display: flex;justify-content: center; align-items: center; margin: 20rpx 0;">
  11. <!-- <view class="people_sy"> 本次优惠剩余名额:{{residueNum}} </view> -->
  12. <view class="people_sy_time">
  13. <!-- <uni-countdown :show-day="false" :hour="testHour" :minute="testMinute" :second="testSecond" /> -->
  14. <text>优惠倒计时:</text><uni-countdown :show-day="true" background-color="#FF9D41" color="#ffffff"
  15. :start="start" :hour="testHour" :minute="testMinute" :second="testSecond" />
  16. </view>
  17. </view>
  18. </template>
  19. <view class="pay_btn_lg" @click="payHandle">
  20. {{hasDiscount? promotionPrice : price}}元解锁专属测试报告
  21. </view>
  22. </view>
  23. <uni-popup ref="popup" type="center">
  24. <view class="pay_dialog">
  25. <view class="btn_area">
  26. <image style="margin-right: 89rpx;" @click="completeHandle"
  27. src="https://test.jue-ming.com:8849/api/show?filePath=./webo/EQtest/paymentPage/complete_btn.png"
  28. mode="widthFix"></image>
  29. <image @click="uncompleteHandle"
  30. src="https://test.jue-ming.com:8849/api/show?filePath=./webo/EQtest/paymentPage/uncomplete_btn.png"
  31. mode="widthFix"></image>
  32. </view>
  33. </view>
  34. </uni-popup>
  35. </template>
  36. <script>
  37. import {
  38. timestampFormatter
  39. } from '../../utils/util.js'
  40. export default {
  41. data() {
  42. return {
  43. orderNo: '',
  44. orderInfo: {},
  45. peopleNum: 0,
  46. residueNum: 0, // 剩余名额
  47. price: 0, // 正常价格
  48. promotionPrice: 0, // 优惠价格
  49. promotionEndTime: 0, // 结束时间(时间戳)
  50. testHour: 0, // 时
  51. testMinute: 0, // 分
  52. testSecond: 0, // 秒
  53. start: false
  54. }
  55. },
  56. onLoad(options) {
  57. if (options.orderNo) {
  58. this.orderNo = options.orderNo;
  59. setTimeout(() => {
  60. this.payEnsure();
  61. }, 200)
  62. }
  63. this.orderInfo = uni.getStorageSync('orderInfo');
  64. this.getPeople();
  65. this.queryPromotion();
  66. },
  67. computed: {
  68. // 是否有折扣
  69. hasDiscount() {
  70. let timeSpan = new Date().getTime();
  71. let endTime = this.promotionEndTime - timeSpan;
  72. return this.residueNum > 0 && endTime > 0
  73. }
  74. },
  75. methods: {
  76. payHandle() {
  77. // #ifdef H5
  78. this.getH5Pay();
  79. // #endif
  80. // #ifdef MP-TOUTIAO
  81. this.createOrder();
  82. // #endif
  83. },
  84. // 检查订单支付状态
  85. checkOrder() {
  86. let _this = this;
  87. _this.$request
  88. .get({
  89. url: `api/wx-pay/queryOrder/${_this.orderNo}`,
  90. loadingTip: "加载中...",
  91. data: {},
  92. })
  93. .then((res) => {
  94. uni.hideLoading();
  95. let resultInfo = JSON.parse(res.data.body)
  96. if (resultInfo.trade_state === 'SUCCESS') {
  97. uni.navigateTo({
  98. url: `/newScale/Charm/testResult?resultId=${this.orderInfo.resultId}&messageShare=1`
  99. });
  100. } else {
  101. return;
  102. }
  103. });
  104. },
  105. // 拉起微信支付
  106. getH5Pay(params) {
  107. let _this = this;
  108. _this.$request
  109. .get({
  110. url: `api/orderInfo/queryOrderByResultIdAndUserId/${this.orderInfo.userId}/${this.orderInfo.resultId}`,
  111. loadingTip: "加载中...",
  112. data: {},
  113. })
  114. .then((res) => {
  115. uni.hideLoading();
  116. if (res.data && res.data.orderStatus === '支付成功') {
  117. uni.navigateTo({
  118. url: `/newScale/Charm/testResult?resultId=${this.orderInfo.resultId}&messageShare=1`
  119. });
  120. } else {
  121. // _this.orderInfo.total = _this.hasDiscount ? _this.promotionPrice : _this.price;
  122. _this.$request
  123. .post({
  124. url: "api/wx-pay/h5Pay",
  125. loadingTip: "加载中...",
  126. data: _this.orderInfo
  127. })
  128. .then((res) => {
  129. let redirect_url = encodeURI(
  130. `http://hnhong-duo.com/webo/newScale/Charm/paymentPage?orderNo=${res.data.orderNo}`
  131. )
  132. window.location.href = `${res.data.codeUrl}&redirect_url=${redirect_url}`;
  133. });
  134. }
  135. });
  136. },
  137. createOrder() {
  138. let _this = this;
  139. let params = {
  140. resultId: _this.orderInfo.resultId,
  141. subject: _this.orderInfo.description,
  142. body: _this.orderInfo.description,
  143. total_amount: _this.orderInfo.total * 100,
  144. msgPage: "",
  145. }
  146. _this.$request
  147. .post({
  148. url: "api/douyin/createOrder",
  149. loadingTip: "加载中...",
  150. data: params
  151. })
  152. .then((res) => {
  153. _this.orderNo = res.data.orderNo;
  154. let imageUrl = 'https://test.jue-ming.com:8849/api/show?filePath=./webo/EQtest/banner1.png';
  155. _this.payToutiao(
  156. res.data.orderId,
  157. res.data.orderToken,
  158. res.data.orderNo
  159. );
  160. });
  161. },
  162. payToutiao(orderId, orderToken, orderNo) {
  163. let _this = this;
  164. tt.pay({
  165. orderInfo: {
  166. order_id: orderId,
  167. order_token: orderToken,
  168. },
  169. service: 5,
  170. success: (response) => {
  171. _this.timer = setInterval(() => {
  172. _this.getQueryOrder(orderNo);
  173. }, 1000);
  174. },
  175. fail: (err) => {
  176. uni.showToast({
  177. icon: "none",
  178. name: "支付失败",
  179. });
  180. },
  181. });
  182. },
  183. // 订单状态
  184. getQueryOrder(orderNo) {
  185. let _this = this;
  186. _this.$request
  187. .get({
  188. url: `api/douyin/queryOrder/${orderNo}`,
  189. loadingTip: "加载中...",
  190. data: {},
  191. })
  192. .then((res) => {
  193. if (res.code == "200") {
  194. if (res.data.statusCode == "SUCCESS") {
  195. let imageUrl =
  196. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/EQtest/banner1.png';
  197. uni.navigateTo({
  198. url: `/newScale/Charm/testResult?resultId=${_this.orderInfo.resultId}&messageShare=1`
  199. });
  200. clearInterval(_this.timer);
  201. uni.showToast({
  202. title: "支付成功",
  203. });
  204. } else if (res.data.statusCode == "CLOSED") {
  205. // console.log("订单支付回调成功===========CLOSED》", _this.trade_state_closed );
  206. } else {
  207. clearInterval(_this.timer);
  208. // console.log("订单支付回调成功CLOSED===========》", _this.trade_state_closed);
  209. }
  210. } else {
  211. uni.showToast({
  212. title: "支付失败",
  213. });
  214. }
  215. });
  216. },
  217. // 查询测试人数
  218. getPeople() {
  219. let _this = this;
  220. _this.$request
  221. .get({
  222. url: "record/countByFlag?flag=20210804164957",
  223. loadingTip: "加载中..."
  224. })
  225. .then((res) => {
  226. _this.peopleNum = res.data + 57000
  227. });
  228. },
  229. payEnsure() {
  230. // console.log(11111)
  231. this.$refs.popup.open();
  232. },
  233. uncompleteHandle() {
  234. this.$refs.popup.close();
  235. },
  236. completeHandle() {
  237. uni.showLoading({
  238. title: ''
  239. });
  240. this.checkOrder();
  241. },
  242. // 查询优惠信息
  243. queryPromotion() {
  244. let _this = this;
  245. _this.$request
  246. .get({
  247. url: `api/promotionInfo/queryPromotionDetail/${this.orderInfo.productId}`,
  248. loadingTip: "加载中...",
  249. data: {},
  250. })
  251. .then((res) => {
  252. this.residueNum = res.data.residueNum
  253. this.price = res.data.price;
  254. this.promotionPrice = res.data.promotionPrice;
  255. this.promotionEndTime = new Date(res.data.promotionEndTime).getTime()
  256. this.getDhms();
  257. uni.hideLoading();
  258. });
  259. },
  260. // 获取天时分秒
  261. getDhms() {
  262. let timeSpan = this.promotionEndTime - new Date().getTime();
  263. let time = timestampFormatter(timeSpan);
  264. this.testHour = time.h;
  265. this.testMinute = time.m;
  266. this.testSecond = time.s;
  267. this.start = true;
  268. }
  269. }
  270. }
  271. </script>
  272. <style>
  273. </style>