addressAdd.vue 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. <template>
  2. <view>
  3. <view class="add-address">
  4. <view class="add-form">
  5. <view class="form-item">
  6. <view class="label">联系人</view>
  7. <view class="content special-content">
  8. <input class="input" @input="bindinputName" placeholder="姓名" :value="address.name" auto-focus placeholder-style="color:#999;font-size:26rpx;" />
  9. <view class="gender-wrapper">
  10. <view class="male" @tap="maleSelect">
  11. <image src="https://mall.zhaijieshi.cc/file/wx-dy/radio-select.png" mode="asceptFit" v-if="gender == 1"></image>
  12. <image src="https://mall.zhaijieshi.cc/file/wx-dy/radio-unselect.png" mode="asceptFit" v-else></image>
  13. <text>先生</text>
  14. </view>
  15. <view class="female" @tap="femaleSelect">
  16. <image src="https://mall.zhaijieshi.cc/file/wx-dy/radio-select.png" mode="asceptFit" v-if="gender == 2"></image>
  17. <image src="https://mall.zhaijieshi.cc/file/wx-dy/radio-unselect.png" mode="asceptFit" v-else></image>
  18. <text>女士</text>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="form-item">
  24. <view class="label">电 话</view>
  25. <view class="content">
  26. <input
  27. class="input"
  28. @input="bindinputMobile"
  29. :value="address.tel"
  30. type="number"
  31. placeholder="手机号码"
  32. maxlength="11"
  33. placeholder-style="color:#999;font-size:26rpx;"
  34. />
  35. </view>
  36. </view>
  37. <!-- bindtap="chooseRegion" -->
  38. <view class="form-item" @tap="goMap">
  39. <view class="label">省市区</view>
  40. <view class="content">
  41. <image src="/static/images/address.png" style="width: 24rpx; height: 30rpx; margin: 12rpx 10rpx 0rpx 0" mode="asceptFit"></image>
  42. <input
  43. class="input"
  44. :value="address.province + address.city + address.county"
  45. :disabled="true"
  46. placeholder="省份、城市、区县"
  47. placeholder-style="color:#999;font-size:26rpx;"
  48. />
  49. <image src="/static/images/arrow.png" style="width: 12rpx; height: 20rpx; margin-right: 10rpx"></image>
  50. </view>
  51. </view>
  52. <!-- <view class="form-item" bindtap="goWebView">
  53. <view class="label">地址</view>
  54. <view class="content">
  55. <image src="/static/images/address.png" style="width: 24rpx;height: 30rpx;margin:12rpx 10rpx 0rpx 0;" mode="asceptFit"></image>
  56. <input class="input" value="{{address.addressname}}" disabled="true" placeholder="请选择地址" placeholder-style="color:#999;font-size:26rpx;"/>
  57. <image src="/static/images/arrow.png" style="width: 12rpx;height: 20rpx;margin-right: 10rpx;"></image>
  58. </view>
  59. </view> -->
  60. <view class="form-item">
  61. <view class="label">地址</view>
  62. <view class="content">
  63. <input class="input" :value="address.addressname" @input="bindAddressDetail" placeholder="请输入详细地址" placeholder-style="color:#999;font-size:26rpx;" />
  64. </view>
  65. </view>
  66. <view class="des" style="color: red">如地图返回地址不详,请手动补全</view>
  67. <view class="form-item">
  68. <view class="label">门牌号</view>
  69. <view class="content">
  70. <input class="input" @input="bindinputAddress" :value="address.detail" placeholder="例:9号楼1505室" placeholder-style="color:#999;font-size:26rpx;" />
  71. </view>
  72. </view>
  73. </view>
  74. <view class="form-default">
  75. <view class="switch-wrapper">
  76. <text class="title">设为默认地址</text>
  77. <switch class="switch" color="#00C0FF" :checked="address.isDefault == 1" @change="bindIsDefault" />
  78. </view>
  79. </view>
  80. <view class="des">*每次下单会默认推荐使用该地址</view>
  81. <!-- <view class="form-item" wx:if="{{address.id>0}}">
  82. <button style="background: #19B3FF;color: white;" data-address-id="{{address.id}}" bindtap="deleteAddress">删除地址</button>
  83. </view> -->
  84. <view class="btns" v-if="address.id > 0">
  85. <!-- <button class="cannel" bindtap="cancelAddress">取消</button> -->
  86. <button class="cannel" :data-address-id="address.id" @tap="deleteAddress">删除地址</button>
  87. <button class="save" @tap="saveAddress">确认修改</button>
  88. </view>
  89. <view v-else class="btns add-btn">
  90. <button class="save" @tap="saveAddress">保存地址</button>
  91. </view>
  92. <view class="region-select" v-if="openSelectRegion">
  93. <view class="hd">
  94. <view class="region-selected">
  95. <view
  96. :class="'item ' + (item.code == 0 ? 'disabled' : '') + ' ' + (regionType - 1 === index ? 'selected' : '')"
  97. @tap="selectRegionType"
  98. :data-region-type-index="index"
  99. v-for="(item, index) in selectRegionList"
  100. :key="index"
  101. >
  102. {{ item.name }}
  103. </view>
  104. </view>
  105. <view :class="'done ' + (selectRegionDone ? '' : 'disabled')" @tap="doneSelectRegion">确定</view>
  106. </view>
  107. <view class="bd">
  108. <scroll-view scroll-y class="region-list">
  109. <view :class="'item ' + (item.selected ? 'selected' : '')" @tap="selectRegion" :data-region-index="index" v-for="(item, index) in regionList" :key="index">
  110. {{ item.name }}
  111. </view>
  112. </scroll-view>
  113. </view>
  114. </view>
  115. </view>
  116. <view class="bg-mask" @tap="cancelSelectRegion" v-if="openSelectRegion"></view>
  117. <!-- 弹框地址超过2公里 -->
  118. <view class="goods-info-overlay" v-if="overDistinctTips1">
  119. <view class="goods-info-popup" cantap="onDiaClick">
  120. <view class="popup-title">提示</view>
  121. <view class="tips-title">您填写的详细地址不在选择的定位区域,请检查地图定位、小区名称、门牌号。</view>
  122. <view class="popup-bottom">
  123. <view class="btn-cancel" @tap="continueModifyAddress">仍然提交</view>
  124. <view class="btn-conf" @tap="onOverDiaClose">确定</view>
  125. </view>
  126. </view>
  127. </view>
  128. <!-- 弹框地址超过2公里 -->
  129. <view class="goods-info-overlay" v-if="overDistinctTips2">
  130. <view class="goods-info-popup">
  131. <view class="popup-title">提示</view>
  132. <view class="tips-title">地址有误,可能会影响您的服务体验,服务人员将再次与您电话核实,请注意接听来电。</view>
  133. <view class="popup-bottom">
  134. <view class="btn-cancel" @tap="continueModifyAddress">仍然提交</view>
  135. <view class="btn-conf" @tap="onOverDiaClose">返回修改</view>
  136. </view>
  137. </view>
  138. </view>
  139. </view>
  140. </template>
  141. <script>
  142. var util = require('../../../utils/util.js');
  143. var api = require('../../../config/api.js');
  144. var check = require('../../../utils/check.js');
  145. var area = require('../../../utils/area.js');
  146. // const chooseLocation = requirePlugin('chooseLocation');
  147. var app = getApp();
  148. export default {
  149. data() {
  150. return {
  151. overDistinctTips1: false,
  152. overDistinctTips2: false,
  153. gender: '1',
  154. selectAddress: '',
  155. isChange: 0,
  156. address: {
  157. id: 0,
  158. areaCode: 0,
  159. address: '',
  160. name: '',
  161. tel: '',
  162. isDefault: 0,
  163. province: '',
  164. city: '',
  165. county: '',
  166. latitude: '',
  167. longitude: '',
  168. addressDetail: '',
  169. detail: '',
  170. addressname: ''
  171. },
  172. addressId: 0,
  173. openSelectRegion: false,
  174. selectRegionList: [
  175. {
  176. code: 0,
  177. name: '省份'
  178. },
  179. {
  180. code: 0,
  181. name: '城市'
  182. },
  183. {
  184. code: 0,
  185. name: '区县'
  186. }
  187. ],
  188. regionType: 1,
  189. regionList: [],
  190. selectRegionDone: false,
  191. addressShow: false
  192. };
  193. },
  194. onLoad: function (options) {
  195. // 页面初始化 options为页面跳转所带来的参数
  196. //console.log(options)
  197. if (options.id && options.id != 0) {
  198. this.setData({
  199. addressId: options.id
  200. });
  201. this.getAddressDetail();
  202. }
  203. app.globalData.mapSelectFinish = false;
  204. //初始化area
  205. //area.init();
  206. },
  207. onReady: function () {},
  208. onShow: function () {
  209. // if(app.globalData.webAddress!=null){
  210. // this.setData({
  211. // 'address.addressname':app.globalData.webAddress.address
  212. // })
  213. // }
  214. // 页面显示
  215. // const location = chooseLocation.getLocation();
  216. // address.province = location.province;
  217. // address.city = location.city;
  218. // address.county = location.district;
  219. // address.addressname = location.name;
  220. // let that=this;
  221. // wx.getLocation({
  222. // success(location) {
  223. // console.log(`经度${location.longitude},维度${location.latitude}`);
  224. // console.log(location);
  225. // if (location != null) {
  226. // let address = that.data.address;
  227. // address.lat = location.latitude;
  228. // address.lng = location.longitude;
  229. // that.setData({
  230. // address: address
  231. // });
  232. // console.log(that.data.address);
  233. // that.getAreaCode();
  234. // }
  235. // },
  236. // fail(res) {
  237. // console.log(`getLocation调用失败`);
  238. // },
  239. // });
  240. if (app.globalData.mapSelectFinish) {
  241. let poi = app.globalData.mapSelectPoi;
  242. let location = poi.location;
  243. let address = this.address;
  244. address.lng = location.split(',')[0];
  245. address.lat = location.split(',')[1];
  246. address.addressname = poi.address;
  247. this.setData({
  248. address: address,
  249. selectAddress: poi.address
  250. });
  251. console.log(this.address);
  252. this.getAreaCode();
  253. }
  254. },
  255. onHide: function () {
  256. // 页面隐藏
  257. },
  258. onUnload: function () {
  259. // 页面关闭
  260. // chooseLocation.setLocation(null);
  261. },
  262. methods: {
  263. onOverDiaClose() {
  264. this.setData({
  265. overDistinctTips1: false,
  266. overDistinctTips2: false
  267. });
  268. },
  269. continueModifyAddress() {
  270. //继续修改地址
  271. console.info(this.overDistinctTips1);
  272. if (this.overDistinctTips1) {
  273. this.setData({
  274. overDistinctTips1: false,
  275. overDistinctTips2: true
  276. });
  277. } else {
  278. this.setData({
  279. overDistinctTips2: false
  280. });
  281. this.submitAddress();
  282. }
  283. },
  284. bindinputMobile(event) {
  285. let address = this.address;
  286. address.tel = event.detail.value;
  287. this.setData({
  288. address: address
  289. });
  290. },
  291. bindinputName(event) {
  292. let address = this.address;
  293. address.name = event.detail.value;
  294. this.setData({
  295. address: address
  296. });
  297. },
  298. bindinputAddress(event) {
  299. let address = this.address;
  300. address.detail = event.detail.value.replace(/[,,]/g, '');
  301. this.setData({
  302. address: address
  303. });
  304. // return value.replace(/[,,]/g,'');
  305. },
  306. bindAddressDetail(event) {
  307. let address = this.address;
  308. address.addressname = event.detail.value.replace(/[,,]/g, '');
  309. this.setData({
  310. address: address
  311. });
  312. },
  313. bindIsDefault() {
  314. let address = this.address;
  315. address.isDefault = !address.isDefault;
  316. this.setData({
  317. address: address
  318. });
  319. },
  320. getAddressDetail() {
  321. let that = this;
  322. util.request(api.AddressDetail, {
  323. id: that.addressId
  324. }).then(function (res) {
  325. if (res.errno === 0) {
  326. if (res.data) {
  327. that.setData({
  328. address: res.data,
  329. gender: res.data.gender
  330. });
  331. let addressDetailList = res.data.addressDetail.split(',');
  332. let address = that.address;
  333. address.addressname = addressDetailList[0];
  334. address.detail = addressDetailList.length > 1 ? addressDetailList[1] : '';
  335. that.setData({
  336. address: address,
  337. selectAddress: addressDetailList[0]
  338. });
  339. }
  340. }
  341. });
  342. },
  343. setRegionDoneStatus() {
  344. let that = this;
  345. let doneStatus = that.selectRegionList.every((item) => {
  346. return item.code != 0;
  347. });
  348. that.setData({
  349. selectRegionDone: doneStatus
  350. });
  351. },
  352. chooseRegion() {
  353. let that = this;
  354. this.setData({
  355. openSelectRegion: !this.openSelectRegion
  356. });
  357. //设置区域选择数据
  358. let address = this.address;
  359. if (address.areaCode > 0) {
  360. let selectRegionList = this.selectRegionList;
  361. console.info(selectRegionList);
  362. selectRegionList[0].code = address.areaCode.slice(0, 2) + '0000';
  363. selectRegionList[0].name = address.province;
  364. selectRegionList[1].code = address.areaCode.slice(0, 4) + '00';
  365. selectRegionList[1].name = address.city;
  366. selectRegionList[2].code = address.areaCode;
  367. selectRegionList[2].name = address.county;
  368. let regionList = area.getList('county', address.areaCode.slice(0, 4));
  369. regionList = regionList.map((item) => {
  370. //标记已选择的
  371. if (address.areaCode === item.code) {
  372. item.selected = true;
  373. } else {
  374. item.selected = false;
  375. }
  376. return item;
  377. });
  378. this.setData({
  379. selectRegionList: selectRegionList,
  380. regionType: 3,
  381. regionList: regionList
  382. });
  383. } else {
  384. let selectRegionList = [
  385. {
  386. code: 0,
  387. name: '省份'
  388. },
  389. {
  390. code: 0,
  391. name: '城市'
  392. },
  393. {
  394. code: 0,
  395. name: '区县'
  396. }
  397. ];
  398. this.setData({
  399. selectRegionList: selectRegionList,
  400. regionType: 1,
  401. regionList: area.getList('province')
  402. });
  403. }
  404. this.setRegionDoneStatus();
  405. },
  406. selectRegionType(event) {
  407. console.info('selectRegionType');
  408. let that = this;
  409. let regionTypeIndex = event.target.dataset.regionTypeIndex;
  410. let selectRegionList = that.selectRegionList;
  411. //判断是否可点击
  412. if (regionTypeIndex + 1 == this.regionType || (regionTypeIndex - 1 >= 0 && selectRegionList[regionTypeIndex - 1].code <= 0)) {
  413. return false;
  414. }
  415. let selectRegionItem = selectRegionList[regionTypeIndex];
  416. let code = selectRegionItem.code;
  417. let regionList;
  418. if (regionTypeIndex === 0) {
  419. // 点击省级,取省级
  420. regionList = area.getList('province');
  421. } else if (regionTypeIndex === 1) {
  422. // 点击市级,取市级
  423. regionList = area.getList('city', code.slice(0, 2));
  424. } else {
  425. // 点击县级,取县级
  426. console.info(code);
  427. regionList = area.getList('county', code.slice(0, 4));
  428. console.info(regionList);
  429. }
  430. regionList = regionList.map((item) => {
  431. //标记已选择的
  432. if (that.selectRegionList[regionTypeIndex].code == item.code) {
  433. item.selected = true;
  434. } else {
  435. item.selected = false;
  436. }
  437. return item;
  438. });
  439. this.setData({
  440. regionList: regionList,
  441. regionType: regionTypeIndex + 1
  442. });
  443. this.setRegionDoneStatus();
  444. },
  445. selectRegion(event) {
  446. let that = this;
  447. let regionIndex = event.target.dataset.regionIndex;
  448. let regionItem = this.regionList[regionIndex];
  449. let regionType = this.regionType;
  450. let selectRegionList = this.selectRegionList;
  451. selectRegionList[regionType - 1] = regionItem;
  452. if (regionType == 3) {
  453. this.setData({
  454. selectRegionList: selectRegionList
  455. });
  456. let regionList = that.regionList.map((item) => {
  457. //标记已选择的
  458. if (that.selectRegionList[that.regionType - 1].code == item.code) {
  459. item.selected = true;
  460. } else {
  461. item.selected = false;
  462. }
  463. return item;
  464. });
  465. this.setData({
  466. regionList: regionList
  467. });
  468. this.setRegionDoneStatus();
  469. return;
  470. }
  471. //重置下级区域为空
  472. selectRegionList.map((item, index) => {
  473. if (index > regionType - 1) {
  474. item.code = 0;
  475. item.name = index == 1 ? '城市' : '区县';
  476. }
  477. return item;
  478. });
  479. //console.info(selectRegionList);
  480. this.setData({
  481. selectRegionList: selectRegionList,
  482. regionType: regionType + 1
  483. });
  484. let code = regionItem.code;
  485. let regionList = [];
  486. if (regionType === 1) {
  487. // 点击省级,取市级
  488. regionList = area.getList('city', code.slice(0, 2));
  489. } else {
  490. // 点击市级,取县级
  491. regionList = area.getList('county', code.slice(0, 4));
  492. }
  493. this.setData({
  494. regionList: regionList
  495. });
  496. this.setRegionDoneStatus();
  497. },
  498. doneSelectRegion() {
  499. if (this.selectRegionDone === false) {
  500. return false;
  501. }
  502. let address = this.address;
  503. let selectRegionList = this.selectRegionList;
  504. address.province = selectRegionList[0].name;
  505. address.city = selectRegionList[1].name;
  506. address.county = selectRegionList[2].name;
  507. address.areaCode = selectRegionList[2].code;
  508. this.setData({
  509. address: address,
  510. openSelectRegion: false
  511. });
  512. },
  513. cancelSelectRegion() {
  514. this.setData({
  515. openSelectRegion: false,
  516. regionType: this.regionDoneStatus ? 3 : 1
  517. });
  518. },
  519. cancelAddress() {
  520. uni.navigateBack();
  521. },
  522. saveAddress() {
  523. console.log(this.address);
  524. let address = this.address;
  525. if (address.name == '') {
  526. util.showErrorToast('请输入姓名');
  527. return false;
  528. }
  529. if (this.gender == null || this.gender == '') {
  530. util.showErrorToast('请选择性别');
  531. return false;
  532. }
  533. if (address.tel == '') {
  534. util.showErrorToast('请输入手机号码');
  535. return false;
  536. }
  537. if (address.areaCode == 0) {
  538. util.showErrorToast('请输入省市区');
  539. return false;
  540. }
  541. if (address.addressname == '') {
  542. util.showErrorToast('请输入详细地址');
  543. return false;
  544. }
  545. if (address.detail == '') {
  546. util.showErrorToast('请输入门牌号');
  547. return false;
  548. }
  549. if (!check.isValidPhone(address.tel)) {
  550. util.showErrorToast('手机号不正确');
  551. return false;
  552. }
  553. if (this.selectAddress != address.addressname) {
  554. this.setData({
  555. isChange: 1
  556. });
  557. } else {
  558. this.setData({
  559. isChange: 0
  560. });
  561. }
  562. if (this.isChange == 1) {
  563. util.request(api.AddressChcek, this.getAddressInfo(), 'POST').then((res) => {
  564. if (res.errno == 601) {
  565. this.setData({
  566. overDistinctTips1: true
  567. });
  568. }
  569. });
  570. } else {
  571. this.submitAddress();
  572. }
  573. },
  574. submitAddress() {
  575. let that = this;
  576. util.request(api.AddressSave, this.getAddressInfo(), 'POST').then(function (res) {
  577. if (res.errno === 0) {
  578. //返回之前,先取出上一页对象,并设置addressId
  579. var pages = getCurrentPages();
  580. var prevPage = pages[pages.length - 2];
  581. console.log(prevPage);
  582. if (prevPage.route == 'pages/index/index') {
  583. var city = address.city.indexOf('市') < 0 ? address.province : address.city;
  584. var addresInfo = {
  585. city: city,
  586. lng: res.data.lng,
  587. lat: res.data.lat,
  588. shopId: res.data.shopId,
  589. address: res.data.addressDetail
  590. };
  591. uni.setStorageSync('addressInfo', addresInfo);
  592. } else if (prevPage.route == 'pages/checkout/checkout') {
  593. // ||prevPage.route == "pages/ucenter/appointOrder/appointOrder"
  594. prevPage.setData({
  595. addressId: res.data.id
  596. });
  597. try {
  598. uni.setStorageSync('addressId', res.data);
  599. uni.setStorageSync('addressName', addressString);
  600. } catch (e) {
  601. console.log('CatchClause', e);
  602. console.log('CatchClause', e);
  603. }
  604. console.log('set address');
  605. } else if (prevPage.route == 'pages/ucenter/appointOrder/appointOrder') {
  606. prevPage.setData({
  607. addressShow: true
  608. });
  609. }
  610. uni.navigateBack();
  611. } else {
  612. uni.showModal({
  613. title: '提醒',
  614. showCancel: false,
  615. content: res.errmsg
  616. });
  617. }
  618. });
  619. },
  620. getAddressInfo() {
  621. let address = this.address;
  622. let addressString = address.detail == '' ? address.addressname : address.addressname + ',' + address.detail;
  623. return {
  624. gender: this.gender,
  625. id: address.id,
  626. name: address.name,
  627. tel: address.tel,
  628. province: address.province,
  629. city: address.city,
  630. county: address.county,
  631. areaCode: address.areaCode,
  632. addressDetail: addressString,
  633. isDefault: address.isDefault,
  634. lat: Number(address.lat).toFixed(5),
  635. lng: Number(address.lng).toFixed(5),
  636. isChange: this.isChange
  637. };
  638. },
  639. deleteAddress(event) {
  640. console.log(event.target);
  641. let that = this;
  642. uni.showModal({
  643. title: '',
  644. content: '确定要删除地址?',
  645. success: function (res) {
  646. if (res.confirm) {
  647. let addressId = event.target.dataset.addressId;
  648. util.request(
  649. api.AddressDelete,
  650. {
  651. id: addressId
  652. },
  653. 'POST'
  654. ).then(function (res) {
  655. if (res.errno === 0) {
  656. uni.navigateBack({
  657. delta: 1,
  658. success: function () {}
  659. });
  660. // that.getAddressList();
  661. // wx.removeStorage({
  662. // key: 'addressId',
  663. // success: function(res) {},
  664. // })
  665. }
  666. });
  667. console.log('用户点击确定');
  668. }
  669. }
  670. });
  671. return false;
  672. },
  673. goMap() {
  674. // const key = "JA2BZ-XGOEU-UNZVD-46G64-S6MYJ-6BBF4";
  675. //使用在腾讯位置服务申请的key
  676. // const key = '6TRBZ-XXC6F-BWWJB-N75ME-BQNOF-YKFQY';
  677. // const referer = '鲸致生活LifePlus';
  678. // const category = '小区,生活服务,娱乐休闲';
  679. // wx.navigateTo({
  680. // url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&category=' + category
  681. // });
  682. let that = this;
  683. // wx.authorize({
  684. // scope: "scope.userLocation",
  685. // success: (res) => {
  686. // console.log("authorize", res);
  687. uni.chooseLocation({
  688. success: (location) => {
  689. console.log('chooseLocation success: ', location);
  690. console.log(`经度${location.longitude},维度${location.latitude}`);
  691. console.log(location);
  692. if (location != null) {
  693. let address = that.address;
  694. address.lat = location.latitude;
  695. address.lng = location.longitude;
  696. address.addressname = location.address;
  697. that.setData({
  698. address: address,
  699. selectAddress: location.address
  700. });
  701. console.log(that.address);
  702. that.getAreaCode();
  703. }
  704. },
  705. fail: (err) => {
  706. console.log('chooseLocation fail: ' + err.errMsg);
  707. }
  708. });
  709. // },
  710. // fail: () => {
  711. // wx.openSetting({});
  712. // },
  713. // });
  714. },
  715. goMap() {
  716. console.log('gomap');
  717. app.globalData.mapSelectFinish = false;
  718. if (this.address.lng && this.address.lat) {
  719. let city = this.address.city == '市辖区' ? this.address.province : this.address.city;
  720. uni.navigateTo({
  721. url: '/pages/map/mapContent/mapContent?lng=' + this.address.lng + '&lat=' + this.address.lat + '&addressname=' + this.address.addressname + '&city=' + city
  722. });
  723. } else {
  724. uni.navigateTo({
  725. url: '/pages/map/mapContent/mapContent'
  726. });
  727. }
  728. },
  729. maleSelect() {
  730. this.setData({
  731. gender: 1
  732. });
  733. },
  734. femaleSelect() {
  735. this.setData({
  736. gender: 2
  737. });
  738. },
  739. getAreaCode() {
  740. let param = {
  741. location: this.address.lng + ',' + this.address.lat,
  742. extensions: 'all',
  743. key: api.gdKey,
  744. radius: 3000
  745. };
  746. uni.request({
  747. url: api.gdUrl,
  748. data: param,
  749. method: 'GET',
  750. header: {
  751. 'Content-Type': 'application/json'
  752. },
  753. success: (res) => {
  754. console.log(res);
  755. if (res.data.infocode == '10000') {
  756. if (res.data.info == 'OK') {
  757. let regeocode = res.data.regeocode.addressComponent;
  758. let cityName = regeocode.city == null || regeocode.city.length == 0 ? regeocode.province : regeocode.city;
  759. let district = regeocode.district == null || regeocode.district.length == 0 ? '' : regeocode.district;
  760. this.setData({
  761. ['address.areaCode']: regeocode.adcode,
  762. ['address.province']: regeocode.province,
  763. ['address.city']: cityName,
  764. ['address.county']: district
  765. // ['address.addressname']:res.data.result.address
  766. });
  767. } else {
  768. uni.showToast({
  769. title: '获取地区码失败',
  770. icon: 'none',
  771. duration: 3000
  772. });
  773. }
  774. } else {
  775. uni.showToast({
  776. title: '获取地区码失败',
  777. icon: 'none',
  778. duration: 3000
  779. });
  780. }
  781. },
  782. fail: function (err) {
  783. reject(err);
  784. }
  785. });
  786. },
  787. goWebView() {
  788. app.globalData.webAddress = null;
  789. uni.navigateTo({
  790. url: '/pages/ucenter/addressChoose/addressChoose'
  791. });
  792. }
  793. }
  794. };
  795. </script>
  796. <style>
  797. page {
  798. height: 100%;
  799. background: #f4f4f4;
  800. padding: 30rpx;
  801. }
  802. .add-address .add-form {
  803. background: #fff;
  804. width: 680rpx;
  805. height: auto;
  806. overflow: hidden;
  807. border-radius: 10rpx;
  808. }
  809. .add-address .form-item {
  810. height: 88rpx;
  811. padding-left: 30rpx;
  812. /* border-bottom: 1px solid #d9d9d9; */
  813. display: flex;
  814. align-items: center;
  815. padding-right: 28rpx;
  816. }
  817. .add-address .input {
  818. flex: 1;
  819. height: 44rpx;
  820. line-height: 44rpx;
  821. overflow: hidden;
  822. margin-top: 10rpx;
  823. }
  824. .add-address .label {
  825. font-size: 30rpx;
  826. color: #333;
  827. /* font-weight: bold; */
  828. margin-right: 28rpx;
  829. width: 126rpx;
  830. text-align: left;
  831. font-weight: 500;
  832. }
  833. .add-address .content {
  834. border-bottom: 2rpx solid #f2f2f2;
  835. height: 88rpx;
  836. line-height: 88rpx;
  837. align-content: center;
  838. /* padding: 40rpx 0 0; */
  839. width: 100%;
  840. display: flex;
  841. align-items: center;
  842. }
  843. .add-address .form-default {
  844. height: 100rpx;
  845. background: #fff;
  846. margin-top: 30rpx;
  847. border-radius: 10rpx;
  848. width: 680rpx;
  849. }
  850. .switch-wrapper {
  851. width: 680rpx;
  852. height: 100rpx;
  853. display: flex;
  854. align-items: center;
  855. justify-content: space-between;
  856. padding: 0 30rpx;
  857. }
  858. .switch-wrapper .switch {
  859. font-size: 24rpx;
  860. /* width:82rpx;
  861. height: 44rpx; */
  862. }
  863. .add-address .form-default .title {
  864. font-size: 30rpx;
  865. /* font-weight: bold; */
  866. color: #333;
  867. }
  868. .add-address .des {
  869. color: #999;
  870. line-height: 44rpx;
  871. height: 44rpx;
  872. font-size: 22rpx;
  873. padding-left: 30rpx;
  874. margin-top: 10rpx;
  875. }
  876. .add-address .form-default .van-checkbox .van-icon {
  877. color: #fff;
  878. }
  879. .add-address .btns {
  880. position: fixed;
  881. bottom: 50rpx;
  882. left: 30rpx;
  883. right: 30rpx;
  884. overflow: hidden;
  885. display: flex;
  886. height: 88rpx;
  887. /* width: 100%; */
  888. }
  889. .add-address .cannel,
  890. .add-address .save {
  891. flex: 1;
  892. height: 88rpx;
  893. text-align: center;
  894. line-height: 88rpx;
  895. font-size: 30rpx;
  896. color: #fff;
  897. border: none;
  898. border-radius: 10rpx;
  899. outline: none;
  900. position: static;
  901. }
  902. .add-address .cannel::after,
  903. .add-address .save::after {
  904. border: none;
  905. }
  906. .add-address .cannel {
  907. color: #333;
  908. margin-right: 18rpx;
  909. border: 2rpx solid #999999;
  910. border-radius: 10rpx;
  911. }
  912. .add-address .save {
  913. background: #00c0ff;
  914. }
  915. .region-select {
  916. width: 100%;
  917. height: 600rpx;
  918. background: #fff;
  919. position: fixed;
  920. z-index: 10;
  921. left: 0;
  922. bottom: 0;
  923. }
  924. .region-select .hd {
  925. height: 108rpx;
  926. width: 100%;
  927. border-bottom: 1px solid #f4f4f4;
  928. padding: 46rpx 30rpx 0 30rpx;
  929. }
  930. .region-select .region-selected {
  931. float: left;
  932. height: 60rpx;
  933. display: flex;
  934. }
  935. .region-select .region-selected .item {
  936. max-width: 140rpx;
  937. margin-right: 30rpx;
  938. text-align: left;
  939. line-height: 60rpx;
  940. height: 100%;
  941. color: #333;
  942. font-size: 28rpx;
  943. overflow: hidden;
  944. text-overflow: ellipsis;
  945. white-space: nowrap;
  946. }
  947. .region-select .region-selected .item.disabled {
  948. color: #999;
  949. }
  950. .region-select .region-selected .item.selected {
  951. color: #b4282d;
  952. }
  953. .region-select .done {
  954. float: right;
  955. height: 60rpx;
  956. width: 60rpx;
  957. border: none;
  958. background: #fff;
  959. line-height: 60rpx;
  960. text-align: center;
  961. color: #333;
  962. font-size: 28rpx;
  963. }
  964. .region-select .done.disabled {
  965. color: #999;
  966. }
  967. .region-select .bd {
  968. height: 492rpx;
  969. width: 100%;
  970. padding: 0 30rpx;
  971. }
  972. .region-select .region-list {
  973. height: 492rpx;
  974. }
  975. .region-select .region-list .item {
  976. width: 100%;
  977. height: 104rpx;
  978. line-height: 104rpx;
  979. text-align: left;
  980. color: #333;
  981. font-size: 28rpx;
  982. }
  983. .region-select .region-list .item.selected {
  984. color: #b4282d;
  985. }
  986. .bg-mask {
  987. height: 100%;
  988. width: 100%;
  989. background: rgba(0, 0, 0, 0.4);
  990. position: fixed;
  991. top: 0;
  992. left: 0;
  993. z-index: 8;
  994. }
  995. .add-address .form-item:last-child .content {
  996. border-bottom: none;
  997. }
  998. .add-address .btns.add-btn {
  999. height: 100rpx;
  1000. }
  1001. .add-address .btns.add-btn .save {
  1002. height: 100rpx;
  1003. border-radius: 100rpx;
  1004. border: none;
  1005. outline: none;
  1006. }
  1007. .add-address .btns.add-btn .save::after {
  1008. border: none;
  1009. }
  1010. .gender-wrapper image {
  1011. width: 26rpx;
  1012. height: 26rpx;
  1013. margin-right: 10rpx;
  1014. }
  1015. .gender-wrapper {
  1016. display: flex;
  1017. align-items: center;
  1018. height: 96rpx;
  1019. justify-content: space-between;
  1020. width: 220rpx;
  1021. }
  1022. .male,
  1023. .female {
  1024. display: flex;
  1025. align-items: center;
  1026. height: 96rpx;
  1027. }
  1028. /* 弹框地址超过2公里 */
  1029. .goods-info-overlay {
  1030. position: fixed;
  1031. top: 0;
  1032. left: 0;
  1033. width: 100%;
  1034. height: 100%;
  1035. background-color: rgba(0, 0, 0, 0.6);
  1036. z-index: 99;
  1037. display: flex;
  1038. align-items: center;
  1039. justify-content: center;
  1040. }
  1041. .goods-info-popup {
  1042. width: 622rpx;
  1043. border-radius: 24rpx;
  1044. background: #fff;
  1045. overflow: hidden;
  1046. }
  1047. .popup-title {
  1048. height: 94rpx;
  1049. line-height: 94rpx;
  1050. text-align: center;
  1051. color: #ffffff;
  1052. font-size: 34rpx;
  1053. background: url('https://mall.zhaijieshi.cc/file/jzmall-dy/verify-dy-title.png') no-repeat center center;
  1054. background-size: 100% 100%;
  1055. background-color: #008dff;
  1056. }
  1057. .tips-title {
  1058. height: 180rpx;
  1059. line-height: 40rpx;
  1060. padding: 34rpx 32rpx;
  1061. font-weight: 600;
  1062. color: #191919;
  1063. font-size: 28rpx;
  1064. }
  1065. .goods-info-popup .goods {
  1066. display: flex;
  1067. padding: 24rpx 20rpx 22rpx 22rpx;
  1068. }
  1069. .goods .img image {
  1070. height: 168rpx;
  1071. width: 168rpx;
  1072. overflow: hidden;
  1073. border-radius: 8rpx;
  1074. }
  1075. .goods .info {
  1076. height: 168rpx;
  1077. flex: 1;
  1078. padding-left: 18rpx;
  1079. }
  1080. .info-main {
  1081. display: flex;
  1082. height: 40rpx;
  1083. align-items: center;
  1084. justify-content: space-between;
  1085. }
  1086. .info .sku-name {
  1087. color: #666666;
  1088. font-size: 24rpx;
  1089. margin: 12rpx 0;
  1090. height: 34rpx;
  1091. line-height: 34rpx;
  1092. }
  1093. .product-name {
  1094. line-height: 40rpx;
  1095. font-size: 28rpx;
  1096. /* padding-left: 20rpx;
  1097. text-indent: -16rpx; */
  1098. overflow: hidden;
  1099. text-overflow: ellipsis;
  1100. white-space: nowrap;
  1101. width: 310rpx;
  1102. font-weight: bold;
  1103. color: rgba(0, 0, 0, 0.9);
  1104. }
  1105. .info-main .price {
  1106. color: rgba(0, 0, 0, 0.9);
  1107. font-size: 24rpx;
  1108. font-weight: bold;
  1109. }
  1110. .info .other-info {
  1111. font-size: 24rpx;
  1112. color: rgba(0, 0, 0, 0.9);
  1113. line-height: 34rpx;
  1114. }
  1115. .popup-bottom {
  1116. height: 106rpx;
  1117. padding: 14rpx 104rpx 34rpx;
  1118. display: flex;
  1119. justify-content: space-between;
  1120. }
  1121. .btn-cancel {
  1122. height: 58rpx;
  1123. line-height: 58rpx;
  1124. border-radius: 58rpx;
  1125. width: 162rpx;
  1126. text-align: center;
  1127. color: #0091ff;
  1128. font-size: 24rpx;
  1129. border: 2rpx solid #0091ff;
  1130. }
  1131. .btn-conf {
  1132. height: 58rpx;
  1133. line-height: 58rpx;
  1134. border-radius: 58rpx;
  1135. width: 162rpx;
  1136. text-align: center;
  1137. color: #fff;
  1138. font-size: 24rpx;
  1139. background: linear-gradient(270deg, #00baff 0%, #008dff 100%);
  1140. }
  1141. </style>