favor.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <view>
  3. <scroll-view :scroll-y="true" class="scroll-box" @scrolltolower="scroll_lower" lower-threshold="60">
  4. <view v-if="data_list.length > 0" class="padding-horizontal-main padding-top-main">
  5. <view v-for="(item, index) in data_list" :key="index" class="padding-main border-radius-main oh bg-white spacing-mb">
  6. <navigator :url="'/pages/plugins/realstore/detail/detail?id=' + item.realstore_info.id" hover-class="none">
  7. <image class="logo fl radius" :src="item.realstore_info.logo" mode="aspectFill"></image>
  8. <view class="base">
  9. <view class="single-text fw-b">{{item.realstore_info.name}}</view>
  10. <view class="multi-text cr-grey margin-top-sm">{{item.realstore_info.describe}}</view>
  11. </view>
  12. </navigator>
  13. <button class="br-yellow cr-yellow bg-white fr round" type="default" size="mini" @tap="cancel_event" :data-value="item.id" :data-index="index" hover-class="none">取消</button>
  14. </view>
  15. </view>
  16. <view v-else>
  17. <!-- 提示信息 -->
  18. <component-no-data :propStatus="data_list_loding_status"></component-no-data>
  19. </view>
  20. <!-- 结尾 -->
  21. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  22. </scroll-view>
  23. </view>
  24. </template>
  25. <script>
  26. const app = getApp();
  27. import componentNoData from "../../../../components/no-data/no-data";
  28. import componentBottomLine from "../../../../components/bottom-line/bottom-line";
  29. export default {
  30. data() {
  31. return {
  32. data_list: [],
  33. data_total: 0,
  34. data_page_total: 0,
  35. data_page: 1,
  36. data_list_loding_status: 1,
  37. data_bottom_line_status: false
  38. };
  39. },
  40. components: {
  41. componentNoData,
  42. componentBottomLine
  43. },
  44. props: {},
  45. onShow() {
  46. // 数据加载
  47. this.init();
  48. // 分享菜单处理
  49. app.globalData.page_share_handle();
  50. },
  51. // 下拉刷新
  52. onPullDownRefresh() {
  53. this.setData({
  54. data_page: 1
  55. });
  56. this.get_data_list(1);
  57. },
  58. methods: {
  59. // 获取数据
  60. init() {
  61. var user = app.globalData.get_user_info(this, "init");
  62. if (user != false) {
  63. // 用户未绑定用户则转到登录页面
  64. if (app.globalData.user_is_need_login(user)) {
  65. uni.redirectTo({
  66. url: "/pages/login/login?event_callback=init"
  67. });
  68. return false;
  69. } else {
  70. // 获取数据
  71. this.get_data_list();
  72. }
  73. } else {
  74. this.setData({
  75. data_list_loding_status: 0,
  76. data_bottom_line_status: false
  77. });
  78. }
  79. },
  80. // 获取数据
  81. get_data_list(is_mandatory) {
  82. // 分页是否还有数据
  83. if ((is_mandatory || 0) == 0) {
  84. if (this.data_bottom_line_status == true) {
  85. uni.stopPullDownRefresh();
  86. return false;
  87. }
  88. }
  89. // 加载loding
  90. uni.showLoading({
  91. title: '加载中...'
  92. });
  93. this.setData({
  94. data_list_loding_status: 1
  95. });
  96. // 获取数据
  97. uni.request({
  98. url: app.globalData.get_request_url("index", "favor", "realstore"),
  99. method: 'POST',
  100. data: {
  101. page: this.data_page
  102. },
  103. dataType: 'json',
  104. success: res => {
  105. uni.hideLoading();
  106. uni.stopPullDownRefresh();
  107. if (res.data.code == 0) {
  108. if (res.data.data.data.length > 0) {
  109. if (this.data_page <= 1) {
  110. var temp_data_list = res.data.data.data;
  111. } else {
  112. var temp_data_list = this.data_list || [];
  113. var temp_data = res.data.data.data;
  114. for (var i in temp_data) {
  115. temp_data_list.push(temp_data[i]);
  116. }
  117. }
  118. this.setData({
  119. data_list: temp_data_list,
  120. data_total: res.data.data.total,
  121. data_page_total: res.data.data.page_total,
  122. data_list_loding_status: 3,
  123. data_page: this.data_page + 1
  124. });
  125. // 是否还有数据
  126. this.setData({
  127. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  128. });
  129. } else {
  130. this.setData({
  131. data_list_loding_status: 0
  132. });
  133. }
  134. } else {
  135. this.setData({
  136. data_list_loding_status: 0
  137. });
  138. if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
  139. app.globalData.showToast(res.data.msg);
  140. }
  141. }
  142. },
  143. fail: () => {
  144. uni.hideLoading();
  145. uni.stopPullDownRefresh();
  146. this.setData({
  147. data_list_loding_status: 2
  148. });
  149. app.globalData.showToast('服务器请求出错');
  150. }
  151. });
  152. },
  153. // 滚动加载
  154. scroll_lower(e) {
  155. this.get_data_list();
  156. },
  157. // 取消
  158. cancel_event(e) {
  159. uni.showModal({
  160. title: '温馨提示',
  161. content: '取消后不可恢复,确定继续吗?',
  162. confirmText: '确认',
  163. cancelText: '不了',
  164. success: result => {
  165. if (result.confirm) {
  166. // 参数
  167. var id = e.currentTarget.dataset.value;
  168. var index = e.currentTarget.dataset.index;
  169. // 加载loding
  170. uni.showLoading({
  171. title: '处理中...'
  172. });
  173. uni.request({
  174. url: app.globalData.get_request_url("delete", "favor", "realstore"),
  175. method: 'POST',
  176. data: {
  177. ids: id
  178. },
  179. dataType: 'json',
  180. success: res => {
  181. uni.hideLoading();
  182. if (res.data.code == 0) {
  183. var temp_data_list = this.data_list;
  184. temp_data_list.splice(index, 1);
  185. this.setData({
  186. data_list: temp_data_list
  187. });
  188. if (temp_data_list.length == 0) {
  189. this.setData({
  190. data_list_loding_status: 0,
  191. data_bottom_line_status: false
  192. });
  193. }
  194. app.globalData.showToast(res.data.msg, 'success');
  195. } else {
  196. if (app.globalData.is_login_check(res.data)) {
  197. app.globalData.showToast(res.data.msg);
  198. } else {
  199. app.globalData.showToast('提交失败,请重试!');
  200. }
  201. }
  202. },
  203. fail: () => {
  204. uni.hideLoading();
  205. app.globalData.showToast('服务器请求出错');
  206. }
  207. });
  208. }
  209. }
  210. });
  211. }
  212. }
  213. };
  214. </script>
  215. <style>
  216. @import './favor.css';
  217. </style>