index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="main">
  3. <!-- <view class="one">
  4. <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索优惠券名称">
  5. </view> -->
  6. <view class="two">
  7. <scroll-view scroll-y="true" class="scroll-view">
  8. <view class="list-scroll-view">
  9. <view class="list" v-for="(item, index) in list" :key="index">
  10. <view class="list_1">
  11. <view class="left">
  12. <view class="left_1">
  13. ¥<text>{{item.discount_config.min}}</text>
  14. </view>
  15. <view class="left_2">
  16. <text v-if="item.discount_config.limit=='0'">无门槛</text>
  17. <text v-else>满{{item.discount_config.limit}}减{{item.discount_config.min}}</text>
  18. </view>
  19. </view>
  20. <view class="center">
  21. <view class="name textOver">{{item.name}}</view>
  22. <view class="content">有效日期:({{item.expire_type_label}}) {{item.time}}
  23. </view>
  24. </view>
  25. <view class="right">
  26. <button class="button" type="primary" @tap="toUser(item)">去使用</button>
  27. </view>
  28. </view>
  29. <view class="list_2">
  30. <uni-collapse>
  31. <uni-collapse-item title="使用规则补充说明" :open="false">
  32. <view class="content">{{item.brief}}</view>
  33. </uni-collapse-item>
  34. </uni-collapse>
  35. </view>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. searchInfo: {},
  47. config: {},
  48. user: {},
  49. list: [],
  50. total: 0,
  51. skip: 0,
  52. limit: 6,
  53. page: 0,
  54. // 数据是否触底
  55. is_bottom: false,
  56. scrollTop: 0,
  57. }
  58. },
  59. onLoad: async function(e) {
  60. const that = this;
  61. that.searchToken();
  62. that.searchConfig();
  63. },
  64. onShow: async function() {
  65. const that = this;
  66. that.clearPage();
  67. await that.search();
  68. },
  69. onPullDownRefresh: async function() {
  70. const that = this;
  71. that.clearPage();
  72. await that.search();
  73. uni.stopPullDownRefresh();
  74. },
  75. methods: {
  76. searchToken() {
  77. const that = this;
  78. try {
  79. const res = uni.getStorageSync('token');
  80. if (res) that.$set(that, `user`, res);
  81. } catch (e) {
  82. uni.showToast({
  83. title: err.errmsg,
  84. icon: 'error',
  85. duration: 2000
  86. });
  87. }
  88. },
  89. searchConfig() {
  90. const that = this;
  91. try {
  92. const res = uni.getStorageSync('config');
  93. if (res) that.$set(that, `config`, res);
  94. } catch (e) {
  95. uni.showToast({
  96. title: err.errmsg,
  97. icon: 'error',
  98. duration: 2000
  99. });
  100. }
  101. },
  102. async search() {
  103. const that = this;
  104. let info = {
  105. skip: that.skip,
  106. limit: that.limit,
  107. user: that.user._id,
  108. }
  109. const res = await that.$api(`/userCoupon/specialQuery`, 'GET', {
  110. ...info,
  111. ...that.searchInfo
  112. })
  113. if (res.errcode == '0') {
  114. let list = [...that.list, ...res.data];
  115. that.$set(that, `list`, list)
  116. that.$set(that, `total`, res.total)
  117. } else {
  118. uni.showToast({
  119. title: res.errmsg,
  120. });
  121. }
  122. },
  123. // 输入框
  124. toInput(e) {
  125. const that = this;
  126. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  127. else that.$set(that, `searchInfo`, {})
  128. that.clearPage();
  129. that.search();
  130. },
  131. // 去使用
  132. toUser(item) {
  133. if (item.type == '0') {
  134. uni.navigateTo({
  135. url: `/pagesHome/hotel/index`
  136. })
  137. } else {
  138. uni.navigateTo({
  139. url: `/pagesHome/ticket/index`
  140. })
  141. }
  142. },
  143. // 分页
  144. toPage(e) {
  145. const that = this;
  146. let list = that.list;
  147. let limit = that.limit;
  148. if (that.total > list.length) {
  149. uni.showLoading({
  150. title: '加载中',
  151. mask: true
  152. })
  153. let page = that.page + 1;
  154. that.$set(that, `page`, page)
  155. let skip = page * limit;
  156. that.$set(that, `skip`, skip)
  157. that.search();
  158. uni.hideLoading();
  159. } else that.$set(that, `is_bottom`, true)
  160. },
  161. toScroll(e) {
  162. const that = this;
  163. let up = that.scrollTop;
  164. that.$set(that, `scrollTop`, e.detail.scrollTop);
  165. let num = Math.sign(up - e.detail.scrollTop);
  166. if (num == 1) that.$set(that, `is_bottom`, false);
  167. },
  168. // 清空列表
  169. clearPage() {
  170. const that = this;
  171. that.$set(that, `list`, [])
  172. that.$set(that, `skip`, 0)
  173. that.$set(that, `limit`, 6)
  174. that.$set(that, `page`, 0)
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .main {
  181. display: flex;
  182. flex-direction: column;
  183. width: 100vw;
  184. height: 100vh;
  185. .one {
  186. padding: 2vw;
  187. input {
  188. padding: 2vw;
  189. background-color: var(--f1Color);
  190. font-size: var(--font14Size);
  191. border-radius: 5px;
  192. }
  193. }
  194. .two {
  195. position: relative;
  196. flex-grow: 1;
  197. margin: 1vw 0 0 0;
  198. background-color: var(--f9Color);
  199. .list {
  200. background-color: var(--mainColor);
  201. border: 1px solid var(--f5Color);
  202. padding: 2vw;
  203. margin: 2vw 2vw 0 2vw;
  204. border-radius: 5px;
  205. .list_1 {
  206. display: flex;
  207. justify-content: space-between;
  208. align-items: center;
  209. .left {
  210. width: 20vw;
  211. display: flex;
  212. flex-direction: column;
  213. justify-content: center;
  214. align-items: center;
  215. color: var(--fF0Color);
  216. font-size: var(--font14Size);
  217. .left_1 {
  218. text {
  219. font-weight: bold;
  220. font-size: 25px;
  221. }
  222. }
  223. .left_2 {
  224. margin: 2px 0 0 0;
  225. font-size: var(--font12Size);
  226. }
  227. }
  228. .center {
  229. width: 40vw;
  230. .name {
  231. font-size: var(--font14Size);
  232. font-weight: bold;
  233. margin: 0 0 1vw 0;
  234. }
  235. .content {
  236. color: var(--f85Color);
  237. font-size: var(--font12Size);
  238. }
  239. }
  240. .right {
  241. .button {
  242. font-size: 12px;
  243. border-radius: 20px;
  244. border: 1px solid var(--fF0Color);
  245. color: var(--fF0Color);
  246. background: var(--mainColor);
  247. }
  248. }
  249. }
  250. .list_2 {
  251. font-size: var(--font12Size);
  252. /deep/.uni-collapse-item__title-box {
  253. padding: 0 !important;
  254. font-size: 12px !important;
  255. }
  256. /deep/.uni-collapse-item__title-text {
  257. font-size: 12px !important;
  258. }
  259. .content {
  260. padding: 2vw;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. </style>