openAShop.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. // pages/openAShop/openAShop.js
  2. var http = require('../../utils/http.js');
  3. var config = require("../../utils/config.js");
  4. const util = require('../../utils/util.js');
  5. var index = [18, 0, 0];
  6. var t = 0;
  7. var show = false;
  8. var moveY = 200;
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. logoImg: {},
  15. idcardFrontImg: {},
  16. idcardBackImg: {},
  17. bussLicenImg: {},
  18. value: [0, 0, 0],
  19. provArray: [],
  20. cityArray: [],
  21. areaArray: [],
  22. province: "",
  23. city: "",
  24. area: "",
  25. provinceId: 0,
  26. cityId: 0,
  27. areaId: 0,
  28. latitude: '', //经度
  29. longitude: '', //纬度
  30. mapAddress: '', //地图定位详细地址
  31. mapAddrName: '', //地图上的地址名称
  32. shopNameValue: '', //店铺名字
  33. shopDescribeValue: '', //店铺描述
  34. shopAddrValue: '', //详细地址
  35. shopOwnerValue: '', //店主姓名
  36. shopOwnerPhoneValue: '', //店主联系电话
  37. auditRemarks: ""
  38. },
  39. /**
  40. * 请求接口传数据
  41. */
  42. submitApply: function() {
  43. if (this.data.shopNameValue.trim().length < 2 || this.data.shopNameValue.trim().length > 10) {
  44. wx.showToast({
  45. title: '请输入正确的店铺名称',
  46. icon: "none"
  47. })
  48. } else if (this.data.shopDescribeValue.trim().length < 10 || this.data.shopDescribeValue.trim().length > 200) {
  49. wx.showToast({
  50. title: '请输入正确店铺描述',
  51. icon: "none"
  52. })
  53. } else if (!this.data.logoImg.path) {
  54. wx.showToast({
  55. title: '请上传店铺LOGO',
  56. icon: "none"
  57. })
  58. } else if (this.data.shopAddrValue.trim().length < 5) {
  59. wx.showToast({
  60. title: '请输入正确的详细地址:不得少于5字',
  61. icon: "none"
  62. })
  63. } else if (this.data.latitude == '') {
  64. wx.showToast({
  65. title: '请选择地理位置',
  66. icon: "none"
  67. })
  68. } else if (this.data.shopOwnerPhoneValue.trim().length < 7) {
  69. wx.showToast({
  70. title: '请输入正确的联系电话',
  71. icon: "none"
  72. })
  73. } else if (!this.data.bussLicenImg.path) {
  74. wx.showToast({
  75. title: '请上传营业执照',
  76. icon: "none"
  77. })
  78. } else if (!this.data.idcardFrontImg.path || !this.data.idcardBackImg.path) {
  79. wx.showToast({
  80. title: '请上传身份证正反两面',
  81. icon: "none"
  82. })
  83. } else {
  84. wx.showLoading();
  85. var params = {
  86. url: "/p/shop/apply",
  87. method: "POST",
  88. data: {
  89. "area": this.data.area,
  90. "areaId": this.data.areaId,
  91. "businessLicense": this.data.bussLicenImg.path,
  92. "city": this.data.city,
  93. "cityId": this.data.cityId,
  94. "identityCardFront": this.data.idcardFrontImg.path,
  95. "identityCardLater": this.data.idcardBackImg.path,
  96. "intro": this.data.shopDescribeValue.trim(),
  97. "province": this.data.province,
  98. "provinceId": this.data.provinceId,
  99. "shopAddress": this.data.shopAddrValue,
  100. "shopLogo": this.data.logoImg.path,
  101. "shopName": this.data.shopNameValue.trim(),
  102. "shopPhotos": "",
  103. "tel": this.data.shopOwnerPhoneValue.trim(),
  104. "shopLat": this.data.latitude,
  105. "shopLng": this.data.longitude,
  106. },
  107. callBack: function(res) {
  108. wx.hideLoading();
  109. wx.showModal({
  110. title: '提交成功,等待审核',
  111. content: '',
  112. showCancel: false,
  113. success: function() {
  114. wx.switchTab({
  115. url: '/pages/user/user',
  116. })
  117. }
  118. })
  119. }
  120. }
  121. http.request(params);
  122. }
  123. },
  124. /**
  125. * 生命周期函数--监听页面加载
  126. */
  127. onLoad: function(options) {
  128. if (options.shopAuditStatus == -1) {
  129. wx.showModal({
  130. title: '提示',
  131. content: '您的开店申请审核未通过,请您修改申请信息后再次提交开店申请',
  132. success: (res) => {
  133. if (res.confirm) {
  134. console.log('用户点击确定')
  135. wx.showLoading();
  136. var params = {
  137. url: "/p/shop",
  138. method: "GET",
  139. data: {},
  140. callBack: (res) => {
  141. wx.hideLoading();
  142. this.setData({
  143. logoImg: {
  144. url: res.shopLogo,
  145. path: res.shopLogo.indexOf(config.picDomain) > -1 ? res.shopLogo.replace(config.picDomain,'') : res.shopLogo
  146. },
  147. idcardFrontImg: {
  148. url: res.identityCardFront,
  149. path: res.identityCardFront.indexOf(config.picDomain) > -1 ? res.identityCardFront.replace(config.picDomain,'') : res.identityCardFront
  150. },
  151. idcardBackImg: {
  152. url: res.identityCardLater,
  153. path: res.identityCardLater.indexOf(config.picDomain) > -1 ? res.identityCardLater.replace(config.picDomain,'') : res.identityCardLater
  154. },
  155. bussLicenImg: {
  156. url: res.businessLicense,
  157. path: res.businessLicense.indexOf(config.picDomain) > -1 ? res.businessLicense.replace(config.picDomain,'') : res.businessLicense
  158. },
  159. province: res.province,
  160. city: res.city,
  161. area: res.area,
  162. provinceId: res.provinceId,
  163. cityId: res.cityId,
  164. areaId: res.areaId,
  165. latitude: res.shopLat,
  166. longitude: res.shopLng,
  167. shopNameValue: res.shopName, //店铺名字
  168. shopDescribeValue: res.intro, //店铺描述
  169. shopAddrValue: res.shopAddress, //详细地址
  170. shopOwnerPhoneValue: res.tel
  171. });
  172. this.initCityData(this.data.provinceId, this.data.cityId, this.data.areaId);
  173. this.getAuditMsg();
  174. }
  175. }
  176. } else if (res.cancel) {
  177. console.log('用户点击取消')
  178. wx.switchTab({
  179. url: '/pages/user/user',
  180. })
  181. }
  182. http.request(params);
  183. }
  184. })
  185. } else {
  186. this.initCityData(this.data.provinceId, this.data.cityId, this.data.areaId);
  187. }
  188. },
  189. getAuditMsg() {
  190. http.request({
  191. url: "/p/shop/shopAudit",
  192. method: "GET",
  193. data: {},
  194. callBack: (res) => {
  195. this.setData({
  196. auditRemarks: res.remarks
  197. });
  198. }
  199. });
  200. },
  201. /**
  202. * 获取经纬度
  203. */
  204. chooseLocation: function(e) {
  205. var that = this
  206. wx.chooseLocation({
  207. success: function (res) {
  208. console.log('succes1')
  209. console.log(res)
  210. that.setMapData(res)
  211. },
  212. fail: function () {
  213. wx.getSetting({
  214. success(res) {
  215. if (!res.authSetting['scope.userLocation']) {
  216. console.log("f1")
  217. wx.authorize({
  218. scope: 'scope.userLocation',
  219. success() {
  220. wx.chooseLocation({
  221. success: function (res) {
  222. that.setMapData(res)
  223. },
  224. })
  225. console.log('success2')
  226. },
  227. fail() {
  228. wx.showToast({
  229. title: '请在「右上角」 - 「关于」 - 「右上角」 - 「设置」授予获取位置信息的权限',
  230. icon: 'none'
  231. })
  232. }
  233. })
  234. }
  235. }
  236. })
  237. }
  238. })
  239. },
  240. setMapData(res) {
  241. var latitude = res.latitude
  242. var longitude = res.longitude
  243. var address = res.address
  244. var name = res.name
  245. console.log("经度:" + latitude, "纬度:" + longitude, "详细地址:" + address)
  246. this.setData({
  247. latitude: latitude,
  248. longitude: longitude,
  249. mapAddress: address,
  250. mapAddrName: name
  251. })
  252. },
  253. /**
  254. * 获取input数据
  255. */
  256. bindShopNameInt: function(e) {
  257. this.setData({
  258. shopNameValue: e.detail.value
  259. })
  260. },
  261. bindShopDescribeInt: function(e) {
  262. this.setData({
  263. shopDescribeValue: e.detail.value
  264. })
  265. },
  266. bindShopAddrInt: function(e) {
  267. this.setData({
  268. shopAddrValue: e.detail.value
  269. })
  270. },
  271. bindShopOwnerInt: function(e) {
  272. this.setData({
  273. shopOwnerValue: e.detail.value
  274. })
  275. },
  276. bindShopOwnerPhoneInt: function(e) {
  277. this.setData({
  278. shopOwnerPhoneValue: e.detail.value
  279. })
  280. },
  281. /**
  282. * 上传图片
  283. */
  284. getUploadImg: function(e) {
  285. const type = e.target.dataset.type
  286. console.log(type);
  287. var ths = this;
  288. wx.chooseImage({
  289. count: 1, // 默认9
  290. sizeType: ['compressed'],
  291. sourceType: ['album', 'camera'],
  292. success: function(res) {
  293. // 图片的本地临时文件路径列表
  294. var tempFilePaths = res.tempFilePaths;
  295. wx.showLoading({
  296. mask: true
  297. })
  298. var params = {
  299. url: "/p/file/upload",
  300. filePath: tempFilePaths[0],
  301. name: 'file',
  302. callBack: function(res2) {
  303. wx.hideLoading();
  304. var img = {};
  305. img.path = JSON.parse(res2).filePath;
  306. img.url = JSON.parse(res2).resourcesUrl + JSON.parse(res2).filePath;
  307. if (type == 'bussLicenImg') {
  308. ths.setData({
  309. bussLicenImg: img
  310. })
  311. } else if (type == 'logoImg') {
  312. ths.setData({
  313. logoImg: img
  314. })
  315. } else if (type == 'idcardFrontImg') {
  316. ths.setData({
  317. idcardFrontImg: img
  318. })
  319. } else if (type == 'idcardBackImg') {
  320. ths.setData({
  321. idcardBackImg: img
  322. })
  323. }
  324. }
  325. };
  326. http.upload(params);
  327. }
  328. })
  329. },
  330. /**
  331. * 删除图片
  332. */
  333. removeImage: function(e) {
  334. const type = e.target.dataset.type
  335. if (type == 'logoImg') {
  336. this.setData({
  337. logoImg: {}
  338. });
  339. } else if (type == 'idcardFrontImg') {
  340. this.setData({
  341. idcardFrontImg: {}
  342. });
  343. } else if (type == 'idcardBackImg') {
  344. this.setData({
  345. idcardBackImg: {}
  346. });
  347. } else if (type == 'bussLicenImg') {
  348. this.setData({
  349. bussLicenImg: {}
  350. });
  351. }
  352. console.log('删除图片')
  353. },
  354. /**
  355. * 生命周期函数--监听页面初次渲染完成
  356. */
  357. onReady: function() {
  358. // 底部弹框动画
  359. this.animation = wx.createAnimation({
  360. transformOrigin: "50% 50%",
  361. duration: 0,
  362. timingFunction: "ease",
  363. delay: 0
  364. })
  365. this.animation.translateY(200 + 'vh').step();
  366. this.setData({
  367. animation: this.animation.export(),
  368. show: show
  369. })
  370. },
  371. /**
  372. * 获取省市区
  373. */
  374. initCityData: function(provinceId, cityId, areaId) {
  375. var ths = this;
  376. wx.showLoading();
  377. var params = {
  378. url: "/p/area/listByPid",
  379. method: "GET",
  380. data: {
  381. pid: 0
  382. },
  383. callBack: function(res) {
  384. //console.log(res)
  385. ths.setData({
  386. provArray: res
  387. });
  388. if (provinceId) {
  389. for (var index in res) {
  390. if (res[index].areaId == provinceId) {
  391. ths.setData({
  392. value: [index, ths.data.value[1], ths.data.value[2]]
  393. });
  394. }
  395. }
  396. }
  397. ths.getCityArray(provinceId ? provinceId : res[0].areaId, cityId, areaId);
  398. wx.hideLoading();
  399. }
  400. }
  401. http.request(params);
  402. },
  403. /**
  404. * 滑动事件
  405. */
  406. bindChange: function(e) {
  407. var ths = this;
  408. var val = e.detail.value
  409. //判断滑动的是第几个column
  410. //若省份column做了滑动则定位到地级市和区县第一位
  411. if (index[0] != val[0]) {
  412. val[1] = 0;
  413. val[2] = 0;
  414. //更新数据
  415. ths.getCityArray(this.data.provArray[val[0]].areaId); //获取地级市数据
  416. } else { //若省份column未做滑动,地级市做了滑动则定位区县第一位
  417. if (index[1] != val[1]) {
  418. val[2] = 0;
  419. //更新数据
  420. ths.getAreaArray(this.data.cityArray[val[1]].areaId); //获取区县数据
  421. } else {
  422. }
  423. }
  424. index = val;
  425. this.setData({
  426. value: [val[0], val[1], val[2]],
  427. })
  428. ths.setData({
  429. province: ths.data.provArray[ths.data.value[0]].areaName,
  430. city: ths.data.cityArray[ths.data.value[1]].areaName,
  431. area: ths.data.areaArray[ths.data.value[2]].areaName,
  432. provinceId: ths.data.provArray[ths.data.value[0]].areaId,
  433. cityId: ths.data.cityArray[ths.data.value[1]].areaId,
  434. areaId: ths.data.areaArray[ths.data.value[2]].areaId
  435. })
  436. },
  437. /**
  438. * 根据省份ID获取 城市数据
  439. */
  440. getCityArray: function(provinceId, cityId, areaId) {
  441. var ths = this;
  442. var params = {
  443. url: "/p/area/listByPid",
  444. method: "GET",
  445. data: {
  446. pid: provinceId
  447. },
  448. callBack: function(res) {
  449. //console.log(res)
  450. ths.setData({
  451. cityArray: res
  452. });
  453. if (cityId) {
  454. for (var index in res) {
  455. if (res[index].areaId == cityId) {
  456. ths.setData({
  457. value: [ths.data.value[0], index, ths.data.value[2]]
  458. });
  459. }
  460. }
  461. }
  462. ths.getAreaArray(cityId ? cityId : res[0].areaId, areaId);
  463. wx.hideLoading();
  464. }
  465. }
  466. http.request(params);
  467. },
  468. /**
  469. * 根据城市ID获取 区数据
  470. */
  471. getAreaArray: function(cityId, areaId) {
  472. var ths = this;
  473. var params = {
  474. url: "/p/area/listByPid",
  475. method: "GET",
  476. data: {
  477. pid: cityId
  478. },
  479. callBack: function(res) {
  480. //console.log(res)
  481. ths.setData({
  482. areaArray: res
  483. });
  484. if (areaId) {
  485. for (var _index in res) {
  486. if (res[_index].areaId == areaId) {
  487. ths.setData({
  488. value: [ths.data.value[0], ths.data.value[1], _index]
  489. });
  490. }
  491. }
  492. index = ths.data.value;
  493. ths.setData({
  494. province: ths.data.province,
  495. city: ths.data.city,
  496. area: ths.data.area,
  497. provinceId: ths.data.provinceId,
  498. cityId: ths.data.cityId,
  499. areaId: ths.data.areaId
  500. })
  501. } else {
  502. ths.setData({
  503. province: ths.data.provArray[ths.data.value[0]].areaName,
  504. city: ths.data.cityArray[ths.data.value[1]].areaName,
  505. area: ths.data.areaArray[ths.data.value[2]].areaName,
  506. provinceId: ths.data.provArray[ths.data.value[0]].areaId,
  507. cityId: ths.data.cityArray[ths.data.value[1]].areaId,
  508. areaId: ths.data.areaArray[ths.data.value[2]].areaId
  509. })
  510. }
  511. wx.hideLoading();
  512. }
  513. }
  514. http.request(params);
  515. },
  516. /**
  517. * 移动按钮点击事件
  518. */
  519. translate: function(e) {
  520. if (t == 0) {
  521. moveY = 0;
  522. show = false;
  523. t = 1;
  524. } else {
  525. moveY = 200;
  526. show = true;
  527. t = 0;
  528. }
  529. this.setData({
  530. show: true
  531. });
  532. // this.animation.translate(arr[0], arr[1]).step();
  533. this.animationEvents(this, moveY, show);
  534. },
  535. /**
  536. * 隐藏弹窗浮层
  537. */
  538. hiddenFloatView(e) {
  539. //console.log(e);
  540. moveY = 200;
  541. show = true;
  542. t = 0;
  543. this.animationEvents(this, moveY, show);
  544. },
  545. /**
  546. * 动画事件
  547. */
  548. animationEvents: function(that, moveY, show) {
  549. //console.log("moveY:" + moveY + "\nshow:" + show);
  550. that.animation = wx.createAnimation({
  551. transformOrigin: "50% 50%",
  552. duration: 400,
  553. timingFunction: "ease",
  554. delay: 0
  555. })
  556. that.animation.translateY(moveY + 'vh').step()
  557. that.setData({
  558. animation: that.animation.export()
  559. })
  560. },
  561. /**
  562. * 生命周期函数--监听页面显示
  563. */
  564. onShow: function() {
  565. },
  566. /**
  567. * 生命周期函数--监听页面隐藏
  568. */
  569. onHide: function() {
  570. },
  571. /**
  572. * 生命周期函数--监听页面卸载
  573. */
  574. onUnload: function() {
  575. },
  576. /**
  577. * 页面相关事件处理函数--监听用户下拉动作
  578. */
  579. onPullDownRefresh: function() {
  580. },
  581. /**
  582. * 页面上拉触底事件的处理函数
  583. */
  584. onReachBottom: function() {
  585. },
  586. /**
  587. * 用户点击右上角分享
  588. */
  589. onShareAppMessage: function() {
  590. }
  591. })