109 lines
No EOL
2.6 KiB
JavaScript
109 lines
No EOL
2.6 KiB
JavaScript
import C from '../../utils/constant';
|
|
import * as F from '../../utils/func';
|
|
import R from '../../utils/request';
|
|
import ActionSheet, { ActionSheetTheme } from 'tdesign-miniprogram/action-sheet/index';
|
|
|
|
Page({
|
|
data: {
|
|
price: '',
|
|
expireDate: F.parseDate(new Date()),
|
|
dateVisible: false,
|
|
start: F.parseDate(new Date()),
|
|
end: F.parseDate(new Date(new Date() * 1 + 24 * 3600 * 366 * 1000 + 1)),
|
|
filter(type, options) {
|
|
if (type === 'year') {
|
|
return options.sort((a, b) => b.value - a.value);
|
|
}
|
|
return options;
|
|
},
|
|
popupProps: {
|
|
usingCustomNavbar: true,
|
|
},
|
|
buy_type: '',
|
|
buy_types: [],
|
|
},
|
|
onLoad() {
|
|
R.get('/index.php/api/v1/config_one', { k: 'buy_types' }).then(({ model }) => {
|
|
this.setData({
|
|
buy_types: model || [],
|
|
buy_type: model[0],
|
|
});
|
|
});
|
|
},
|
|
handleSelected(e) {
|
|
console.log(e.detail);
|
|
this.setData({
|
|
buy_type: e.detail.selected.label,
|
|
});
|
|
},
|
|
handleAction() {
|
|
ActionSheet.show({
|
|
theme: ActionSheetTheme.List,
|
|
selector: '#t-action-sheet',
|
|
context: this,
|
|
items: this.data.buy_types.map((item) => ({
|
|
label: item,
|
|
})),
|
|
});
|
|
},
|
|
onConfirm(e) {
|
|
const { value } = e.detail;
|
|
this.setData({
|
|
expireDate: value,
|
|
dateVisible: false,
|
|
});
|
|
},
|
|
showPicker() {
|
|
this.setData({ dateVisible: true });
|
|
},
|
|
onClose() {
|
|
this.setData({ dateVisible: false });
|
|
},
|
|
validate() {
|
|
const { price, expireDate } = this.data;
|
|
if (!price) {
|
|
wx.showToast({ title: '请输入分销金额', icon: 'none' });
|
|
return false;
|
|
}
|
|
if (!/^\d+(\.\d+)?$/.test(price)) {
|
|
wx.showToast({ title: '请输入正确的金额', icon: 'none' });
|
|
return false;
|
|
}
|
|
|
|
if (!expireDate) {
|
|
wx.showToast({ title: '请选择付款有效期', icon: 'none' });
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
share() {
|
|
if (!this.validate()) return;
|
|
// TODO: 调用分享接口
|
|
// console.log('share1', this.data);
|
|
// wx.showShareMenu({
|
|
// withShareTicket: true,
|
|
// menus: ['shareAppMessage']
|
|
// });
|
|
},
|
|
onShareAppMessage(e) {
|
|
if (!this.validate()) {
|
|
return {
|
|
title: '',
|
|
path: '',
|
|
imageUrl: '',
|
|
promise: Promise.reject(),
|
|
}
|
|
}
|
|
const { price, expireDate, buy_type } = this.data;
|
|
return R.get('/index.php/api/v1/create_share', {
|
|
price, expireDate, buy_type,
|
|
}).then(({ model }) => {
|
|
return {
|
|
title: model.title,
|
|
path: model.path || '/pages/sharebuy/sharebuy?id=' + model.id,
|
|
imageUrl: model.img,
|
|
promise: Promise.resolve(),
|
|
};
|
|
});
|
|
},
|
|
}); |