index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view>
  3. <view v-if="(data_base || null) != null && (data_base.banner_images || null) != null" class="padding-horizontal-main padding-top-main">
  4. <image class="wh-auto dis-block border-radius-main" :src="data_base.banner_images" mode="widthFix" :data-value="data_base.url || ''" @tap="url_event"></image>
  5. </view>
  6. <!-- 优惠劵列表 -->
  7. <view v-if="data_list.length > 0" class="plugins-coupon-container padding-horizontal-main padding-top-main">
  8. <block v-for="(item, index) in data_list" :key="index">
  9. <view :class="'item border-radius-main bg-white spacing-mb ' + (item.is_operable == 0 ? 'item-disabled' : '')">
  10. <view class="v-left fl">
  11. <view class="base single-text" :style="'color:' + item.bg_color_value + ';'">
  12. <text v-if="item.type == 0" class="symbol">{{currency_symbol}}</text>
  13. <text class="price">{{item.discount_value}}</text>
  14. <text class="unit">{{item.type_unit}}</text>
  15. <text v-if="(item.desc || null) != null" class="desc cr-gray">{{item.desc}}</text>
  16. </view>
  17. <view v-if="(item.use_limit_type_name || null) != null" class="base-tips cr-base single-text text-size-xs">{{item.use_limit_type_name}}</view>
  18. </view>
  19. <view class="v-right fr cp" @tap="coupon_receive_event" :data-index="index" :data-value="item.id" :style="'background:' + item.bg_color_value + ';'">
  20. <text class="circle"></text>
  21. <text>{{item.is_operable_name}}</text>
  22. </view>
  23. </view>
  24. </block>
  25. </view>
  26. <view v-else>
  27. <!-- 提示信息 -->
  28. <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
  29. </view>
  30. <!-- 结尾 -->
  31. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  32. </view>
  33. </template>
  34. <script>
  35. const app = getApp();
  36. import componentNoData from "../../../../components/no-data/no-data";
  37. import componentBottomLine from "../../../../components/bottom-line/bottom-line";
  38. export default {
  39. data() {
  40. return {
  41. data_bottom_line_status: false,
  42. data_list_loding_status: 1,
  43. data_list_loding_msg: '',
  44. currency_symbol: app.globalData.data.currency_symbol,
  45. data_list: [],
  46. data_base: null,
  47. // 优惠劵领取
  48. temp_coupon_receive_index: null,
  49. temp_coupon_receive_value: null,
  50. // 自定义分享信息
  51. share_info: {}
  52. };
  53. },
  54. components: {
  55. componentNoData,
  56. componentBottomLine
  57. },
  58. props: {},
  59. onShow() {
  60. // 数据加载
  61. this.init();
  62. // 初始化配置
  63. this.init_config();
  64. },
  65. // 下拉刷新
  66. onPullDownRefresh() {
  67. this.get_data_list();
  68. },
  69. methods: {
  70. // 初始化配置
  71. init_config(status) {
  72. if ((status || false) == true) {
  73. this.setData({
  74. currency_symbol: app.globalData.get_config('currency_symbol')
  75. });
  76. } else {
  77. app.globalData.is_config(this, 'init_config');
  78. }
  79. },
  80. // 获取数据
  81. init() {
  82. this.get_data_list();
  83. },
  84. // 获取数据
  85. get_data_list() {
  86. var self = this;
  87. uni.showLoading({
  88. title: '加载中...'
  89. });
  90. if (self.data_list.length <= 0) {
  91. self.setData({
  92. data_list_loding_status: 1
  93. });
  94. }
  95. uni.request({
  96. url: app.globalData.get_request_url("index", "index", "coupon"),
  97. method: 'POST',
  98. data: {},
  99. dataType: 'json',
  100. success: res => {
  101. uni.hideLoading();
  102. uni.stopPullDownRefresh();
  103. if (res.data.code == 0) {
  104. var data = res.data.data;
  105. var status = (data.data || []).length > 0;
  106. this.setData({
  107. data_base: data.base || null,
  108. data_list: data.data || [],
  109. data_list_loding_msg: '',
  110. data_list_loding_status: status ? 3 : 0,
  111. data_bottom_line_status: status
  112. });
  113. if ((this.data_base || null) != null) {
  114. // 基础自定义分享
  115. this.setData({
  116. share_info: {
  117. title: this.data_base.seo_title || this.data_base.application_name,
  118. desc: this.data_base.seo_desc,
  119. path: '/pages/plugins/coupon/index/index'
  120. }
  121. });
  122. // 导航名称
  123. if((this.data_base.application_name || null) != null) {
  124. uni.setNavigationBarTitle({
  125. title: this.data_base.application_name
  126. });
  127. }
  128. }
  129. } else {
  130. self.setData({
  131. data_bottom_line_status: false,
  132. data_list_loding_status: 2,
  133. data_list_loding_msg: res.data.msg
  134. });
  135. app.globalData.showToast(res.data.msg);
  136. }
  137. // 分享菜单处理
  138. app.globalData.page_share_handle(this.share_info);
  139. },
  140. fail: () => {
  141. uni.hideLoading();
  142. uni.stopPullDownRefresh();
  143. self.setData({
  144. data_bottom_line_status: false,
  145. data_list_loding_status: 2,
  146. data_list_loding_msg: '服务器请求出错'
  147. });
  148. app.globalData.showToast('服务器请求出错');
  149. }
  150. });
  151. },
  152. // 优惠劵领取事件
  153. coupon_receive_event(e) {
  154. // 参数处理
  155. if ((e || null) == null) {
  156. var index = this.temp_coupon_receive_index;
  157. var value = this.temp_coupon_receive_value;
  158. } else {
  159. var index = e.currentTarget.dataset.index;
  160. var value = e.currentTarget.dataset.value;
  161. this.setData({
  162. temp_coupon_receive_index: index,
  163. temp_coupon_receive_value: value
  164. });
  165. }
  166. // 登录校验
  167. var user = app.globalData.get_user_info(this, 'coupon_receive_event');
  168. if (user != false) {
  169. // 用户未绑定用户则转到登录页面
  170. if (app.globalData.user_is_need_login(user)) {
  171. uni.navigateTo({
  172. url: "/pages/login/login?event_callback=coupon_receive_event"
  173. });
  174. return false;
  175. } else {
  176. var temp_list = this.data_list;
  177. if (temp_list[index]['is_operable'] != 0) {
  178. uni.showLoading({
  179. title: '处理中...'
  180. });
  181. uni.request({
  182. url: app.globalData.get_request_url("receive", "coupon", "coupon"),
  183. method: 'POST',
  184. data: {
  185. "coupon_id": value
  186. },
  187. dataType: 'json',
  188. success: res => {
  189. uni.hideLoading();
  190. if (res.data.code == 0) {
  191. app.globalData.showToast(res.data.msg, 'success');
  192. if (this.data_base != null && this.data_base.is_repeat_receive !=
  193. 1) {
  194. temp_list[index]['is_operable'] = 0;
  195. temp_list[index]['is_operable_name'] = '已领取';
  196. this.setData({
  197. data_list: temp_list
  198. });
  199. }
  200. } else {
  201. if (app.globalData.is_login_check(res.data, this, 'coupon_receive_event')) {
  202. app.globalData.showToast(res.data.msg);
  203. }
  204. }
  205. },
  206. fail: () => {
  207. uni.hideLoading();
  208. app.globalData.showToast('服务器请求出错');
  209. }
  210. });
  211. }
  212. }
  213. }
  214. },
  215. // url事件
  216. url_event(e) {
  217. app.globalData.url_event(e);
  218. }
  219. }
  220. };
  221. </script>
  222. <style>
  223. </style>