index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. const Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. const dateF = require('../../../../utils/date')
  4. const rechText = require('../../../../utils/rech-text')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. twoModal: false,
  11. tives: 1,
  12. region: ['江西省', '南昌市', '东湖区'], // 初始值
  13. showheader: true,
  14. showfoot: false,
  15. type: '',
  16. title: "",
  17. show: false,
  18. nextShow: false,
  19. name: '',
  20. mobile: '',
  21. company: '',
  22. product: ''
  23. },
  24. bindRegionChange: function(e) { // picker值发生改变都会触发该方法
  25. console.log('picker发送选择改变,携带值为', e.detail.value)
  26. this.setData({
  27. region: e.detail.value
  28. })
  29. },
  30. hideRule: function() {
  31. this.setData({
  32. twoModal: false
  33. })
  34. },
  35. nextstep(e) {
  36. let {
  37. tives
  38. } = e.currentTarget.dataset
  39. let name = this.data.name
  40. let mobile = this.data.mobile
  41. if (!name || !mobile) {
  42. wx.showToast({
  43. title: '请将信息填写完整',
  44. icon: 'none'
  45. })
  46. return
  47. }
  48. let myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  49. if (!myreg.test(mobile)) {
  50. wx.showToast({
  51. title: '请填写正确手机号',
  52. icon: 'none'
  53. })
  54. return
  55. }
  56. this.setData({
  57. tives
  58. })
  59. },
  60. prostep() {
  61. let {
  62. tives
  63. } = e.currentTarget.dataset
  64. this.setData({
  65. tives
  66. })
  67. },
  68. shopsubmit: function() {
  69. this.setData({
  70. twoModal: true
  71. })
  72. },
  73. submit() {
  74. let company = this.data.company
  75. let product = this.data.product
  76. if (!company || product) {
  77. wx.showToast({
  78. title: '请将信息填写完整',
  79. icon: 'none'
  80. })
  81. return
  82. }
  83. wx.showToast({
  84. title: '提交成功',
  85. icon: 'success'
  86. })
  87. },
  88. shoppreventTouchMove: function() {
  89. this.setData({
  90. twoModal: false
  91. })
  92. },
  93. cancenlClicknext: function() {
  94. this.setData({
  95. twoModal: false
  96. })
  97. },
  98. confirmClick1: function() {
  99. console.log('确认收货了')
  100. this.setData({
  101. twoModal: false
  102. })
  103. },
  104. go1: function() {
  105. this.setData({
  106. twoModal: false
  107. })
  108. },
  109. showPopup() {
  110. this.setData({
  111. show: true
  112. });
  113. },
  114. nextPopup() {
  115. this.setData({
  116. nextShow: true
  117. });
  118. },
  119. onClose() {
  120. this.setData({
  121. show: false
  122. });
  123. },
  124. /**
  125. * 生命周期函数--监听页面加载
  126. */
  127. onLoad: async function(options) {
  128. let title = options.title
  129. let aid = options.aid
  130. let showheader = true
  131. console.log(options)
  132. let article = await this.getArticle(aid)
  133. // let user = article.getUser
  134. if (options.showheader) {
  135. showheader = true
  136. this.setData({
  137. showheader: true
  138. })
  139. }
  140. let showfoot = false
  141. let type = ''
  142. if (title == '链商城') {
  143. showfoot = true
  144. type = 'open-shop'
  145. }
  146. console.log(article)
  147. if (article && article.objectId) {
  148. this.setData({
  149. title: title,
  150. article: article,
  151. showfoot: showfoot,
  152. type: type
  153. })
  154. }
  155. },
  156. async getArticle(aid) {
  157. let Article = new Parse.Query('Article')
  158. Article.include('author')
  159. let article = await Article.get(aid)
  160. if (article && article.id) {
  161. console.log(article)
  162. let articleJSON = article.toJSON()
  163. articleJSON.date = articleJSON.publishDate ? dateF.formatTime("YYYY-mm-dd", articleJSON.publishDate.iso) : dateF.formatTime("YYYY-mm-dd", articleJSON.createdAt)
  164. if (articleJSON.content) {
  165. articleJSON.content = rechText.formatRichText(articleJSON.content)
  166. }
  167. return articleJSON
  168. }
  169. },
  170. blur(e) {
  171. let name = e.currentTarget.dataset.name
  172. this.setData({
  173. [name]: e.detail.value
  174. })
  175. },
  176. /**
  177. * 生命周期函数--监听页面初次渲染完成
  178. */
  179. onReady: function() {
  180. },
  181. /**
  182. * 生命周期函数--监听页面显示
  183. */
  184. onShow: function() {
  185. },
  186. /**
  187. * 生命周期函数--监听页面隐藏
  188. */
  189. onHide: function() {
  190. },
  191. /**
  192. * 生命周期函数--监听页面卸载
  193. */
  194. onUnload: function() {
  195. },
  196. /**
  197. * 页面相关事件处理函数--监听用户下拉动作
  198. */
  199. onPullDownRefresh: function() {
  200. },
  201. /**
  202. * 页面上拉触底事件的处理函数
  203. */
  204. onReachBottom: function() {
  205. },
  206. /**
  207. * 用户点击右上角分享
  208. */
  209. onShareAppMessage: function() {
  210. let user = Parse.User.current()
  211. let title = this.data.article.title
  212. let aid = this.data.article.objectId
  213. let image = this.data.article.image
  214. let query
  215. if (user) {
  216. query = `invite=${user.id}&aid=${aid}`
  217. } else {
  218. query = `aid=${aid}`
  219. }
  220. return {
  221. title: title,
  222. query: query,
  223. imageUrl: image,
  224. success: function(res) {
  225. // 转发成功
  226. },
  227. fail: function(res) {
  228. // 转发失败
  229. },
  230. };
  231. }
  232. })