pay.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <!-- eslint-disable no-prototype-builtins -->
  2. <script setup lang="ts">
  3. import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
  4. import { ref, reactive } from "vue";
  5. import {
  6. createOrderApi,
  7. payAppointmentApi,
  8. queryOrderStatusApi,
  9. queryParamsApi,
  10. saveReportApi,
  11. queryReportListApi
  12. } from "@/services/home";
  13. import type { QueryPa } from "@/types/home";
  14. import HomeList from "./components/HomeList.vue";
  15. import { loginUser } from "@/hooks/useIsLogin";
  16. import { useMemberStore } from "@/stores";
  17. import ShuiWuSH from "@/components/ShuiWuSH.vue";
  18. const userInfo = useMemberStore();
  19. //1 未支付 --可查看全部信息
  20. //2 openId相等 但是状态是支付中 --可查看全部状态
  21. //3 openId不相等 状态是别人在支付中 --不可查看任何信息
  22. //4 openId 相等 但是已支付 --不再支付可查看生成的报告
  23. //5 openId 不相等 别人已支付 --不可查看任何信息
  24. /**
  25. * 总结 当返回状态是
  26. * 1或2时--按钮是微信支付---且列表显示--全部信息展示
  27. * 3和5时 所有信息不展示
  28. * 4时 按钮为查看风险评估
  29. *
  30. */
  31. //获取到的传输过来的唯一值
  32. const params = reactive<any>({
  33. title: "", //标题
  34. num: "", //剩余次数
  35. time: "", //有效截止日期
  36. flag: "", //当前订单的状态
  37. });
  38. let orderParams = reactive<any>({
  39. userId: '',
  40. linId: '',
  41. channelId: '', //渠道id
  42. title: '', //标题
  43. amount: '',
  44. times: '',
  45. effectiveDate: '', //天数
  46. createDate: '',
  47. staffId: '',
  48. staffName: '',
  49. backGround: '',
  50. status: '',
  51. flag: ''
  52. })
  53. // const userId = ref<string>("");
  54. //调用查询参数需要的入参
  55. const scene = ref<QueryPa>({ scene: "", userId: "" });
  56. const orderId = ref<string>("");
  57. //onLoad方法 --在页面初次加载时触发,仅会在页面初次加载时触发一次
  58. //应该将二维码获取唯一标识放到缓存中--这样即使从其他页面过来就回调用就能记住这个标识--然后根据标识去查询
  59. onLoad((options) => {
  60. //获取的二维码中得到的参数信息
  61. // console.log(decodeURIComponent(options?.scene));
  62. // scene.value.scene = decodeURIComponent(options?.scene);
  63. // userInfo.saveScene(decodeURIComponent(options?.scene));
  64. //根据页面中的options 获取参数
  65. //1判断是否含有这个参数
  66. //2如果没有则是表明是从另一个页面进来的不是扫码进来的
  67. //3则需要调用接口需要看到访问次数和过期时间
  68. const option = options as any;
  69. console.log(option.hasOwnProperty("scene"));
  70. console.log(option.hasOwnProperty("id"));
  71. if (option.hasOwnProperty("scene")) {
  72. //
  73. userInfo.saveScene(option.scene);
  74. } else {
  75. userInfo.saveScene("");
  76. //获取参数接口
  77. }
  78. //将scene存入缓存中
  79. // loginUser().then((res) => {
  80. // //这时已经有返回信息了且用户数据已经
  81. // scene.value.userId = res as string;
  82. // //获取到userId了
  83. // queryParams(scene.value);
  84. // });
  85. });
  86. onShow(() => {
  87. //从缓存中取出信息
  88. // scene.value.scene = decodeURIComponent(options?.scene);
  89. //将scene存入缓存中
  90. //需要判断是否有scene
  91. scene.value.scene = userInfo.scene;
  92. //不等于空的话就说明是从扫码进来的
  93. //如果是空的话就是渠道点击进来的
  94. if (scene.value.scene !== "") {
  95. loginUser().then((res) => {
  96. //这时已经有返回信息了且用户数据已经
  97. scene.value.userId = res as string;
  98. //获取到userId了
  99. queryParams(scene.value);
  100. });
  101. } else {
  102. //如果是渠道点击进来的
  103. //则调用渠道接口//然后返回数据
  104. }
  105. });
  106. //查询 根据唯一键值对
  107. const queryParams = async (val : QueryPa) => {
  108. const res = await queryParamsApi(val);
  109. params.flag = res.data.flag;
  110. if (params.flag == 3 || params.flag == 5) {
  111. return;
  112. }
  113. params.title = res.data.title;
  114. params.num = res.data.times;
  115. params.time = formatterData(res.data.createDate, res.data.effectiveDays);
  116. orderParams.userId = userInfo.userInfo.id;
  117. orderParams.linId = res.data.id;
  118. orderParams.channelId = res.data.channelId;
  119. orderParams.title = res.data.title;
  120. orderParams.amount = res.data.amount;
  121. orderParams.times = res.data.times;
  122. orderParams.effectiveDate = res.data.effectiveDays;
  123. orderParams.createDate = res.data.createDate;
  124. orderParams.staffId = res.data.staffId;
  125. orderParams.staffName = res.data.staffName;
  126. orderParams.backGround = res.data.backGround;
  127. orderParams.status = res.data.status;
  128. orderParams.flag = res.data.flag;
  129. };
  130. // 邀约订单查询报告记录
  131. const queryReportList = async (val : any) => {
  132. const res = await queryReportListApi({
  133. linkId: orderParams.linId,
  134. pageNum: 1,
  135. pageSize: 6
  136. });
  137. }
  138. //有效日期
  139. const formatterData = (date : any, day : any) => {
  140. //将data日期格式化为初始的毫秒值
  141. //将day 日期格式化为day
  142. let dateF = new Date(date).getTime();
  143. let dayF = day * 24 * 60 * 60 * 1000;
  144. console.log(dateF);
  145. console.log(dayF);
  146. let dataN = dateF + dayF;
  147. //然后将毫秒值转化为具体时间
  148. let dataNew = new Date(dataN);
  149. let y = dataNew.getFullYear();
  150. let m =
  151. dataNew.getMonth() + 1 < 10 ? "0" + (dataNew.getMonth() + 1) : dataNew.getMonth() + 1;
  152. let d = dataNew.getDate() < 10 ? "0" + dataNew.getDate() : dataNew.getDate();
  153. return y + "-" + m + "-" + d;
  154. };
  155. //1先生成订单号
  156. //2订单号生成后调用后台获取核心参数 核心参数获取到以后
  157. //3调用位置支付、、 查看成功与否
  158. //4如果是成功支付和用户取消了订单
  159. //5否则循环调用查询支付接口
  160. //支付完成后进行下边的逻辑--开始查询报告
  161. //点击支付按钮生成的方法
  162. const payButton = () => {
  163. //先调用订单生成
  164. creatOrderFun(orderParams)
  165. };
  166. //生成订单号
  167. const creatOrderFun = async (val : any) => {
  168. const res = await createOrderApi(val);
  169. if (res.code == 200) {
  170. uni.showToast({
  171. title: '支付成功'
  172. })
  173. params.flag = 4;
  174. }
  175. //获取到订单号了
  176. //然后调用预支付接口后去核心数据
  177. //payFun(val)
  178. };
  179. //支付接口调用
  180. //调用后台接口返回订单号
  181. //调用后台接口返回 下单核心数据
  182. const payFun = async (val : any) => {
  183. const res = await payAppointmentApi(val);
  184. //核心参数返回后
  185. //调用微信支付方法
  186. uni.requestPayment({
  187. ...val,
  188. success: (res : any) => {
  189. if (res) {
  190. console.log(res);
  191. if (res.errMsg == "requestPayment:ok") {
  192. //
  193. console.log("支付成功");
  194. }
  195. }
  196. },
  197. fail: (res : any) => {
  198. console.log(res);
  199. if (res.errMsg == "requestPayment:fail cancel") {
  200. console.log("用户取消了支付");
  201. } else {
  202. queryOrderFor();
  203. //调用支付失败的具体原因
  204. //这时是不是就应该定时器调用订单状态
  205. }
  206. },
  207. });
  208. };
  209. //点击税务风险检测--弹出输入税务号的信息
  210. const swGet = ref<any>();
  211. const openSW = () => {
  212. queryReportList();
  213. // swGet.value.openSH();
  214. };
  215. const goCheck = () => {
  216. }
  217. //查询订单状态
  218. const queryOrderStatus = async (val : any) => {
  219. const res = await queryOrderStatusApi(val);
  220. //判定返回参数
  221. //如果订单完成了
  222. //如果是满了返回了
  223. //需要去掉定时器
  224. clearInterval(timeMe.value);
  225. };
  226. //定时器参数
  227. const timeMe = ref<any>();
  228. //创建一个定时器
  229. const queryOrderFor = () => {
  230. //进来的时候清除定时器
  231. clearInterval(timeMe.value);
  232. timeMe.value = setInterval(() => {
  233. //嗲用方法
  234. queryOrderStatus({});
  235. }, 3000);
  236. };
  237. //销毁页面
  238. onUnload(() => {
  239. //来清除定时器
  240. clearInterval(timeMe.value);
  241. });
  242. </script>
  243. <template>
  244. <view class="payBg">
  245. <ShuiWuTop />
  246. <view class="pay_params">
  247. <view class="pay_card_title1">
  248. {{ params.title }}
  249. </view>
  250. <view class="pay_card_num"> 剩余生成次数:{{ params.num }} </view>
  251. <view class="pay_card_time"> 有效日期:{{ params.time }} </view>
  252. </view>
  253. <view v-show="params.flag == 1 || params.flag == 2"><button class="pay_button" @click="payButton">立即支付</button>
  254. </view>
  255. <view v-show="params.flag == 4"><button class="detection_button" @click="openSW">税务风险检测</button></view>
  256. <view v-show="params.flag == 4">
  257. <HomeList class="home_list_com" />
  258. </view>
  259. <ShuiWuSH ref="swGet" />
  260. </view>
  261. </template>
  262. <style lang="scss">
  263. page {
  264. height: 100%;
  265. }
  266. .payBg {
  267. width: 750rpx;
  268. height: 100%;
  269. padding: 0rpx 20rpx;
  270. .pay_params {
  271. width: 703rpx;
  272. height: 273rpx;
  273. color: #333333;
  274. margin-top: 60rpx;
  275. padding: 20rpx 40rpx;
  276. background: url(https://test.jue-ming.com:8849/api/show?filePath=./jinhong/index/pay_card.png) no-repeat top;
  277. background-size: cover;
  278. display: flex;
  279. flex-direction: column;
  280. .pay_card_title1 {
  281. font-family: 'Alibaba PuHuiTi 2.0';
  282. font-weight: normal;
  283. font-size: 32rpx;
  284. color: #0056FF;
  285. padding: 20rpx 0 40rpx 20rpx;
  286. }
  287. .pay_card_num {
  288. font-family: 'Alibaba PuHuiTi 2.0';
  289. font-weight: normal;
  290. font-size: 28rpx;
  291. color: #333333;
  292. padding-left: 20rpx;
  293. margin-top: 20rpx;
  294. }
  295. .pay_card_time {
  296. font-family: 'Alibaba PuHuiTi 2.0';
  297. font-weight: normal;
  298. font-size: 28rpx;
  299. color: #333333;
  300. padding-left: 20rpx;
  301. margin-top: 20rpx;
  302. margin-bottom: 40rpx;
  303. }
  304. }
  305. .pay_button {
  306. width: 703rpx;
  307. line-height: 77rpx;
  308. background: linear-gradient(90deg, #BC63F4 0%, #4A89FB 100%);
  309. border-radius: 20rpx;
  310. border: 1px solid #FFFFFF;
  311. font-family: Alibaba PuHuiTi 2.0;
  312. font-weight: normal;
  313. font-size: 32rpx;
  314. color: #FFFFFF;
  315. margin: 72rpx 0 60rpx;
  316. }
  317. .detection_button {
  318. width: 703rpx;
  319. line-height: 77rpx;
  320. background: linear-gradient(90deg, #BC63F4 0%, #4A89FB 100%);
  321. border-radius: 20rpx;
  322. border: 1px solid #FFFFFF;
  323. font-family: Alibaba PuHuiTi 2.0;
  324. font-weight: normal;
  325. font-size: 32rpx;
  326. color: #FFFFFF;
  327. margin: 72rpx 0 60rpx;
  328. }
  329. }
  330. </style>