buy.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view>
  3. <view v-if="(data_base || null) != null">
  4. <view v-if="(data_list || null) != null && data_list.length > 0" class="page-bottom-fixed">
  5. <!-- 导航 -->
  6. <scroll-view class="nav scroll-view-horizontal bg-white tc oh" scroll-x="true">
  7. <block v-for="(item, index) in data_list" :key="index">
  8. <view :class="'item dis-inline-block padding-left-xxl padding-right-xxl cr-gray ' + (selected_tabs_index === index ? 'cr-main' : '')" @tap="tabs_event" :data-index="index">{{item.name}}</view>
  9. </block>
  10. </scroll-view>
  11. <!-- 内容 -->
  12. <block v-for="(item, index) in data_list" :key="index">
  13. <block v-if="selected_tabs_index == index">
  14. <block v-if="(item.pay_period_rules || null) != null">
  15. <view class="data-list padding-horizontal-main padding-top-main">
  16. <block v-for="(rules, ri) in item.pay_period_rules" :key="ri">
  17. <view :class="'item padding-main border-radius-main bg-white oh tc spacing-mb ' + (selected_content_index === ri ? 'border-color-main' : '')" @tap="content_event" :data-index="ri">
  18. <view class="fl number single-text">
  19. <text class="fw-b cr-base text-size">{{((rules.number || null) == null) ? '终身' : rules.value}}</text>
  20. <text v-if="(rules.unit || null) != null" class="cr-grey margin-left-sm">{{rules.unit}}</text>
  21. </view>
  22. <view class="fr price bg-white single-text">
  23. <text class="cr-main">¥</text>
  24. <text class=" fw-b cr-main text-size-lg">{{rules.price}}</text>
  25. <text class="cr-grey margin-left-sm">元</text>
  26. </view>
  27. </view>
  28. </block>
  29. <view class="bottom-fixed">
  30. <button class="bg-main br-main cr-white round text-size margin-horizontal-main margin-bottom-main" type="default" hover-class="none" @tap="submit_event" :disabled="submit_disabled_status">确认支付</button>
  31. </view>
  32. </view>
  33. <!-- 结尾 -->
  34. <component-bottom-line :propStatus="true"></component-bottom-line>
  35. </block>
  36. <block v-else>
  37. <!-- 提示信息 -->
  38. <component-no-data propStatus="0" propMsg="购买时长未配置"></component-no-data>
  39. </block>
  40. </block>
  41. </block>
  42. </view>
  43. <view v-else>
  44. <!-- 提示信息 -->
  45. <component-no-data propStatus="0" propMsg="未配置会员等级"></component-no-data>
  46. </view>
  47. </view>
  48. <view v-else>
  49. <!-- 提示信息 -->
  50. <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. const app = getApp();
  56. import componentNoData from "../../../../components/no-data/no-data";
  57. import componentBottomLine from "../../../../components/bottom-line/bottom-line";
  58. export default {
  59. data() {
  60. return {
  61. data_bottom_line_status: false,
  62. data_list_loding_status: 1,
  63. data_list_loding_msg: '',
  64. data_list: [],
  65. data_base: null,
  66. selected_tabs_index: 0,
  67. selected_content_index: null,
  68. submit_disabled_status: false
  69. };
  70. },
  71. components: {
  72. componentNoData,
  73. componentBottomLine
  74. },
  75. props: {},
  76. onLoad(params) {
  77. this.init();
  78. },
  79. onShow() {
  80. // 分享菜单处理
  81. app.globalData.page_share_handle();
  82. },
  83. // 下拉刷新
  84. onPullDownRefresh() {
  85. this.get_data_list();
  86. },
  87. methods: {
  88. init() {
  89. // 获取数据
  90. this.get_data_list();
  91. },
  92. // 获取数据
  93. get_data_list() {
  94. uni.showLoading({
  95. title: '加载中...'
  96. });
  97. if (this.data_list.length <= 0) {
  98. this.setData({
  99. data_list_loding_status: 1
  100. });
  101. }
  102. uni.request({
  103. url: app.globalData.get_request_url("index", "buy", "membershiplevelvip"),
  104. method: 'POST',
  105. data: {},
  106. dataType: 'json',
  107. success: res => {
  108. uni.hideLoading();
  109. uni.stopPullDownRefresh();
  110. if (res.data.code == 0) {
  111. var data = res.data.data;
  112. var status = (data.data || []).length > 0;
  113. this.setData({
  114. data_base: data.base || null,
  115. data_list: data.data || [],
  116. data_list_loding_msg: '',
  117. data_list_loding_status: status ? 3 : 0,
  118. data_bottom_line_status: status
  119. });
  120. } else {
  121. this.setData({
  122. data_bottom_line_status: false,
  123. data_list_loding_status: 2,
  124. data_list_loding_msg: res.data.msg
  125. });
  126. if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
  127. app.globalData.showToast(res.data.msg);
  128. }
  129. }
  130. },
  131. fail: () => {
  132. uni.hideLoading();
  133. uni.stopPullDownRefresh();
  134. this.setData({
  135. data_bottom_line_status: false,
  136. data_list_loding_status: 2,
  137. data_list_loding_msg: '服务器请求出错'
  138. });
  139. app.globalData.showToast('服务器请求出错');
  140. }
  141. });
  142. },
  143. // tabs事件
  144. tabs_event(e) {
  145. this.setData({
  146. selected_tabs_index: e.currentTarget.dataset.index || 0,
  147. selected_content_index: null
  148. });
  149. },
  150. // 时长事件
  151. content_event(e) {
  152. this.setData({
  153. selected_content_index: e.currentTarget.dataset.index || 0
  154. });
  155. },
  156. // 确认支付事件
  157. submit_event(e) {
  158. if (this.selected_tabs_index < 0 || this.selected_content_index === null) {
  159. app.globalData.showToast('请选择开通时长');
  160. return false;
  161. }
  162. // 请求参数
  163. var item = this.data_list[this.selected_tabs_index] || null;
  164. if (item == null) {
  165. app.globalData.showToast('开通时长有误');
  166. return false;
  167. }
  168. var rules = (item['pay_period_rules'] || null) == null ? null : item['pay_period_rules'][this.selected_content_index] || null;
  169. if (rules == null) {
  170. app.globalData.showToast('开通时长有误');
  171. return false;
  172. }
  173. // 请求生成支付订单
  174. this.setData({
  175. submit_disabled_status: true
  176. });
  177. uni.showLoading({
  178. title: '处理中...'
  179. });
  180. uni.request({
  181. url: app.globalData.get_request_url("create", "buy", "membershiplevelvip"),
  182. method: 'POST',
  183. data: {
  184. opening: item['id'] + '-' + rules['number']
  185. },
  186. dataType: 'json',
  187. success: res => {
  188. uni.hideLoading();
  189. this.setData({
  190. submit_disabled_status: false
  191. });
  192. if (res.data.code == 0) {
  193. uni.setStorageSync(app.globalData.data.cache_page_pay_key, {order_ids: res.data.data.id});
  194. uni.redirectTo({
  195. url: '/pages/plugins/membershiplevelvip/order/order'
  196. });
  197. } else {
  198. if (app.globalData.is_login_check(res.data, this, 'submit_event')) {
  199. app.globalData.showToast(res.data.msg);
  200. }
  201. }
  202. },
  203. fail: () => {
  204. this.setData({
  205. submit_disabled_status: false
  206. });
  207. uni.hideLoading();
  208. app.globalData.showToast('服务器请求出错');
  209. }
  210. });
  211. }
  212. }
  213. };
  214. </script>
  215. <style>
  216. @import './buy.css';
  217. </style>