小程序显示数据

1.当遍历是一条数据,取数据是个数据需要遍历,只需要取

base.y_slide进行遍历即可。

$base[‘y_slide‘] = unserialize($base[‘y_slide‘]);
$num = count($base[‘y_slide‘]);
for($i = 0; $i < $num; $i++) {
$base[‘y_slide‘][$i]=$_W[‘attachurl‘].$base[‘y_slide‘][$i];
}

 

2.遍历的是多条数据

foreach ($item as &$values) {
     $values[‘k_slide‘] = unserialize($values[‘k_slide‘]);
     $num = count($values[‘k_slide‘]);
    for ($i = 0; $i < $num ; $i++) {
            $values[‘k_slide‘][$i]=$_W[‘attachurl‘].$values[‘k_slide‘][$i];
}
}

3.传数据给下一个页面传id

data-k_id=‘{{item.k_id}}‘
点击事件   传id
departmentDetailClick: function(e) {
 
console.log(e.currentTarget.dataset.k_id)
var k_id = e.currentTarget.dataset.k_id
wx.navigateTo({

url: ‘/hyb_zylxc/department_detail/department_detail?k_id=‘ + k_id,
})
},
 
下一个页面  接收id
onLoad: function(options) {
var that = this;
var id = options.k_id;
that.getKeshixq(id);
// that.getIntroduction(id);
},
 
