address_editor.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <view class="wrap">
  3. <navbar :iSimmersive="false" title-color="#ffffff" background="#1b43c4" :placeholder="true" title="编辑地址"></navbar>
  4. <view class="theForm">
  5. <form @submit="formSubmit">
  6. <view class="fields-box">
  7. <view>姓名</view>
  8. <view>
  9. <input type="text" class="uni-input" name="name" :value="name" placeholder="收货人姓名" />
  10. </view>
  11. </view>
  12. <view class="fields-box">
  13. <view>电话</view>
  14. <view>
  15. <input type="text" class="uni-input" name="tel" :value="tel" placeholder="收货人手机号" />
  16. </view>
  17. </view>
  18. <view class="fields-box">
  19. <view>地区</view>
  20. <view>
  21. <lb-picker ref="picker"
  22. v-model="area"
  23. mode="multiSelector"
  24. :list="list"
  25. :level="3"
  26. @change="handleChange"
  27. @confirm="handleConfirm"
  28. @cancel="handleCancel">
  29. </lb-picker>
  30. <input @click="handleTap('picker')" type="text" class="uni-input" :value="area_name" disabled="true" placeholder="请选择您所在地区" />
  31. </view>
  32. </view>
  33. <view class="fields-box">
  34. <view>地址</view>
  35. <view>
  36. <input type="text" class="uni-input" name="addressDetail" :value="addressDetail" placeholder="请填写您所在地址" />
  37. </view>
  38. </view>
  39. <view class="switch-box">
  40. <view>默认地址</view>
  41. <view>
  42. <switch :checked="is_default" @change="switchChange" />
  43. </view>
  44. </view>
  45. <view class="btn">
  46. <button form-type="submit">提 交</button>
  47. </view>
  48. </form>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import areaData from '@/common/area-data-min'
  54. import * as check from '@/common/check'
  55. import navbar from "@/components/navbar/navbar";
  56. export default {
  57. components: {
  58. navbar
  59. },
  60. data(){
  61. return {
  62. id: 0,
  63. name: "",
  64. tel: "",
  65. province: "",
  66. county: "",
  67. city: "",
  68. areaCode: [],
  69. addressDetail: "",
  70. is_default: false,
  71. list: areaData,
  72. area_name: '',
  73. area: [],
  74. isSelected: false
  75. };
  76. },
  77. onLoad(options) {
  78. this.id = options.id != undefined ? options.id : 0;
  79. this.isSelected = this.$storage.get("ORDER_CONFIRM_SELECT") ? true : false;
  80. },
  81. onShow() {
  82. let users = this.$storage.getJson("users");
  83. if(users == null){
  84. this.$utils.navigateTo('public/login');
  85. }else{
  86. this.$http.getAddressData({ id: this.id,client_type: "0" }).then(res=>{
  87. if(res.data.area_name != undefined){
  88. let arr = res.data.area_name.split(",");
  89. this.name = res.data.name;
  90. this.tel = res.data.tel;
  91. this.province = arr[0];
  92. this.county = arr[2];
  93. this.city = arr[1];
  94. }
  95. this.areaCode = [res.data.province,res.data.county,res.data.city];
  96. this.addressDetail = res.data.addressDetail;
  97. this.is_default = res.data.isDefault ? true : false;
  98. this.area_name = res.data.area_name;
  99. this.area = [res.data.province,res.data.county,res.data.city];
  100. });
  101. }
  102. },
  103. onBackPress(e) {
  104. this.$storage.remove("ORDER_CONFIRM_SELECT");
  105. return false;
  106. },
  107. methods:{
  108. switchChange(e){
  109. this.is_default = e.target.value;
  110. },
  111. formSubmit(e){
  112. let formdata = e.detail.value;
  113. if(formdata.name.length <= 0){
  114. this.$utils.msg("请填写用户名");
  115. return ;
  116. }
  117. if(!check.checkPhone(formdata.tel)){
  118. this.$utils.msg("您填写的手机号码不正确!");
  119. return ;
  120. }
  121. if(formdata.addressDetail.length <= 0){
  122. this.$utils.msg("请填写收货地址!");
  123. return ;
  124. }else if(formdata.addressDetail.length >= 120){
  125. this.$utils.msg("您填写的收货地址过长,请勿超过120个字符!");
  126. return ;
  127. }
  128. if(this.areaCode.length <= 0){
  129. this.$utils.msg("请选择所在地区!");
  130. return ;
  131. }
  132. let params = {
  133. id: this.id,
  134. client_type: "0",
  135. name: formdata.name,
  136. tel: formdata.tel,
  137. province: this.province,
  138. county: this.county,
  139. city: this.city,
  140. areaCode: this.areaCode,
  141. addressDetail: formdata.addressDetail,
  142. is_default: this.is_default ? 1 : 0,
  143. };
  144. this.$http.editorAddress(params).then((res)=>{
  145. if(res.status){
  146. if(this.isSelected){
  147. params.id = res.data;
  148. this.onReturnOrderAddress(params);
  149. }else{
  150. this.$utils.navigateTo("ucenter/address");
  151. }
  152. }else{
  153. this.$utils.msg(res.info);
  154. }
  155. });
  156. },
  157. onReturnOrderAddress(data){
  158. this.$utils.prePage().address = {
  159. id: data.id,
  160. name: data.name,
  161. tel: data.tel,
  162. address: data.addressDetail
  163. };
  164. this.$utils.prePage().params.address_id = data.id;
  165. this.$utils.prePage().chosenAddressId = data.id;
  166. this.$utils.prePage().isAddressStatus = false;
  167. this.$storage.remove("ORDER_CONFIRM_SELECT");
  168. this.$utils.navigateBack();
  169. },
  170. handleTap (picker) {
  171. this.$refs[picker].show()
  172. },
  173. handleChange (item) {
  174. //console.log('change::', item)
  175. },
  176. handleConfirm (data) {
  177. // this.province = data.value[0];
  178. // this.county = data.value[1];
  179. // this.city = data.value[2] != undefined ? data.value[2] : 0;
  180. let arr = [];
  181. for(let i in data.item){
  182. arr.push(data.item[i].label);
  183. }
  184. // console.log(arr);
  185. this.province = arr[0];
  186. this.city = arr[1];
  187. this.county = arr[2] != undefined ? arr[2] : 0;
  188. if(arr.length > 0){
  189. this.area_name = arr.join(",");
  190. }
  191. this.areaCode = data.value;
  192. },
  193. handleCancel (item) {
  194. //console.log('cancel::', item)
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .wrap{
  201. width: 100%;
  202. height: 100vh;
  203. background-color: #fff;
  204. }
  205. .theForm{
  206. width: 650rpx;
  207. padding-top: 50rpx;
  208. margin: 0 auto;
  209. .fields-box{
  210. width: 100%;
  211. float: left;
  212. font-size: 31rpx;
  213. height: 110rpx;
  214. line-height: 110rpx;
  215. border: 2rpx solid #e0e0e0;
  216. border-left: 0;
  217. border-right: 0;
  218. &:nth-child(1){
  219. border-top: 0;
  220. border-bottom: 0;
  221. }
  222. &:nth-child(2){
  223. border-bottom: 0;
  224. }
  225. &:nth-child(3){
  226. border-bottom: 0;
  227. }
  228. view:first-child {
  229. float: left;
  230. width: 160rpx;
  231. color: #999;
  232. }
  233. view:last-child {
  234. float: right;
  235. width: 490rpx;
  236. color: #333;
  237. input {
  238. height: 110rpx;
  239. line-height: 110rpx;
  240. }
  241. }
  242. }
  243. .switch-box{
  244. background-color: #fff;
  245. width: 100%;
  246. float: left;
  247. font-size: 31rpx;
  248. height: 110rpx;
  249. line-height: 110rpx;
  250. view:first-child {
  251. float: left;
  252. color: #999;
  253. }
  254. view:last-child {
  255. float: right;
  256. }
  257. }
  258. .btn{
  259. float: left;
  260. margin: 25rpx 0;
  261. button {
  262. width: 650rpx;
  263. height: 100rpx;
  264. line-height: 100rpx;
  265. text-align: center;
  266. background-color: #1b43c4;
  267. border: 1px solid #1b43c4;
  268. color: #fff;
  269. font-size: 33rpx;
  270. }
  271. }
  272. }
  273. </style>