Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

interestsList.vue 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="content">
  3. <view class="item" v-for="(item,index) in state.list" :key='index'>
  4. <view class="title" @click="addInterestsList(item)">
  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="addInterestsList()">
  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 { equityProductsApi } 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. addProduct,
  47. queryDetails,
  48. getOpenidApi
  49. } from "@/utils/network/api";
  50. import {
  51. getItem,
  52. StorageKeys,
  53. setItem
  54. } from "@/utils/storage";
  55. const imgURL = `${fileURL}image/`;
  56. const state = reactive({
  57. openid: "",
  58. orderId: "",
  59. id: "",
  60. clientFee: "",
  61. list: [], //权益数据
  62. choiceValue: [], //选择的权益数据的下标
  63. choiceValueComplete: [], //选择的权益数据的具体数据
  64. isValueCard: "",
  65. type: 0,
  66. userType: 0,
  67. promoteId: "", //产品id
  68. totalAmount: 0, //产品+权益产品金额
  69. })
  70. onLoad((option : any) => {
  71. // getList("promoteId", option);
  72. console.log("promoteId", option)
  73. state.orderId = option.orderId;
  74. state.clientFee = option.clientFee;
  75. state.id = option.id;
  76. state.userType = option.userType;
  77. state.type = option.type;
  78. state.isValueCard = option.isValueCard;
  79. state.promoteId = option.promoteId;
  80. state.totalAmount = option.fee;
  81. getList();
  82. getOpenID();
  83. console.log("option", option)
  84. })
  85. const addInterestsList = (item) => {
  86. console.log("item", item)
  87. state.totalAmount = Number(state.totalAmount) + Number(item.discountPrice)
  88. uni.redirectTo({
  89. url: `/subpackage/orders/essential-information?promoteId=${getItem("promoteId")}&userType=${state.userType}&type=${state.type}&isValueCard=${state.isValueCard}&totalAmount=${state.totalAmount}&equityId=${item.equityId}`,
  90. });
  91. return;
  92. state.choiceValueComplete = [];
  93. for (var i = 0; i < state.choiceValue.length; i++) {
  94. state.choiceValueComplete.push(state.list[state.choiceValue[i]])
  95. }
  96. let items = encodeURIComponent(JSON.stringify(state.choiceValueComplete));
  97. console.log("state.openid", state);
  98. const data = JSON.parse(decodeURIComponent(items));
  99. let productId = [];
  100. state.productMoney = 0;
  101. for (var i = 0; i < data.length; i++) {
  102. data['isOpened'] = 'node';
  103. state.productMoney += data[i]['discountPrice'] / 100;
  104. productId.push(data[i]['equityId'])
  105. }
  106. const options = {
  107. type: 2,
  108. data: {
  109. orderId: state.orderId, //订单编号
  110. },
  111. method: "POST",
  112. showLoading: true,
  113. };
  114. console.log("options", options);
  115. request(queryDetails, options).then((res) => {
  116. state.detailsObj = stringToJson(res.bizContent);
  117. console.log("state.detailsObj", state.detailsObj)
  118. let allMoney = (parseFloat(state.detailsObj.product.oncePrice * 0.01) + parseFloat(state.productMoney)).toFixed(2)
  119. const optionss = {
  120. type: 2,
  121. data: {
  122. orderId: state.orderId, //订单编号
  123. openId: getItem(StorageKeys.OpenId), //操作人 id
  124. equityId: productId.toString(), //权益Id
  125. totalAmount: allMoney * 100, //总金额
  126. isRepeatPurchase: 0
  127. },
  128. method: "POST",
  129. showLoading: true,
  130. };
  131. console.log("optionss", optionss);
  132. request(addProduct, optionss).then((res) => {
  133. // uni.redirectTo({
  134. // url: `/subpackage/orders/product-detail?orderId=${state.orderId}&&clientFee=${state.clientFee}&&id=${state.id}&&data=${items}&&isValueCard=${state.detailsObj.isValueCard}`,
  135. // });
  136. uni.redirectTo({
  137. url: `/subpackage/orders/essential-information?promoteId=${getItem("promoteId")}&userType=${state.userType}&type=${state.type}&isValueCard=${state.isValueCard}`,
  138. });
  139. });
  140. });
  141. }
  142. const getList = () => {
  143. const options = {
  144. type: 2,
  145. data: {
  146. "promoteId": state.promoteId,
  147. },
  148. method: 'POST',
  149. showLoading: true,
  150. }
  151. request(equityProductsApi, options).then((res) => {
  152. const data = stringToJson(res.bizContent);
  153. for (var i = 0; i < data.data.length; i++) {
  154. data.data[i]['isShow'] = false;
  155. }
  156. state.list = data.data
  157. console.log("222", data.data)
  158. })
  159. }
  160. const change = (e) => {
  161. console.log(e);
  162. }
  163. //获取微信小程序openid
  164. const getOpenID = () => {
  165. // #ifdef MP-WEIXIN
  166. uni.login({
  167. provider: "weixin",
  168. success: function (e) {
  169. console.log(e);
  170. getOpenid(e.code);
  171. },
  172. });
  173. //#endif
  174. };
  175. const getOpenid = (code) => {
  176. const options = {
  177. type: 2,
  178. data: {
  179. "jsCode": code
  180. },
  181. method: "POST",
  182. showLoading: true,
  183. };
  184. // #ifdef MP-WEIXIN
  185. request(getOpenidApi, options).then((res) => {
  186. const result = stringToJson(res.bizContent);
  187. console.log("获取微信小程序openid", result);
  188. const openidData = stringToJson(result.data);
  189. state.openid = openidData.openid;
  190. setItem("QYorder", state);
  191. // setItem("QYorder", result.data);
  192. // state.openid = result.data.openid
  193. });
  194. // #endif
  195. }
  196. const changeIsShow = (index) => {
  197. console.log(index, state.list[index]['isShow'], !state.list[index]['isShow'])
  198. state.list[index]['isShow'] = !state.list[index]['isShow']
  199. console.log("state.list", state.list)
  200. }
  201. const getValue = (value) => {
  202. if (state.choiceValue.length == 0) {
  203. console.log("第一次")
  204. state.choiceValue.push(value)
  205. console.log("state.choiceValue", state.choiceValue)
  206. } else {
  207. var index = state.choiceValue.indexOf(value);
  208. if (index > -1) {//大于0 代表存在,
  209. state.choiceValue.splice(index, 1);//存在就删除
  210. } else {
  211. state.choiceValue.push(value)
  212. }
  213. console.log("state.choiceValue", state.choiceValue)
  214. }
  215. }
  216. </script>
  217. <style scoped lang="scss">
  218. .content {
  219. width: 100%;
  220. height: 100vh;
  221. }
  222. .button {
  223. height: 80rpx;
  224. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  225. border-radius: 40rpx;
  226. font-size: 32rpx;
  227. font-weight: 400;
  228. color: #ffffff;
  229. line-height: 80rpx;
  230. margin: 20rpx;
  231. }
  232. .imageDefault {
  233. height: 40rpx;
  234. width: 40rpx;
  235. transform: rotate(270deg);
  236. margin-right: 12rpx;
  237. color: white;
  238. }
  239. .imageChange {
  240. height: 40rpx;
  241. width: 40rpx;
  242. transform: rotate(90deg);
  243. margin-right: 12rpx;
  244. color: white;
  245. }
  246. .item {
  247. width: 90%;
  248. margin: 20rpx auto;
  249. background-color: rgb(41, 199, 207);
  250. border-radius: 20rpx;
  251. padding: 20rpx;
  252. box-sizing: border-box;
  253. color: white;
  254. font-size: 32rpx;
  255. }
  256. .item>.title {
  257. width: 100%;
  258. display: flex;
  259. justify-content: space-between;
  260. align-items: center;
  261. }
  262. .title>checkbox-group {
  263. // float: right;
  264. }
  265. .children {
  266. margin-left: 50rpx;
  267. margin-top: 16rpx;
  268. }
  269. .children>view {
  270. height: 50rpx;
  271. line-height: 50rpx;
  272. }
  273. .show {
  274. display: inline-block;
  275. }
  276. .hide {
  277. display: none;
  278. }
  279. checkbox {
  280. transform: scale(0.8);
  281. }
  282. </style>