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.

interestsList.vue 7.3KB

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