index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <!-- 编辑/添加地址 -->
  3. <view class="add-address-container">
  4. <JHeader width="50" height="50" title="地址管理" style="padding: 24upx 0;"></JHeader>
  5. <view class="addressBack-box">
  6. <view class="consignee-box bor-line-F7F7F7">
  7. <input
  8. v-model="addressData.username" maxlength="20" class="fs28" placeholder-class="consignee"
  9. placeholder="收货人"
  10. />
  11. </view>
  12. <view class="iphoneNum-box bor-line-F7F7F7">
  13. <input
  14. v-model="addressData.phone" type="number" maxlength="11" class="fs28"
  15. placeholder-class="iphoneNum"
  16. placeholder="手机号码"
  17. />
  18. </view>
  19. <view class="location-box bor-line-F7F7F7 flex-row-plus flex-sp-between flex-items" @click="locationClick">
  20. <view class="fs28 location">所在地</view>
  21. <view class="locationBox">
  22. <JCity :text="addressData.ssqText" placeholder="请选择所在地" @confirm="cityChange"></JCity>
  23. <tui-icon :size="31" color="#999999" name="arrowright" margin="0 0 0 20upx"></tui-icon>
  24. </view>
  25. </view>
  26. <view class="detailAddress-box">
  27. <input
  28. v-model="addressData.address" class="fs28" maxlength="60" placeholder-class="detailAddress"
  29. placeholder="详细地址:如道路、门牌号、小区、楼栋号、单元等"
  30. />
  31. </view>
  32. </view>
  33. <view class="addressTagBack-box">
  34. <view class="addressTag-box bor-line-F7F7F7 flex-row-plus flex-sp-between flex-items" @click="addressTagClick">
  35. <view class="fs28 addressTag">地址标签</view>
  36. <view class="flex-items">
  37. <text v-model="tag">{{ tag }}</text>
  38. <tui-icon :size="31" color="#999999" name="arrowright" margin="0 0 0 20upx"></tui-icon>
  39. </view>
  40. </view>
  41. <view class="defaultState-box flex-row-plus flex-sp-between flex-items">
  42. <view class="fs28 defaultState">设为默认地址</view>
  43. <tui-switch
  44. :scale-ratio="0.6" color="#C5AA7B"
  45. :checked="!!ifDefault" @change="(e) => ifDefault = Number(e.value)"
  46. ></tui-switch>
  47. </view>
  48. </view>
  49. <view v-if="type == 2" class="deleteAddress-box" @click="delAddress">
  50. <text class="font-color-C5AA7B">删除收货地址</text>
  51. </view>
  52. <view class="saveAddress-box">
  53. <view v-if="type == 1 || type == 3" class="saveAddress" @click="addAddressClick">保存</view>
  54. <view v-else class="saveAddress" @click="saveAddressClick">保存</view>
  55. </view>
  56. <tui-picker
  57. :show="addressTagShowFalg" :picker-data="addressTagList" :value="[ tag ]"
  58. @hide="addressTagShowFalg = false" @change="(e) => tag = e.text"
  59. >
  60. </tui-picker>
  61. </view>
  62. </template>
  63. <script>
  64. import { T_RECEIVE_ITEM } from '../../../constant'
  65. import { getReceiveAddressByIdApi, updateReceiveAddressApi, addReceiveAddressApi, deleteReceiveAddressApi } from '../../../api/anotherTFInterface'
  66. export default {
  67. name: 'AddAddress',
  68. data() {
  69. return {
  70. show: false,
  71. type: 1, // 1.添加新地址 2.编辑收货地址
  72. locationShowFalg: false,
  73. locationList: [],
  74. locationName: '',
  75. provinceName: '',
  76. cityName: '',
  77. districtName: '',
  78. addressTagList: [
  79. {
  80. value: '1',
  81. text: '家'
  82. },
  83. {
  84. value: '2',
  85. text: '公司'
  86. },
  87. {
  88. value: '3',
  89. text: '学校'
  90. }
  91. ],
  92. addressTagShowFalg: false,
  93. areaList: [],
  94. username: '',
  95. phone: '',
  96. ssqText: '',
  97. address: '',
  98. tag: '',
  99. ifDefault: 0,
  100. province: '',
  101. city: '',
  102. area: '',
  103. id: '',
  104. ordertype: 0,
  105. editAddress: {},
  106. // defaultRegion: [],
  107. addressData: {
  108. username: '',
  109. phone: '',
  110. ssqText: '',
  111. address: '',
  112. defaultRegion: [],
  113. city: '',
  114. province: ''
  115. }
  116. }
  117. },
  118. onLoad(options) {
  119. this.type = options.type
  120. if (options.ordertype == 1) {
  121. this.ordertype = 1
  122. }
  123. const receiveId = options.receiveId
  124. this.id = receiveId
  125. if (this.type == 2) {
  126. // uni.showLoading({
  127. // mask: true,
  128. // title: '请稍后...',
  129. // })
  130. getReceiveAddressByIdApi({ receiveId }).then((res) => {
  131. this.editAddress = res.data
  132. this.addressData.username = this.editAddress.receiveName
  133. this.addressData.phone = this.editAddress.receivePhone
  134. this.addressData.ssqText = this.editAddress.receiveAdress
  135. this.addressData.address = this.editAddress.address
  136. this.tag = this.editAddress.label
  137. this.ifDefault = this.editAddress.ifDefault
  138. this.addressData.defaultRegion = this.addressData.ssqText.split('-')
  139. this.addressData.province = this.addressData.defaultRegion[0]
  140. this.addressData.city = this.addressData.defaultRegion[1]
  141. this.addressData.area = this.addressData.defaultRegion[2]
  142. this.addressData.id = this.editAddress.receiveId
  143. uni.hideLoading()
  144. })
  145. }
  146. if (this.type == 3) {
  147. const obj = JSON.parse(options.wxAddressData)
  148. this.addressData = obj
  149. // this.username = obj.username
  150. // this.phone = obj.phone
  151. // this.ssqText = obj.ssqText
  152. // this.defaultRegion = obj.defaultRegion
  153. // this.address = obj.address
  154. // this.province = obj.provinceName
  155. // this.city = obj.cityName
  156. }
  157. },
  158. methods: {
  159. cityChange(e) {
  160. this.addressData.ssqText = e.province.text + '-' + e.city.text + '-' + e.county.text
  161. this.addressData.province = e.province.text
  162. this.addressData.city = e.city.text
  163. this.addressData.area = e.county.text
  164. },
  165. locationClick() {
  166. this.locationShowFalg = true
  167. },
  168. locationConfirm(e) {
  169. this.provinceName = e[0].label
  170. this.cityName = e[1].label
  171. this.districtName = e[2].label
  172. this.locationDot = '·'
  173. },
  174. addressTagClick() {
  175. this.addressTagShowFalg = true
  176. },
  177. // 编辑地址
  178. saveAddressClick() {
  179. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  180. if (this.addressData.username == '') {
  181. uni.showToast({
  182. title: '请输入收货人!',
  183. duration: 2000,
  184. icon: 'none'
  185. })
  186. } else if (this.addressData.phone == '') {
  187. uni.showToast({
  188. title: '请输入手机号!',
  189. duration: 2000,
  190. icon: 'none'
  191. })
  192. } else if (!phoneCodeVerification.test(this.addressData.phone)) {
  193. uni.showToast({
  194. title: '请输入正确的手机号!',
  195. duration: 2000,
  196. icon: 'none'
  197. })
  198. } else if (this.addressData.province == '' || this.addressData.city == '') {
  199. uni.showToast({
  200. title: '所在地不能为空!',
  201. duration: 2000,
  202. icon: 'none'
  203. })
  204. } else if (this.addressData.address == '') {
  205. uni.showToast({
  206. title: '请输入详细地址!',
  207. duration: 2000,
  208. icon: 'none'
  209. })
  210. } else {
  211. updateReceiveAddressApi({
  212. receiveId: this.id,
  213. receiveName: this.addressData.username,
  214. receivePhone: this.addressData.phone,
  215. receiveAdress: this.addressData.ssqText,
  216. address: this.addressData.address,
  217. label: this.tag,
  218. ifDefault: this.ifDefault ? 1 : 0
  219. }).then((res) => {
  220. uni.navigateBack({
  221. delta: 1
  222. })
  223. })
  224. }
  225. },
  226. // 新增地址
  227. addAddressClick() {
  228. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  229. if (this.addressData.username == '') {
  230. uni.showToast({
  231. title: '请输入收货人!',
  232. duration: 2000,
  233. icon: 'none'
  234. })
  235. } else if (this.addressData.phone == '') {
  236. uni.showToast({
  237. title: '请输入手机号!',
  238. duration: 2000,
  239. icon: 'none'
  240. })
  241. } else if (!phoneCodeVerification.test(this.addressData.phone)) {
  242. uni.showToast({
  243. title: '请输入正确的手机号!',
  244. duration: 2000,
  245. icon: 'none'
  246. })
  247. } else if (this.addressData.province == '' || this.addressData.city == '') {
  248. uni.showToast({
  249. title: '所在地不能为空!',
  250. duration: 2000,
  251. icon: 'none'
  252. })
  253. } else if (this.addressData.address == '') {
  254. uni.showToast({
  255. title: '请输入详细地址!',
  256. duration: 2000,
  257. icon: 'none'
  258. })
  259. } else {
  260. addReceiveAddressApi({
  261. receiveName: this.addressData.username,
  262. receivePhone: this.addressData.phone,
  263. receiveAdress: this.addressData.ssqText,
  264. address: this.addressData.address,
  265. label: this.tag,
  266. ifDefault: this.ifDefault ? 1 : 0
  267. }).then((res) => {
  268. if (this.ordertype == 1) {
  269. uni.setStorageSync(T_RECEIVE_ITEM, res.data)
  270. uni.navigateBack({
  271. delta: 2
  272. })
  273. } else {
  274. uni.navigateBack({
  275. delta: 1
  276. })
  277. }
  278. })
  279. }
  280. },
  281. // 删除地址
  282. delAddress() {
  283. uni.showModal({
  284. title: '温馨提示',
  285. content: '是否删除此地址?',
  286. confirmText: '确定',
  287. cancelText: '取消',
  288. success: (res) => {
  289. if (res.confirm) {
  290. this.subm()
  291. }
  292. }
  293. })
  294. },
  295. subm() {
  296. deleteReceiveAddressApi({
  297. receiveId: this.id
  298. }).then((res) => {
  299. if (res.code === '200') {
  300. uni.navigateBack({
  301. delta: 1
  302. })
  303. }
  304. })
  305. }
  306. }
  307. }
  308. </script>
  309. <style lang="scss" scoped>
  310. .add-address-container {
  311. background-color: #F7F7F7;
  312. min-height: 100vh;
  313. box-sizing: border-box;
  314. .addressBack-box {
  315. background-color: #FFFFFF;
  316. padding: 30upx 30upx;
  317. .consignee-box {
  318. padding-bottom: 36upx;
  319. width: 690upx;
  320. margin-top: 20upx;
  321. .consignee {
  322. color: #999999;
  323. font-size: 28upx;
  324. }
  325. }
  326. .iphoneNum-box {
  327. padding-bottom: 36upx;
  328. width: 690upx;
  329. margin-top: 36upx;
  330. .iphoneNum {
  331. color: #999999;
  332. font-size: 28upx;
  333. }
  334. }
  335. .location-box {
  336. padding-bottom: 36upx;
  337. width: 690upx;
  338. margin-top: 36upx;
  339. .location {
  340. color: #999999;
  341. font-size: 28upx;
  342. }
  343. .locationBox {
  344. display: flex;
  345. align-items: center;
  346. }
  347. }
  348. .detailAddress-box {
  349. padding-bottom: 36upx;
  350. width: 690upx;
  351. margin-top: 36upx;
  352. input {
  353. width: 100%;
  354. }
  355. .detailAddress {
  356. color: #999999;
  357. font-size: 28upx;
  358. }
  359. }
  360. }
  361. .addressTagBack-box {
  362. background-color: #FFFFFF;
  363. padding: 30upx 30upx;
  364. margin-top: 20upx;
  365. .addressTag-box {
  366. padding-bottom: 36upx;
  367. width: 690upx;
  368. .addressTag {
  369. color: #999999;
  370. font-size: 28upx;
  371. }
  372. }
  373. .defaultState-box {
  374. padding-bottom: 10upx;
  375. width: 690upx;
  376. margin-top: 36upx;
  377. .defaultState {
  378. color: #999999;
  379. font-size: 28upx;
  380. }
  381. }
  382. }
  383. .saveAddress-box {
  384. position: fixed;
  385. bottom: 50upx;
  386. left: 30upx;
  387. .saveAddress {
  388. width: 690upx;
  389. height: 100upx;
  390. text-align: center;
  391. line-height: 100upx;
  392. background: #333333;
  393. color: #FFEBC4;
  394. }
  395. }
  396. .wxAddress {
  397. height: 80rpx;
  398. text-align: center;
  399. line-height: 80rpx;
  400. color: #999999;
  401. .wxBtnBox {
  402. width: 100rpx;
  403. height: 80rpx;
  404. image {
  405. width: 80rpx;
  406. height: 80rpx;
  407. }
  408. }
  409. }
  410. }
  411. .deleteAddress-box {
  412. background-color: #FFFFFF;
  413. padding: 30upx 30upx;
  414. margin-top: 20upx;
  415. }
  416. </style>