金诚优选前端代码
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.

250 lines
6.2 KiB

  1. <template>
  2. <view id="pointstore-index">
  3. <view class="contents">
  4. <view class="list">
  5. <view class="top">
  6. <view class="login" v-if="!token" @tap="jumpLogin">
  7. 快速登录 / 注册
  8. </view>
  9. <view class="point-info" :style="'background: ' + config.mainColor" v-else>
  10. <view class="left">
  11. <view>
  12. 当前积分
  13. </view>
  14. <view class="num">
  15. {{point.pointValid}}
  16. </view>
  17. </view>
  18. <view class="right">
  19. <view class="record" @tap="jumpRecord">兑换记录</view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="no-list" v-if="init">暂无可兑换商品</view>
  24. <view class="commodity-bottom" v-else>
  25. <view v-for="(item, idx) in storeList" :key="idx">
  26. <view class="commodity-out" :data-id="item.id" v-for="(item, index) in storeList[idx]" :key="index" @tap="jump">
  27. <view class="commodity-box">
  28. <view class="commodity-img">
  29. <image mode="widthFix" :src="item.img"></image>
  30. </view>
  31. <view class="commodity-name">
  32. {{item.name}}
  33. </view>
  34. <view class="commodity-money">
  35. <view class="money">
  36. {{item.redeem_point}}积分
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="loadingbox" :hidden="!show">
  43. 正在加载下一页数据
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  52. export default {
  53. data() {
  54. return {
  55. page: 1,
  56. storeList: [],
  57. meta: '',
  58. show: false,
  59. point: {},
  60. token: '',
  61. init: false,
  62. config: ''
  63. };
  64. },
  65. onReachBottom() {
  66. var hasMore = this.meta.pagination.total_pages > this.meta.pagination.current_page;
  67. if (hasMore) {
  68. this.setData({
  69. show: true
  70. });
  71. var query = {
  72. is_largess: 1
  73. };
  74. var page = this.meta.pagination.current_page + 1;
  75. this.queryCommodityList(query, page);
  76. } else {
  77. wx.showToast({
  78. image: '../../../static/error.png',
  79. title: '再拉也没有啦'
  80. });
  81. }
  82. },
  83. onLoad() {
  84. // 第三方平台配置颜色
  85. var gbConfig = this.$cookieStorage.get('globalConfig') || '';
  86. this.setData({
  87. config: gbConfig
  88. });
  89. var token = this.$cookieStorage.get('user_token');
  90. this.setData({
  91. token: token
  92. });
  93. if (token) {
  94. this.queryUserPoint('default');
  95. }
  96. var query = {
  97. is_largess: 1
  98. };
  99. this.queryCommodityList(query);
  100. },
  101. methods: {
  102. jump(e) {
  103. var id = e.currentTarget.dataset.id;
  104. wx.navigateTo({
  105. url: '/pages/pointStore/detail/detail?id=' + id
  106. });
  107. },
  108. jumpRecord() {
  109. wx.navigateTo({
  110. url: '/pages/pointStore/record/record'
  111. });
  112. },
  113. jumpLogin() {
  114. var url = getUrl();
  115. wx.navigateTo({
  116. url: '/pages/user/register/register?url=' + url
  117. });
  118. },
  119. // 商品列表
  120. queryCommodityList(query = {}, page = 1) {
  121. var params = Object.assign({}, query, {
  122. page
  123. });
  124. wx.showLoading({
  125. title: '加载中',
  126. mask: true
  127. });
  128. this.$http.get({
  129. api: 'api/store/list',
  130. data: params
  131. }).then(res => {
  132. if (res.statusCode == 200) {
  133. res = res.data;
  134. if (res.status) {
  135. // 商品列表页赋值
  136. this.setData({
  137. [`storeList.${page - 1}`]: res.data,
  138. meta: res.meta
  139. });
  140. if (res.data != '') {
  141. this.setData({
  142. init: false
  143. });
  144. } else {
  145. this.setData({
  146. init: true
  147. });
  148. }
  149. } else {
  150. wx.showModal({
  151. title: '',
  152. content: res.message,
  153. showCancel: false
  154. });
  155. }
  156. } else {
  157. wx.showModal({
  158. title: '',
  159. content: "请求失败",
  160. showCancel: false
  161. });
  162. }
  163. this.setData({
  164. show: false
  165. });
  166. wx.hideLoading();
  167. }).catch(rej => {
  168. wx.showModal({
  169. title: '',
  170. content: '请求失败',
  171. success: res => {
  172. if (res.confirm) {}
  173. }
  174. });
  175. this.setData({
  176. show: false
  177. });
  178. wx.hideLoading();
  179. });
  180. },
  181. // 查询用户积分
  182. queryUserPoint(type) {
  183. var token = this.$cookieStorage.get('user_token');
  184. this.$http.get({
  185. api: 'api/users/point',
  186. header: {
  187. Authorization: token
  188. },
  189. data: {
  190. type: type
  191. }
  192. }).then(res => {
  193. if (res.statusCode == 200) {
  194. res = res.data;
  195. this.setData({
  196. point: res.data
  197. });
  198. } else {
  199. wx.showModal({
  200. content: '请求失败',
  201. showCancel: false
  202. });
  203. }
  204. });
  205. },
  206. setData: function (obj) {
  207. let that = this;
  208. let keys = [];
  209. let val, data;
  210. Object.keys(obj).forEach(function (key) {
  211. keys = key.split('.');
  212. val = obj[key];
  213. data = that.$data;
  214. keys.forEach(function (key2, index) {
  215. if (index + 1 == keys.length) {
  216. that.$set(data, key2, val);
  217. } else {
  218. if (!data[key2]) {
  219. that.$set(data, key2, {});
  220. }
  221. }
  222. data = data[key2];
  223. });
  224. });
  225. }
  226. },
  227. computed: {},
  228. watch: {}
  229. };
  230. </script>
  231. <style rel="stylesheet/less" lang="less">
  232. @import "index";
  233. </style>