goodsList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <!--
  2. [商品兑换] 样式1 - 商品列表
  3. http://localhost:5173/card/#/pages/exchange/style1/goodsList
  4. https://oss-mbh5.colormaprun.com/card/#/pages/exchange/style1/goodsList
  5. -->
  6. <template>
  7. <view class="body">
  8. <view v-if="pageReady" class="content uni-column">
  9. <view class="uni-column exchg-top">
  10. <my-topbar :exchangeTitle="exchangeTitle" ruleLable="兑换地点" class="exchgbar-color" @btnBackClick="btnBack"
  11. @btnInfoClick="btnInfo"></my-topbar>
  12. <view class="top-content">
  13. <view class="scoreBox-cornerMark">仅限本赛事</view>
  14. <view class="scoreBox uni-column uni-ais uni-jcse">
  15. <view class="scoreBox-title">剩余积分</view>
  16. <view class="scoreBox-score uni-row">
  17. <image class="scoreBox-score-ico" mode="aspectFit" src="/static/exchange/score.png"></image>
  18. <view class="scoreBox-score-value">{{scoreRs.score}}</view>
  19. <!-- <view class="scoreBox-score-unite">分</view> -->
  20. </view>
  21. <view class="scoreBox-expire">{{fmtTime(scoreRs.extTime)}} 到期</view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="main uni-column">
  26. <view class="gl-title">兑换商品列表</view>
  27. <view class="norecord" v-if="goodsList == null || goodsList.length == 0">暂无记录</view>
  28. <view class="list uni-row" v-else>
  29. <view class="item uni-column" v-for="(item, index) in goodsList" :key="index"
  30. @click="showDetail(item)">
  31. <view class="item-picbox">
  32. <view class="item-cornerMark">库存 {{fmtStockQty(item.goodsLeftNum)}}</view>
  33. <image class="item-pic" mode="aspectFit" :src="item.goodsPic"></image>
  34. </view>
  35. <view class="item-introduce uni-column uni-jcse uni-ais">
  36. <view class="item-introduce-name" style="margin-top: 3rpx;">{{item.goodsName}}</view>
  37. <view class="uni-row">
  38. <image class="item-introduce-ico" mode="aspectFit" src="/static/exchange/score2.png">
  39. </image>
  40. <view class="item-introduce-score">-{{item.corrScore}}</view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <my-popup ref="mypopupExchg" :config="cardConfigData.popupExchgConfig" :dataList="cardConfigData.popupExchgList"></my-popup>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import tools from '/common/tools';
  52. import cardfunc from '../../../common/cardfunc';
  53. import {
  54. localCardConfig
  55. } from "./cardconfig/test.js";
  56. import {
  57. token,
  58. apiOnlineScoreQuery,
  59. apiCanExchangeGoodsList,
  60. checkResCode
  61. } from '/common/api';
  62. export default {
  63. data() {
  64. return {
  65. cardConfigData: cardfunc.cardConfigData,
  66. pageReady: false,
  67. pageName: "goodsList",
  68. firstEnterKey: 'firstEnter-exchange-style1',
  69. queryObj: {},
  70. queryString: "",
  71. from: "", // 来源页面
  72. token: "",
  73. exchangeTitle: "兑换商品",
  74. ecId: 0, // 卡片id
  75. scoreRs: {
  76. score: 260, // 可用积分
  77. extTime: 0, // 积分到期时间戳
  78. },
  79. goodsList: [{
  80. goodsId: 0, // 商品id
  81. goodsName: "", // 商品名称
  82. goodsPic: "", // 商品图片
  83. goodsLeftNum: 0, // 商品剩余数量
  84. corrScore: 0, // 兑换所需积分
  85. }],
  86. /* goodsList: [
  87. {
  88. goodsId: 0, // 商品id
  89. goodsName: "正宗农家土鸡蛋1枚", // 商品名称
  90. goodsPic: "/static/common/jidanquan.png", // 商品图片
  91. goodsLeftNum: 99999, // 商品剩余数量
  92. corrScore: 20, // 兑换所需积分
  93. },
  94. {
  95. goodsId: 0, // 商品id
  96. goodsName: "正宗农家土鸡蛋2222枚", // 商品名称
  97. goodsPic: "/static/common/lingxiucheng.png", // 商品图片
  98. goodsLeftNum: 60, // 商品剩余数量
  99. corrScore: 20, // 兑换所需积分
  100. },
  101. {
  102. goodsId: 0, // 商品id
  103. goodsName: "正宗农家土鸡蛋 1 枚", // 商品名称
  104. goodsPic: "/static/common/baihuagongyuan.png", // 商品图片
  105. goodsLeftNum: 60, // 商品剩余数量
  106. corrScore: 20, // 兑换所需积分
  107. },
  108. {
  109. goodsId: 0, // 商品id
  110. goodsName: "正宗农家土鸡蛋 正宗农家土鸡蛋 正宗农家土鸡蛋", // 商品名称
  111. goodsPic: "/static/common/sdzxxq2.png", // 商品图片
  112. goodsLeftNum: 60, // 商品剩余数量
  113. corrScore: 20, // 兑换所需积分
  114. },
  115. {
  116. goodsId: 0, // 商品id
  117. goodsName: "正宗农家土鸡蛋 1 枚", // 商品名称
  118. goodsPic: "/static/common/baihuagongyuan.png", // 商品图片
  119. goodsLeftNum: 60, // 商品剩余数量
  120. corrScore: 20, // 兑换所需积分
  121. },
  122. {
  123. goodsId: 0, // 商品id
  124. goodsName: "正宗农家土鸡蛋 正宗农家土鸡蛋 正宗农家土鸡蛋", // 商品名称
  125. goodsPic: "/static/common/sdzxxq2.png", // 商品图片
  126. goodsLeftNum: 60, // 商品剩余数量
  127. corrScore: 20, // 兑换所需积分
  128. },
  129. ] */
  130. }
  131. },
  132. computed: {},
  133. onLoad(query) { // 类型非必填,可自动推导
  134. // console.log(query);
  135. this.queryObj = query;
  136. this.queryString = tools.objectToQueryString(this.queryObj);
  137. // console.log(queryString);
  138. this.from = query["from"] ?? "";
  139. this.token = query["token"] ?? token;
  140. this.ecId = query["id"] ?? 0;
  141. this.firstEnterKey += "-" + this.ecId;
  142. console.log("firstEnterKey:", this.firstEnterKey);
  143. cardfunc.init(this, this.token, this.ecId);
  144. cardfunc.getCardConfig(this.cardConfigQueryCallback, localCardConfig);
  145. this.onlineScoreQuery();
  146. this.canExchangeGoodsList();
  147. },
  148. // 页面初次渲染完成,此时组件已挂载完成,DOM 树($el)已可用
  149. onReady() {},
  150. onShow() {},
  151. onUnload() {},
  152. methods: {
  153. fmtTime(timestamp, type = 3) {
  154. return tools.timestampToTime(timestamp * 1000, type);
  155. },
  156. // 格式化库存数量
  157. fmtStockQty(num) {
  158. let fmtNum = num;
  159. if (num > 99) {
  160. fmtNum = "99+";
  161. }
  162. return fmtNum;
  163. },
  164. cardConfigQueryCallback(cardconfig) {
  165. this.loadConfig(cardconfig);
  166. // setTimeout(this.dealFirstEnter, 500);
  167. },
  168. loadConfig(cardconfig) {
  169. cardconfig = cardfunc.parseCardConfig(cardconfig);
  170. // console.log("[loadCardConfig] cardconfig:", cardconfig);
  171. // 加载卡片通用配置
  172. if (cardconfig.common != undefined) {
  173. cardfunc.loadCardCommonConfig(cardconfig.common);
  174. }
  175. // -------- 加载当前页面的配置 --------
  176. const config = cardfunc.parseCardConfig(cardconfig[this.pageName]);
  177. // console.log("[loadConfig] config_page:", config);
  178. if (config == undefined || config == null) {
  179. this.pageReady = true;
  180. return;
  181. }
  182. // 加载CSS样式
  183. const css = config.css;
  184. if (css != undefined && css.length > 0) {
  185. tools.loadCssCode(css);
  186. }
  187. this.pageReady = true;
  188. },
  189. // 卡片内可用积分查询
  190. onlineScoreQuery() {
  191. uni.request({
  192. url: apiOnlineScoreQuery,
  193. header: {
  194. "Content-Type": "application/x-www-form-urlencoded",
  195. "token": this.token,
  196. },
  197. method: "POST",
  198. data: {
  199. ecId: this.ecId
  200. },
  201. success: (res) => {
  202. // console.log("onlineScoreQuery", res);
  203. if (checkResCode(res)) {
  204. this.scoreRs = res.data.data;
  205. }
  206. },
  207. fail: (err) => {
  208. console.log("onlineScoreQuery err", err);
  209. },
  210. });
  211. },
  212. // 积分可兑换商品列表查询
  213. canExchangeGoodsList() {
  214. uni.request({
  215. url: apiCanExchangeGoodsList,
  216. header: {
  217. "Content-Type": "application/x-www-form-urlencoded",
  218. "token": this.token,
  219. },
  220. method: "POST",
  221. data: {
  222. ecId: this.ecId
  223. },
  224. success: (res) => {
  225. // console.log("canExchangeGoodsList", res);
  226. this.goodsList = res.data.data;
  227. },
  228. fail: (err) => {
  229. console.log("canExchangeGoodsList err", err);
  230. },
  231. });
  232. },
  233. btnBack() {
  234. if (this.from != '') {
  235. const url = this.from + '?' + this.queryString;
  236. tools.appAction(url, "uni.navigateTo");
  237. } else {
  238. const url = `action://to_home/`;
  239. tools.appAction(url);
  240. }
  241. // window.history.back();
  242. },
  243. btnInfo() {
  244. this.$refs.mypopupExchg.popupOpen();
  245. },
  246. showDetail(data) {
  247. console.log("showDetail data:", data);
  248. this.queryObj.goodsId = data.goodsId;
  249. this.queryString = tools.objectToQueryString(this.queryObj);
  250. const url = '/pages/exchange/style1/goodsDetail?' + this.queryString;
  251. tools.appAction(url, "uni.navigateTo");
  252. }
  253. }
  254. }
  255. </script>
  256. <style scoped>
  257. .content {
  258. width: 100vw;
  259. height: 100vh;
  260. background: linear-gradient(119.37deg, #FFEF9E 0%, #FFEEDB 31.6%, #FFF3C2 100%);
  261. }
  262. .exchg-top {
  263. width: 100%;
  264. /* height: 170px; */
  265. padding-top: 36px;
  266. justify-content: space-between;
  267. }
  268. .exchgbar-color {
  269. /* color: #000000; */
  270. }
  271. .main {
  272. width: 100%;
  273. flex-grow: 1;
  274. margin-top: 10px;
  275. padding-bottom: 20px;
  276. border-radius: 19px 19px 0px 0px;
  277. border: 1px solid #FFFFFF;
  278. background: #F6F6F6;
  279. }
  280. .top-content {
  281. position: relative;
  282. width: 90%;
  283. height: 90px;
  284. margin-top: 10px;
  285. /* align-content: center; */
  286. border-radius: 8px;
  287. background: url('/static/exchange/top_right.png'), linear-gradient(117.53deg, #FFCD29 0%, #FFE694 42.36%, #FFC508 100%);
  288. background-repeat: no-repeat;
  289. background-position-x: 90%, center;
  290. background-position-y: 80%, center;
  291. background-size: 89px 53px, 100%;
  292. }
  293. .scoreBox {
  294. height: 80%;
  295. margin-left: 20px;
  296. margin-top: 10px;
  297. }
  298. .scoreBox-cornerMark {
  299. position: absolute;
  300. right: 0%;
  301. width: 60px;
  302. height: 17px;
  303. opacity: 1;
  304. border-radius: 0px 8px 0px 8px;
  305. background: #FFFFFF;
  306. font-size: 10px;
  307. font-weight: 500;
  308. color: #A65600;
  309. text-align: center;
  310. line-height: 17px;
  311. }
  312. .scoreBox-title {
  313. font-size: 12px;
  314. font-weight: 550;
  315. color: #000000;
  316. }
  317. .scoreBox-score {
  318. font-size: 12px;
  319. font-weight: 500;
  320. color: #A65600;
  321. }
  322. .scoreBox-score-ico {
  323. width: 23px;
  324. height: 19px;
  325. }
  326. .scoreBox-score-value {
  327. margin: 0 6px;
  328. font-size: 32px;
  329. font-weight: 700;
  330. }
  331. .scoreBox-score-unite {
  332. margin-top: 12px;
  333. }
  334. .scoreBox-expire {
  335. font-size: 10px;
  336. font-weight: 500;
  337. color: #A65600;
  338. }
  339. .gl-title {
  340. width: 90%;
  341. padding-top: 10px;
  342. padding-left: 20px;
  343. font-size: 15px;
  344. font-weight: 550;
  345. text-align: left;
  346. }
  347. .norecord {
  348. font-weight: 500;
  349. color: #818181;
  350. font-size: 14px;
  351. text-align: center;
  352. line-height: 58vh;
  353. }
  354. .list {
  355. width: 90%;
  356. flex-wrap: wrap;
  357. justify-content: flex-start;
  358. /* background-color: #FFCD29; */
  359. }
  360. .item {
  361. width: 43.8%;
  362. margin: 20rpx 20rpx;
  363. border-radius: 6px;
  364. background-color: #FFFFFF;
  365. }
  366. .item-picbox {
  367. position: relative;
  368. width: 100%;
  369. background: linear-gradient(180deg, #DBF1FF 0%, #FFFFDB 100%);
  370. border-radius: 6px 6px 0px 0px;
  371. }
  372. .item-cornerMark {
  373. position: absolute;
  374. left: 0%;
  375. width: 63px;
  376. height: 20px;
  377. opacity: 1;
  378. background: linear-gradient(90deg, rgb(255, 238, 184, 1) 0%, rgb(255, 239, 186, 0.3) 100%);
  379. border-radius: 6px 0px 6px 0px;
  380. font-size: 12px;
  381. font-weight: 400;
  382. color: #383838;
  383. text-align: center;
  384. line-height: 20px;
  385. white-space: nowrap;
  386. }
  387. .item-pic {
  388. width: 100%;
  389. height: 25vw;
  390. padding-top: 22px;
  391. padding-bottom: 10px;
  392. }
  393. .item-introduce {
  394. width: 86%;
  395. height: 60px;
  396. /* margin-top: 10rpx; */
  397. }
  398. .item-introduce-name {
  399. width: 100%;
  400. font-size: 14px;
  401. font-weight: 500;
  402. color: #000;
  403. white-space: nowrap;
  404. overflow: hidden;
  405. /* text-overflow: ellipsis; */
  406. }
  407. .item-introduce-ico {
  408. width: 30px;
  409. height: 20px;
  410. }
  411. .item-introduce-score {
  412. margin: 0 3px;
  413. font-size: 16px;
  414. font-weight: 500;
  415. color: #FF8D1A;
  416. }
  417. </style>