getKeshixq:function(id){
var that = this;
console.log(id)
app.util.request({
‘url‘: ‘entry/wxapp/Keshijianjie‘,
data: {
k_id: id
},
success: function (res) {

console.log(res.data.data)
that.setData({
keshi: res.data.data,
})
wx.setNavigationBarTitle({ title: ‘科室简介‘ });
WxParse.wxParse(‘article‘, ‘html‘, res.data.data.k_jianjie, that, 5);//百度编辑器去除非法字符显示数据

},
//百度编辑器显示数据  article
<view class="wxParse bgcf bsbb p30 fs26 c6 bgcf">
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>
</view>
 
4.   遍历显示数据   下拉 点击选择
<picker name="u_consultation" bindchange="zhuanjiachange" value="{{index}}" range="{{zjarrs}}">
<view wx:if="{{index == ‘‘}}" class=‘fs24 c9 ml100‘>
请选择要预约的专家
</view>
 
<view wx:else class="fs26 c6 ml100">
<!-- <view wx:for="{{expert}}" wx:for-item="items"> -->
<!-- {{zjarrs[index]}} -->
<input name="u_consultation" value=‘{{zjarrs[index]}}‘ disabled=‘true‘/>
<!-- </view> -->
</view>
</picker>
 
 
onLoad: function (options) {
var that = this;
that.bindPickerChange();
},
 
 
bindPickerChange: function () {
var that =this;
app.util.request({
‘url‘: "entry/wxapp/YuZhuanjia",
success:function(e){
var arrs = e.data.data;
var zjarrs = [];
for (var i = 0; i < arrs.length;i++){
zjarrs.push(arrs[i].z_name);
}
that.setData({
expert: e.data.data,
zjarrs: zjarrs
})
}
})
},
zhuanjiachange:function(e){
console.log(‘picker发送选择改变,携带值为‘, e.detail.value)
console.log(this.data.expert);//预约专家
this.setData({
index:e.detail.value
})
},
 
 
5.地图
 
<view data-longitude="{{longitude}}" data-latitude="{{latitude}}" class=‘bdl2 df fdc w50 aic jcc bdbb pt30 pb30‘ bindtap=‘Position‘>
 
//来院路线
choosePosition: function() {
var that = this;
app.util.request({
‘url‘: ‘entry/wxapp/Base‘,
success: function (res) {
console.log(res.data.data);
that.setData({
base: res.data.data,
latitude:res.data.data.latitude,
longitude:res.data.data.longitude
})
},
fail: function (err) {
console.log(err)
},
});
},
Position:function(e){
var latitude = e.currentTarget.dataset.latitude
var longitude = e.currentTarget.dataset.longitude
console.log(latitude, longitude);
wx.openLocation({
latitude: parseFloat(latitude),
longitude: parseFloat(longitude),
scale: 28
})
},
 
6.点击切换
<scroll-view class=‘bsbb pl30 bgcf bdb2‘ scroll-x style=‘white-space:nowrap;‘>
<block wx:for="{{caseArr}}" wx:key="unique">
<text data-index="{{index}}" class=‘fs24 dib bsbb h80 mr50 {{current == index?"c bdb4":"c9"}}‘ bindtap=‘huoqu‘>{{item.j_name}}</text>
</block>
</scroll-view>

<!-- <my-sku-page data-index="{{pIndex[index]}}" wx:key="unique" binddetailBtn="checkClick" style="display:{{current == pIndex[index]?‘block‘:‘none‘}}" >
 
</my-sku-page> -->

<!-- <view wx:for="{{caseArr}}" wx:for-item="items"> -->
<scroll-view class="bsbb pl30 df pt30 pb30 bgcf h310" scroll-x style=‘white-space:nowrap;‘>
<block wx:for="{{caseArr[current].binzhen}}" wx:key="unique">
<view data-j_id="{{item.j_id}}" class=‘dib tac mr15‘ bindtap="checkClick">
<view>
<image mode=‘aspectFill‘ style=‘width:178rpx;height:178rpx;‘ src=‘{{item.j_thumb}}‘ class=‘db‘></image>
</view>
<text class=‘db fs26 c9 mt20‘>{{item.j_name}}</text>
</view>
</block>
</scroll-view>
 
 
current: 0,
 
huoqu: function(e) {
var that = this
console.log(e)
var index = e.currentTarget.dataset.index
var current = index;

that.setData({
current: current
})
 
7.分享转发
onShareAppMessage: function() {
//分享
// console.log("分享")
var that = this
// console.log("分享1")
return {
title: ‘双十一来了瞧一瞧看一看喽‘,
path: ‘/hyb_zylxc/index/index‘,
success: res => {
// console.log("分享2")
// console.log("分享成功" + res)
console.log(res.shareTickets[0]);
// shareTicket 是获取转发目标群信息的票据,只有拥有 shareTicket 才能拿到群信息,用户每次转发都会生成对应唯一的shareTicket 。
// 如果这里有 shareTickets,则说明是分享到群de 如果没有则是转发到好友的
wx.getShareInfo({
shareTicket: res.shareTickets[0],
success: res => {
that.setData({
isShow: true
})
console.log(that.setData.isShow)
},
fail: function (res) { console.log(res) },
complete: function (res) { console.log(res) }
})
},
fail: function (res) {
console.log("分享失败" + res)
}
}
 
}
 
8.检索事件选择,选择男装的上衣
<picker bindchange="bindDepartmentChange" value="{{index}}" range="{{introduction}}" class="w33">
<view wx:if="{{index == ‘‘}}" class=‘df jcc aic fs28 c9‘>
<text>全部科室</text>
<image mode=‘widthFix‘ style=‘width:27rpx‘ src=‘../images/down.png‘ class=‘ml15‘></image>
</view>
<view wx:else class=‘df jcc aic fs28 c9 ‘>
<text>{{introduction[index]}}</text>
<!-- <input name="u_consultation" value=‘{{introduction[index]}}‘ disabled=‘true‘ /> -->
<image mode=‘widthFix‘ style=‘width:27rpx‘ src=‘../images/down.png‘ class=‘ml15‘></image>
</view>

</picker>
 
下标:data :{
    
           index: "",
}
 
that.getYuZhuanjiajiansuo(‘‘, ‘‘, ‘‘);//专家检索
 
选择显示
bindPickerChange: function () {
var that = this;
app.util.request({
‘url‘: "entry/wxapp/Keshi",
success: function (e) {
console.log(e.data.data);
var arrs = e.data.data;
var introduction = [];
for (var i = 0; i < arrs.length; i++) {
introduction.push(arrs[i].k_name);
}
that.setData({
keshi: e.data.data,
introduction: introduction
})
}
})
},
//科室
bindDepartmentChange: function (e) {
var that = this;
that.setData({
index: e.detail.value//下标
})
var keshi = that.data.introduction[e.detail.value];
var zhicheng = that.data.zhicheng[that.data.appellation];
var shanchang = that.data.specialityArr[that.data.speciality]
if(zhicheng==undefined){
var zhicheng = ‘‘;
}
if (shanchang==undefined){
var shanchang = "";
}
that.getYuZhuanjiajiansuo(keshi, zhicheng, shanchang);
},
 
 
 
getYuZhuanjiajiansuo:function(keshi,zhicheng,shanchang){
var that = this;
app.util.request({
‘url‘: ‘entry/wxapp/YuZhuanjiajiansuo‘,
‘data‘:{
keshi: keshi,
zhicheng:zhicheng,
shanchang: shanchang
},
success: function (res) {
console.log(res.data.data);
that.setData({
expert: res.data.data,
 
})
},
fail: function (err) {
console.log(err)
},
});
},
 
 

//专家检索
public function doPageYuZhuanjiajiansuo(){
global $_W,$_GPC;
$uniacid = $_W[‘uniacid‘];
$keshi = $_REQUEST[‘keshi‘];
$zhicheng = $_REQUEST[‘zhicheng‘];
$shanchang = $_REQUEST[‘shanchang‘];
$where = " where uniacid=:uniacid";
if (!empty($keshi)) {
$where.=" and keshi=:keshi";
$data[":keshi"] = $keshi;
}
if (!empty($zhicheng)) {
$where.=" and z_zhicheng=:zhicheng";
$data[":zhicheng"] = $zhicheng;
}
if (!empty($shanchang)) {
$where.=" and z_shanchang like ‘%$shanchang%‘";    //很多不止一个,
}
$data[‘:uniacid‘] = $uniacid;
$sql = "SELECT * FROM ".tablename("hyb_ylxc_zhuanjia").$where;
// $sql = "SELECT * FROM ".tablename("hyb_ylxc_zhuanjia")."where uniacid=:uniacid",array(":uniacid"=>$uniacid);
$list = pdo_fetchall($sql,$data);
if (!empty($list)) {
foreach ($list as &$value) {
$value[‘z_thumbs‘] = $_W[‘attachurl‘].$value[‘z_thumbs‘];
$base = pdo_fetch("SELECT * FROM ".tablename("hyb_ylxc_base")." where uniacid=:uniacid",array(":uniacid"=>$uniacid));
$value[‘yiyuan‘] = $base[‘y_title‘];

}

}
return $this->result(0,"success",$list);
}

 

9.用户授权

//获取用户信息
public function doPageTyMember() {
global $_GPC, $_W;
$uniacid = $_W[‘uniacid‘];
$openid = $_REQUEST[‘openid‘];
// $openid = "oiw7_0FlOxmb4SmYHwT7K0rBdCnY";
$item[‘u_name‘] = $_GPC[‘u_name‘];
$item[‘u_thumb‘] = $_GPC[‘u_thumb‘];
$item[‘uniacid‘] = $uniacid;
if ($openid) {
$res = pdo_update(‘hyb_ylxc_userinfo‘, $item, array(‘openid‘ => $openid));
}
if (!$res[‘u_id‘]) {
$res = pdo_fetch(‘SELECT `u_id` FROM ‘ . tablename(‘hyb_ylxc_userinfo‘) . " where `openid`=‘{$openid}‘");
}
$message = ‘success‘;
$errno = 0;
return $this->result($errno, $message, $item);
}
public function doPageGetUid() {

global $_GPC, $_W;
$uniacid = $_W[‘uniacid‘];
$result = pdo_fetch(‘SELECT * FROM ‘ . tablename(‘hyb_ylxc_key‘) . " where `uniacid`=‘{$uniacid}‘");
// $APPID = "wxbcf230862644aa93";
$APPID = $result[‘appid‘];
$SECRET = $result[‘appsecret‘];
// $SECRET = "1ad4414c9da569ca333d216cc6d0f643";
$openid = $_REQUEST[‘openid‘];
$openid = "oiw7_0FlOxmb4SmYHwT7K0rBdCnY";
$code = trim($_GPC[‘code‘]);
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$APPID}&secret={$SECRET}&js_code={$code}&grant_type=authorization_code";
$data[‘userinfo‘] = json_decode($this->httpGet($url));
$openid = $data[‘userinfo‘]->openid;
$item[‘openid‘] = $openid;
if ($openid) {
$res = pdo_fetch(‘SELECT `u_id` FROM ‘ . tablename(‘hyb_ylxc_userinfo‘) . " where `openid`=‘{$openid}‘");
if (!$res[‘u_id‘]) {
$res = pdo_insert(‘hyb_ylxc_userinfo‘, $item);
}
}
$data[‘openid‘] = $openid;
$message = ‘success‘;
$errno = 0;
return $this->result($errno, $message, $data);
}

 

 

bindGetUserInfo: function(e) {
var that = this;
console.log(e);
console.log(e.detail.userInfo)
wx.login({
success: res => {
// ------ 获取凭证 ------
 
var code = res.code;
console.log(code);
if (code) {
// console.log(‘获取用户登录凭证:‘ + code);
// ------ 发送凭证 ------
app.util.request({
"url": "entry/wxapp/GetUid",
data: {
code: code
},
method: ‘POST‘,
header: {
‘content-type‘: ‘application/json‘
},
success: function(res) {
console.log(res);
var openid = res.data;
if (res.statusCode == 200) {
// console.log("获取到的openid为:" + res.data)
// that.globalData.openid = res.data
wx.setStorageSync(‘openid‘, res.data),
wx.setStorage({
key: ‘userinfo‘,
data: true,
}),
that.setData({
userinfo: true
})
//设置用户信息
wx.getUserInfo({
success: res => {
console.log(res);
var u_name = e.detail.userInfo.nickName;
var u_thumb = e.detail.userInfo.avatarUrl;
console.log(u_name);
console.log("aa" + res)
console.log("aa"+res.errMsg)
wx.setStorageSync("avatar", res.userInfo.avatarUrl)
if (res.userInfo.nickName != wx.getStorageSync("nickName")) {
app.util.request({
"url": ‘entry/wxapp/TyMember‘,
data :{
u_name:u_name,
u_thumb:u_thumb,
 
},
method: ‘POST‘,
header: {
‘content-type‘: ‘application/json‘
},
success: function (res) {
console.log(res);
if (res.statusCode == 200) {
// console.log("获取到的openid为:" + res.data)
// that.globalData.openid = res.data
wx.setStorageSync(‘u_name‘, res.data)
wx.getStorageSync(‘u_thumb‘, res.data)
} else {
console.log(res.errMsg)
}
},
})
}
}
})
} else {
console.log(res.errMsg)
 
}
}
})
}
 
},
fail: function (err) {
console.info(err.errMsg);
wx: showModal({
title: ‘警告‘,
cancelText: ‘不授权‘,
confirmText: ‘授权‘,
confirmColor: ‘#37c31a‘,
content: ‘若不授权微信登录,则无法使用XXXXXX;点击重新获取授权,则可重新使用;‘ +
‘若点击不授权,将无法使用便捷服务。‘,
success: function (res) {
if (res.confirm) {
console.log(‘用户点击确认‘);
wx.openSetting({
success: res => {
if (res.authSetting[‘scope.userInfo‘]) {
wx.getUserInfo({
success: res => {
console.log(‘用户同意授权‘ + res.userInfo.nickName)
app.util.request({
‘url‘: ‘entry/wxapp/TyMember‘,
data: {
u_name: u_name,
u_thumb: u_thumb
},
method: ‘POST‘,
header: {
‘content-type‘: ‘application/json‘
},
success: function (res) {
console.log(res);
if (res.statusCode == 200) {
// console.log("获取到的openid为:" + res.data)
// that.globalData.openid = res.data
wx.setStorageSync(‘openid‘, res.data)
} else {
console.log(res.errMsg)
}
},
})
}
})
} else {
console.info(‘再次不允许‘);
}
}
})
} else if (res.cancel) {
console.log(‘弹出框用户点击取消‘)
}
}
})
}
})
 
},

private function httpGet($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}

 

10   查询男女  数据库是1  0,页面显示男女

$sex = $data["h_sex"];
if($sex==1){
$data[‘h_sex‘] = "女";

}
else{
$data[‘h_sex‘] = "男";
}

 

11.   

  

小程序显示数据

上一篇:小程序自定义组件


下一篇:微信小程序(五)