extraction-address.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <view>
  3. <view class="page">
  4. <view v-if="data_list.length > 0" class="padding-main">
  5. <view v-for="(item, index) in data_list" :key="index" class="item bg-white padding-main border-radius-main spacing-mb">
  6. <view @tap="address_conent_event" :data-index="index" class="oh">
  7. <view v-if="(item.logo || null) != null" class="fl oh margin-right-lg">
  8. <image class="dis-block address-logo radius" :src="item.logo" mode="widthFix"></image>
  9. </view>
  10. <view class="oh">
  11. <view class="base oh padding-bottom-main padding-top-xs">
  12. <text v-if="(item.alias || null) != null" class="address-alias br-main cr-main round margin-right-sm">{{item.alias}}</text>
  13. <text>{{item.name}}</text>
  14. <text class="fr">{{item.tel}}</text>
  15. </view>
  16. <view class="address oh padding-top-sm">
  17. <image class="item-icon fl margin-top-xs" :src="common_static_url+'map-icon.png'" mode="widthFix"></image>
  18. <view class="text fr">
  19. {{item.province_name || ''}}{{item.city_name || ''}}{{item.county_name || ''}}{{item.address || ''}}
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <view v-if="((item.distance_value || null) != null && (item.distance_unit || null) != null) || ((item.lng || 0) != 0 && (item.lat || 0) != 0)" class="item-operation br-t oh padding-top-main margin-top-main">
  25. <view v-if="(item.distance_value || null) != null && (item.distance_unit || null) != null" class="fl margin-top-lg">
  26. <text class="cr-gray">距离</text>
  27. <text class="cr-base">{{item.distance_value}}</text>
  28. <text class="cr-gray">{{item.distance_unit}}</text>
  29. </view>
  30. <button v-if="(item.lng || 0) != 0 && (item.lat || 0) != 0" class="fr round bg-white cr-base br" type="default" size="mini" @tap="address_map_event" :data-index="index" hover-class="none">查看地图</button>
  31. </view>
  32. </view>
  33. </view>
  34. <view v-else>
  35. <!-- 提示信息 -->
  36. <component-no-data :propStatus="data_list_loding_status"></component-no-data>
  37. </view>
  38. <!-- 结尾 -->
  39. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. const app = getApp();
  45. import componentNoData from "../../components/no-data/no-data";
  46. import componentBottomLine from "../../components/bottom-line/bottom-line";
  47. var common_static_url = app.globalData.get_static_url('common');
  48. export default {
  49. data() {
  50. return {
  51. common_static_url: common_static_url,
  52. data_list_loding_status: 1,
  53. data_bottom_line_status: false,
  54. data_list: [],
  55. params: null,
  56. is_default: 0,
  57. user_location_cache_key: app.globalData.data.cache_userlocation_key,
  58. user_location: null,
  59. is_first: 1,
  60. home_extraction_address_position: 0
  61. };
  62. },
  63. components: {
  64. componentNoData,
  65. componentBottomLine
  66. },
  67. props: {},
  68. onLoad(params) {
  69. this.setData({
  70. params: params,
  71. home_extraction_address_position: app.globalData.get_config('config.home_extraction_address_position', 0)
  72. });
  73. },
  74. onReady: function() {
  75. // 清除位置缓存信息
  76. uni.removeStorage({
  77. key: this.user_location_cache_key
  78. });
  79. // #ifndef MP-KUAISHOU
  80. // 是否获取位置
  81. if ((this.params.is_buy || 0) == 1 && this.home_extraction_address_position == 1) {
  82. uni.navigateTo({
  83. url: '/pages/common/open-setting-location/open-setting-location'
  84. });
  85. }
  86. // #endif
  87. },
  88. onShow() {
  89. // #ifndef MP-KUAISHOU
  90. // 是否需要选择地理位置
  91. if (this.home_extraction_address_position == 1) {
  92. // 首次不请求数据
  93. if (this.is_first == 0) {
  94. this.user_location_init();
  95. this.init();
  96. }
  97. } else {
  98. this.init();
  99. }
  100. // #endif
  101. // #ifdef MP-KUAISHOU
  102. this.init();
  103. // #endif
  104. this.setData({
  105. is_first: 0
  106. });
  107. // 分享菜单处理
  108. app.globalData.page_share_handle();
  109. },
  110. // 下拉刷新
  111. onPullDownRefresh() {
  112. this.get_data_list();
  113. },
  114. methods: {
  115. // 初始化
  116. init() {
  117. var user = app.globalData.get_user_info(this, "init");
  118. if (user != false) {
  119. // 用户未绑定用户则转到登录页面
  120. if (app.globalData.user_is_need_login(user)) {
  121. uni.redirectTo({
  122. url: "/pages/login/login?event_callback=init"
  123. });
  124. return false;
  125. } else {
  126. // 获取数据
  127. this.get_data_list();
  128. }
  129. } else {
  130. this.setData({
  131. data_list_loding_status: 0,
  132. data_bottom_line_status: false
  133. });
  134. }
  135. },
  136. // 地址信息初始化
  137. user_location_init() {
  138. var result = uni.getStorageSync(this.user_location_cache_key) || null;
  139. var data = null;
  140. if (result != null) {
  141. data = {
  142. name: result.name || null,
  143. address: result.address || null,
  144. lat: result.latitude || null,
  145. lng: result.longitude || null
  146. };
  147. }
  148. this.setData({
  149. user_location: data
  150. });
  151. },
  152. // 获取数据列表
  153. get_data_list() {
  154. // 加载loding
  155. uni.showLoading({
  156. title: '加载中...'
  157. });
  158. this.setData({
  159. data_list_loding_status: 1
  160. });
  161. // 获取数据
  162. var data = this.params || {};
  163. // 是否有坐标
  164. if ((this.user_location || null) != null) {
  165. data['lng'] = this.user_location.lng;
  166. data['lat'] = this.user_location.lat;
  167. }
  168. // 请求接口
  169. uni.request({
  170. url: app.globalData.get_request_url("extraction", "useraddress"),
  171. method: 'POST',
  172. data: data,
  173. dataType: 'json',
  174. success: res => {
  175. uni.hideLoading();
  176. uni.stopPullDownRefresh();
  177. if (res.data.code == 0) {
  178. if (res.data.data.length > 0) {
  179. // 获取当前默认地址
  180. var is_default = 0;
  181. for (var i in res.data.data) {
  182. if (res.data.data[i]['is_default'] == 1) {
  183. is_default = res.data.data[i]['id'];
  184. }
  185. }
  186. // 设置数据
  187. this.setData({
  188. data_list: res.data.data,
  189. is_default: is_default,
  190. data_list_loding_status: 3,
  191. data_bottom_line_status: true
  192. });
  193. } else {
  194. this.setData({
  195. data_list_loding_status: 0
  196. });
  197. }
  198. } else {
  199. this.setData({
  200. data_list_loding_status: 0
  201. });
  202. if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
  203. app.globalData.showToast(res.data.msg);
  204. }
  205. }
  206. },
  207. fail: () => {
  208. uni.hideLoading();
  209. uni.stopPullDownRefresh();
  210. this.setData({
  211. data_list_loding_status: 2
  212. });
  213. app.globalData.showToast('服务器请求出错');
  214. }
  215. });
  216. },
  217. // 地图查看
  218. address_map_event(e) {
  219. var index = e.currentTarget.dataset.index || 0;
  220. var data = this.data_list[index] || null;
  221. if (data == null) {
  222. app.globalData.showToast("地址有误");
  223. return false;
  224. }
  225. // 打开地图
  226. var name = data.alias || data.name || '';
  227. var address = (data.province_name || '') + (data.city_name || '') + (data.county_name || '') + (data.address || '');
  228. app.globalData.open_location(data.lng, data.lat, name, address);
  229. },
  230. // 地址内容事件
  231. address_conent_event(e) {
  232. var index = e.currentTarget.dataset.index || 0;
  233. var is_back = this.params.is_back || 0;
  234. if (is_back == 1) {
  235. uni.setStorage({
  236. key: app.globalData.data.cache_buy_user_address_select_key,
  237. data: this.data_list[index]
  238. });
  239. uni.navigateBack();
  240. }
  241. }
  242. }
  243. };
  244. </script>
  245. <style>
  246. @import './extraction-address.css';
  247. </style>