shoplist.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="container">
  3. <view class="top">
  4. <view class="search">
  5. <uni-easyinput class="uni-input" prefixIcon="search" v-model="formData.name" placeholder="请输入商户名称"></uni-easyinput>
  6. <button class="searchBtn" type="default" size="mini" @click="handleSearch">搜索</button>
  7. </view>
  8. </view>
  9. <uni-list border class="list">
  10. <uni-list-item
  11. v-for="(item, index) in resultList"
  12. :key="index"
  13. :ellipsis="2"
  14. :title="item.district"
  15. :note=getAddress(item)
  16. :rightText=getMerchantName(item)
  17. showArrow
  18. clickable
  19. @click="listItemBtn(item)">
  20. </uni-list-item>
  21. </uni-list>
  22. <uni-load-more :status="more" />
  23. </view>
  24. </template>
  25. <script>
  26. import dictApi from '../../api/dict.js';
  27. import shopApi from '../../api/shop.js';
  28. import { BASE_URL } from '../../env.js';
  29. export default {
  30. data() {
  31. return {
  32. statusOptions: [],
  33. formData: {
  34. pageNum: 0,
  35. pageSize: 20,
  36. district: null,
  37. tag: null,
  38. status: null,
  39. name: null,
  40. },
  41. resultList: [],
  42. more: 'more'
  43. }
  44. },
  45. onLoad: function (option) {
  46. this.formData.district = option.district;
  47. this.formData.tag = option.tag;
  48. if(option.status==1){
  49. this.formData.status = "已使用";
  50. }else{
  51. this.formData.status = "未使用";
  52. }
  53. },
  54. onShow: function() {
  55. // this.init();
  56. },
  57. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  58. onReachBottom() {
  59. if(this.more != 'noMore') {
  60. this.more = 'more';
  61. this.getShopList();
  62. }
  63. },
  64. async mounted() {
  65. await this.getDicts();
  66. await this.getShopList();
  67. },
  68. methods: {
  69. async getDicts() {
  70. const resp_vacant = await dictApi.getDict('vacant_status');
  71. if (resp_vacant.code == 200)
  72. this.statusOptions = resp_vacant.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  73. },
  74. // 搜索函数
  75. async getShopList() {
  76. this.more = 'loading';
  77. const queryParams = {};
  78. this.getFormParams(queryParams);
  79. const resp = await shopApi.getShopList({...queryParams});
  80. this.resultList.push(...resp.rows);
  81. this.updateMoreStatus(resp.total);
  82. },
  83. // 搜索函数
  84. async handleSearch() {
  85. this.resultList.length = 0;
  86. this.formData.pageNum = 0;
  87. await this.getShopList();
  88. },
  89. async handleReset() {
  90. this.formData.pageNum = 0;
  91. this.formData.name = null;
  92. // this.formData.status = null;
  93. this.resultList.length = 0;
  94. await this.getShopList();
  95. },
  96. // 列表点击函数
  97. listItemBtn(e) {
  98. uni.navigateTo({ url: `/pages/shop/info?id=${e.shopId}` })
  99. },
  100. getAddress(shop){
  101. return shop.tag + " 铺位号:" + shop.number;
  102. },
  103. getMerchantName(shop){
  104. if(shop.status === "未使用")
  105. return shop.status;
  106. if(shop.name != null && shop.name != '' && shop.name != undefined)
  107. return shop.name;
  108. return "未知";
  109. },
  110. getFormParams(queryParams){
  111. this.formData.pageNum += 1;
  112. for (const key in this.formData) {
  113. if (this.formData[key] !== null
  114. && this.formData[key] !== undefined
  115. && this.formData[key] !== '') {
  116. queryParams[key] = this.formData[key];
  117. }
  118. }
  119. },
  120. updateMoreStatus(total){
  121. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  122. this.more = this.formData.pageNum >= Math.ceil(total / this.formData.pageSize) ? 'noMore' : 'more';
  123. }
  124. }
  125. }
  126. </script>
  127. <style>
  128. .container {
  129. width: 100%;
  130. background-color: #fff;
  131. }
  132. .top {
  133. width: 100%;
  134. z-index: 999;
  135. background-color: #fff;
  136. overflow: hidden;
  137. }
  138. .tabsBox {
  139. width: 100%;
  140. border-bottom: 1px solid #d3d3d3;
  141. display: flex;
  142. }
  143. .tab {
  144. width: 25%;
  145. }
  146. .text {
  147. display: block;
  148. width: 80%;
  149. margin: 0 auto;
  150. text-align: center;
  151. }
  152. .current {
  153. color: #ff9302;
  154. border-bottom: 1px solid #ff9302;
  155. }
  156. .search {
  157. width: 90%;
  158. height: 2em;
  159. border: 1px solid #f3f3f3;
  160. background-color: #fff !important;
  161. border-radius: 12px;
  162. display: flex;
  163. margin: 20px auto;
  164. }
  165. .uni-easyinput {
  166. width: 70%;
  167. margin-left: 5%;
  168. height: 100%;
  169. font-size: 14px;
  170. }
  171. .uni-easyinput .uni-easyinput__content {
  172. border: none !important;
  173. height: 100%;
  174. line-height: 2em;
  175. }
  176. .searchBtn {
  177. width: 20%;
  178. background-color: #ff9302 !important;
  179. border: none;
  180. color: #fff !important;
  181. height: 2em;
  182. margin-top: 0.2em;
  183. margin-left: 4%;
  184. border-radius: 12px;
  185. }
  186. .list {
  187. display: block;
  188. }
  189. </style>