Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

interestsList.vue 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <view class="content">
  3. <view class="item" v-for="(item,index) in state.list" :key='index'>
  4. <view class="title">
  5. <view>
  6. <view v-if='item.children' style="display: inline-block;">
  7. <image :class="item.isShow?'imageChange':'imageDefault'" @click="changeIsShow(index)"
  8. src="../../static/image/icon-back.png" alt="" srcset=""></image>
  9. </view>
  10. <text><text>{{item.productName}}</text>&nbsp;&nbsp;<text>¥{{item.discountPrice * 0.01}}</text></text>
  11. </view>
  12. <checkbox-group @change='getValue(index)'>
  13. <label>
  14. <checkbox :value="index" />
  15. </label>
  16. </checkbox-group>
  17. </view>
  18. <view v-if="item.isShow" class="children" v-for="(itemChild,index) in item.children" :key='index'>
  19. <view><text>{{itemChild.productName}}</text>&nbsp;&nbsp;<text>{{itemChild.discountPrice * 0.01}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. <button type="default" class="button" @click="savaHandle()">
  24. 开通服务
  25. </button>
  26. </view>
  27. </template>
  28. <script setup lang="ts">
  29. import { onLoad, onShow } from "@dcloudio/uni-app";
  30. import { reactive } from "vue";
  31. import { queryInterestsList } from "@/utils/network/api.js";
  32. import { stringToJson } from "@/utils/network/encryption";
  33. import { request } from "@/utils/network/request";
  34. import { etcQYAction } from "@/utils/network/api.js";
  35. import { fileURL } from "@/datas/fileURL.js";
  36. import navBar from "@/components/nav-bar/nav-bar2.vue";
  37. import navBgCar from "./components/nav-bg-car4";
  38. import { setItem } from "@/utils/storage";
  39. import { msg } from "@/utils/utils";
  40. import {
  41. checkOrderStatus,
  42. orderPay,
  43. wechatAppID,
  44. wechatPayConfigId,
  45. wechatSecret,
  46. } from "@/utils/network/api";
  47. const imgURL = `${fileURL}image/`;
  48. const state = reactive({
  49. openid: "",
  50. orderId: "",
  51. id: "",
  52. clientFee: "",
  53. list: [], //权益数据
  54. choiceValue: [], //选择的权益数据的下标
  55. choiceValueComplete: [] //选择的权益数据的具体数据
  56. })
  57. onLoad((option : any) => {
  58. getList(option.orderId);
  59. getOpenID();
  60. state.orderId = option.orderId;
  61. state.clientFee = option.clientFee;
  62. state.id = option.id;
  63. console.log("option", option)
  64. })
  65. const getList = (id) => {
  66. const options = {
  67. type: 2,
  68. data: { "orderId": id },
  69. method: 'POST',
  70. showLoading: true,
  71. }
  72. request(queryInterestsList, options).then((res) => {
  73. const data = stringToJson(res.bizContent);
  74. for (var i = 0; i < data.data.length; i++) {
  75. data.data[i]['isShow'] = false;
  76. }
  77. state.list = data.data
  78. console.log("222", state.list)
  79. })
  80. }
  81. const change = (e) => {
  82. console.log(e);
  83. }
  84. //获取微信小程序openid
  85. const getOpenID = () => {
  86. uni.login({
  87. provider: "weixin",
  88. success: function (e) {
  89. console.log(e);
  90. uni.request({
  91. url: `https://api.weixin.qq.com/sns/jscode2session?appid=${wechatAppID}&secret=${wechatSecret}&js_code=${e.code}&grant_type=authorization_code`,
  92. success: (res : any) => {
  93. state.openid = res.data.openid;
  94. setItem("QYorder", state);
  95. console.log(res);
  96. },
  97. fail: (err : any) => {
  98. uni.showToast({
  99. title: "网络异常,请重试!" + err.errcode,
  100. icon: "error",
  101. duration: 500,
  102. });
  103. return;
  104. },
  105. });
  106. },
  107. });
  108. };
  109. const savaHandle = () => {
  110. state.choiceValueComplete = [];
  111. for (var i = 0; i < state.choiceValue.length; i++) {
  112. state.choiceValueComplete.push(state.list[state.choiceValue[i]])
  113. }
  114. let items = encodeURIComponent(JSON.stringify(state.choiceValueComplete));
  115. console.log("state.choiceValueComplete", state.choiceValueComplete)
  116. console.log("openid*******", state.openid);
  117. //如果获取openId成功
  118. if (state.openid) {
  119. var data = {
  120. orderId: state.orderId,
  121. subOpenId: state.openid,
  122. };
  123. const options = {
  124. type: 2,
  125. data: data,
  126. method: "POST",
  127. showLoading: true,
  128. };
  129. request(etcQYAction, options).then((res) => {
  130. const data = stringToJson(res.bizContent);
  131. if (data.userState === "UNAUTHORIZED") {
  132. uni.navigateToMiniProgram({
  133. appId: "wxbcad394b3d99dac9",
  134. path: "pages/route/index",
  135. extraData: {
  136. appid: "wxcb1388c809fe25a9",
  137. sub_appid: "wx008c60533388527a",
  138. mch_id: "1500877591",
  139. sub_mch_id: "1622652848",
  140. nonce_str: data.nonceStr,
  141. sign_type: "HMAC-SHA256",
  142. trade_scene: "HIGHWAY",
  143. plate_number: data.plateNumber,
  144. sub_openid: data.subOpenId,
  145. sign: data.sign,
  146. },
  147. success(res) {
  148. console.log(res);
  149. },
  150. complete(res) {
  151. console.log(res);
  152. },
  153. fail(res) {
  154. console.log(res);
  155. // 未成功跳转到车主小程序
  156. },
  157. });
  158. } else if (data.userState === "NORMAL") {
  159. msg("已开通车主服务");
  160. uni.navigateTo({
  161. url: `/subpackage/orders/product-detail?orderId=${state.orderId}&&clientFee=${state.clientFee}&&id=${state.id}&&data=${items}`,
  162. });
  163. } else if (data.userState === "PAUSED") {
  164. msg("已暂停车主服务");
  165. return;
  166. } else if (data.userState === "OVERDUE") {
  167. msg("用户已开通车主服务,但欠费状态。提示用户还款,请跳转到车主服务");
  168. return;
  169. }
  170. });
  171. } else {
  172. //如果获取openId失败
  173. uni.showToast({
  174. title: "网络异常,请重试!",
  175. icon: "none",
  176. duration: 1000,
  177. });
  178. return;
  179. }
  180. };
  181. const changeIsShow = (index) => {
  182. console.log(index, state.list[index]['isShow'], !state.list[index]['isShow'])
  183. state.list[index]['isShow'] = !state.list[index]['isShow']
  184. console.log("state.list", state.list)
  185. }
  186. const getValue = (value) => {
  187. if (state.choiceValue.length == 0) {
  188. console.log("第一次")
  189. state.choiceValue.push(value)
  190. console.log("state.choiceValue", state.choiceValue)
  191. } else {
  192. var index = state.choiceValue.indexOf(value);
  193. if (index > -1) {//大于0 代表存在,
  194. state.choiceValue.splice(index, 1);//存在就删除
  195. } else {
  196. state.choiceValue.push(value)
  197. }
  198. console.log("state.choiceValue", state.choiceValue)
  199. }
  200. }
  201. </script>
  202. <style scoped lang="scss">
  203. .content {
  204. width: 100%;
  205. height: 100vh;
  206. }
  207. .button {
  208. height: 80rpx;
  209. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  210. border-radius: 40rpx;
  211. font-size: 32rpx;
  212. font-weight: 400;
  213. color: #ffffff;
  214. line-height: 80rpx;
  215. margin: 20rpx;
  216. }
  217. .imageDefault {
  218. height: 40rpx;
  219. width: 40rpx;
  220. transform: rotate(270deg);
  221. margin-right: 12rpx;
  222. color: white;
  223. }
  224. .imageChange {
  225. height: 40rpx;
  226. width: 40rpx;
  227. transform: rotate(90deg);
  228. margin-right: 12rpx;
  229. color: white;
  230. }
  231. .item {
  232. width: 90%;
  233. margin: 10rpx auto;
  234. background-color: rgb(41, 199, 207);
  235. // height: 150rpx;
  236. border-radius: 20rpx;
  237. padding: 20rpx;
  238. box-sizing: border-box;
  239. color: white;
  240. font-size: 32rpx;
  241. }
  242. .item>.title {
  243. width: 100%;
  244. display: flex;
  245. justify-content: space-between;
  246. align-items: center;
  247. }
  248. .title>checkbox-group {
  249. // float: right;
  250. }
  251. .children {
  252. margin-left: 50rpx;
  253. margin-top: 16rpx;
  254. }
  255. .children>view {
  256. height: 50rpx;
  257. line-height: 50rpx;
  258. }
  259. .show {
  260. display: inline-block;
  261. }
  262. .hide {
  263. display: none;
  264. }
  265. checkbox {
  266. transform: scale(0.8);
  267. }
  268. </style>