index.js 10 KB

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