index.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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,this.data.locations);
  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. locations:store.location
  206. })
  207. console.log('首页',this.data.locations);
  208. this.Getlocation()
  209. this.selectComponent('#hf_editor').setHtml(this.data.html);
  210. this.getQiniuOption()
  211. },
  212. async getQiniuOption() {
  213. let uploadData = await this.getUptoken()
  214. if (uploadData) {
  215. this.setData({
  216. uploadURL: uploadData.zoneUrl,
  217. domain: uploadData.domain,
  218. uptokenURL: uploadData.uptoken,
  219. })
  220. }
  221. console.log(this.data.uploadURL, this.data.domain, this.data.uptokenURL);
  222. },
  223. getUptoken() {
  224. return Parse.Cloud.run('qiniu_uptoken', { company: company })
  225. },
  226. /**
  227. * 生命周期函数--监听页面初次渲染完成
  228. */
  229. onReady: function() {
  230. },
  231. /**
  232. * 生命周期函数--监听页面显示
  233. */
  234. onShow: function() {
  235. },
  236. /**
  237. * 生命周期函数--监听页面隐藏
  238. */
  239. onHide: function() {
  240. },
  241. /**
  242. * 生命周期函数--监听页面卸载
  243. */
  244. onUnload: function() {
  245. },
  246. /**
  247. * 页面相关事件处理函数--监听用户下拉动作
  248. */
  249. onPullDownRefresh: function() {
  250. },
  251. /**
  252. * 页面上拉触底事件的处理函数
  253. */
  254. onReachBottom: function() {
  255. },
  256. /**
  257. * 用户点击右上角分享
  258. */
  259. onShareAppMessage: function() {
  260. },
  261. //选择地理位置
  262. chooseGeoPoint() {
  263. wx.chooseLocation({
  264. latitude: 0,
  265. longitude: 0,
  266. success: (res) => {
  267. let {
  268. latitude,
  269. longitude,
  270. address,
  271. name
  272. } = res;
  273. let locations = new Parse.GeoPoint(latitude, longitude)
  274. this.setData({
  275. locations,
  276. address:address
  277. })
  278. console.log(locations);
  279. console.log(address + name);
  280. // this.data.formData[field] = locations
  281. // this.data.formData['address'] = address + name
  282. // this.data.formData['address'] = address
  283. // this.setData({
  284. // formData: this.data.formData,
  285. // })
  286. }
  287. })
  288. },
  289. //解析地理位置
  290. Getlocation() {
  291. // 假设 this.storeList[0].location 是一个 Parse.GeoPoint 对象
  292. const storeLocation = this.data.locations;
  293. // 从 GeoPoint 对象中获取经纬度
  294. const latitude = storeLocation.latitude; // 纬度
  295. const longitude = storeLocation.longitude; // 经度
  296. console.log('获取到的经纬度:', latitude, longitude); // 添加日志
  297. // 调用 API 解析地址
  298. wx.request({
  299. url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=sHZTomd7grslfP7sPKB8tRgT49FK9TEu&output=json&coordtype=gcj02&location=' + latitude + ',' + longitude,
  300. data: {},
  301. header: {
  302. 'Content-Type': 'application/json'
  303. },
  304. success: (ops) => { // 使用箭头函数
  305. console.log(ops);
  306. const address = ops.data.result.formatted_address;
  307. this.setData({
  308. address: address,
  309. });
  310. console.log(this.data.address);
  311. },
  312. fail: function (resq) {
  313. wx.showModal({
  314. title: '信息提示',
  315. content: '请求失败',
  316. showCancel: false,
  317. confirmColor: '#f37938'
  318. });
  319. },
  320. complete: function () {}
  321. });
  322. },
  323. })