You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
6.0 KiB

6 months ago
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="row">
  5. <view class="nominal">
  6. 收件人
  7. </view>
  8. <view class="input">
  9. <input placeholder="请输入收件人姓名" type="text" v-model="name" />
  10. </view>
  11. </view>
  12. <view class="row">
  13. <view class="nominal">
  14. 电话号码
  15. </view>
  16. <view class="input">
  17. <input placeholder="请输入收件人电话号码" type="text" v-model="tel" />
  18. </view>
  19. </view>
  20. <view class="row">
  21. <view class="nominal">
  22. 所在地区
  23. </view>
  24. <view class="input" @tap="chooseCity">
  25. {{region.label}}
  26. </view>
  27. </view>
  28. <view class="row">
  29. <view class="nominal">
  30. 详细地址
  31. </view>
  32. <view class="input">
  33. <textarea v-model="detailed" auto-height="true" placeholder="输入详细地址"></textarea>
  34. </view>
  35. </view>
  36. <!-- <view class="row">
  37. <view class="nominal">
  38. 设置默认地址
  39. </view>
  40. <view class="input switch">
  41. <switch color="#f06c7a" :checked="isDefault" @change=isDefaultChange />
  42. </view>
  43. </view> -->
  44. <!-- <view class="row" v-if="editType=='edit'" @tap="del">
  45. <view class="del">
  46. 删除收货地址
  47. </view>
  48. </view> -->
  49. </view>
  50. <view class="save" @tap="save">
  51. <view class="btn">
  52. 保存地址
  53. </view>
  54. </view>
  55. <mpvue-city-picker :themeColor="themeColor" ref="mpvueCityPicker" :pickerValueDefault="cityPickerValue" @onCancel="onCancel" @onConfirm="onConfirm"></mpvue-city-picker>
  56. </view>
  57. </template>
  58. <script>
  59. import mpvueCityPicker from '@/components/mpvue-citypicker/mpvueCityPicker.vue'
  60. export default {
  61. components: {
  62. mpvueCityPicker
  63. },
  64. data() {
  65. return {
  66. editType:'edit',
  67. id:'',
  68. name:'',
  69. tel:'',
  70. detailed:'',
  71. isDefault:false,
  72. cityPickerValue: [0, 0, 1],
  73. themeColor: '#007AFF',
  74. region:{label:"请点击选择地址",value:[],cityCode:""}
  75. };
  76. },
  77. methods: {
  78. onCancel(e) {
  79. console.log(e)
  80. },
  81. chooseCity() {
  82. this.$refs.mpvueCityPicker.show()
  83. },
  84. onConfirm(e) {
  85. this.region = e;
  86. this.cityPickerValue = e.value;
  87. },
  88. isDefaultChange(e){
  89. this.isDefault = e.detail.value;
  90. },
  91. async savaeditaddress() {
  92. let userinfo=uni.getStorageSync('userinfo');
  93. let re = await this.$api.editaddress({action:'editaddress',uid:userinfo.uid,username:this.name,tel:this.tel,address:this.region.label+'--'+this.detailed,addresscode:this.region.value});
  94. if(re.code==1){
  95. userinfo.name=this.name;
  96. userinfo.address=this.region.label;
  97. userinfo.detail=this.detailed;
  98. userinfo.tel=this.tel;
  99. userinfo.addresscode=this.region.value
  100. uni.setStorage({
  101. key:'userinfo',
  102. data:userinfo,
  103. success() {
  104. uni.hideLoading();
  105. uni.navigateBack();
  106. }
  107. })
  108. }
  109. uni.hideLoading();
  110. },
  111. del(){
  112. uni.showModal({
  113. title: '删除提示',
  114. content: '你将删除这个收货地址',
  115. success: (res)=>{
  116. if (res.confirm) {
  117. uni.setStorage({
  118. key:'delAddress',
  119. data:{id:this.id},
  120. success() {
  121. uni.navigateBack();
  122. }
  123. })
  124. } else if (res.cancel) {
  125. console.log('用户点击取消');
  126. }
  127. }
  128. });
  129. },
  130. save(){
  131. let data={"name":this.name,"head":this.name.substr(0,1),"tel":this.tel,"address":{"region":this.region,"detailed":this.detailed},"isDefault":this.isDefault}
  132. if(this.editType=='edit'){
  133. data.id = this.id
  134. }
  135. if(!data.name){
  136. uni.showToast({title:'请输入收件人姓名',icon:'none'});
  137. return ;
  138. }
  139. if(!data.tel){
  140. uni.showToast({title:'请输入收件人电话号码',icon:'none'});
  141. return ;
  142. }
  143. if(!data.address.detailed){
  144. uni.showToast({title:'请输入收件人详细地址',icon:'none'});
  145. return ;
  146. }
  147. if(data.address.region.value.length==0){
  148. uni.showToast({title:'请选择收件地址',icon:'none'});
  149. return ;
  150. }
  151. uni.showLoading({
  152. title:'正在提交'
  153. })
  154. this.savaeditaddress();
  155. //实际应用中请提交ajax,模板定时器模拟提交效果
  156. // setTimeout(()=>{
  157. // },300)
  158. }
  159. },
  160. onLoad(e) {
  161. //获取传递过来的参数
  162. this.editType = e.type;
  163. if(e.type=='edit'){
  164. uni.getStorage({
  165. key:'address',
  166. success: (e) => {
  167. this.id = e.data.id;
  168. this.name = e.data.name;
  169. this.tel = e.data.tel;
  170. this.detailed = e.data.detail;
  171. this.cityPickerValue = [e.data.addresscode];
  172. this.region = {label:e.data.address,value:[e.data.addresscode],cityCode:""};
  173. }
  174. })
  175. }
  176. },
  177. onBackPress() {
  178. if (this.$refs.mpvueCityPicker.showPicker) {
  179. this.$refs.mpvueCityPicker.pickerCancel();
  180. return true;
  181. }
  182. },
  183. onUnload() {
  184. if (this.$refs.mpvueCityPicker.showPicker) {
  185. this.$refs.mpvueCityPicker.pickerCancel()
  186. }
  187. }
  188. };
  189. </script>
  190. <style lang="scss">
  191. .save{
  192. view{
  193. display: flex;
  194. }
  195. position: fixed;
  196. bottom: 0;
  197. width: 100%;
  198. height: 120upx;
  199. display: flex;
  200. justify-content: center;
  201. align-items: center;
  202. .btn{
  203. box-shadow: 0upx 5upx 10upx rgba(0,0,0,0.4);
  204. width: 70%;
  205. height: 80upx;
  206. border-radius: 80upx;
  207. background-color: #f06c7a;
  208. color: #fff;
  209. justify-content: center;
  210. align-items: center;
  211. .icon{
  212. height: 80upx;
  213. color: #fff;
  214. font-size: 30upx;
  215. justify-content: center;
  216. align-items: center;
  217. }
  218. font-size: 30upx;
  219. }
  220. }
  221. .content{
  222. display: flex;
  223. flex-wrap: wrap;
  224. view{
  225. display: flex;
  226. }
  227. .row{
  228. width: 94%;
  229. margin: 0 3%;
  230. border-top: solid 1upx #eee;
  231. .nominal{
  232. width: 30%;
  233. height: 120upx;
  234. font-weight: 200;
  235. font-size: 30upx;
  236. align-items: center;
  237. }
  238. .input{
  239. width: 70%;
  240. padding: 20upx 0;
  241. align-items: center;
  242. font-size: 30upx;
  243. &.switch{
  244. justify-content: flex-end;
  245. }
  246. .textarea{
  247. margin: 20upx 0;
  248. min-height: 120upx;
  249. }
  250. }
  251. .del{
  252. width: 100%;
  253. height: 100upx;
  254. justify-content: center;
  255. align-items: center;
  256. font-size: 36upx;
  257. color: #f06c7a;
  258. background-color: rgba(255,0,0,0.05);
  259. border-bottom: solid 1upx #eee;
  260. }
  261. }
  262. }
  263. </style>