index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. let Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. const qiniuUploader = require("../../../../../../utils/qiniuUploader");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. imageList: [],
  10. licenseList: [],
  11. merchant: null,
  12. store: null,
  13. stores: null,
  14. perCapita: null,
  15. cover: [],
  16. image: [],
  17. storeName: null,
  18. perCapita: null,
  19. desc: null,
  20. name: null,
  21. workingTime: null,
  22. uploadURL: null,
  23. domain: null,
  24. uptokenURL: null,
  25. html: null,
  26. content: null,
  27. id: null,
  28. },
  29. getHtml(e) { //从组件获取值
  30. let html = e.detail.content.html
  31. console.log(html);
  32. // this.setData({ html: html })
  33. // let field = event.currentTarget.dataset.field;
  34. // let html = event.detail.content.html;
  35. this.setData({ html: html })
  36. },
  37. insertImage() { //图片上传插入示例
  38. let that = this
  39. wx.chooseImage({
  40. count: 1,
  41. success(res) {
  42. // 本地测试图片插入
  43. // this.selectComponent('#hf_editor').insertSrc(res.tempFilePaths[0]);
  44. // console.log(res.tempFilePaths[0]);
  45. let tempFilePaths = res.tempFilePaths[0];
  46. console.log(tempFilePaths);
  47. qiniuUploader.upload(
  48. tempFilePaths,
  49. (res) => {
  50. let img = res.imageURL;
  51. that.selectComponent('#hf_editor').insertSrc(img); //调用组件insertSrc方法
  52. },
  53. (error) => {
  54. console.log("error: " + error);
  55. }, {
  56. region: "SCN",
  57. uploadURL: that.data.uploadURL,
  58. domain: that.data.domain,
  59. uptoken: that.data.uptokenURL,
  60. }
  61. );
  62. }
  63. })
  64. },
  65. changeFile(e) {
  66. if (e.detail && e.detail.length > 0) {
  67. this.setData({
  68. cover: [e.detail[0].url]
  69. })
  70. } else {
  71. this.setData({
  72. cover: []
  73. })
  74. }
  75. },
  76. changeFiles(e) {
  77. if (e.detail && e.detail.length > 0) {
  78. this.setData({
  79. image: e.detail
  80. })
  81. } else {
  82. this.setData({
  83. image: []
  84. })
  85. }
  86. },
  87. blur(e) {
  88. let name = e.currentTarget.dataset.name
  89. this.setData({
  90. [name]: e.detail.value
  91. })
  92. },
  93. mobile() {
  94. let id = this.data.store.objectId
  95. console.log(id);
  96. wx.navigateTo({
  97. url: '/nova-tourism/pages/my/merchant/merchant-home/account/mobile/index?id=' + id
  98. });
  99. },
  100. password() {
  101. let id = this.data.store.objectId
  102. console.log(id);
  103. wx.navigateTo({
  104. url: '/nova-tourism/pages/my/merchant/merchant-home/account/password/index?id=' + id
  105. });
  106. },
  107. async determine() {
  108. let image = []
  109. for (let index = 0; index < this.data.image.length; index++) {
  110. let item = this.data.image[index];
  111. image.push(item.url)
  112. }
  113. console.log(this.data.perCapita, this.data.name, image, this.data.storeName, this.data.perCapita, this.data.desc, this.data.workingTime, this.data.html);
  114. let query = new Parse.Query("ShopStore")
  115. let ShopStore = await query.get(this.data.id)
  116. ShopStore.set("perCapita", this.data.perCapita)
  117. ShopStore.set("name", this.data.name)
  118. ShopStore.set("image", image)
  119. ShopStore.set("storeName", this.data.storeName)
  120. ShopStore.set("perCapita", this.data.perCapita)
  121. ShopStore.set("desc", this.data.desc)
  122. ShopStore.set("workingTime", this.data.workingTime)
  123. ShopStore.set("content", this.data.html)
  124. ShopStore.save().then(res => {
  125. console.log(res)
  126. wx.showToast({
  127. title: '修改成功',
  128. icon: 'none'
  129. })
  130. wx.navigateBack({
  131. delta: 1
  132. });
  133. })
  134. },
  135. /**
  136. * 生命周期函数--监听页面加载
  137. */
  138. onLoad: async function(options) {
  139. let merchant = wx.getStorageSync('merchant'); //用户
  140. let ShopStore = new Parse.Query('ShopStore')
  141. ShopStore.notEqualTo('isDeleted', "true")
  142. ShopStore.equalTo('company',company)
  143. ShopStore.include('user')
  144. ShopStore.equalTo('user',merchant.objectId)
  145. let store = await ShopStore.first()
  146. store = store.toJSON()
  147. console.log(store);
  148. let imageList = []
  149. let licenseList = []
  150. // store.cover[0].forEach(i => {
  151. imageList.push({
  152. url: store.cover
  153. })
  154. // })
  155. console.log(imageList);
  156. store.image.forEach(i => {
  157. licenseList.push({
  158. url: i
  159. })
  160. })
  161. this.setData({
  162. imageList: imageList,
  163. store: store,
  164. cover: store.cover,
  165. image: store.image,
  166. perCapita: store.perCapita,
  167. storeName: store.storeName,
  168. perCapita: store.perCapita,
  169. desc: store.desc,
  170. name: store.name,
  171. workingTime: store.workingTime,
  172. html: store.content,
  173. id: store.objectId,
  174. licenseList: licenseList,
  175. })
  176. console.log(this.data.html);
  177. this.selectComponent('#hf_editor').setHtml(this.data.html);
  178. this.getQiniuOption()
  179. },
  180. async getQiniuOption() {
  181. let uploadData = await this.getUptoken()
  182. if (uploadData) {
  183. this.setData({
  184. uploadURL: uploadData.zoneUrl,
  185. domain: uploadData.domain,
  186. uptokenURL: uploadData.uptoken,
  187. })
  188. }
  189. console.log(this.data.uploadURL, this.data.domain, this.data.uptokenURL);
  190. },
  191. getUptoken() {
  192. return Parse.Cloud.run('qiniu_uptoken', { company: company })
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onReady: function() {
  198. },
  199. /**
  200. * 生命周期函数--监听页面显示
  201. */
  202. onShow: function() {
  203. },
  204. /**
  205. * 生命周期函数--监听页面隐藏
  206. */
  207. onHide: function() {
  208. },
  209. /**
  210. * 生命周期函数--监听页面卸载
  211. */
  212. onUnload: function() {
  213. },
  214. /**
  215. * 页面相关事件处理函数--监听用户下拉动作
  216. */
  217. onPullDownRefresh: function() {
  218. },
  219. /**
  220. * 页面上拉触底事件的处理函数
  221. */
  222. onReachBottom: function() {
  223. },
  224. /**
  225. * 用户点击右上角分享
  226. */
  227. onShareAppMessage: function() {
  228. }
  229. })