list.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <view class="list">
  3. <view class="search">
  4. <div class="dist_search">
  5. <picker @change="bindPickerChange" :value="cityIndex" :range="cityArr">
  6. <view class="district">{{cityArr[cityIndex]}}</view>
  7. </picker>
  8. <view class="icon"></view>
  9. </div>
  10. <view class="separate">
  11. </view>
  12. <view class="inp">
  13. <view class="icon">
  14. </view>
  15. <input type="text" v-model="filterCityText" placeholder="请输入油站名称" />
  16. </view>
  17. </view>
  18. <view class="postion">
  19. <view class="icon"></view>
  20. <view class="current" @click="reGetLocation">
  21. 当前位置:{{location}}
  22. </view>
  23. <view class="refresh" @click="refresh">
  24. </view>
  25. </view>
  26. <view class="collection">
  27. <view class="station"
  28. v-for="ele in filterCityArr"
  29. @click="goBuy($event, ele.stationId)"
  30. >
  31. <view class="content">
  32. <image :src="ele.stationPic" mode=""></image>
  33. <view class="detail">
  34. <view class="name">{{ ele.stationName }}</view>
  35. <view class="other">
  36. <text v-show="ele.distance!==undefined">{{ele.distance + ' '}}km | </text>
  37. {{ ' ' + ele.stationAddress }}
  38. </view>
  39. </view>
  40. </view>
  41. <view class="footer">
  42. <view class="gothere" @click.stop="goThere($event, ele.stationLatitude, ele.stationLongitude)">
  43. 去这里
  44. </view>
  45. <view class="separator">|</view>
  46. <view class="gobuy" @click.stop="goBuy($event, ele.stationId)">
  47. 去买单
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. mapState,
  57. mapMutations,
  58. mapGetters
  59. } from "vuex";
  60. import Parse from "../../util/parse.js"
  61. // import getPermission from "../../util/permission.js"
  62. export default {
  63. data() {
  64. return {
  65. // notice: '',
  66. stationList: [],
  67. filterCityText: '',
  68. res: {},
  69. // cityArr:['泰安市','济南市'],
  70. cityIndex:0,
  71. location:'正在拼命拉取中...'
  72. }
  73. },
  74. async created() {
  75. // 调试
  76. // wx.setEnableDebug({
  77. // enableDebug: true
  78. // })
  79. this.init()
  80. },
  81. computed: {
  82. filterCityArr(){
  83. return this.stationList.filter((ele)=>{
  84. if(this.cityArr[this.cityIndex] == '全部'){
  85. return ele.stationName.includes(this.filterCityText) || ele.stationAddress.includes(this.filterCityText)
  86. }
  87. return ele.city === this.cityArr[this.cityIndex] && (ele.stationName.includes(this.filterCityText) || ele.stationAddress.includes(this.filterCityText))
  88. })
  89. },
  90. cityArr(){
  91. const cityArrSet = new Set(['全部']);
  92. this.stationList.map((ele)=>{
  93. cityArrSet.add(ele.city)
  94. })
  95. return [...cityArrSet]
  96. }
  97. },
  98. methods: {
  99. ...mapMutations(["updateStationId","clearEmployeeId"]),
  100. test() {
  101. console.log(132)
  102. },
  103. async init() {
  104. uni.showLoading({
  105. title: '加载中...',
  106. mask: true
  107. });
  108. const oldStationList = this.stationList;
  109. const oldLocation = this.location
  110. try{
  111. this.location = '正在拼命拉取中...'
  112. const stationListData = await this.$Request({
  113. url: "/getStationListByAppId",
  114. method: "GET",
  115. data: {
  116. appId: this.appId
  117. }
  118. })
  119. if(stationListData.retCode !== 0){
  120. throw new Error("初始油站信息失败")
  121. }
  122. // 单站
  123. if(stationListData.data.length === 1){
  124. this.updateStationId(stationListData.data[0].stationId)
  125. const [redirectErr, redirectData] = await uni.redirectTo({
  126. url: "/pages/index/index"
  127. })
  128. return
  129. }
  130. this.stationList = stationListData.data;
  131. const locationData = await uni.getLocation()
  132. if(locationData[0] !== null && locationData[0].errMsg === 'getLocation:fail auth deny' ){
  133. // 用户拒绝位置
  134. this.location = "您拒绝了授权~"
  135. uni.hideLoading();
  136. return
  137. }else if(locationData[0] !== null && locationData[0].errMsg === 'getLocation:fail 频繁调用会增加电量损耗,可考虑使用 wx.onLocationChange 监听地理位置变化' ){
  138. // 频繁调用时兼容处理
  139. this.location = oldLocation
  140. this.stationList = oldStationList
  141. uni.hideLoading();
  142. return
  143. }else if(locationData[0] !== null && locationData[0].errMsg === 'getLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF' ){
  144. this.location = "您的手机未开启定位"
  145. uni.hideLoading();
  146. return
  147. }else if(locationData[0] !== null){
  148. this.location = "没有获取到您的位置"
  149. uni.hideLoading();
  150. return
  151. }
  152. const stationLocationData = await this.$Request({
  153. url: "/getStationInfoListNew",
  154. method: "GET",
  155. data: {
  156. stationLongitude:locationData[1].longitude,
  157. stationLatitude: locationData[1].latitude,
  158. pageNum: 1,
  159. pageSize:1000,
  160. appId: this.appId
  161. }
  162. })
  163. if(stationLocationData.retCode !== 0){
  164. throw new Error("获取定位信息失败")
  165. }
  166. this.stationList = stationLocationData.data.stationInfoResponseList
  167. this.location = stationLocationData.data.address
  168. // const stationLocationListData = await this.$Request({
  169. // url: "/getStationInfoList",
  170. // method: "GET",
  171. // data: {
  172. // stationLongitude:locationData[1].longitude,
  173. // stationLatitude: locationData[1].latitude,
  174. // pageNum: 1,
  175. // pageSize:1000,
  176. // appId: this.appId
  177. // }
  178. // })
  179. // if(stationLocationListData.retCode !== 0){
  180. // throw new Error("获取详细油站信息失败")
  181. // }
  182. // this.stationList = stationLocationListData.data.stationInfoResponseList
  183. uni.hideLoading();
  184. }catch(e){
  185. // uni.hideLoading();
  186. uni.showToast({
  187. title: e
  188. })
  189. }
  190. },
  191. goBuy(e, stationId) {
  192. e.stopPropagation()
  193. this.updateStationId(stationId)
  194. this.clearEmployeeId()
  195. uni.navigateTo({
  196. url: "/pages/index/index"
  197. })
  198. return
  199. },
  200. goThere(e, latitude, longitude) {
  201. e.stopPropagation()
  202. uni.openLocation({
  203. latitude: parseFloat(latitude),
  204. longitude: parseFloat(longitude),
  205. success: function() {
  206. console.log('success');
  207. }
  208. });
  209. },
  210. async refresh(){
  211. // uni.getSetting({
  212. // success(res) {
  213. // console.log(res.authSetting)
  214. // }
  215. // })
  216. this.init()
  217. },
  218. async reGetLocation(){
  219. const that = this
  220. // try{
  221. const getSetPro = await uni.getSetting()
  222. if(getSetPro[0] === null){
  223. if(!getSetPro[1].authSetting['scope.userLocation']){
  224. uni.openSetting({
  225. success(res) {
  226. if(res.authSetting['scope.userLocation']){
  227. that.refresh();
  228. }else{
  229. uni.showToast({
  230. icon:'error',
  231. title:'还没授权呦~',
  232. mask: true
  233. })
  234. }
  235. }
  236. })
  237. }else{
  238. that.refresh()
  239. }
  240. }else{
  241. throw new Error("")
  242. }
  243. // }catch(e){
  244. // uni.showToast({
  245. // icon:'error',
  246. // title:'授权时出错~',
  247. // duration:1200,
  248. // mask: true
  249. // })
  250. // setTimeout(()=>{
  251. // that.refresh();
  252. // },1600)
  253. // }
  254. },
  255. bindPickerChange(e){
  256. this.cityIndex = e.detail.value
  257. }
  258. }
  259. }
  260. </script>
  261. <style lang="scss">
  262. page {
  263. .list {
  264. padding: 30rpx;
  265. background: #F6F6F6;
  266. height: 100vh;
  267. .search {
  268. width: 690rpx;
  269. height: 80rpx;
  270. background: #FFFFFF;
  271. box-shadow: 0px 2rpx 9rpx 4rpx rgba(99, 99, 99, 0.1);
  272. border-radius: 40rpx;
  273. // position: relative;
  274. display:flex;
  275. flex-direction: row;
  276. justify-content:space-around;
  277. align-items: center;
  278. .dist_search {
  279. // position: absolute;
  280. // top: 20rpx;
  281. // left: 30rpx;
  282. // width: 100%;
  283. height: 80rpx;
  284. max-width: 130rpx;
  285. white-space: nowrap;
  286. display: flex;
  287. margin-left: 20rpx;
  288. .district {
  289. height: 80rpx;
  290. font-size: 28rpx;
  291. font-weight: bold;
  292. color: #111111;
  293. line-height: 80rpx;
  294. overflow: hidden;
  295. white-space: nowrap;
  296. text-overflow: ellipsis;
  297. max-width: 110rpx;
  298. }
  299. >.icon {
  300. background: url(../../static/icon/1_b01_down.2x.png) no-repeat 0px 0px;
  301. background-size: 100% 100%;
  302. width: 13rpx;
  303. height: 8rpx;
  304. line-height: 80rpx;
  305. margin-top: 38rpx;
  306. margin-left: 10rpx;
  307. }
  308. }
  309. .separate {
  310. width: 1rpx;
  311. height: 35rpx;
  312. border: .5rpx solid #CCCCCC;
  313. box-sizing: border-box;
  314. // position: absolute;
  315. // top: 20rpx;
  316. // left: 180rpx;
  317. }
  318. .inp {
  319. // position: absolute;
  320. // top: 15rpx;
  321. // left: 200rpx;
  322. width: 450rpx;
  323. height: 80rpx;
  324. // position: relative;
  325. .icon {
  326. display: inline-block;
  327. background: url(../../static/icon/1_b01_search.2x.png) no-repeat 0px 0px;
  328. background-size: 100% 100%;
  329. width: 26rpx;
  330. height: 26rpx;
  331. margin-bottom: 25rpx;
  332. // // top: 162rpx;
  333. // position: absolute;
  334. // top: 27rpx;
  335. }
  336. >input {
  337. display: inline-block;
  338. margin-left: 20rpx;
  339. width: 310rpx;
  340. height: 80rpx;
  341. line-height: 80rpx;
  342. }
  343. }
  344. }
  345. .postion {
  346. margin: 30rpx 30rpx 0 30rpx ;
  347. .icon {
  348. background: url(../../static/icon/1_b01_location.2x.png) no-repeat 0px 0px;
  349. background-size: 100% 100%;
  350. width: 33rpx;
  351. height: 35rpx;
  352. display: inline-block;
  353. }
  354. .current {
  355. margin-left: 20rpx;
  356. display: inline-block;
  357. height: 40rpx;
  358. font-size: 28rpx;
  359. color: #868686;
  360. line-height: 40rpx;
  361. max-width: 550rpx;
  362. overflow: hidden;
  363. white-space: nowrap;
  364. text-overflow: ellipsis;
  365. }
  366. .refresh {
  367. background: url(../../static/icon/icon_shuaxin.2x.png) no-repeat 0px 0px;
  368. background-size: 100% 100%;
  369. // background-color: #868686;
  370. margin-top: 5rpx;
  371. width: 27rpx;
  372. height: 27rpx;
  373. float: right;
  374. }
  375. }
  376. .collection {
  377. margin-top: 30rpx;
  378. .station {
  379. margin-bottom: 30rpx;
  380. // padding: 30rpx;
  381. padding: 40rpx;
  382. width: 690rpx;
  383. height: 285rpx;
  384. background: #FFFFFF;
  385. box-shadow: 0px 2rpx 9rpx 4rpx rgba(99, 99, 99, 0.1);
  386. border-radius: 18rpx;
  387. box-sizing: border-box;
  388. .content {
  389. display: flex;
  390. >image {
  391. width: 155rpx;
  392. height: 155rpx;
  393. display: inline-block;
  394. }
  395. .detail {
  396. margin-left: 20rpx;
  397. width: 450rpx;
  398. height: 155rpx;
  399. display: inline-block;
  400. .name {
  401. height: 45rpx;
  402. font-size: 32rpx;
  403. font-weight: bold;
  404. color: #111111;
  405. line-height: 45rpx;
  406. overflow: hidden;
  407. white-space: nowrap;
  408. text-overflow: ellipsis;
  409. }
  410. }
  411. }
  412. .footer {
  413. margin-top: 40rpx;
  414. display: flex;
  415. justify-content: space-around;
  416. .gothere {
  417. height: 40rpx;
  418. width: 250rpx;
  419. font-size: 28rpx;
  420. font-weight: bold;
  421. color: #6c6c6c;
  422. line-height: 40rpx;
  423. text-align: center;
  424. }
  425. .separator {
  426. // width: 1px;
  427. // height: 46rpx;
  428. // border: 1px solid #CCCCCC;
  429. color: #CCCCCC;
  430. }
  431. .gobuy {
  432. height: 40rpx;
  433. font-size: 28rpx;
  434. font-weight:bold;
  435. width: 250rpx;
  436. color: #F3B235;
  437. line-height: 40rpx;
  438. text-align: center;
  439. }
  440. }
  441. }
  442. }
  443. }
  444. }
  445. </style>