facade.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <template>
  2. <view class="facade">
  3. <navbar
  4. :config="config"
  5. @searchConfirm="searchConfirm"
  6. @searchBlur="searchBlur"
  7. >
  8. <view class="map" slot="left">
  9. <picker
  10. class="pickerList"
  11. mode="multiSelector"
  12. :range="newProvinceDataList"
  13. range-key="label"
  14. :value="multiIndex"
  15. @change="pickerChange"
  16. @columnchange="pickerColumnchange"
  17. >
  18. <text>{{ city }}</text>
  19. <text class="iconfont down">&#xe645;</text>
  20. </picker>
  21. </view>
  22. </navbar>
  23. <view class="top">
  24. <view
  25. class="item"
  26. :class="activeIndex==index?'active':''"
  27. v-for="(item ,index) in cates"
  28. :key="item.id"
  29. @click="changeCateId(item,index)"
  30. >
  31. {{ item.name }}
  32. </view>
  33. </view>
  34. <view class="content" v-if="shops.length > 0">
  35. <view class="item" v-for="(item,key) in shops" :key="key">
  36. <view class="item-top" @click="goShop(item.shop_id)">
  37. <view class="top-name">{{ item.shop_name }} </view>
  38. <view class="score-and-distance">
  39. <view class="score">
  40. <!-- <text class="iconfont" v-for="star in item.average" :key="star.id"
  41. >&#xe624;</text
  42. > -->
  43. <uni-rate :max="5" :value="item.average" size="17" readonly="true" color="#B3B3B3" allowHalf='true' margin="4" activeColor="#FF5112" />
  44. <view class="five-stars"> {{ item.average }}分 </view>
  45. </view>
  46. <view class="distance"
  47. >{{ item.area_name }}
  48. <text v-if="item.distance > 1000"
  49. >{{ (item.distance / 1000).toFixed(1) }}KM</text
  50. >
  51. <text v-else>{{ item.distance.toFixed(1) }}m</text>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="middle">
  56. <view
  57. class="middle-item"
  58. v-for="good in item.list"
  59. :key="good.id"
  60. @click="goProductDetails(good.id)"
  61. >
  62. <view class="img">
  63. <image :src="good.cover" mode="aspectFill"></image>
  64. </view>
  65. <view class="introduce">
  66. <view class="name"> {{ good.title }} </view>
  67. <view class="title">
  68. <view class="title-item"> 消费{{ good.result_sale_num }} </view>
  69. </view>
  70. <view class="bottom">
  71. <view class="large">
  72. <rich-text
  73. :nodes="$mUtil.priceBigSmall(good.sale_price)"
  74. ></rich-text
  75. ></view>
  76. <view class="small"> ¥ {{ good.market_price }} </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="see-more" v-if="item.service_goods_total > 2" @click="goShop(item.shop_id)">
  82. 查看其他{{ item.service_goods_total - 2 }}个商品
  83. <text class="iconfont">&#xe645;</text>
  84. </view>
  85. </view>
  86. </view>
  87. <nodata v-else :config="{ top: 1, content: '暂无数据~' }"></nodata>
  88. </view>
  89. </template>
  90. <script>
  91. import permision from "@/js_sdk/wa-permission/permission.js";
  92. export default {
  93. data() {
  94. return {
  95. cates: [],
  96. config: {
  97. back: true, //false是tolbar页面 是则不写
  98. title: "店铺",
  99. color: "#1A1A1A",
  100. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  101. backgroundColor: [1, "#ffffff"],
  102. search: {
  103. value: "",
  104. placeholder: "",
  105. disabled: false,
  106. },
  107. leftSlot: true,
  108. },
  109. city: '',
  110. newProvinceDataList: [[], [], []],
  111. multiIndex: [0, 0, 0],
  112. oldpProvinceDataList: [],
  113. params: {},
  114. shops: [],
  115. activeIndex:null
  116. };
  117. },
  118. method(){
  119. },
  120. onShow() {
  121. this.getCate();
  122. this.getLocalAddress();
  123. },
  124. onPullDownRefresh() {
  125. this.getShop();
  126. uni.stopPullDownRefresh();
  127. },
  128. methods: {
  129. async requestAndroidPermission(permisionID) {
  130. var result = await permision.requestAndroidPermission(permisionID)
  131. var strStatus
  132. if (result == 1) {
  133. uni.getLocation({
  134. type: "gcj02",
  135. geocode: true,
  136. success: (res) => {
  137. this.city = res.address.city;
  138. this.params.city = this.city;
  139. this.params.lon = res.longitude;
  140. this.params.lat = res.latitude;
  141. this.setStorage(
  142. res.address.city,
  143. res.longitude,
  144. res.latitude
  145. );
  146. this.$http
  147. .get(
  148. "/cnarea/get-address/" + res.latitude + "," + res.longitude
  149. )
  150. .then((res) => {
  151. console.log(res + JSON.stringify(res));
  152. if (res && res.code == 200) {
  153. }
  154. });
  155. this.getShop();
  156. console.log("当前位置的经度:" + res.longitude);
  157. console.log("当前位置的纬度:" + res.latitude);
  158. console.log(
  159. "res" + res.address.city,
  160. JSON.stringify(res.address)
  161. );
  162. },
  163. });
  164. } else if (result == 0) {
  165. strStatus = "未获得授权"
  166. } else {
  167. strStatus = "被永久拒绝权限"
  168. }
  169. // uni.showModal({
  170. // content:"定位" + strStatus,
  171. // showCancel: false
  172. // });
  173. this.$mUtil.toast(strStatus);
  174. },
  175. // 小程序获取位置
  176. wxGetLocal() {
  177. uni.getLocation({
  178. type: "gcj02",
  179. geocode: true,
  180. success: (res) => {
  181. console.log(res)
  182. this.$http
  183. .get(
  184. "/cnarea/get-address/" + res.latitude + "," + res.longitude
  185. )
  186. .then((res2) => {
  187. console.log(res + JSON.stringify(res));
  188. if (res2 && res2.code == 200) {
  189. this.params.city = res2.date.address_component.city;
  190. this.params.lon = res.longitude;
  191. this.params.lat = res.latitude;
  192. this.city = res2.date.address_component.city
  193. this.setStorage(
  194. res2.date.address_component.city,
  195. res.longitude,
  196. res.latitude
  197. );
  198. this.getShop();
  199. }
  200. });
  201. // this.city = res.address.city;
  202. // this.params.city = this.city;
  203. // this.params.lon = res.longitude;
  204. // this.params.lat = res.latitude;
  205. // this.setStorage(
  206. // res.address.city,
  207. // res.longitude,
  208. // res.latitude
  209. // );
  210. // this.$http
  211. // .get(
  212. // "/cnarea/get-address/" + res.latitude + "," + res.longitude
  213. // )
  214. // .then((res) => {
  215. // console.log(res + JSON.stringify(res));
  216. // if (res && res.code == 200) {
  217. // }
  218. // });
  219. // this.getShop();
  220. // console.log("当前位置的经度:" + res.longitude);
  221. // console.log("当前位置的纬度:" + res.latitude);
  222. // console.log(
  223. // "res" + res.address.city,
  224. // JSON.stringify(res.address)
  225. // );
  226. },
  227. });
  228. },
  229. goProductDetails(id) {
  230. uni.navigateTo({
  231. url: "/pages/product/goods/serviceGood?id=" + id,
  232. });
  233. },
  234. goShop(shopid) {
  235. console.log('dsddsdssds454545454554')
  236. // uni.navigateTo({
  237. // url: "/pages/user/merchant/registerAndAudit",
  238. // });
  239. uni.navigateTo({
  240. url: "/pages/research/homepage/shopHomepage?shopId=" + shopid,
  241. fail(err) {
  242. console.log(err)
  243. }
  244. });
  245. },
  246. searchBlur(e) {
  247. if (e.value == "") {
  248. delete this.params.title;
  249. }
  250. this.getShop();
  251. },
  252. searchConfirm(e) {
  253. // if (e.value) {
  254. // }
  255. if (e.value.length > 50) {
  256. this.$mUtil.toast("搜索最多50个字符");
  257. return false;
  258. }
  259. this.params.title = e.value;
  260. if (e.value == "") {
  261. delete this.params.title;
  262. }
  263. this.getShop();
  264. },
  265. /**获取数据 */
  266. getShop() {
  267. console.log("数据 " + JSON.stringify(this.params));
  268. this.$http.get("/service/goods/nearby", this.params).then((res) => {
  269. if (res && res.code == 200) {
  270. this.shops = res.list;
  271. }
  272. });
  273. },
  274. /**得到分类 */
  275. getCate() {
  276. this.$http.get("/classify/all").then((res) => {
  277. if (res && res.code == 200) {
  278. this.cates = res.list;
  279. }
  280. });
  281. },
  282. /**获取当前位置 */
  283. getLocalAddress() {
  284. this.$http.get("/cnarea/tree-lbs/city").then(async (res) => {
  285. let provincesList = res.tree.children;
  286. for (let i = 0; i < provincesList.length; i++) {
  287. this.newProvinceDataList[0].push(provincesList[i]);
  288. }
  289. this.oldpProvinceDataList = provincesList;
  290. });
  291. if (uni.getStorageSync("localAddress")) {
  292. let local = JSON.parse(uni.getStorageSync("localAddress"));
  293. this.city = local.city;
  294. this.params.city = this.city;
  295. this.params.lon = local.lon;
  296. this.params.lat = local.lat;
  297. this.getShop();
  298. } else {
  299. console.log(1)
  300. // this.requestAndroidPermission("android.permission.ACCESS_FINE_LOCATION")
  301. this.wxGetLocal()
  302. }
  303. },
  304. /**点击分类切换数据 */
  305. changeCateId(item,index) {
  306. if(index==this.activeIndex){
  307. this.activeIndex=null
  308. delete this.params.category_id
  309. }else{
  310. this.activeIndex=index
  311. this.params.category_id = item.id;
  312. let local = JSON.parse(uni.getStorageSync("localAddress"));
  313. this.params.city = local.city;
  314. this.params.lon = local.lon;
  315. this.params.lat = local.lat;
  316. }
  317. this.getShop();
  318. },
  319. /**缓存城市code */
  320. setStorage(city, lon, lat) {
  321. uni.setStorageSync(
  322. "localAddress",
  323. JSON.stringify({ city: city, lon: lon, lat: lat })
  324. );
  325. },
  326. // 省市区确认事件
  327. pickerChange(e) {
  328. this.multiIndex = e.detail.value;
  329. if (this.newProvinceDataList[1].length > 0) {
  330. // this.params.lat = this.newProvinceDataList[1][
  331. // this.multiIndex[1]
  332. // ].latitude;
  333. // this.params.lon = this.newProvinceDataList[1][
  334. // this.multiIndex[1]
  335. // ].longitude;
  336. this.city = this.newProvinceDataList[1][this.multiIndex[1]].label;
  337. this.params.city = this.city;
  338. } else {
  339. // this.params.lat = this.newProvinceDataList[0][
  340. // this.multiIndex[0]
  341. // ].latitude;
  342. // this.params.lon = this.newProvinceDataList[0][
  343. // this.multiIndex[0]
  344. // ].longitude;
  345. this.city = this.newProvinceDataList[0][this.multiIndex[0]].label;
  346. this.params.city = this.city;
  347. }
  348. this.setStorage(
  349. this.city,
  350. this.params.lon,
  351. this.params.lat
  352. );
  353. this.getShop();
  354. },
  355. pickerColumnchange(e) {
  356. // 第几列滑动
  357. // console.log(e.detail.column);
  358. // 第几列滑动的下标
  359. // console.log(e.detail.value)
  360. // 第一列滑动
  361. if (e.detail.column === 0) {
  362. this.multiIndex = [0, 0, 0];
  363. this.multiIndex[0] = e.detail.value;
  364. this.newProvinceDataList[1] = this.oldpProvinceDataList[
  365. this.multiIndex[0]
  366. ].children.map((item, index) => {
  367. return item;
  368. });
  369. //当三级存在
  370. if (
  371. this.oldpProvinceDataList[this.multiIndex[0]].children.length > 0 &&
  372. this.oldpProvinceDataList[this.multiIndex[0]].children[0].children
  373. ) {
  374. if (
  375. this.oldpProvinceDataList[this.multiIndex[0]].children[
  376. this.multiIndex[1]
  377. ]
  378. ) {
  379. this.newProvinceDataList[2] = this.oldpProvinceDataList[
  380. this.multiIndex[0]
  381. ].children[this.multiIndex[1]].children.map((item, index) => {
  382. return item;
  383. });
  384. }
  385. } else {
  386. this.newProvinceDataList[2] = [];
  387. }
  388. // 第一列滑动 第二列 和第三列 都变为第一个
  389. // this.multiIndex.splice(1, 1, 0);
  390. // this.multiIndex.splice(2, 1, 0);
  391. }
  392. // 第二列滑动
  393. if (e.detail.column === 1) {
  394. this.multiIndex[1] = e.detail.value;
  395. if (
  396. this.oldpProvinceDataList[this.multiIndex[0]].children[0].children
  397. ) {
  398. this.newProvinceDataList[2] = this.oldpProvinceDataList[
  399. this.multiIndex[0]
  400. ].children[this.multiIndex[1]].children.map((item, index) => {
  401. return item;
  402. });
  403. } else {
  404. this.newProvinceDataList[2] = [];
  405. }
  406. // 第二列 滑动 第三列 变成第一个
  407. this.multiIndex.splice(2, 1, 0);
  408. }
  409. // 第三列滑动
  410. if (e.detail.column === 2) {
  411. this.multiIndex[2] = e.detail.value;
  412. }
  413. },
  414. },
  415. };
  416. </script>
  417. <style>
  418. </style>
  419. <style lang="scss" scoped>
  420. /deep/.hx-navbar__content__main_search_hxicon {
  421. span {
  422. font-size: 30rpx;
  423. }
  424. }
  425. /deep/.uni-input-placeholder {
  426. background-color: #fafafa;
  427. color: #b3b3b3 !important;
  428. font-size: 22rpx;
  429. }
  430. /deep/.hx-navbar__content__main_search_input {
  431. background-color: #fafafa;
  432. font-size: 30rpx;
  433. }
  434. .down {
  435. font-size: 25rpx;
  436. margin-left: 10rpx;
  437. }
  438. .content {
  439. padding: 40rpx 30rpx;
  440. background-color: #f5f5f5;
  441. border-radius: 40rpx;
  442. .item {
  443. background-color: #ffffff;
  444. margin-bottom: 30rpx;
  445. border-radius: 26rpx;
  446. .item-top {
  447. border-bottom: 1rpx solid #e6e6e6;
  448. padding: 44rpx 22rpx 30rpx 22rpx;
  449. padding-bottom: 40rpx;
  450. .top-name {
  451. font-size: 32rpx;
  452. font-weight: 700;
  453. color: #333333;
  454. }
  455. .score-and-distance {
  456. display: flex;
  457. justify-content: space-between;
  458. margin-top: 13rpx;
  459. .score {
  460. display: flex;
  461. align-items: center;
  462. .iconfont {
  463. color: #ff4e15;
  464. padding-right: 10rpx;
  465. }
  466. .five-stars {
  467. font-size: 28rpx;
  468. color: #ff4e15;
  469. font-weight: 500;
  470. margin-left: 6rpx;
  471. }
  472. }
  473. .distance {
  474. font-size: 24rpx;
  475. color: #666666;
  476. font-weight: 500;
  477. margin-right: 24rpx;
  478. }
  479. }
  480. }
  481. .see-more {
  482. color: #999999;
  483. font-size: 22rpx;
  484. font-weight: 400;
  485. text-align: center;
  486. padding-bottom: 45rpx;
  487. margin-top: 30rpx;
  488. }
  489. .middle {
  490. padding: 0rpx 30rpx 0rpx 22rpx;
  491. .middle-item {
  492. padding: 40rpx 0 30rpx 0;
  493. display: flex;
  494. border-bottom: 1rpx solid #e6e6e6;
  495. padding-bottom: 30rpx;
  496. .img {
  497. border-radius: 14rpx;
  498. overflow: hidden;
  499. image {
  500. width: 214rpx;
  501. height: 144rpx;
  502. }
  503. }
  504. .introduce {
  505. flex: 1;
  506. margin-left: 16rpx;
  507. .name {
  508. font-size: 26rpx;
  509. color: #333333;
  510. width: 400rpx;
  511. font-weight: 500;
  512. overflow: hidden;
  513. white-space: nowrap;
  514. text-overflow: ellipsis;
  515. margin-bottom: 6rpx;
  516. }
  517. .title {
  518. display: flex;
  519. .title-item {
  520. color: #a27714;
  521. font-size: 22rpx;
  522. font-weight: 400;
  523. margin-right: 16rpx;
  524. background-color: #dac6a1;
  525. padding: 1rpx 6rpx;
  526. border-radius: 16rpx 16rpx 16rpx 0;
  527. }
  528. }
  529. .bottom {
  530. display: flex;
  531. align-items: flex-end;
  532. margin-top: 26rpx;
  533. .large {
  534. font-size: 36rpx;
  535. color: #ff0000;
  536. font-weight: Bold;
  537. text {
  538. margin-left: 16rpx;
  539. font-size: 36rpx;
  540. }
  541. }
  542. .small {
  543. font-size: 22rpx;
  544. font-weight: 500;
  545. color: #cccccc;
  546. text-decoration: line-through;
  547. margin-left: 16rpx;
  548. }
  549. }
  550. }
  551. }
  552. }
  553. }
  554. }
  555. .top {
  556. display: flex;
  557. overflow: scroll;
  558. white-space: nowrap;
  559. .item {
  560. padding: 30rpx 0rpx;
  561. margin: 0 30rpx;
  562. font-size: 28rpx;
  563. color: #999999;
  564. font-weight: 500;
  565. }
  566. .active{
  567. color: #0B844A;
  568. font-weight: 600;
  569. border-bottom: 4rpx solid #0B844A;
  570. }
  571. }
  572. .map {
  573. font-size: 36rpx;
  574. color: #1a1a1a;
  575. font-weight: 500;
  576. text {
  577. }
  578. }
  579. </style>