style.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // pages/style/style.js
  2. const $api = require('../../utils/api.js').API;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. arr1: [],
  9. arr2: [],
  10. arr3: [],
  11. arr4: [],
  12. form:{
  13. join_time: '',
  14. zq: [],
  15. cw: [],
  16. df: [],
  17. username: '',
  18. account_img: ''
  19. }
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. $api.getEnumList().then(res => {
  26. this.setData({
  27. arr1: res.data.data.zq,
  28. arr2: res.data.data.cw,
  29. arr3: res.data.data.df,
  30. arr4: res.data.data.pz
  31. })
  32. })
  33. $api.getMyStyle().then(res=>{
  34. var form = res.data.data;
  35. form.zq = form.zq?form.zq.split(','):[]
  36. form.cw = form.cw?form.cw.split(','):[]
  37. form.df = form.df?form.df.split(','):[]
  38. form.pz = form.pz?form.pz.split(','):[]
  39. this.setData({
  40. form: form
  41. })
  42. })
  43. },
  44. change(e){
  45. let value = e.target.dataset.id, item = e.target.dataset.item;
  46. let form=this.data.form;
  47. // form[item] = value;
  48. // console.log(form[item].indexOf(value))
  49. if (form[item].indexOf(value)<0){
  50. form[item].push(value)
  51. }else{
  52. form[item].splice(form[item].indexOf(value),1)
  53. }
  54. this.setData({
  55. form: form
  56. })
  57. },
  58. bindDateChange(e) {
  59. let form = this.data.form;
  60. form.join_time = e.detail.value;
  61. this.setData({
  62. form: form
  63. })
  64. },
  65. bindinput(e){
  66. let form = this.data.form;
  67. form.username = e.detail.value;
  68. this.setData({
  69. form: form
  70. })
  71. },
  72. uploadImg(){
  73. var form = this.data.form;
  74. wx.chooseImage({
  75. success: res => {
  76. wx.showLoading({
  77. title: '正在上传',
  78. })
  79. const tempFilePaths = res.tempFiles
  80. for (let i = 0; i < tempFilePaths.length; i++) {
  81. $api.uploadAvatar(tempFilePaths[i].path,'file').then(res=>{
  82. wx.hideLoading()
  83. if(res.code == 0){
  84. form.avatar=res.data.url;
  85. this.setData({
  86. form: form
  87. })
  88. }else{
  89. wx.showToast({
  90. title: '上传失败',
  91. })
  92. }
  93. })
  94. .catch(err=>{
  95. wx.hideLoading()
  96. })
  97. }
  98. }
  99. })
  100. },
  101. preview(){
  102. wx.previewImage({
  103. urls: [this.data.form.avatar],
  104. current: this.data.form.avatar
  105. })
  106. },
  107. del(){
  108. let form = this.data.form;
  109. form.avatar ='';
  110. this.setData({
  111. form: form
  112. })
  113. },
  114. post(){
  115. var form = { ...this.data.form};
  116. form.zq = form.zq.join(',')
  117. form.cw = form.cw.join(',')
  118. form.df = form.df.join(',')
  119. form.pz = form.pz.join(',')
  120. if (!form.zq) {
  121. wx.showToast({
  122. title: '请选择周期',
  123. icon:'none'
  124. })
  125. return
  126. }
  127. if (!form.cw) {
  128. wx.showToast({
  129. title: '请选择仓位',
  130. icon: 'none'
  131. })
  132. return
  133. }
  134. if (!form.df) {
  135. wx.showToast({
  136. title: '请选择打法',
  137. icon: 'none'
  138. })
  139. return
  140. }
  141. if (!form.pz) {
  142. wx.showToast({
  143. title: '请选择品种',
  144. icon: 'none'
  145. })
  146. return
  147. }
  148. if (!form.join_time){
  149. wx.showToast({
  150. title: '请选择入市时间',
  151. icon: 'none'
  152. })
  153. return
  154. }
  155. // if (!form.init_fund) {
  156. // wx.showToast({
  157. // title: '请输入参赛金额',
  158. // icon: 'none'
  159. // })
  160. // return
  161. // }
  162. // if (!form.account_img) {
  163. // wx.showToast({
  164. // title: '请上传账号截图',
  165. // icon: 'none'
  166. // })
  167. // return
  168. // }
  169. wx.showLoading({
  170. title: '正在提交',
  171. })
  172. $api.updateStyle(form).then(res=>{
  173. wx.hideLoading()
  174. wx.showToast({
  175. title: '保存成功',
  176. icon:'success',
  177. success:function(){
  178. setTimeout(() => {
  179. wx.navigateBack({
  180. delta: 0,
  181. })
  182. }, 1500);
  183. }
  184. })
  185. })
  186. .catch(err=>{
  187. wx.hideLoading()
  188. })
  189. },
  190. /**
  191. * 生命周期函数--监听页面初次渲染完成
  192. */
  193. onReady: function () {
  194. },
  195. /**
  196. * 生命周期函数--监听页面显示
  197. */
  198. onShow: function () {
  199. },
  200. /**
  201. * 生命周期函数--监听页面隐藏
  202. */
  203. onHide: function () {
  204. },
  205. /**
  206. * 生命周期函数--监听页面卸载
  207. */
  208. onUnload: function () {
  209. },
  210. /**
  211. * 页面相关事件处理函数--监听用户下拉动作
  212. */
  213. onPullDownRefresh: function () {
  214. },
  215. /**
  216. * 页面上拉触底事件的处理函数
  217. */
  218. onReachBottom: function () {
  219. },
  220. /**
  221. * 用户点击右上角分享
  222. */
  223. onShareAppMessage: function () {
  224. }
  225. })