parentPay.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <view class="container">
  3. <view class="content1" v-if="content1">
  4. <view class="mark" v-show="showSearch"></view>
  5. <view class="messageBg1"></view>
  6. <view class="messageBg2"></view>
  7. <view class="messageCard">
  8. <image src="../../static/images/null.png" mode="scaleToFill" />
  9. <text>暂无缴费信息</text>
  10. <button hover-class="button-hover" @click="toSearch">帮人代缴</button>
  11. </view>
  12. <view class="pop-up" v-show="showSearch">
  13. <view class="top">
  14. <text>代缴人信息</text>
  15. <view class="close" @click="close1">
  16. <image
  17. src="../../static/images/close.png"
  18. mode="scaleToFill"
  19. @click="close1"
  20. />
  21. </view>
  22. </view>
  23. <view class="name">
  24. <text>姓 名</text>
  25. <input
  26. v-model="SeaStudentName"
  27. type="text"
  28. placeholder="请输入姓名"
  29. placeholder-style="color:rgba(0, 0, 0, 0.29);"
  30. />
  31. </view>
  32. <view class="studentNo">
  33. <text>学 号</text>
  34. <input
  35. v-model="SeaStudentNo"
  36. type="text"
  37. placeholder="请输入学号"
  38. placeholder-style="color:rgba(0, 0, 0, 0.29);"
  39. />
  40. </view>
  41. <view class="remark">
  42. 备注:新生输入身份证号码代替学号,老生输入学号
  43. </view>
  44. <view class="confirm">
  45. <button hover-class="button-hover" @click="close1">取消</button>
  46. <button hover-class="button-hover" @click="searchDetailMess">
  47. 确认
  48. </button>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="content2" v-if="showMess">
  53. <view class="order">订单号:{{ orderNo }}</view>
  54. <view class="mark" v-show="showSearch"></view>
  55. <view class="messageBg1"></view>
  56. <view class="messageBg2"></view>
  57. <view class="messageCard">
  58. <view class="item-form">
  59. <view class="item">
  60. <text class="ite">收费单位 </text>
  61. <text class="content">南昌交通学院</text>
  62. </view>
  63. <view class="item">
  64. <text class="ite">姓名 </text>
  65. <text class="content">{{ studentName }}</text>
  66. </view>
  67. <view class="item">
  68. <text class="ite">学号 </text>
  69. <text class="content">{{ studentNo }}</text>
  70. </view>
  71. <view class="item">
  72. <text class="ite">专业 </text>
  73. <text class="content">{{ majorName }}</text>
  74. </view>
  75. <view class="item">
  76. <text class="ite">班级 </text>
  77. <text class="content">{{ className }}</text>
  78. </view>
  79. <view class="item">
  80. <text class="ite">缴费学年 </text>
  81. <text class="content">{{ years }}</text>
  82. </view>
  83. <!-- <template v-if="(itemArr.length = 0)"> -->
  84. <view class="item-pay" v-for="item in Arr">
  85. <text class="ite">{{ item.id }} </text>
  86. <text class="content">¥{{ item.money }}</text>
  87. </view>
  88. <!-- </template> -->
  89. <view class="item">
  90. <text class="ite">总金额 </text>
  91. <text class="content">¥{{ realPayAmount }}</text>
  92. </view>
  93. </view>
  94. <button @click="getPay()" hover-class="button-hover" v-if="payStatu1">
  95. 支付
  96. </button>
  97. <text class="okPay" v-if="payStatu2">已支付</text>
  98. <view class="bottom-a"></view>
  99. </view>
  100. </view>
  101. </view>
  102. </template>
  103. <script>
  104. export default {
  105. data() {
  106. return {
  107. content1: true,
  108. showMess: false,
  109. showSearch: false,
  110. studentName: "",
  111. studentNo: "",
  112. SeaStudentName: "",
  113. SeaStudentNo: "",
  114. majorName: "",
  115. className: "",
  116. years: "",
  117. realPayAmount: "",
  118. Arr: [],
  119. payStatu1: true,
  120. payStatu2: false,
  121. homeUrl: "https://jtishfw.ncjti.edu.cn/jiaofei/backendApi",
  122. openId: "",
  123. cardNumber: "",
  124. orderNo: "", //订单号
  125. //微信支付参数
  126. appId: "",
  127. timeStamp: "",
  128. nonceStr: "",
  129. package: "",
  130. signType: "",
  131. paySign: "",
  132. };
  133. },
  134. onLoad(options) {
  135. this.getOpenId();
  136. },
  137. methods: {
  138. toSearch() {
  139. this.showSearch = !this.showSearch;
  140. },
  141. close1() {
  142. this.showSearch = !this.showSearch;
  143. },
  144. toShowMess() {
  145. this.showMess = !this.showMess;
  146. this.content1 = false;
  147. },
  148. //获取openId
  149. getOpenId() {
  150. let openId = localStorage.getItem("openId");
  151. if (!openId) {
  152. let openId = this.getQueryString("openId");
  153. let error = this.getQueryString("error");
  154. let homeWeb =
  155. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd87cbe1db0437303&redirect_uri=https://jtishfw.ncjti.edu.cn/jiaofei/backendApi/wechat/pub/auth&response_type=code&scope=snsapi_base&state=pages/parentPay/parentPay#wechat_redire";
  156. if (!openId) {
  157. window.location.href = homeWeb;
  158. } else if (error) {
  159. uni.showToast({
  160. title: "openId获取失败",
  161. icon: "error",
  162. mask: true,
  163. duration: 1000,
  164. });
  165. } else {
  166. localStorage.setItem("openId", openId);
  167. }
  168. }
  169. },
  170. //代缴费
  171. searchDetailMess() {
  172. if (!this.SeaStudentNo || !this.SeaStudentName) {
  173. uni.showToast({
  174. title: "学号或姓名不能为空",
  175. icon: "error",
  176. mask: true,
  177. duration: 1000,
  178. });
  179. } else {
  180. let that = this;
  181. let cardNumber = localStorage.getItem("cardNumber");
  182. let url =
  183. that.homeUrl +
  184. `/tuitionpayment/payableinfo/payableInfo/${that.SeaStudentNo}/${that.SeaStudentName}`;
  185. uni.request({
  186. url: url,
  187. header: {
  188. card_number: cardNumber,
  189. Accept: "application/json",
  190. "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
  191. "X-Requested-With": "XMLHttpRequest",
  192. },
  193. method: "GET",
  194. sslVerify: true,
  195. success: ({ data, statusCode, header }) => {
  196. if (!data.success) {
  197. uni.showToast({
  198. title: data.message,
  199. icon: "error",
  200. mask: true,
  201. duration: 1000,
  202. });
  203. } else {
  204. uni.showToast({
  205. title: "信息查询中",
  206. icon: "loading",
  207. mask: true,
  208. duration: 500,
  209. });
  210. that.showSearch = !that.showSearch;
  211. that.toShowMess();
  212. let res = data.data;
  213. that.studentName = res.studentName;
  214. that.studentNo = res.studentNo;
  215. that.years = res.years;
  216. that.majorName = res.majorName;
  217. that.className = res.className;
  218. that.realPayAmount = res.realPayAmount;
  219. that.getPayDetail(res.payItemDetail);
  220. if (res.pay) {
  221. that.payStatu1 = false;
  222. that.payStatu2 = true;
  223. } else {
  224. that.payStatu1 = true;
  225. that.payStatu2 = false;
  226. }
  227. }
  228. },
  229. fail: (error) => {},
  230. });
  231. }
  232. },
  233. //获取学费明细
  234. getPayDetail(len) {
  235. //获取明细款项名称数组
  236. var arr = len.match(/[^\\u4e00-\\u9fa5]+/g);
  237. var itemIdArr = arr.filter(function (value) {
  238. return value !== ".";
  239. });
  240. //获取明细金额数组
  241. var itemMoneyArr = len.match(/([0-9]+\.[0-9]+)+/g);
  242. //拼接成对象数组
  243. var item = [];
  244. for (var i in (itemIdArr, itemMoneyArr)) {
  245. var c = {
  246. id: itemIdArr[i],
  247. money: itemMoneyArr[i],
  248. };
  249. item.push(c);
  250. }
  251. this.Arr = item;
  252. },
  253. //支付
  254. getPay() {
  255. uni.showToast({
  256. title: "支付中,请稍等",
  257. icon: "loading",
  258. mask: true,
  259. duration: 1000,
  260. });
  261. this.getOrderNo(); //获取订单号
  262. },
  263. //获取订单号
  264. getOrderNo() {
  265. let that = this;
  266. let cardNumber = localStorage.getItem("cardNumber");
  267. let url =
  268. that.homeUrl + `/tuitionpayment/payorder/${that.studentNo}/create`;
  269. uni.request({
  270. url: url,
  271. data: {},
  272. header: {
  273. card_number: cardNumber,
  274. Accept: "application/json",
  275. "Content-Type": "application/json",
  276. "X-Requested-With": "XMLHttpRequest",
  277. },
  278. method: "POST",
  279. sslVerify: true,
  280. success: ({ data, statusCode, header }) => {
  281. let res = data.data;
  282. that.orderNo = res.orderNo;
  283. if (!data.success) {
  284. uni.showToast({
  285. title: data.message,
  286. icon: "error",
  287. mask: true,
  288. duration: 2000,
  289. });
  290. } else {
  291. that.getwxParam(); //拿微信支付参数
  292. }
  293. },
  294. fail: (error) => {},
  295. });
  296. },
  297. //获取微信支付参数
  298. getwxParam() {
  299. let that = this;
  300. let cardNumber = localStorage.getItem("cardNumber");
  301. let openId = localStorage.getItem("openId");
  302. let url = that.homeUrl + "/pay/ccb/getJsApiParam";
  303. uni.request({
  304. url: url,
  305. data: {
  306. orderNo: that.orderNo,
  307. openId: openId,
  308. },
  309. header: {
  310. card_number: cardNumber,
  311. Accept: "application/json",
  312. "Content-Type": "application/json",
  313. "X-Requested-With": "XMLHttpRequest",
  314. },
  315. method: "GET",
  316. sslVerify: true,
  317. success: ({ data, statusCode, header }) => {
  318. if (!data.success) {
  319. uni.showToast({
  320. title: data.message,
  321. icon: "error",
  322. mask: true,
  323. duration: 2000,
  324. });
  325. } else {
  326. let res = data.data;
  327. that.appId = res.appId;
  328. that.timeStamp = res.timeStamp;
  329. that.nonceStr = res.nonceStr;
  330. that.package = res.package;
  331. that.signType = res.signType;
  332. that.paySign = res.paySign;
  333. that.wxPay();
  334. }
  335. },
  336. fail: (error) => {},
  337. });
  338. },
  339. //吊起微信支付
  340. wxPay() {
  341. let that = this;
  342. function onBridgeReady() {
  343. WeixinJSBridge.invoke(
  344. "getBrandWCPayRequest",
  345. {
  346. appId: that.appId, //公众号ID,由商户传入
  347. timeStamp: that.timeStamp, //时间戳,自1970年以来的秒数
  348. nonceStr: that.nonceStr, //随机串
  349. package: that.package,
  350. signType: that.signType, //微信签名方式:
  351. paySign: that.paySign, //微信签名
  352. },
  353. function (res) {
  354. if (res.err_msg == "get_brand_wcpay_request:ok") {
  355. // 使用以上方式判断前端返回,微信团队郑重提示:
  356. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  357. }
  358. }
  359. );
  360. }
  361. if (typeof WeixinJSBridge == "undefined") {
  362. if (document.addEventListener) {
  363. document.addEventListener(
  364. "WeixinJSBridgeReady",
  365. onBridgeReady,
  366. false
  367. );
  368. } else if (document.attachEvent) {
  369. document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
  370. document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
  371. }
  372. } else {
  373. onBridgeReady();
  374. }
  375. },
  376. //获取当前URL指定参数
  377. getQueryString(name) {
  378. let url = window.location.href; // 获取URL
  379. let pattern = new RegExp("[\?\&]" + name + "=([^\&]+)", "i"); // 正则匹配URL
  380. let matcher = pattern.exec(url);
  381. if (matcher == null || matcher.length < 1) {
  382. return false;
  383. }
  384. return decodeURIComponent(matcher[1]); // 输出指定的参数值 中文也可以
  385. },
  386. },
  387. };
  388. </script>
  389. <style lang="scss" scoped>
  390. @import url("./css/parentPay.min.css");
  391. </style>