js部分:
// pages/location/location.js
var app = getApp(); //应用程序
Page({
/**
* 页面的初始数据
*/
data: {
dataList: [], //所店铺名及城市名集合
// latitude:'',//纬度
// longitude: '',//经度
},
onLoad: function(options) {
app.callback = (res) => {}//回调app.js里的登录函数,为了在运行单独页面时进行openID的调用
wx.showLoading({
title: '加载中...',
})
var that = this;
wx.request({
url: 'https://www.php',
header: {
' ...........'
},
method: 'POST',
data: {
openid: app.userLogin.openid,
type: 'empStoreList'
},
success: function(e) {
console.log('店铺获取数据:', e.data)
that.setData({
dataList: e.data.str
})
wx.hideLoading();
console.log('所店铺名及城市名dataList:', that.data.dataList)
var arr = [];
var arr1 = [];
for (var i = 0; i < that.data.dataList.length; i++) {
arr.push(that.data.dataList[i].store)
}
console.log("获取店铺:", arr)
for (var y = 0; y < arr.length; y++) { //外层数组(1)
// arr1.push(arr[y])
for (var x = 0; x < arr[y].length; x++) { //内层数组(2)
arr1.push(arr[y][x])
}
}
that.setData({
dataList: arr1
})
console.log("获取全部店铺:", arr1)
}
})
},
})
wxml部分:
<!--pages/location/location.wxml-->
<view class="dp_location_main">
<view class='list'>
<block wx:for='{{dataList}}' wx:key='list' wx:for-item="item">
<view class="list_item">
<navigator url='../qianwang_location/qianwang_location?ID={{item.CODE}}&NAME={{item.NAME}}&CITY={{item.CITY}}&longitude={{item.longitude}}' hover-class="navigator-hover">
<view class='img'>
<image src="../image/1.png" mode="scaleToFill" />
</view>
<view class='info'>
<view class='title'>{{item.NAME}}</view>
<view class='price' >{{item.longitude==null?"未定位":"已定位"}}</view>
<!-- <view class='price' wx:if='{{dingwei_tiaojian}}'>{{dianpu_dingwei}}</view> -->
<view class='num'>所在城市:{{item.CITY}}</view>
</view>
</navigator>
<view class='clear'></view>
</view>
</block>
</view>
</view>
css部分:
/* pages/location/location.wxss */
.dp_location_main {
margin: 0;
}
.clear {
clear: both;
overflow: hidden;
}
navigator {
display: inline;
}
.list {
margin-top: 10rpx;
}
.list .list_item {
margin-top: 10rpx;
padding: 10rpx;
height: 123rpx;
border: 2.5rpx solid #eeeef8;
}
.list .list_item .img {
float: left;
width: 20%;
height: 100%;
}
.list .list_item .img image {
width: 68%;
height: 71%;
position: relative;
top: 14rpx;
}
.list .list_item .info {
width: 60%;
float: right;
height: 100rpx;
position: relative;
}
.list .list_item .info .title {
color: #333;
margin-left: -110rpx;
font-size: 30rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
/* border-bottom: 1rpx solid black; */
}
.list .list_item .info .price {
color: #ff2727;
margin-left: 332rpx;
margin-top: 49rpx;
font-size: 30rpx;
}
.list .list_item .info .num {
position: absolute;
left: 0rpx;
bottom: 10rpx;
color: #747474;
margin-left: -110rpx;
font-size: 30rpx;
top: 65rpx;
}