index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. is_use: "0"
  109. }
  110. const res = await that.$api(`/userCoupon/specialQuery`, 'GET', {
  111. ...info,
  112. ...that.searchInfo
  113. })
  114. if (res.errcode == '0') {
  115. let list = [...that.list, ...res.data];
  116. that.$set(that, `list`, list)
  117. that.$set(that, `total`, res.total)
  118. } else {
  119. uni.showToast({
  120. title: res.errmsg,
  121. });
  122. }
  123. },
  124. // 输入框
  125. toInput(e) {
  126. const that = this;
  127. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  128. else that.$set(that, `searchInfo`, {})
  129. that.clearPage();
  130. that.search();
  131. },
  132. // 去使用
  133. toUser(item) {
  134. if (item.type == '0') {
  135. uni.navigateTo({
  136. url: `/pagesHome/hotel/index`
  137. })
  138. } else {
  139. uni.navigateTo({
  140. url: `/pagesHome/ticket/index`
  141. })
  142. }
  143. },
  144. // 分页
  145. toPage(e) {
  146. const that = this;
  147. let list = that.list;
  148. let limit = that.limit;
  149. if (that.total > list.length) {
  150. uni.showLoading({
  151. title: '加载中',
  152. mask: true
  153. })
  154. let page = that.page + 1;
  155. that.$set(that, `page`, page)
  156. let skip = page * limit;
  157. that.$set(that, `skip`, skip)
  158. that.search();
  159. uni.hideLoading();
  160. } else that.$set(that, `is_bottom`, true)
  161. },
  162. toScroll(e) {
  163. const that = this;
  164. let up = that.scrollTop;
  165. that.$set(that, `scrollTop`, e.detail.scrollTop);
  166. let num = Math.sign(up - e.detail.scrollTop);
  167. if (num == 1) that.$set(that, `is_bottom`, false);
  168. },
  169. // 清空列表
  170. clearPage() {
  171. const that = this;
  172. that.$set(that, `list`, [])
  173. that.$set(that, `skip`, 0)
  174. that.$set(that, `limit`, 6)
  175. that.$set(that, `page`, 0)
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. .main {
  182. display: flex;
  183. flex-direction: column;
  184. width: 100vw;
  185. height: 100vh;
  186. .one {
  187. padding: 2vw;
  188. input {
  189. padding: 2vw;
  190. background-color: var(--f1Color);
  191. font-size: var(--font14Size);
  192. border-radius: 5px;
  193. }
  194. }
  195. .two {
  196. position: relative;
  197. flex-grow: 1;
  198. margin: 1vw 0 0 0;
  199. background-color: var(--f9Color);
  200. .list {
  201. background-color: var(--mainColor);
  202. border: 1px solid var(--f5Color);
  203. padding: 2vw;
  204. margin: 2vw 2vw 0 2vw;
  205. border-radius: 5px;
  206. .list_1 {
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. .left {
  211. width: 20vw;
  212. display: flex;
  213. flex-direction: column;
  214. justify-content: center;
  215. align-items: center;
  216. color: var(--fF0Color);
  217. font-size: var(--font14Size);
  218. .left_1 {
  219. text {
  220. font-weight: bold;
  221. font-size: 25px;
  222. }
  223. }
  224. .left_2 {
  225. margin: 2px 0 0 0;
  226. font-size: var(--font12Size);
  227. }
  228. }
  229. .center {
  230. width: 40vw;
  231. .name {
  232. font-size: var(--font14Size);
  233. font-weight: bold;
  234. margin: 0 0 1vw 0;
  235. }
  236. .content {
  237. color: var(--f85Color);
  238. font-size: var(--font12Size);
  239. }
  240. }
  241. .right {
  242. .button {
  243. font-size: 12px;
  244. border-radius: 20px;
  245. border: 1px solid var(--fF0Color);
  246. color: var(--fF0Color);
  247. background: var(--mainColor);
  248. }
  249. }
  250. }
  251. .list_2 {
  252. font-size: var(--font12Size);
  253. /deep/.uni-collapse-item__title-box {
  254. padding: 0 !important;
  255. font-size: 12px !important;
  256. }
  257. /deep/.uni-collapse-item__title-text {
  258. font-size: 12px !important;
  259. }
  260. .content {
  261. padding: 2vw;
  262. }
  263. }
  264. }
  265. }
  266. }
  267. </style>