index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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="formData.name" 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="formData.type" :localdata="typeOptions" @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="formData.community" :localdata="communityOptions" @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" @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" @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 resultList"
  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. typeOptions: [],
  59. communityOptions: [],
  60. formData: {
  61. pageNum: 0,
  62. pageSize: 20,
  63. type: null,
  64. community: null,
  65. name: null,
  66. },
  67. resultList: [],
  68. more: 'more'
  69. }
  70. },
  71. onShow: function() {
  72. // this.init();
  73. },
  74. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  75. onReachBottom() {
  76. if(this.more != 'noMore') {
  77. this.more = 'more';
  78. this.getMerchantList();
  79. }
  80. },
  81. async mounted() {
  82. await this.getDicts();
  83. await this.getMerchantList();
  84. },
  85. methods: {
  86. async getDicts() {
  87. const resp_type = await dictApi.getDict('community_merchant_type');
  88. if (resp_type.code == 200)
  89. this.typeOptions = 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.communityOptions = resp_community.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  93. },
  94. // 搜索函数
  95. async getMerchantList() {
  96. this.more = 'loading';
  97. const queryParams = {};
  98. this.getFormParams(queryParams);
  99. const resp = await merchantApi.getMerchantList({...queryParams});
  100. this.resultList.push(...resp.rows);
  101. this.updateMoreStatus(resp.total);
  102. },
  103. // 搜索函数
  104. async handleSearch() {
  105. this.resultList = [];
  106. this.formData.pageNum = 0;
  107. await this.getMerchantList();
  108. },
  109. async handleReset() {
  110. this.resultList = [];
  111. this.formData.pageNum = 0;
  112. this.formData.name = null;
  113. this.formData.type = null;
  114. this.formData.community = null;
  115. await this.getMerchantList();
  116. },
  117. async changeType(e) {
  118. this.formData.type = e;
  119. },
  120. async changeCommunity(e) {
  121. this.formData.community = e;
  122. },
  123. // 列表点击函数
  124. listItemBtn(e) {
  125. uni.navigateTo({ url: `/pages/merchant/info?id=${e.merchantId}`})
  126. },
  127. getTitle(merchant){
  128. return merchant.name;
  129. },
  130. getFormParams(queryParams){
  131. this.formData.pageNum += 1;
  132. for (const key in this.formData) {
  133. if (this.formData[key] !== null
  134. && this.formData[key] !== undefined
  135. && this.formData[key] !== '') {
  136. queryParams[key] = this.formData[key];
  137. }
  138. }
  139. },
  140. updateMoreStatus(total){
  141. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  142. this.more = this.formData.pageNum >= Math.ceil(total / this.formData.pageSize) ? 'noMore' : 'more';
  143. }
  144. }
  145. }
  146. </script>
  147. <style>
  148. .container {
  149. width: 100%;
  150. background-color: #fff;
  151. }
  152. .top {
  153. width: 100%;
  154. z-index: 999;
  155. background-color: #fff;
  156. /* overflow: hidden; */
  157. }
  158. .search {
  159. width: 98%;
  160. border: 1px solid #f3f3f3;
  161. background-color: #fff !important;
  162. border-radius: 5px;
  163. margin: 2px;
  164. padding: 2rpx;
  165. display: block;
  166. }
  167. .demo-uni-row {
  168. margin-bottom: 10px;
  169. display: block;
  170. }
  171. /deep/ .uni-row {
  172. margin-bottom: 10px;
  173. }
  174. .demo-uni-col {
  175. height: 24px;
  176. margin-bottom: 10px;
  177. border-radius: 4px;
  178. }
  179. .uni-easyinput {
  180. width: 100%;
  181. font-size: 14px;
  182. display: block;
  183. }
  184. .uni-easyinput .uni-easyinput__content {
  185. border: 1px solid #f3f3f3;
  186. border-radius: 10px;
  187. }
  188. .search-data-select{
  189. width: 100%;
  190. border-radius: 10px;
  191. }
  192. .searchBtn {
  193. width: 98%;
  194. background-color: #ff9302 !important;
  195. border: none;
  196. color: #fff !important;
  197. border-radius: 12px;
  198. padding-left: 2px;
  199. padding-right: 2px;
  200. margin-left: 2px;
  201. margin-right: 2px;
  202. font-size: 13px;
  203. }
  204. .list {
  205. display: block;
  206. }
  207. </style>