style.js 4.5 KB

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