index.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. address:'',
  29. locations:null,
  30. },
  31. getHtml(e) { //从组件获取值
  32. let html = e.detail.content.html
  33. console.log(html);
  34. // this.setData({ html: html })
  35. // let field = event.currentTarget.dataset.field;
  36. // let html = event.detail.content.html;
  37. this.setData({ html: html })
  38. },
  39. insertImage() { //图片上传插入示例
  40. let that = this
  41. wx.chooseImage({
  42. count: 1,
  43. success(res) {
  44. // 本地测试图片插入
  45. // this.selectComponent('#hf_editor').insertSrc(res.tempFilePaths[0]);
  46. // console.log(res.tempFilePaths[0]);
  47. let tempFilePaths = res.tempFilePaths[0];
  48. console.log(tempFilePaths);
  49. qiniuUploader.upload(
  50. tempFilePaths,
  51. (res) => {
  52. let img = res.imageURL;
  53. that.selectComponent('#hf_editor').insertSrc(img); //调用组件insertSrc方法
  54. },
  55. (error) => {
  56. console.log("error: " + error);
  57. }, {
  58. region: "SCN",
  59. uploadURL: that.data.uploadURL,
  60. domain: that.data.domain,
  61. uptoken: that.data.uptokenURL,
  62. }
  63. );
  64. }
  65. })
  66. },
  67. changeFile(e) {
  68. if (e.detail && e.detail.length > 0) {
  69. this.setData({
  70. cover: [e.detail[0].url]
  71. })
  72. } else {
  73. this.setData({
  74. cover: []
  75. // cover:this.data.imageList[0].url
  76. })
  77. }
  78. },
  79. changeFiles(e) {
  80. if (e.detail && e.detail.length > 0) {
  81. this.setData({
  82. image: e.detail
  83. })
  84. console.log('图片',this.data.image);
  85. } else {
  86. this.setData({
  87. image: []
  88. })
  89. }
  90. },
  91. blur(e) {
  92. let name = e.currentTarget.dataset.name
  93. this.setData({
  94. [name]: e.detail.value
  95. })
  96. },
  97. mobile() {
  98. let id = this.data.store.objectId
  99. console.log(id);
  100. wx.navigateTo({
  101. url: '../account/mobile/index?id=' + id
  102. });
  103. },
  104. password() {
  105. let id = this.data.store.objectId
  106. console.log(id);
  107. wx.navigateTo({
  108. url: '../account/password/index?id=' + id
  109. });
  110. },
  111. async determine() {
  112. let image = []
  113. if(this.data.image[0].url){
  114. for (let index = 0; index < this.data.image.length; index++) {
  115. let item = this.data.image[index];
  116. image.push(item.url)
  117. }
  118. // 设置图片格式判断
  119. console.log('店铺图片',image);
  120. }else{
  121. image=this.data.image
  122. }
  123. console.log(this.data.name, image, this.data.storeName, this.data.perCapita, this.data.desc, this.data.workingTime, this.data.html);
  124. let query = new Parse.Query("ShopStore")
  125. let ShopStore = await query.get(this.data.id)
  126. // ShopStore.set("perCapita", this.data.perCapita)
  127. ShopStore.set("name", this.data.name)
  128. ShopStore.set("cover", this.data.cover)
  129. ShopStore.set("image", image)
  130. if(this.data.locations){
  131. ShopStore.set("location", this.data.locations)
  132. }else{
  133. wx.showToast({
  134. title: '请选择民宿地址',
  135. icon: 'none'
  136. })
  137. return
  138. }
  139. ShopStore.set("storeName", this.data.storeName)
  140. if(Number(this.data.perCapita)){
  141. ShopStore.set("perCapita", Number(this.data.perCapita))
  142. }else{
  143. wx.showToast({
  144. title: '请输入正确人均消费',
  145. icon: 'none'
  146. })
  147. return
  148. }
  149. ShopStore.set("desc", this.data.desc)
  150. ShopStore.set("workingTime", this.data.workingTime)
  151. ShopStore.set("content", this.data.html)
  152. ShopStore.save().then(res => {
  153. console.log(res)
  154. wx.showToast({
  155. title: '修改成功',
  156. icon: 'none'
  157. })
  158. setTimeout(()=>{
  159. wx.navigateBack({
  160. delta: 1
  161. });
  162. },1000)
  163. })
  164. },
  165. /**
  166. * 生命周期函数--监听页面加载
  167. */
  168. onLoad: async function(options) {
  169. let merchant = wx.getStorageSync('merchant'); //用户
  170. let ShopStore = new Parse.Query('ShopStore')
  171. ShopStore.notEqualTo('isDeleted', "true")
  172. ShopStore.equalTo('company',company)
  173. ShopStore.include('user')
  174. ShopStore.equalTo('user',merchant.objectId)
  175. let store = await ShopStore.first()
  176. store = store.toJSON()
  177. console.log(store);
  178. let imageList = []
  179. let licenseList = []
  180. // store.cover[0].forEach(i => {
  181. imageList.push({
  182. url: store.cover
  183. })
  184. // })
  185. console.log(imageList);
  186. store.image.forEach(i => {
  187. licenseList.push({
  188. url: i
  189. })
  190. })
  191. this.setData({
  192. imageList: imageList,
  193. store: store,
  194. cover: store.cover,
  195. image: store.image,
  196. // perCapita: store.perCapita,
  197. storeName: store.storeName,
  198. perCapita: store.perCapita,
  199. desc: store.desc,
  200. name: store.name,
  201. workingTime: store.workingTime,
  202. html: store.content,
  203. id: store.objectId,
  204. licenseList: licenseList,
  205. })
  206. console.log('首页',this.data.perCapita);
  207. this.selectComponent('#hf_editor').setHtml(this.data.html);
  208. this.getQiniuOption()
  209. },
  210. async getQiniuOption() {
  211. let uploadData = await this.getUptoken()
  212. if (uploadData) {
  213. this.setData({
  214. uploadURL: uploadData.zoneUrl,
  215. domain: uploadData.domain,
  216. uptokenURL: uploadData.uptoken,
  217. })
  218. }
  219. console.log(this.data.uploadURL, this.data.domain, this.data.uptokenURL);
  220. },
  221. getUptoken() {
  222. return Parse.Cloud.run('qiniu_uptoken', { company: company })
  223. },
  224. /**
  225. * 生命周期函数--监听页面初次渲染完成
  226. */
  227. onReady: function() {
  228. },
  229. /**
  230. * 生命周期函数--监听页面显示
  231. */
  232. onShow: function() {
  233. },
  234. /**
  235. * 生命周期函数--监听页面隐藏
  236. */
  237. onHide: function() {
  238. },
  239. /**
  240. * 生命周期函数--监听页面卸载
  241. */
  242. onUnload: function() {
  243. },
  244. /**
  245. * 页面相关事件处理函数--监听用户下拉动作
  246. */
  247. onPullDownRefresh: function() {
  248. },
  249. /**
  250. * 页面上拉触底事件的处理函数
  251. */
  252. onReachBottom: function() {
  253. },
  254. /**
  255. * 用户点击右上角分享
  256. */
  257. onShareAppMessage: function() {
  258. },
  259. chooseGeoPoint() {
  260. wx.chooseLocation({
  261. latitude: 0,
  262. longitude: 0,
  263. success: (res) => {
  264. let {
  265. latitude,
  266. longitude,
  267. address,
  268. name
  269. } = res;
  270. let locations = new Parse.GeoPoint(latitude, longitude)
  271. this.setData({
  272. locations,
  273. address:address
  274. })
  275. console.log(locations);
  276. console.log(address + name);
  277. // this.data.formData[field] = locations
  278. // this.data.formData['address'] = address + name
  279. // this.data.formData['address'] = address
  280. // this.setData({
  281. // formData: this.data.formData,
  282. // })
  283. }
  284. })
  285. },
  286. })