index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="container">
  3. <view class="top">
  4. <view class="search">
  5. <uni-row class="demo-uni-row" :width="nvueWidth">
  6. <uni-col>
  7. <view class="demo-uni-col">
  8. <uni-easyinput size="mini" class="uni-input" prefixIcon="search" v-model="searchVal" placeholder="请输入商户名称"></uni-easyinput>
  9. </view>
  10. </uni-col>
  11. </uni-row>
  12. <uni-row class="demo-uni-row" :width="nvueWidth">
  13. <uni-col :span="8">
  14. <view class="demo-uni-col">
  15. <uni-data-select class="search-data-select" v-model="typeValue" :localdata="typeRange" @change="changeType">类型</uni-data-select>
  16. </view>
  17. </uni-col>
  18. <uni-col :span="8">
  19. <view class="demo-uni-col">
  20. <uni-data-select class="search-data-select" v-model="communityValue" :localdata="communityRange" @change="changeCommunity">社区</uni-data-select>
  21. </view>
  22. </uni-col>
  23. <uni-col :span="4">
  24. <view class="demo-uni-col">
  25. <button class="searchBtn" type="default" size="mini" @click="handleSearch">搜索</button>
  26. </view>
  27. </uni-col>
  28. <uni-col :span="4">
  29. <view class="demo-uni-col">
  30. <button class="searchBtn" type="default" size="mini" @click="handleReset">重置</button>
  31. </view>
  32. </uni-col>
  33. </uni-row>
  34. </view>
  35. </view>
  36. <uni-list border class="list">
  37. <uni-list-item
  38. v-for="(item, index) in dataList"
  39. :key="index"
  40. :ellipsis="2"
  41. :title=getTitle(item)
  42. :note="item.createTime"
  43. showArrow
  44. clickable
  45. @click="listItemBtn(item)">
  46. </uni-list-item>
  47. </uni-list>
  48. <uni-load-more :status="more" />
  49. </view>
  50. </template>
  51. <script>
  52. import dictApi from '../../api/dict.js';
  53. import merchantApi from '../../api/merchant.js';
  54. import { BASE_URL } from '../../env.js';
  55. export default {
  56. data() {
  57. return {
  58. searchVal: '',
  59. // more = 加载前, loading = 加载中, noMore = 没有更多
  60. more: 'more',
  61. dataList: [],
  62. typeValue: null,
  63. typeRange: [],
  64. communityValue: null,
  65. communityRange: [],
  66. queryForm: {
  67. pageNum: 1,
  68. pageSize: 12,
  69. type: null,
  70. community: null,
  71. name: null,
  72. }
  73. }
  74. },
  75. onShow: function() {
  76. // this.init();
  77. },
  78. async mounted() {
  79. this.getMerchantList();
  80. await this.getDicts();
  81. },
  82. methods: {
  83. getTitle(merchant){
  84. return merchant.name;
  85. },
  86. async getDicts() {
  87. const resp_type = await dictApi.getDict('community_merchant_type');
  88. if (resp_type.code == 200)
  89. this.typeRange = resp_type.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  90. const resp_community = await dictApi.getDict('community_merchant_belongs');
  91. if (resp_community.code == 200)
  92. this.communityRange = resp_community.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  93. },
  94. // 列表点击函数
  95. listItemBtn(e) {
  96. uni.navigateTo({ url: `/pages/merchant/info?id=${e.merchantId}`})
  97. },
  98. // 搜索函数
  99. async getMerchantList() {
  100. this.reset();
  101. this.more = 'loading';
  102. const queryParams = {};
  103. for (const key in this.queryForm) {
  104. if (this.queryForm[key] !== null
  105. && this.queryForm[key] !== undefined
  106. && this.queryForm[key] !== '') {
  107. queryParams[key] = this.queryForm[key];
  108. }
  109. }
  110. const resp = await merchantApi.getMerchantList({...queryParams});
  111. this.dataList.push(...resp.data.map(e => {return {...e}}))
  112. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  113. this.more = this.page >= Math.ceil(resp.total / this.size) ? 'noMore' : 'more';
  114. },
  115. // 搜索函数
  116. async handleSearch() {
  117. await this.getMerchantList();
  118. },
  119. async handleReset() {
  120. this.typeValue = null;
  121. this.communityValue = null;
  122. this.searchVal = null;
  123. await this.getMerchantList();
  124. },
  125. async changeType(e) {
  126. // const resp = await shopApi.listBuildingByDistrict(e);
  127. // console.log(resp);
  128. console.log("e:", e);
  129. },
  130. async changeCommunity(e) {
  131. console.log("e:", e);
  132. },
  133. reset() {
  134. this.dataList.length = 0;
  135. this.queryForm.pageNum = 1;
  136. this.queryForm.pageSize= 12;
  137. this.queryForm.type = this.typeValue;
  138. this.queryForm.community= this.communityValue;
  139. this.queryForm.name = this.searchVal;
  140. }
  141. },
  142. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  143. onReachBottom() {
  144. if(this.more != 'noMore') {
  145. this.more = 'more';
  146. this.getMerchantList();
  147. }
  148. }
  149. }
  150. </script>
  151. <style>
  152. .container {
  153. width: 100%;
  154. background-color: #fff;
  155. }
  156. .top {
  157. width: 100%;
  158. z-index: 999;
  159. background-color: #fff;
  160. /* overflow: hidden; */
  161. }
  162. .search {
  163. width: 98%;
  164. border: 1px solid #f3f3f3;
  165. background-color: #fff !important;
  166. border-radius: 5px;
  167. margin: 2px;
  168. padding: 2rpx;
  169. display: block;
  170. }
  171. .demo-uni-row {
  172. margin-bottom: 10px;
  173. display: block;
  174. }
  175. /deep/ .uni-row {
  176. margin-bottom: 10px;
  177. }
  178. .demo-uni-col {
  179. height: 24px;
  180. margin-bottom: 10px;
  181. border-radius: 4px;
  182. }
  183. .uni-easyinput {
  184. width: 100%;
  185. font-size: 14px;
  186. display: block;
  187. }
  188. .uni-easyinput .uni-easyinput__content {
  189. border: 1px solid #f3f3f3;
  190. border-radius: 10px;
  191. }
  192. .search-data-select{
  193. width: 100%;
  194. border-radius: 10px;
  195. }
  196. .searchBtn {
  197. width: 98%;
  198. background-color: #ff9302 !important;
  199. border: none;
  200. color: #fff !important;
  201. border-radius: 12px;
  202. }
  203. .list {
  204. display: block;
  205. }
  206. </style>