extraction-switch.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view>
  3. <view class="page">
  4. <view v-if="data_list.length > 0" class="data-list 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="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. <view class="item-operation fr oh">
  31. <button v-if="(item.is_default || 0) == 0" class="round bg-white cr-green br-green" type="default" size="mini" @tap="address_switch_event" :data-index="index" hover-class="none">选择</button>
  32. <button v-if="(item.lng || 0) != 0 && (item.lat || 0) != 0" class="round bg-white cr-base br" type="default" size="mini" @tap="address_map_event" :data-index="index" hover-class="none">查看地图</button>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view v-else>
  38. <!-- 提示信息 -->
  39. <component-no-data :propStatus="data_list_loding_status"></component-no-data>
  40. </view>
  41. <!-- 结尾 -->
  42. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. const app = getApp();
  48. import componentNoData from "../../../../components/no-data/no-data";
  49. import componentBottomLine from "../../../../components/bottom-line/bottom-line";
  50. var common_static_url = app.globalData.get_static_url('common');
  51. export default {
  52. data() {
  53. return {
  54. common_static_url: common_static_url,
  55. data_list_loding_status: 1,
  56. data_bottom_line_status: false,
  57. data_list: [],
  58. params: null,
  59. user_location_cache_key: app.globalData.data.cache_userlocation_key,
  60. user_location: null,
  61. is_first: 1,
  62. home_extraction_address_position: 0
  63. };
  64. },
  65. components: {},
  66. props: {},
  67. onLoad(params) {
  68. this.setData({
  69. params: params,
  70. home_extraction_address_position: app.globalData.get_config('config.home_extraction_address_position', 0)
  71. });
  72. },
  73. onReady: function() {
  74. // 清除位置缓存信息
  75. uni.removeStorage({
  76. key: this.user_location_cache_key
  77. });
  78. // 是否获取位置
  79. if (this.home_extraction_address_position == 1) {
  80. uni.navigateTo({
  81. url: '/pages/common/open-setting-location/open-setting-location'
  82. });
  83. }
  84. },
  85. onShow() {
  86. // 是否需要选择地理位置
  87. if (this.home_extraction_address_position == 1) {
  88. // 首次不请求数据
  89. if (this.is_first == 0) {
  90. this.user_location_init();
  91. this.init();
  92. }
  93. } else {
  94. this.init();
  95. }
  96. this.setData({
  97. is_first: 0
  98. });
  99. // 分享菜单处理
  100. app.globalData.page_share_handle();
  101. },
  102. // 下拉刷新
  103. onPullDownRefresh() {
  104. this.get_data_list();
  105. },
  106. methods: {
  107. // 初始化
  108. init() {
  109. var user = app.globalData.get_user_info(this, "init");
  110. if (user != false) {
  111. // 用户未绑定用户则转到登录页面
  112. if (app.globalData.user_is_need_login(user)) {
  113. uni.redirectTo({
  114. url: "/pages/login/login?event_callback=init"
  115. });
  116. return false;
  117. } else {
  118. // 获取数据
  119. this.get_data_list();
  120. }
  121. } else {
  122. this.setData({
  123. data_list_loding_status: 0,
  124. data_bottom_line_status: false
  125. });
  126. }
  127. },
  128. // 地址信息初始化
  129. user_location_init() {
  130. var result = uni.getStorageSync(this.user_location_cache_key) || null;
  131. var data = null;
  132. if (result != null) {
  133. data = {
  134. name: result.name || null,
  135. address: result.address || null,
  136. lat: result.latitude || null,
  137. lng: result.longitude || null
  138. };
  139. }
  140. this.setData({
  141. user_location: data
  142. });
  143. },
  144. // 获取数据列表
  145. get_data_list() {
  146. // 加载loding
  147. uni.showLoading({
  148. title: '加载中...'
  149. });
  150. this.setData({
  151. data_list_loding_status: 1
  152. });
  153. // 获取数据
  154. var data = {};
  155. // 是否有坐标
  156. if ((this.user_location || null) != null) {
  157. data['lng'] = this.user_location.lng;
  158. data['lat'] = this.user_location.lat;
  159. }
  160. // 请求接口
  161. uni.request({
  162. url: app.globalData.get_request_url("switchinfo", "extraction", "distribution"),
  163. method: 'POST',
  164. data: data,
  165. dataType: 'json',
  166. success: res => {
  167. uni.hideLoading();
  168. uni.stopPullDownRefresh();
  169. if (res.data.code == 0) {
  170. var data = res.data.data;
  171. if (data.extraction_address.length > 0) {
  172. this.setData({
  173. data_list: data.extraction_address,
  174. data_list_loding_status: 3,
  175. data_bottom_line_status: true
  176. });
  177. } else {
  178. this.setData({
  179. data_list_loding_status: 0
  180. });
  181. }
  182. } else {
  183. this.setData({
  184. data_list_loding_status: 0
  185. });
  186. if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
  187. app.globalData.showToast(res.data.msg);
  188. }
  189. }
  190. },
  191. fail: () => {
  192. uni.hideLoading();
  193. uni.stopPullDownRefresh();
  194. this.setData({
  195. data_list_loding_status: 2
  196. });
  197. app.globalData.showToast('服务器请求出错');
  198. }
  199. });
  200. },
  201. // 地图查看
  202. address_map_event(e) {
  203. var index = e.currentTarget.dataset.index || 0;
  204. var data = this.data_list[index] || null;
  205. if (data == null) {
  206. app.globalData.showToast("地址有误");
  207. return false;
  208. }
  209. // 打开地图
  210. var name = data.alias || data.name || '';
  211. var address = (data.province_name || '') + (data.city_name || '') + (data.county_name || '') + (data.address || '');
  212. app.globalData.open_location(data.lng, data.lat, name, address);
  213. },
  214. // 地址内容事件
  215. address_conent_event(e) {
  216. var index = e.currentTarget.dataset.index || 0;
  217. var is_back = this.params.is_back || 0;
  218. if (is_back == 1) {
  219. uni.setStorage({
  220. key: app.globalData.data.cache_buy_user_address_select_key,
  221. data: this.data_list[index]
  222. });
  223. uni.navigateBack();
  224. }
  225. },
  226. // 切换选择事件
  227. address_switch_event(e) {
  228. var index = e.currentTarget.dataset.index || 0;
  229. var temp_data = this.data_list;
  230. if ((temp_data[index] || null) == null) {
  231. app.globalData.showToast('数据有误');
  232. return false;
  233. }
  234. // 请求切换
  235. uni.showLoading({
  236. title: '处理中...'
  237. });
  238. uni.request({
  239. url: app.globalData.get_request_url("switchsave", "extraction", "distribution"),
  240. method: 'POST',
  241. data: {
  242. "id": temp_data[index]['id'],
  243. "value": temp_data[index]['id_old'] || 0
  244. },
  245. dataType: 'json',
  246. success: res => {
  247. uni.hideLoading();
  248. if (res.data.code == 0) {
  249. app.globalData.showToast(res.data.msg, 'success');
  250. var temp_data = this.data_list;
  251. for(var i in temp_data) {
  252. temp_data[i]['is_default'] = (i == index) ? 1 : 0;
  253. }
  254. this.setData({
  255. data_list: temp_data
  256. });
  257. } else {
  258. if (app.globalData.is_login_check(res.data)) {
  259. app.globalData.showToast(res.data.msg);
  260. } else {
  261. app.globalData.showToast('提交失败,请重试!');
  262. }
  263. }
  264. },
  265. fail: () => {
  266. uni.hideLoading();
  267. app.globalData.showToast('服务器请求出错');
  268. }
  269. });
  270. }
  271. }
  272. };
  273. </script>
  274. <style>
  275. @import './extraction-switch.css';
  276. </style>