index.vue 7.0 KB

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