index.js 11 KB

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