orglist.vue 5.17 KB
Newer Older
潘琦 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
<template>
  <div class="full-page">
    <div class="container orgListPage">
      <div class="head">
        <div class="search-control">
          <span class="placeholder" v-if="placeholder">
            <i class="glyphicon glyphicon-search"></i> 搜索您要找的社区医院
          </span>
          <input type="search" @focus="searchTextFocus" @blur="searchTextBlur" @keyup.enter="changesearch" v-model="searchOrgName"/>
        </div>
      </div>
      <div class="content">
        <ul
          v-infinite-scroll="loadMore"
          infinite-scroll-disabled="loading"
          infinite-scroll-distance="10">
          <li v-for="(item, index) in data" :key="index">
            <div class="org-item">
              <div class="cell picture">
                <div class="avatar" :style="{backgroundImage: 'url(' + (item.orgPictUrl ? item.orgPictUrl : defaultImg) + ')'}"></div>
              </div>
              <div class="cell info">
                <div class="title">{{item.orgname}}</div>
                <div class="des">{{item.saleaaddr}}</div>
                <small class="distance">距您 {{item.distance}}km</small>
              </div>
            </div>
          </li>
        </ul>
        <p class="text-center tips" v-show="!loadMoreState">
          --- 这已经是最下面了 ---
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import { getOrgListByPosition } from '@/api/sjkgbasic/sjkgbasic'
import _defaultImg from '../../assets/images/org-default-picture.png'
export default {
  name: 'orglist',
  data () {
    return {
      data: [],
      placeholder: true, // 搜索框提示占位符显示状态
      searchOrgName: '', // 机构名称手动搜索
      searchCurPage: 0, // 机构列表页数
      latitude: '28.22778',
      longitude: '112.93886',
      size: 10,
      tipsVisible: false,
      loadMoreState: true, // 加载更多状态
      enterSearchState: false, // 回车搜索状态
      defaultImg: _defaultImg
    }
  },
  created () {
    // this.getOrgListFn() // 获取附近机构
  },
  mounted: function () {
  },
  computed: {
  },
  components: {
  },
  methods: {
    getOrgListFn () {
      if (!this.latitude || !this.longitude || this.latitude === '' || this.longitude === '') {
        this.$toast({
          message: '未获取到当前位置信息!',
          position: 'center',
          duration: 3000
        })
        return false
      }
      let params = {
        current: this.searchCurPage,
        latitude: this.latitude,
        longitude: this.longitude,
        size: this.size
      }
      if (this.searchOrgName !== '') {
        params.key = this.searchOrgName
      }
      this.$Indicator.open()
      getOrgListByPosition(params).then(res => {
        this.$Indicator.close()
        if (res.code === 0 && res.data.records.length > 0) {
          this.data = this.data.concat(res.data.records)
          this.loadMoreState = true
        } else {
          this.loadMoreState = false
          this.searchCurPage = this.searchCurPage - 1
        //   this.tipsVisible = true
        }
      }).catch((error) => {
        this.$Indicator.close()
        this.$toast({
          message: error.message,
          position: 'center',
          duration: 3000
        })
      })
    },
    loadMore () {
      if (this.loadMoreState) {
        this.searchCurPage = this.searchCurPage + 1
        this.getOrgListFn()
      }
    },
    changesearch () {
      console.log('change')
      this.loadMoreState = false
      this.data = []
      this.searchCurPage = 1
      this.getOrgListFn()
    },
    searchTextFocus () {
      this.placeholder = false
    },
    searchTextBlur () {
      if (this.searchOrgName === '') {
        this.placeholder = true
      } else {
        this.placeholder = false
      }
      // this.changesearch()
    }
  }
}
</script>

<style scoped>
  .full-page {
    background-color: #f5f6f7;
  }

  .orgListPage .head {
    padding: 1em 0;
    position: fixed;
    width: 100%;
    left: 0;
    background-color: #f5f6f7;
    z-index: 1;
  }

  .orgListPage .head .search-control{
    margin: 0 1em;
  }
  .orgListPage .content {
    padding-top: 17%;
  }
  .orgListPage ul > li {
    background-color: #fff;
    padding: 0.5em;
    margin-bottom: 1em;
  }

  .org-item {
    display: table;
    width: 100%;
  }
  .org-item > .cell {
    display: table-cell;
    vertical-align: middle;
  }
  .org-item > .cell.picture {
    width: 8em;
  }
  .org-item > .cell.picture > .avatar{
    width: 7em;
    height: 7em;
    border-radius: 10px;
    background-repeat: no-repeat;
    background-size: 100% auto;
    background-position: center center;
  }

  .org-item > .cell.info{
    position: relative;
    vertical-align: top;
  }
  .org-item > .cell.info > .title {
    font-size: 1.1em;
    white-space:nowrap;
    text-overflow:ellipsis;
    max-width: 14em;
    overflow:hidden;
    margin-bottom: 5px;
  }
  .org-item > .cell.info > .des {
    color:#9aa0a4;
    white-space:nowrap;
    text-overflow:ellipsis;
    max-width: 14em;
    overflow:hidden;
  }
  .org-item > .cell.info > .distance{
    color:#9aa0a4;
    position:absolute;
    bottom:0;
    left:0;
  }

  .tips {
    color: #80848f;
    font-size: 0.9em;
  }
</style>