index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 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="11">
  14. <view class="demo-uni-col">
  15. <uni-data-picker :localdata="addressOptions" v-model="selectedAddress" placeholder="商铺位置" popup-title="选择商铺位置"
  16. @change="onchange"
  17. @nodeclick="onnodeclick"
  18. @popupclosed="onpopupclosed"></uni-data-picker>
  19. </view>
  20. </uni-col>
  21. <uni-col :span="5">
  22. <view class="demo-uni-col">
  23. <uni-data-select class="search-data-select" placeholder="使用状态" v-model="formData.status" :localdata="statusOptions">状态</uni-data-select>
  24. </view>
  25. </uni-col>
  26. <uni-col :span="4">
  27. <view class="demo-uni-col">
  28. <button class="searchBtn" type="default" size="mini" @click="handleSearch">搜索</button>
  29. </view>
  30. </uni-col>
  31. <uni-col :span="4">
  32. <view class="demo-uni-col">
  33. <button class="searchBtn" type="default" size="mini" @click="handleReset">重置</button>
  34. </view>
  35. </uni-col>
  36. </uni-row>
  37. </view>
  38. </view>
  39. <uni-list border class="list">
  40. <uni-list-item
  41. v-for="(item, index) in resultList"
  42. :key="index"
  43. :ellipsis="2"
  44. :title=getTitle(item)
  45. :note="item.createTime"
  46. showArrow
  47. clickable
  48. @click="listItemBtn(item)">
  49. </uni-list-item>
  50. </uni-list>
  51. <uni-load-more :status="more" />
  52. </view>
  53. </template>
  54. <script>
  55. import dictApi from '../../api/dict.js';
  56. import shopApi from '../../api/shop.js';
  57. import { BASE_URL } from '../../env.js';
  58. export default {
  59. data() {
  60. return {
  61. addressOptions: [],
  62. statusOptions: [],
  63. currentAddress: null,
  64. selectedAddress: null,
  65. formData: {
  66. pageNum: 0,
  67. pageSize: 20,
  68. district: null,
  69. building: null,
  70. floor: null,
  71. status: null,
  72. name: null,
  73. },
  74. resultList: [],
  75. more: 'more'
  76. }
  77. },
  78. onShow: function() {
  79. // this.init();
  80. },
  81. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  82. onReachBottom() {
  83. if(this.more != 'noMore') {
  84. this.more = 'more';
  85. this.getShopList();
  86. }
  87. },
  88. async mounted() {
  89. await this.getDicts();
  90. await this.getDistrictBuildingFloor();
  91. await this.getShopList();
  92. },
  93. methods: {
  94. async getDicts() {
  95. const resp_vacant = await dictApi.getDict('vacant_status');
  96. if (resp_vacant.code == 200)
  97. this.statusOptions = resp_vacant.data.map(l => ({ ...l, value: l.dictValue, text: l.dictLabel }));
  98. },
  99. async getDistrictBuildingFloor() {
  100. const resp_address = await shopApi.getDistrictBuildingFloor();
  101. this.addressOptions = resp_address.data.map(node => this.flattenValues(node));
  102. },
  103. flattenValues(node, parentValue='') {
  104. if(parentValue!==''){
  105. node.value = parentValue + ':' + node.value;
  106. }
  107. if (!node.isleaf && node.children!=null && node.children.length != 0) {
  108. node.children.map(child => this.flattenValues(child, node.value));
  109. }
  110. return node;
  111. },
  112. // 搜索函数
  113. async getShopList() {
  114. this.more = 'loading';
  115. const queryParams = {};
  116. this.getFormParams(queryParams);
  117. const resp = await shopApi.getShopList({...queryParams});
  118. this.resultList.push(...resp.rows);
  119. this.updateMoreStatus(resp.total);
  120. },
  121. // 搜索函数
  122. async handleSearch() {
  123. this.resultList.length = 0;
  124. this.formData.pageNum = 0;
  125. await this.getShopList();
  126. },
  127. async handleReset() {
  128. this.currentAddress = null;
  129. this.selectedAddress = null;
  130. this.formData.pageNum = 0;
  131. this.formData.name = null;
  132. this.formData.district = null;
  133. this.formData.building = null;
  134. this.formData.floor = null;
  135. this.formData.status = null;
  136. this.resultList.length = 0;
  137. await this.getShopList();
  138. },
  139. onchange(nodesPath) {
  140. const value = nodesPath.detail.value[0];
  141. if (!value) {
  142. this.currentAddress = null;
  143. }
  144. },
  145. onnodeclick(node) {
  146. this.currentAddress = node;
  147. },
  148. onpopupclosed() {
  149. this.$nextTick(() => {
  150. this.selectedAddress = this.currentAddress.value
  151. });
  152. },
  153. // 列表点击函数
  154. listItemBtn(e) {
  155. uni.navigateTo({ url: `/pages/shop/info?id=${e.shopId}` })
  156. },
  157. getTitle(shop){
  158. const title = shop.district
  159. + " 楼栋:" + shop.building
  160. + " 楼层:" + shop.floor
  161. + " 铺位号:" + shop.number;
  162. + "商户:" + shop.name;
  163. + "状态:" + shop.status;
  164. return title;
  165. },
  166. getFormParams(queryParams){
  167. this.formData.pageNum += 1;
  168. if(this.currentAddress != null){
  169. var parts = this.currentAddress.value.split(":");
  170. if (parts.length >= 1) this.formData.district = parts[0];
  171. if (parts.length >= 2) this.formData.building = parts[1];
  172. if (parts.length >= 3) this.formData.floor = parts[2];
  173. }
  174. for (const key in this.formData) {
  175. if (this.formData[key] !== null
  176. && this.formData[key] !== undefined
  177. && this.formData[key] !== '') {
  178. queryParams[key] = this.formData[key];
  179. }
  180. }
  181. },
  182. updateMoreStatus(total){
  183. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  184. this.more = this.formData.pageNum >= Math.ceil(total / this.formData.pageSize) ? 'noMore' : 'more';
  185. }
  186. }
  187. }
  188. </script>
  189. <style>
  190. .container {
  191. width: 100%;
  192. background-color: #fff;
  193. }
  194. .top {
  195. width: 100%;
  196. z-index: 999;
  197. background-color: #fff;
  198. /* overflow: hidden; */
  199. }
  200. .tabsBox {
  201. width: 100%;
  202. border-bottom: 1px solid #d3d3d3;
  203. display: flex;
  204. }
  205. .tab {
  206. width: 25%;
  207. }
  208. .text {
  209. display: block;
  210. width: 80%;
  211. margin: 0 auto;
  212. text-align: center;
  213. }
  214. .current {
  215. color: #ff9302;
  216. border-bottom: 1px solid #ff9302;
  217. }
  218. .search {
  219. width: 98%;
  220. border: 1px solid #f3f3f3;
  221. background-color: #fff !important;
  222. border-radius: 5px;
  223. margin: 2px;
  224. padding: 2rpx;
  225. display: block;
  226. }
  227. .demo-uni-row {
  228. margin-bottom: 10px;
  229. display: block;
  230. }
  231. /deep/ .uni-row {
  232. margin-bottom: 10px;
  233. }
  234. .demo-uni-col {
  235. height: 24px;
  236. margin-bottom: 10px;
  237. border-radius: 4px;
  238. }
  239. .uni-easyinput {
  240. width: 100%;
  241. font-size: 14px;
  242. display: block;
  243. }
  244. .uni-easyinput .uni-easyinput__content {
  245. border: 1px solid #f3f3f3;
  246. border-radius: 10px;
  247. }
  248. .search-data-select{
  249. width: 100%;
  250. border-radius: 10px;
  251. }
  252. .searchBtn {
  253. width: 98%;
  254. background-color: #ff9302 !important;
  255. border: none;
  256. color: #fff !important;
  257. border-radius: 12px;
  258. }
  259. .list {
  260. display: block;
  261. }
  262. </style>