You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sign-up.vue 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <image style="
  3. margin-top: 20rpx;
  4. width: 100%;
  5. height: 240rpx;
  6. background-color: #eeeeee;
  7. " :src="`${$imgUrl}applyCard/car-service.png`"></image>
  8. <view class="title"> 微信车主服务 </view>
  9. <view class="value">
  10. <view class="content_1">
  11. 微信车主服务是微信支付为车主用户提供的安全便捷的智慧服务
  12. </view>
  13. <view class="content_2">
  14. 本次将为贵州黔通智联科技股份有限公司开启免密支付服务,后续相关的费用将通过微信车主服务从你的微信支付账户扣除
  15. </view>
  16. <view class="content_3">
  17. 注:签约成功后请返回本页面,再次点击开通服务
  18. </view>
  19. </view>
  20. <view class="as-layout-horizontal agreement">
  21. <checkbox-group @change="checkboxChange">
  22. <checkbox :checked="state.checked" style="transform: scale(0.8)" />我已阅读并同意
  23. </checkbox-group>
  24. <text style="color:#007AFF;text-decoration: underline;" @click="downAuthD()">《代扣协议》</text>
  25. </view>
  26. <view class="action">
  27. <button type="default" class="button" @click="savaHandle()">
  28. {{state.channelSing=="0"?'开通服务':'恢复签约'}}
  29. </button>
  30. </view>
  31. </template>
  32. <script setup lang="ts">
  33. import { onLoad, onShow } from "@dcloudio/uni-app";
  34. import { reactive } from "vue";
  35. import { etcQYAction, channelSingQueryApi } from "@/utils/network/api.js";
  36. import { request } from "@/utils/network/request.js";
  37. import { stringToJson } from "@/utils/network/encryption";
  38. import { fileURL } from "@/datas/fileURL.js";
  39. import navBar from "@/components/nav-bar/nav-bar2.vue";
  40. import navBgCar from "./components/nav-bg-car4";
  41. import { setItem } from "@/utils/storage";
  42. import { msg } from "@/utils/utils";
  43. import {
  44. checkOrderStatus,
  45. wechatAppID,
  46. wechatSecret,
  47. getOpenidApi,
  48. infoQuery,
  49. envs
  50. } from "@/utils/network/api";
  51. const imgURL = `${fileURL}image/`;
  52. const state = reactive({
  53. openid: "",
  54. orderId: "",
  55. id: "",
  56. clientFee: "",
  57. checked: false,
  58. agreeURL: "",
  59. channelSing: "0",//0 正常签约 1恢复签约
  60. vehiclePlate: "",
  61. code: ""
  62. });
  63. onLoad((option : any) => {
  64. getOpenID();
  65. state.orderId = option.orderId;
  66. if (option.channelSing) {
  67. state.channelSing = option.channelSing;
  68. }
  69. state.vehiclePlate = option.vehiclePlate;
  70. getInfo();
  71. });
  72. const checkboxChange = (e) => {
  73. state.checked = !state.checked;
  74. console.log(state.checked);
  75. };
  76. const getInfo = () => {
  77. //参数说明
  78. let options = {
  79. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  80. data: {
  81. businessType: 'WITHHOLD_AGREEMENT' //代扣协议
  82. }, //请求参数
  83. method: "POST", //提交方式(默认POST)
  84. showLoading: true, //是否显示加载中(默认显示)
  85. };
  86. //调用方式
  87. request(infoQuery, options)
  88. .then((res) => {
  89. let data = stringToJson(res.bizContent)
  90. if (data.textType = "URL") {
  91. state.agreeURL = envs[process.env.NODE_ENV].baseUrl + data.text
  92. }
  93. console.log("代扣协议", state.agreeURL);
  94. })
  95. .catch((err) => {
  96. console.log(err);
  97. });
  98. }
  99. //获取微信小程序openid
  100. const getOpenID = () => {
  101. // #ifdef MP-WEIXIN
  102. uni.login({
  103. provider: "weixin",
  104. success: function (e) {
  105. console.log(e);
  106. state.code = e.code
  107. getOpenid(e.code);
  108. },
  109. });
  110. // #endif
  111. };
  112. const downAuthD = () => {
  113. // tools.showLoadingAlert("加载中");
  114. uni.downloadFile({
  115. url: state.agreeURL,
  116. filePath: wx.env.USER_DATA_PATH + '/' + '代扣协议.docx',
  117. success(res) {
  118. const filePath = res.filePath
  119. uni.openDocument({
  120. filePath: filePath,
  121. fileType: 'docx',
  122. showMenu: true, //关键点
  123. success: function (res) {
  124. msg("打开文档成功");
  125. },
  126. fail: function (err) {
  127. msg("打开文档失败");
  128. }
  129. });
  130. },
  131. fail: function (err) {
  132. msg("下载文档失败");
  133. console.log("err", err)
  134. },
  135. complete(res) {
  136. }
  137. })
  138. }
  139. const getOpenid = (code) => {
  140. const options = {
  141. type: 2,
  142. data: {
  143. "jsCode": code
  144. },
  145. method: "POST",
  146. showLoading: true,
  147. };
  148. // #ifdef MP-WEIXIN
  149. request(getOpenidApi, options).then((res) => {
  150. const result = stringToJson(res.bizContent);
  151. const openidData = stringToJson(result.data);
  152. state.openid = openidData.openid;
  153. console.log("获取微信小程序openid", state.openid);
  154. setItem("QYorder", state);
  155. });
  156. // #endif
  157. }
  158. const savaHandle = () => {
  159. if (!state.checked) {
  160. msg("请勾选协议!")
  161. return;
  162. }
  163. console.log("openid*******", state.openid);
  164. //如果获取openId成功
  165. if (state.openid) {
  166. var data = {
  167. orderId: state.orderId,
  168. subOpenId: state.openid,
  169. };
  170. const options = {
  171. type: 2,
  172. data: data,
  173. method: "POST",
  174. showLoading: true,
  175. };
  176. request(etcQYAction, options).then((res) => {
  177. const data = stringToJson(res.bizContent);
  178. console.log("data", data)
  179. if (data.userState === "UNAUTHORIZED") {
  180. if (state.channelSing == "0") {
  181. uni.navigateToMiniProgram({
  182. appId: "wxbcad394b3d99dac9",
  183. path: "pages/route/index",
  184. extraData: {
  185. appid: "wxcb1388c809fe25a9",
  186. sub_appid: "wx008c60533388527a",
  187. mch_id: "1500877591",
  188. sub_mch_id: "1622652848",
  189. nonce_str: data.nonceStr,
  190. sign_type: "HMAC-SHA256",
  191. trade_scene: "HIGHWAY",
  192. plate_number: data.plateNumber,
  193. sub_openid: data.subOpenId,
  194. sign: data.sign,
  195. channel_type: "ETC"
  196. },
  197. success(res) {
  198. console.log(res);
  199. },
  200. complete(res) {
  201. console.log(res);
  202. },
  203. fail(res) {
  204. console.log(res);
  205. // 未成功跳转到车主小程序
  206. },
  207. });
  208. } else {
  209. // 恢复签约
  210. const optionss = {
  211. type: 2,
  212. data: {
  213. plateNumber: state.vehiclePlate,
  214. openid: state.openid,
  215. channelId: '52010188925',
  216. tradeScene: 'HIGHWAY',
  217. code: state.code
  218. },
  219. method: "POST",
  220. showLoading: true,
  221. };
  222. request(channelSingQueryApi, optionss)
  223. .then((res) => {
  224. let data = stringToJson(res.bizContent)
  225. uni.navigateToMiniProgram({
  226. appId: "wxbcad394b3d99dac9",
  227. path: "pages/route/index",
  228. extraData: {
  229. appid: data.appid,
  230. sub_appid: data.subAppid,
  231. mch_id: data.mchId,
  232. sub_mch_id: data.subMchId,
  233. nonce_str: data.nonceStr,
  234. sign_type: data.signType,
  235. trade_scene: data.tradeScene,
  236. plate_number: data.plateNumber,
  237. sub_openid: data.subOpenid,
  238. sign: data.sign,
  239. channel_type: data.channelType
  240. },
  241. success(res) {
  242. },
  243. complete(res) {
  244. console.log(res);
  245. },
  246. fail(res) {
  247. console.log(res);
  248. // 未成功跳转到车主小程序
  249. },
  250. });
  251. })
  252. .catch((err) => {
  253. console.log(err);
  254. });
  255. }
  256. } else if (data.userState === "NORMAL") {
  257. msg("已开通车主服务");
  258. setTimeout(() => {
  259. uni.switchTab({
  260. url: "/pages/order/order"
  261. })
  262. }, 1500)
  263. } else if (data.userState === "PAUSED") {
  264. msg("已暂停车主服务");
  265. return;
  266. } else if (data.userState === "OVERDUE") {
  267. msg("用户已开通车主服务,但欠费状态。提示用户还款,请跳转到车主服务");
  268. return;
  269. }
  270. });
  271. } else {
  272. //如果获取openId失败
  273. uni.showToast({
  274. title: "网络异常,请重试!",
  275. icon: "none",
  276. duration: 1000,
  277. });
  278. return;
  279. }
  280. };
  281. </script>
  282. <style lang="scss" scoped>
  283. .action {
  284. margin-top: 40rpx;
  285. padding-left: 20rpx;
  286. padding-right: 20rpx;
  287. padding-bottom: 30rpx;
  288. .button {
  289. height: 80rpx;
  290. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  291. border-radius: 40rpx;
  292. font-size: 32rpx;
  293. font-weight: 400;
  294. color: #ffffff;
  295. line-height: 80rpx;
  296. }
  297. }
  298. .title {
  299. text-align: center;
  300. margin-top: 15rpx;
  301. font-size: 36rpx;
  302. font-family: Microsoft YaHei;
  303. font-weight: 400;
  304. color: #333333;
  305. line-height: 36rpx;
  306. }
  307. .value {
  308. padding: 0rpx 60rpx;
  309. }
  310. .content_1 {
  311. margin-top: 60rpx;
  312. font-size: 30rpx;
  313. font-family: Microsoft YaHei;
  314. font-weight: 400;
  315. color: #666666;
  316. line-height: 58rpx;
  317. }
  318. .content_2 {
  319. margin-top: 50rpx;
  320. font-size: 30rpx;
  321. font-family: Microsoft YaHei;
  322. font-weight: 400;
  323. color: #666666;
  324. line-height: 58rpx;
  325. }
  326. .content_3 {
  327. margin-top: 50rpx;
  328. font-size: 30rpx;
  329. font-family: Microsoft YaHei;
  330. font-weight: 400;
  331. color: #ff0000;
  332. line-height: 58rpx;
  333. }
  334. .agreement {
  335. font-size: 30rpx;
  336. display: flex;
  337. flex-wrap: wrap;
  338. margin-top: 20rpx;
  339. align-items: center;
  340. justify-content: center;
  341. }
  342. </style>