index.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. // cover:this.data.imageList[0].url
  74. })
  75. }
  76. },
  77. changeFiles(e) {
  78. if (e.detail && e.detail.length > 0) {
  79. this.setData({
  80. image: e.detail
  81. })
  82. console.log('图片',this.data.image);
  83. } else {
  84. this.setData({
  85. image: []
  86. })
  87. }
  88. },
  89. blur(e) {
  90. let name = e.currentTarget.dataset.name
  91. this.setData({
  92. [name]: e.detail.value
  93. })
  94. },
  95. mobile() {
  96. let id = this.data.store.objectId
  97. console.log(id);
  98. wx.navigateTo({
  99. url: '../account/mobile/index?id=' + id
  100. });
  101. },
  102. password() {
  103. let id = this.data.store.objectId
  104. console.log(id);
  105. wx.navigateTo({
  106. url: '../account/password/index?id=' + id
  107. });
  108. },
  109. async determine() {
  110. let image = []
  111. if(this.data.image[0].url){
  112. for (let index = 0; index < this.data.image.length; index++) {
  113. let item = this.data.image[index];
  114. image.push(item.url)
  115. }
  116. // 设置图片格式判断
  117. console.log('店铺图片',image);
  118. }else{
  119. image=this.data.image
  120. }
  121. console.log(this.data.name, image, this.data.storeName, this.data.perCapita, this.data.desc, this.data.workingTime, this.data.html);
  122. let query = new Parse.Query("ShopStore")
  123. let ShopStore = await query.get(this.data.id)
  124. // ShopStore.set("perCapita", this.data.perCapita)
  125. ShopStore.set("name", this.data.name)
  126. ShopStore.set("cover", this.data.cover)
  127. ShopStore.set("image", image)
  128. ShopStore.set("storeName", this.data.storeName)
  129. if(Number(this.data.perCapita)){
  130. ShopStore.set("perCapita", Number(this.data.perCapita))
  131. }else{
  132. wx.showToast({
  133. title: '请输入正确人均消费',
  134. icon: 'none'
  135. })
  136. return
  137. }
  138. ShopStore.set("desc", this.data.desc)
  139. ShopStore.set("workingTime", this.data.workingTime)
  140. ShopStore.set("content", this.data.html)
  141. ShopStore.save().then(res => {
  142. console.log(res)
  143. wx.showToast({
  144. title: '修改成功',
  145. icon: 'none'
  146. })
  147. wx.navigateBack({
  148. delta: 1
  149. });
  150. })
  151. },
  152. /**
  153. * 生命周期函数--监听页面加载
  154. */
  155. onLoad: async function(options) {
  156. let merchant = wx.getStorageSync('merchant'); //用户
  157. let ShopStore = new Parse.Query('ShopStore')
  158. ShopStore.notEqualTo('isDeleted', "true")
  159. ShopStore.equalTo('company',company)
  160. ShopStore.include('user')
  161. ShopStore.equalTo('user',merchant.objectId)
  162. let store = await ShopStore.first()
  163. store = store.toJSON()
  164. console.log(store);
  165. let imageList = []
  166. let licenseList = []
  167. // store.cover[0].forEach(i => {
  168. imageList.push({
  169. url: store.cover
  170. })
  171. // })
  172. console.log(imageList);
  173. store.image.forEach(i => {
  174. licenseList.push({
  175. url: i
  176. })
  177. })
  178. this.setData({
  179. imageList: imageList,
  180. store: store,
  181. cover: store.cover,
  182. image: store.image,
  183. // perCapita: store.perCapita,
  184. storeName: store.storeName,
  185. perCapita: store.perCapita,
  186. desc: store.desc,
  187. name: store.name,
  188. workingTime: store.workingTime,
  189. html: store.content,
  190. id: store.objectId,
  191. licenseList: licenseList,
  192. })
  193. console.log('首页',this.data.perCapita);
  194. this.selectComponent('#hf_editor').setHtml(this.data.html);
  195. this.getQiniuOption()
  196. },
  197. async getQiniuOption() {
  198. let uploadData = await this.getUptoken()
  199. if (uploadData) {
  200. this.setData({
  201. uploadURL: uploadData.zoneUrl,
  202. domain: uploadData.domain,
  203. uptokenURL: uploadData.uptoken,
  204. })
  205. }
  206. console.log(this.data.uploadURL, this.data.domain, this.data.uptokenURL);
  207. },
  208. getUptoken() {
  209. return Parse.Cloud.run('qiniu_uptoken', { company: company })
  210. },
  211. /**
  212. * 生命周期函数--监听页面初次渲染完成
  213. */
  214. onReady: function() {
  215. },
  216. /**
  217. * 生命周期函数--监听页面显示
  218. */
  219. onShow: function() {
  220. },
  221. /**
  222. * 生命周期函数--监听页面隐藏
  223. */
  224. onHide: function() {
  225. },
  226. /**
  227. * 生命周期函数--监听页面卸载
  228. */
  229. onUnload: function() {
  230. },
  231. /**
  232. * 页面相关事件处理函数--监听用户下拉动作
  233. */
  234. onPullDownRefresh: function() {
  235. },
  236. /**
  237. * 页面上拉触底事件的处理函数
  238. */
  239. onReachBottom: function() {
  240. },
  241. /**
  242. * 用户点击右上角分享
  243. */
  244. onShareAppMessage: function() {
  245. }
  246. })