index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="body-transaction" v-infinite-scroll="scroll" infinite-scroll-immediate="false">
  3. <main-title>购买方式及经销商</main-title>
  4. <div class="list">
  5. <a v-for="(x, key) in shop" :key="key" :href="x.url | httpUrl" target="_blank">
  6. <el-image :src="x.icon">
  7. <div slot="placeholder" class="img-loading">
  8. <i class="el-icon-loading"></i>
  9. </div>
  10. <div slot="error" class="image-slot">
  11. <i class="el-icon-picture-outline"></i>
  12. </div>
  13. </el-image>
  14. <h4>{{ x.name }}</h4>
  15. </a>
  16. </div>
  17. <div class="map-box">
  18. <h6>
  19. <i class="el-icon-map-location"></i>
  20. 附近经销商
  21. </h6>
  22. <ul class="map-box-list">
  23. <li v-for="(x, key) in dealerList" :key="key">
  24. <div style="flex:1">
  25. <h4>
  26. <i class="el-icon-location"></i>
  27. {{ x.dealerName || '' }}
  28. </h4>
  29. <p>{{ x.dealerAddress || '' }}</p>
  30. <p>
  31. <span>(0851)84399589</span>
  32. <span>直线距离{{ x.distance }}KM</span>
  33. </p>
  34. </div>
  35. <div class="map-go" @click="go(x)">
  36. <i class="iconfont iconche"></i>
  37. 去这里
  38. </div>
  39. </li>
  40. <div class="list-loading" v-if="listLoading || noMore">
  41. <i class="el-icon-loading" v-if="!noMore"></i>
  42. {{loadText}}
  43. </div>
  44. </ul>
  45. </div>
  46. <bottom>订购电话:{{ info.tel || '' }}</bottom>
  47. </div>
  48. </template>
  49. <script>
  50. import bottom from '../../components/bottom.vue';
  51. import wx from '../../script/wxApi/index.js';
  52. export default {
  53. components: {
  54. bottom
  55. },
  56. data() {
  57. const size = 20;
  58. return {
  59. timeFun: this.$timeFun(),
  60. list: [],
  61. pageNo: 1,
  62. pageSize: size,
  63. total: size,
  64. listLoading: false
  65. };
  66. },
  67. filters: {
  68. httpUrl(src) {
  69. src += '';
  70. const x = src.slice(0, 2);
  71. switch (src.slice(0, 7)) {
  72. case 'http://':
  73. case 'https:/':
  74. return src;
  75. break;
  76. default:
  77. return `${x == '//' ? '' : '//'}${src}`;
  78. break;
  79. }
  80. }
  81. },
  82. created() { },
  83. watch: {
  84. fkOrgGuid: {
  85. handler() {
  86. this.get();
  87. }
  88. },
  89. pageNo: {
  90. handler() {
  91. this.get();
  92. },
  93. // 代表在wacth里声明了pageNo这个方法之后立即先去执行handler方法
  94. immediate: true
  95. }
  96. },
  97. computed: {
  98. noMore() {
  99. return this.list.length >= this.total;
  100. },
  101. loadText() {
  102. return !this.noMore ? "加载中……" : "没有数据了";
  103. },
  104. fkOrgGuid() {
  105. return this.info.fkOrgGuid;
  106. },
  107. info() {
  108. return this.$store.state.info;
  109. },
  110. shop() {
  111. let arr = [];
  112. this.info.jdUrl &&
  113. arr.push({
  114. url: this.info.jdUrl,
  115. icon: require('./jd.png'),
  116. name: '京东'
  117. });
  118. this.info.tmallUrl &&
  119. arr.push({
  120. url: this.info.tmallUrl,
  121. icon: require('./tm.png'),
  122. name: '天猫'
  123. });
  124. this.info.companyUrl &&
  125. arr.push({
  126. url: this.info.companyUrl,
  127. icon: require('./qt.png'),
  128. name: '官网'
  129. });
  130. return arr;
  131. },
  132. //经过换算的列表
  133. dealerList() {
  134. const EARTH_RADIUS = 6378137.0, //单位M
  135. Rad = d => {
  136. return (d * Math.PI) / 180.0;
  137. },
  138. { latitude: lat2, longitude: lng2 } = this.$store.state.location; //第二点纬度,经度
  139. let list = this.list.map((x, i) => {
  140. // 第一点的纬度,经度
  141. const [lng1, lat1] = (x.latitudeLongitude + '').split(','),
  142. radLat1 = Rad(lat1),
  143. radLat2 = Rad(lat2),
  144. a = radLat1 - radLat2,
  145. b = Rad(lng1) - Rad(lng2);
  146. let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  147. s = s * 6378.137; // EARTH_RADIUS;
  148. s = Math.round(s * 10000) / 10000; //输出为公里
  149. s = s.toFixed(2);
  150. return {
  151. ...x,
  152. distance: isNaN(s) ? '--' : s
  153. };
  154. });
  155. return list;
  156. }
  157. },
  158. methods: {
  159. go(e) {
  160. const { dealerName, latitudeLongitude, dealerAddress } = e,
  161. l = (latitudeLongitude + '').split(',');
  162. wx.openLocation({
  163. longitude: l[0], // 经度,浮点数,范围为180 ~ -180。
  164. latitude: l[1], // 纬度,浮点数,范围为90 ~ -90
  165. name: dealerName, // 位置名
  166. address: dealerAddress, // 地址详情说明
  167. scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大
  168. infoUrl: '' // 在查看位置界面底部显示的超链接,可点击跳转
  169. });
  170. },
  171. scroll(e) {
  172. if (!this.listLoading) {
  173. this.pageNo += 1;
  174. }
  175. },
  176. get() {
  177. const { fkOrgGuid, pageNo, pageSize, noMore } = this;
  178. if (!noMore && fkOrgGuid && pageNo) {
  179. this.listLoading = true;
  180. this.timeFun(e => {
  181. this.$http
  182. .selectGoodsDealer({
  183. fkOrgGuid,
  184. pageNo,
  185. pageSize
  186. })
  187. .then(res => {
  188. this.listLoading = false;
  189. this.list = [...this.list, ...(res.list)];
  190. this.total = res.total;
  191. });
  192. });
  193. }
  194. }
  195. }
  196. };
  197. </script>
  198. <style lang="less" scoped="scoped">
  199. .body-transaction {
  200. .list {
  201. display: flex;
  202. flex-wrap: wrap;
  203. justify-content: space-between;
  204. padding: 0.6rem 0.4rem;
  205. > a {
  206. > .el-image {
  207. width: 1.5rem;
  208. height: 1.5rem;
  209. display: flex;
  210. justify-content: center;
  211. align-items: center;
  212. border-radius: 0.1rem;
  213. box-shadow: 1px 1px 0.2rem 1px rgba(0, 0, 0, 0.2);
  214. img {
  215. width: 100%;
  216. height: 100%;
  217. }
  218. }
  219. > h4 {
  220. font-size: 0.26rem;
  221. color: #20374d;
  222. text-align: center;
  223. margin: 0.2rem 0;
  224. }
  225. }
  226. }
  227. .map-box {
  228. background: #f6f6f7;
  229. border-radius: 0.1rem;
  230. padding: 0.2rem;
  231. font-size: 0.3rem;
  232. > h6 {
  233. display: flex;
  234. align-items: center;
  235. margin: 0.2rem;
  236. > i {
  237. font-size: 1.6em;
  238. margin-right: 0.2em;
  239. }
  240. }
  241. &-list {
  242. > li {
  243. background: #fff;
  244. border-radius: 0.1rem;
  245. box-shadow: 2px 2px 5px 0 rgba(0, 0, 0, 0.1);
  246. padding: 0.2rem 0.2rem 0.2rem 0.6rem;
  247. font-size: 0.2rem;
  248. margin: 0.2rem 0;
  249. display: flex;
  250. justify-content: space-between;
  251. h4 {
  252. display: flex;
  253. align-items: center;
  254. > i {
  255. margin-left: -0.3rem;
  256. transform: translateY(0.01rem) translateX(-0.02rem);
  257. font-size: 1.6em;
  258. }
  259. }
  260. p {
  261. font-size: 0.8em;
  262. margin: 0.1rem 0;
  263. display: flex;
  264. flex-wrap: wrap;
  265. align-items: center;
  266. justify-content: space-between;
  267. padding-right: 0.2rem;
  268. }
  269. > .map-go {
  270. display: flex;
  271. flex-direction: column;
  272. align-items: center;
  273. justify-content: center;
  274. > i {
  275. background: #20374d;
  276. color: #fff;
  277. border-radius: 50%;
  278. font-size: 0.4rem;
  279. box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.2);
  280. padding: 0.2rem;
  281. line-height: 1em;
  282. margin-bottom: 0.05rem;
  283. }
  284. }
  285. }
  286. .list-loading {
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. align-content: center;
  291. font-size: 10px;
  292. color: #000;
  293. opacity: 0.5;
  294. > i {
  295. font-size: 1.3em;
  296. }
  297. }
  298. }
  299. }
  300. }
  301. </style>