index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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&&this.data.address) {
  133. ShopStore.set("location", this.data.locations)
  134. ShopStore.set("storeAddress", this.data.address)
  135. } else {
  136. wx.showToast({
  137. title: '请选择民宿地址',
  138. icon: 'none'
  139. })
  140. return
  141. }
  142. ShopStore.set("storeName", this.data.storeName)
  143. if (Number(this.data.perCapita)) {
  144. ShopStore.set("perCapita", Number(this.data.perCapita))
  145. } else {
  146. wx.showToast({
  147. title: '请输入正确人均消费',
  148. icon: 'none'
  149. })
  150. return
  151. }
  152. ShopStore.set("desc", this.data.desc)
  153. ShopStore.set("workingTime", this.data.workingTime)
  154. // ShopStore.set("content", this.data.html)
  155. ShopStore.save().then(res => {
  156. console.log(res)
  157. wx.showToast({
  158. title: '修改成功',
  159. icon: 'none'
  160. })
  161. setTimeout(() => {
  162. wx.navigateBack({
  163. delta: 1
  164. });
  165. }, 1000)
  166. })
  167. },
  168. /**
  169. * 生命周期函数--监听页面加载
  170. */
  171. onLoad: async function (options) {
  172. let merchant = wx.getStorageSync('merchant'); //用户
  173. let ShopStore = new Parse.Query('ShopStore')
  174. ShopStore.notEqualTo('isDeleted', "true")
  175. ShopStore.equalTo('company', company)
  176. ShopStore.include('user')
  177. ShopStore.equalTo('user', merchant.objectId)
  178. let store = await ShopStore.first()
  179. store = store.toJSON()
  180. console.log(store);
  181. let imageList = []
  182. let licenseList = []
  183. // store.cover[0].forEach(i => {
  184. imageList.push({
  185. url: store.cover
  186. })
  187. // })
  188. console.log(imageList);
  189. store.image.forEach(i => {
  190. licenseList.push({
  191. url: i
  192. })
  193. })
  194. this.setData({
  195. imageList: imageList,
  196. store: store,
  197. cover: store.cover,
  198. image: store.image,
  199. // perCapita: store.perCapita,
  200. storeName: store.storeName,
  201. perCapita: store.perCapita,
  202. desc: store.desc,
  203. name: store.name,
  204. workingTime: store.workingTime,
  205. html: store.content,
  206. id: store.objectId,
  207. licenseList: licenseList,
  208. locations: store.location,
  209. address:store.storeAddress
  210. })
  211. console.log('首页', this.data.locations);
  212. // this.Getlocation()
  213. // this.selectComponent('#hf_editor').setHtml(this.data.html);
  214. this.getQiniuOption()
  215. },
  216. async getQiniuOption() {
  217. let uploadData = await this.getUptoken()
  218. if (uploadData) {
  219. this.setData({
  220. uploadURL: uploadData.zoneUrl,
  221. domain: uploadData.domain,
  222. uptokenURL: uploadData.uptoken,
  223. })
  224. }
  225. console.log(this.data.uploadURL, this.data.domain, this.data.uptokenURL);
  226. },
  227. getUptoken() {
  228. return Parse.Cloud.run('qiniu_uptoken', {
  229. company: company
  230. })
  231. },
  232. /**
  233. * 生命周期函数--监听页面初次渲染完成
  234. */
  235. onReady: function () {
  236. },
  237. /**
  238. * 生命周期函数--监听页面显示
  239. */
  240. onShow: function () {
  241. },
  242. /**
  243. * 生命周期函数--监听页面隐藏
  244. */
  245. onHide: function () {
  246. },
  247. /**
  248. * 生命周期函数--监听页面卸载
  249. */
  250. onUnload: function () {
  251. },
  252. /**
  253. * 页面相关事件处理函数--监听用户下拉动作
  254. */
  255. onPullDownRefresh: function () {
  256. },
  257. /**
  258. * 页面上拉触底事件的处理函数
  259. */
  260. onReachBottom: function () {
  261. },
  262. /**
  263. * 用户点击右上角分享
  264. */
  265. onShareAppMessage: function () {
  266. },
  267. //选择地理位置
  268. chooseGeoPoint() {
  269. wx.chooseLocation({
  270. // latitude: 28.8025354729244,
  271. // longitude: 115.921421511343,
  272. success: (res) => {
  273. let {
  274. latitude,
  275. longitude,
  276. address,
  277. name
  278. } = res;
  279. let locations = new Parse.GeoPoint(latitude, longitude);
  280. this.setData({
  281. locations,
  282. address: address
  283. });
  284. console.log(locations);
  285. console.log(address + name);
  286. },
  287. fail: (error) => {
  288. // 处理选择位置失败的情况
  289. console.error('选择位置失败:', error);
  290. wx.showToast({
  291. title: '选择位置失败,请重试',
  292. icon: 'none'
  293. });
  294. }
  295. });
  296. },
  297. //解析地理位置
  298. Getlocation() {
  299. // 假设 this.storeList[0].location 是一个 Parse.GeoPoint 对象
  300. // if (this.data.locations) {
  301. // const storeLocation = this.data.locations;
  302. // // 从 GeoPoint 对象中获取经纬度
  303. // const latitude = storeLocation.latitude; // 纬度
  304. // const longitude = storeLocation.longitude; // 经度
  305. // console.log('获取到的经纬度:', latitude, longitude); // 添加日志
  306. // // 调用 API 解析地址
  307. // wx.request({
  308. // url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=sHZTomd7grslfP7sPKB8tRgT49FK9TEu&output=json&coordtype=gcj02&location=' + latitude + ',' + longitude,
  309. // data: {},
  310. // header: {
  311. // 'Content-Type': 'application/json'
  312. // },
  313. // success: (ops) => { // 使用箭头函数
  314. // console.log(ops);
  315. // const address = ops.data.result.formatted_address;
  316. // this.setData({
  317. // address: address,
  318. // });
  319. // console.log(this.data.address);
  320. // },
  321. // fail: function (resq) {
  322. // wx.showModal({
  323. // title: '信息提示',
  324. // content: '请求失败',
  325. // showCancel: false,
  326. // confirmColor: '#f37938'
  327. // });
  328. // },
  329. // complete: function () {}
  330. // });
  331. // }
  332. },
  333. })