123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- // pages/style/style.js
- const $api = require('../../utils/api.js').API;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- arr1: [],
- arr2: [],
- arr3: [],
- arr4: [],
- form:{
- join_time: '',
- zq: [],
- cw: [],
- df: [],
- username: '',
- account_img: ''
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- $api.getEnumList().then(res => {
- this.setData({
- arr1: res.data.data.zq,
- arr2: res.data.data.cw,
- arr3: res.data.data.df,
- arr4: res.data.data.pz
- })
- })
- $api.getMyStyle().then(res=>{
- var form = res.data.data;
- form.zq = form.zq?form.zq.split(','):[]
- form.cw = form.cw?form.cw.split(','):[]
- form.df = form.df?form.df.split(','):[]
- form.pz = form.pz?form.pz.split(','):[]
- this.setData({
- form: form
- })
- })
- },
- change(e){
- let value = e.target.dataset.id, item = e.target.dataset.item;
- let form=this.data.form;
- // form[item] = value;
- // console.log(form[item].indexOf(value))
- if (form[item].indexOf(value)<0){
- form[item].push(value)
- }else{
- form[item].splice(form[item].indexOf(value),1)
- }
- this.setData({
- form: form
- })
- },
- bindDateChange(e) {
- let form = this.data.form;
- form.join_time = e.detail.value;
- this.setData({
- form: form
- })
- },
- bindinput(e){
- let form = this.data.form;
- form.username = e.detail.value;
- this.setData({
- form: form
- })
- },
- uploadImg(){
- var form = this.data.form;
- wx.chooseImage({
- success: res => {
- wx.showLoading({
- title: '正在上传',
- })
- const tempFilePaths = res.tempFiles
- for (let i = 0; i < tempFilePaths.length; i++) {
- $api.uploadAvatar(tempFilePaths[i].path,'file').then(res=>{
- wx.hideLoading()
- if(res.code == 0){
- form.avatar=res.data.url;
- this.setData({
- form: form
- })
- }else{
- wx.showToast({
- title: '上传失败',
- })
- }
- })
- .catch(err=>{
- wx.hideLoading()
- })
- }
- }
- })
- },
- preview(){
- wx.previewImage({
- urls: [this.data.form.avatar],
- current: this.data.form.avatar
- })
- },
- del(){
- let form = this.data.form;
- form.avatar ='';
- this.setData({
- form: form
- })
- },
- post(){
- var form = { ...this.data.form};
- form.zq = form.zq.join(',')
- form.cw = form.cw.join(',')
- form.df = form.df.join(',')
- form.pz = form.pz.join(',')
- if (!form.zq) {
- wx.showToast({
- title: '请选择周期',
- icon:'none'
- })
- return
- }
- if (!form.cw) {
- wx.showToast({
- title: '请选择仓位',
- icon: 'none'
- })
- return
- }
- if (!form.df) {
- wx.showToast({
- title: '请选择打法',
- icon: 'none'
- })
- return
- }
- if (!form.pz) {
- wx.showToast({
- title: '请选择品种',
- icon: 'none'
- })
- return
- }
- if (!form.join_time){
- wx.showToast({
- title: '请选择入市时间',
- icon: 'none'
- })
- return
- }
- // if (!form.init_fund) {
- // wx.showToast({
- // title: '请输入参赛金额',
- // icon: 'none'
- // })
- // return
- // }
- // if (!form.account_img) {
- // wx.showToast({
- // title: '请上传账号截图',
- // icon: 'none'
- // })
- // return
- // }
- wx.showLoading({
- title: '正在提交',
- })
- $api.updateStyle(form).then(res=>{
- wx.hideLoading()
- wx.showToast({
- title: '保存成功',
- icon:'success',
- success:function(){
- setTimeout(() => {
- wx.navigateBack({
- delta: 0,
- })
- }, 1500);
- }
-
- })
- })
- .catch(err=>{
- wx.hideLoading()
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|