Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

interestsList.vue 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. <button type="default" class="button" @click="addInterestsList()">
  27. 加购权益
  28. </button>
  29. </view>
  30. </template>
  31. <script setup lang="ts">
  32. import { onLoad, onShow } from "@dcloudio/uni-app";
  33. import { reactive } from "vue";
  34. import { queryInterestsList } from "@/utils/network/api.js";
  35. import { stringToJson } from "@/utils/network/encryption";
  36. import { request } from "@/utils/network/request";
  37. import { etcQYAction } from "@/utils/network/api.js";
  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. orderPay,
  46. wechatAppID,
  47. wechatPayConfigId,
  48. wechatSecret,
  49. addProduct,
  50. queryDetails
  51. } from "@/utils/network/api";
  52. import {
  53. getItem,
  54. StorageKeys,
  55. setItem
  56. } from "@/utils/storage";
  57. const imgURL = `${fileURL}image/`;
  58. const state = reactive({
  59. openid: "",
  60. orderId: "",
  61. id: "",
  62. clientFee: "",
  63. list: [], //权益数据
  64. choiceValue: [], //选择的权益数据的下标
  65. choiceValueComplete: [] //选择的权益数据的具体数据
  66. })
  67. onLoad((option : any) => {
  68. getList(option.orderId);
  69. getOpenID();
  70. state.orderId = option.orderId;
  71. state.clientFee = option.clientFee;
  72. state.id = option.id;
  73. console.log("option", option)
  74. })
  75. const addInterestsList=()=>{
  76. state.choiceValueComplete = [];
  77. for (var i = 0; i < state.choiceValue.length; i++) {
  78. state.choiceValueComplete.push(state.list[state.choiceValue[i]])
  79. }
  80. let items = encodeURIComponent(JSON.stringify(state.choiceValueComplete));
  81. console.log("state.openid", state);
  82. const data = JSON.parse(decodeURIComponent(items));
  83. let productId = [];
  84. state.productMoney = 0;
  85. for (var i = 0; i < data.length; i++) {
  86. data['isOpened'] = 'node';
  87. state.productMoney += data[i]['discountPrice'] / 100;
  88. productId.push(data[i]['equityId'])
  89. }
  90. const options = {
  91. type: 2,
  92. data: {
  93. orderId: state.orderId, //订单编号
  94. },
  95. method: "POST",
  96. showLoading: true,
  97. };
  98. console.log("options", options);
  99. request(queryDetails, options).then((res) => {
  100. state.detailsObj = stringToJson(res.bizContent);
  101. console.log("state.detailsObj",state.detailsObj)
  102. let allMoney = (parseFloat(state.detailsObj.product.oncePrice * 0.01) + parseFloat(state.productMoney)).toFixed(2)
  103. const optionss = {
  104. type: 2,
  105. data: {
  106. orderId: state.orderId, //订单编号
  107. openId: getItem(StorageKeys.OpenId), //操作人 id
  108. equityId: productId.toString(), //权益Id
  109. totalAmount: allMoney * 100, //总金额
  110. isRepeatPurchase: 0
  111. },
  112. method: "POST",
  113. showLoading: true,
  114. };
  115. console.log("optionss", optionss);
  116. request(addProduct, optionss).then((res) => {
  117. uni.navigateTo({
  118. url: `/subpackage/orders/order_payment?orderId=${state.orderId}&&clientFee=${state.clientFee}&&id=${state.id}&&data=${items}`,
  119. });
  120. });
  121. });
  122. }
  123. const getList = (id) => {
  124. const options = {
  125. type: 2,
  126. data: { "orderId": id },
  127. method: 'POST',
  128. showLoading: true,
  129. }
  130. request(queryInterestsList, options).then((res) => {
  131. const data = stringToJson(res.bizContent);
  132. for (var i = 0; i < data.data.length; i++) {
  133. data.data[i]['isShow'] = false;
  134. }
  135. state.list = data.data
  136. console.log("222", state.list)
  137. })
  138. }
  139. const change = (e) => {
  140. console.log(e);
  141. }
  142. //获取微信小程序openid
  143. const getOpenID = () => {
  144. uni.login({
  145. provider: "weixin",
  146. success: function (e) {
  147. console.log(e);
  148. uni.request({
  149. url: `https://api.weixin.qq.com/sns/jscode2session?appid=${wechatAppID}&secret=${wechatSecret}&js_code=${e.code}&grant_type=authorization_code`,
  150. success: (res : any) => {
  151. state.openid = res.data.openid;
  152. setItem("QYorder", state);
  153. console.log(res);
  154. },
  155. fail: (err : any) => {
  156. uni.showToast({
  157. title: "网络异常,请重试!" + err.errcode,
  158. icon: "error",
  159. duration: 500,
  160. });
  161. return;
  162. },
  163. });
  164. },
  165. });
  166. };
  167. const savaHandle = () => {
  168. state.choiceValueComplete = [];
  169. for (var i = 0; i < state.choiceValue.length; i++) {
  170. state.choiceValueComplete.push(state.list[state.choiceValue[i]])
  171. }
  172. let items = encodeURIComponent(JSON.stringify(state.choiceValueComplete));
  173. console.log("state.choiceValueComplete", state.choiceValueComplete)
  174. console.log("openid*******", state.openid);
  175. //如果获取openId成功
  176. if (state.openid) {
  177. var data = {
  178. orderId: state.orderId,
  179. subOpenId: state.openid,
  180. };
  181. const options = {
  182. type: 2,
  183. data: data,
  184. method: "POST",
  185. showLoading: true,
  186. };
  187. request(etcQYAction, options).then((res) => {
  188. const data = stringToJson(res.bizContent);
  189. if (data.userState === "UNAUTHORIZED") {
  190. uni.navigateToMiniProgram({
  191. appId: "wxbcad394b3d99dac9",
  192. path: "pages/route/index",
  193. extraData: {
  194. appid: "wxcb1388c809fe25a9",
  195. sub_appid: "wx008c60533388527a",
  196. mch_id: "1500877591",
  197. sub_mch_id: "1622652848",
  198. nonce_str: data.nonceStr,
  199. sign_type: "HMAC-SHA256",
  200. trade_scene: "HIGHWAY",
  201. plate_number: data.plateNumber,
  202. sub_openid: data.subOpenId,
  203. sign: data.sign,
  204. },
  205. success(res) {
  206. console.log(res);
  207. },
  208. complete(res) {
  209. console.log(res);
  210. },
  211. fail(res) {
  212. console.log(res);
  213. // 未成功跳转到车主小程序
  214. },
  215. });
  216. } else if (data.userState === "NORMAL") {
  217. msg("已开通车主服务");
  218. uni.navigateTo({
  219. url: `/subpackage/orders/product-detail?orderId=${state.orderId}&&clientFee=${state.clientFee}&&id=${state.id}&&data=${items}`,
  220. });
  221. } else if (data.userState === "PAUSED") {
  222. msg("已暂停车主服务");
  223. return;
  224. } else if (data.userState === "OVERDUE") {
  225. msg("用户已开通车主服务,但欠费状态。提示用户还款,请跳转到车主服务");
  226. return;
  227. }
  228. });
  229. } else {
  230. //如果获取openId失败
  231. uni.showToast({
  232. title: "网络异常,请重试!",
  233. icon: "none",
  234. duration: 1000,
  235. });
  236. return;
  237. }
  238. };
  239. const changeIsShow = (index) => {
  240. console.log(index, state.list[index]['isShow'], !state.list[index]['isShow'])
  241. state.list[index]['isShow'] = !state.list[index]['isShow']
  242. console.log("state.list", state.list)
  243. }
  244. const getValue = (value) => {
  245. if (state.choiceValue.length == 0) {
  246. console.log("第一次")
  247. state.choiceValue.push(value)
  248. console.log("state.choiceValue", state.choiceValue)
  249. } else {
  250. var index = state.choiceValue.indexOf(value);
  251. if (index > -1) {//大于0 代表存在,
  252. state.choiceValue.splice(index, 1);//存在就删除
  253. } else {
  254. state.choiceValue.push(value)
  255. }
  256. console.log("state.choiceValue", state.choiceValue)
  257. }
  258. }
  259. </script>
  260. <style scoped lang="scss">
  261. .content {
  262. width: 100%;
  263. height: 100vh;
  264. }
  265. .button {
  266. height: 80rpx;
  267. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  268. border-radius: 40rpx;
  269. font-size: 32rpx;
  270. font-weight: 400;
  271. color: #ffffff;
  272. line-height: 80rpx;
  273. margin: 20rpx;
  274. }
  275. .imageDefault {
  276. height: 40rpx;
  277. width: 40rpx;
  278. transform: rotate(270deg);
  279. margin-right: 12rpx;
  280. color: white;
  281. }
  282. .imageChange {
  283. height: 40rpx;
  284. width: 40rpx;
  285. transform: rotate(90deg);
  286. margin-right: 12rpx;
  287. color: white;
  288. }
  289. .item {
  290. width: 90%;
  291. margin: 10rpx auto;
  292. background-color: rgb(41, 199, 207);
  293. // height: 150rpx;
  294. border-radius: 20rpx;
  295. padding: 20rpx;
  296. box-sizing: border-box;
  297. color: white;
  298. font-size: 32rpx;
  299. }
  300. .item>.title {
  301. width: 100%;
  302. display: flex;
  303. justify-content: space-between;
  304. align-items: center;
  305. }
  306. .title>checkbox-group {
  307. // float: right;
  308. }
  309. .children {
  310. margin-left: 50rpx;
  311. margin-top: 16rpx;
  312. }
  313. .children>view {
  314. height: 50rpx;
  315. line-height: 50rpx;
  316. }
  317. .show {
  318. display: inline-block;
  319. }
  320. .hide {
  321. display: none;
  322. }
  323. checkbox {
  324. transform: scale(0.8);
  325. }
  326. </style>