1、拉起微信支付
let data = res.Data.m_values;
wx.requestPayment({
'timeStamp': data.timeStamp,
'nonceStr': data.nonceStr,
'package': data.package,
'signType': data.signType,
'paySign': data.paySign,
'success': function (res) {
if (res.errMsg == 'requestPayment:ok') {
wx.setNavigationBarTitle({
title: ''
})
that.setData({
showSuccess: true
})
}
},
'fail': function (err) {
wx.redirectTo({
url: '/pages/myOrderDetail/myOrderDetail?orderid=' + that.data.orderid,
})
}
})
2、picker日期选择
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
const formatTime = () => {
let date = new Date;
const year = date.getFullYear()
const month = date.getMonth() + 1
return [year, month].map(formatNumber).join('-')
}
data: {
date: formatTime()
}
//切换日期
bindDateChange(e) {
this.setData({
date: e.detail.value
});
},
3、 tab栏滑动切换
bindChange(e) {
this.setData({
currentTab: e.detail.current,
});
}
4、组件间通信
具体参数详情见文档组件间通信
在对组件进行封装时
在当前页面想要获取组件中的某一状态
需要使用到this.triggerEvent(' ',{},{})
3、手机拨打电话(涉及组件间通信)
//json
"usingComponents": {
"i-modal": "/components/iview/modal/index"
}
<view bindtap="callTel"></view>
//拨打电话模态框
<i-modal visible="{{ showTel }}" ok-text="拨打" bind:ok="makeCall" bind:cancel="downphone">
<view>{{callPhone}}</view>
</i-modal>
callTel() {
wx.showActionSheet({
//电话列表数据
itemList: this.data.phoneList,
success: res => {
let phoneNums = this.data.phoneNums;
let callPhone = phoneNums[res.tapIndex];
this.setData({
callPhone
})
this.downphone();
},
fail: err => {
// console.log(err.errMsg)
}
})
}
//modal子组件
Component({
externalClasses: ['i-class', 'i-class-mask'],
properties: {
visible: {
type: Boolean,
value: false
},
title: {
type: String,
value: ''
},
showOk: {
type: Boolean,
value: true
},
showCancel: {
type: Boolean,
value: true
},
okText: {
type: String,
value: '确定'
},
cancelText: {
type: String,
value: '取消'
},
// 按钮组,有此值时,不显示 ok 和 cancel 按钮
actions: {
type: Array,
value: []
},
// horizontal || vertical
actionMode: {
type: String,
value: 'horizontal'
}
},
methods: {
handleClickItem ({ currentTarget = {} }) {
const dataset = currentTarget.dataset || {};
const { index } = dataset;
this.triggerEvent('click', { index });
},
handleClickOk () {
this.triggerEvent('ok');
},
handleClickCancel () {
this.triggerEvent('cancel');
}
}
});