user-favor.vue 10 KB

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