球星卡微信小程序
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.

246 lines
6.1 KiB

  1. <template>
  2. <view class="flex-col page">
  3. <view class="flex-col group_4">
  4. <view class="flex-col section_2">
  5. <view class="top-group flex-row">
  6. <text class="text_2 lf-m-r-18">收货人</text>
  7. <u-input class="input" v-model="address.name" placeholder="请填写收货人姓名" border="surround" :clearable="true" ></u-input>
  8. </view>
  9. <view class="top-group flex-row">
  10. <text class="text_4 lf-m-r-18">手机号码</text>
  11. <u-input class="input" v-model="address.phone" placeholder="请填写收货人手机号码" border="surround" maxlength="11" :clearable="true" ></u-input>
  12. </view>
  13. <view class="flex-col group_5">
  14. <picker mode="region" :value="address.region" @change="pickerChnage">
  15. <view class="top-group justify-between">
  16. <view class="flex-row">
  17. <text class="text_6 lf-m-r-18">所在地区</text>
  18. <text class="text_7" :class="{'black-color': regionNotEmpty}">{{ address.region.length > 0 ? address.region.join(',') : '请选择所在地区' }}</text>
  19. </view>
  20. <image
  21. src="https://project-user-resource-1256085488.cos.ap-guangzhou.myqcloud.com/62677e395a7e3f03107ffc5f/62677e4a35a7e10011e93a80/16509497893779891395.png"
  22. class="image_6"
  23. />
  24. </view>
  25. </picker>
  26. <view class="flex-row group_7" style="align-items: flex-start;">
  27. <text class="text_8 lf-m-r-18 lf-m-t-12">详细地址</text>
  28. <u-textarea v-model="address.desc" placeholder="请填写详细地址:如道路、门牌号、楼栋号、单元室等" ></u-textarea>
  29. </view>
  30. </view>
  31. <view class="top-group flex-row">
  32. <text class="text_4 lf-m-r-18">默认地址</text>
  33. <u-switch v-model="address.default" style="margin-left: 18rpx;" activeColor="#e7a23f"></u-switch>
  34. </view>
  35. </view>
  36. <view class="flex-col group_8">
  37. <view class="flex-col items-center button" @click="save">
  38. <text>保存</text>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import { addNewAddress, addressDetail } from '@/service/address.js';
  46. export default {
  47. data() {
  48. return {
  49. id: null,
  50. address: {
  51. name: '',
  52. phone: '',
  53. region: [],
  54. regionCode: '',
  55. desc: '',
  56. default: false
  57. }
  58. };
  59. },
  60. computed: {
  61. regionNotEmpty(){
  62. return this.address.region.length > 0;
  63. }
  64. },
  65. onLoad(options){
  66. this.id = options.id || null;
  67. this.id && this.getAddressDetail();
  68. },
  69. onReady(){
  70. let title = '新增收货地址';
  71. if(this.id){
  72. title = '编辑收货地址';
  73. }
  74. uni.setNavigationBarTitle({
  75. title: title
  76. })
  77. },
  78. methods: {
  79. // 编辑进入,根据地址id查询后做修改
  80. async getAddressDetail(){
  81. let res = await addressDetail(this.id);
  82. let details = res.data.datas;
  83. this.address = {
  84. name: details.name,
  85. phone: details.tel,
  86. region: details.area_name.split(','),
  87. regionCode: details.area_id,
  88. desc: details.desc,
  89. default: Boolean(details.default)
  90. }
  91. },
  92. pickerChnage(event){
  93. console.log(event);
  94. this.address.region = event.detail.value;
  95. this.address.regionCode = event.detail.code.splice(2).join();
  96. },
  97. // 新增/编辑 保存
  98. save(){
  99. console.log(this.address)
  100. let address = this.address;
  101. if(!address.name) return this.$msg('请填写收货人');
  102. if(!address.phone) return this.$msg('请填写手机号');
  103. if(address.region.length === 0) return this.$msg('请选择地区');
  104. if(!address.desc) return this.$msg('请填写详细信息');
  105. let data = {
  106. tel: address.phone,
  107. name: address.name,
  108. desc: address.desc,
  109. default: Number(address.default),
  110. area_id: address.regionCode
  111. }
  112. if(this.id){ // 编辑地址,多传入原地址id
  113. data.addr_id = this.id;
  114. }
  115. addNewAddress(data).then(res => {
  116. console.log(res);
  117. this.$msg('操作成功', {icon: 'success'}).then(() => {
  118. this.$toBack();
  119. })
  120. });
  121. }
  122. }
  123. };
  124. </script>
  125. <style scoped lang="css">
  126. .top-group {
  127. padding: 40rpx 0 38rpx;
  128. border-bottom: solid 2rpx rgb(239, 239, 239);
  129. }
  130. .page {
  131. background-color: #f6f6f6;
  132. width: 100%;
  133. overflow-y: auto;
  134. height: 100%;
  135. }
  136. .group_4 {
  137. padding-top: 2rpx;
  138. flex: 1 1 auto;
  139. overflow-y: auto;
  140. }
  141. .section_2 {
  142. padding: 0 32rpx;
  143. background-color: rgb(255, 255, 255);
  144. }
  145. .group_8 {
  146. margin-top: 64rpx;
  147. padding: 16rpx 32rpx;
  148. color: rgb(231, 162, 63);
  149. font-size: 32rpx;
  150. font-weight: 600;
  151. line-height: 44rpx;
  152. white-space: nowrap;
  153. }
  154. .group_5 {
  155. padding-top: 2rpx;
  156. }
  157. .button {
  158. padding: 24rpx 0;
  159. border-radius: 10rpx;
  160. border: solid 2rpx rgb(231, 162, 63);
  161. }
  162. .text_2 {
  163. color: rgb(51, 51, 51);
  164. font-size: 32rpx;
  165. font-weight: 500;
  166. line-height: 44rpx;
  167. white-space: nowrap;
  168. width: 140rpx;
  169. }
  170. .text_3 {
  171. margin-left: 72rpx;
  172. color: rgb(195, 195, 195);
  173. font-size: 32rpx;
  174. line-height: 44rpx;
  175. white-space: nowrap;
  176. }
  177. .text_4 {
  178. color: rgb(51, 51, 51);
  179. font-size: 32rpx;
  180. font-weight: 500;
  181. line-height: 44rpx;
  182. white-space: nowrap;
  183. width: 140rpx;
  184. }
  185. .text_5 {
  186. margin-left: 40rpx;
  187. color: rgb(195, 195, 195);
  188. font-size: 32rpx;
  189. line-height: 44rpx;
  190. white-space: nowrap;
  191. }
  192. .group_7 {
  193. margin-right: 6rpx;
  194. padding: 40rpx 0;
  195. }
  196. .image_6 {
  197. width: 44rpx;
  198. height: 44rpx;
  199. }
  200. .text_8 {
  201. color: rgb(51, 51, 51);
  202. font-size: 32rpx;
  203. font-weight: 500;
  204. line-height: 44rpx;
  205. white-space: nowrap;
  206. width: 140rpx;
  207. }
  208. .text_9 {
  209. margin-left: 40rpx;
  210. flex: 1 1 auto;
  211. color: rgb(195, 195, 195);
  212. font-size: 32rpx;
  213. line-height: 44rpx;
  214. text-align: left;
  215. }
  216. .text_6 {
  217. color: rgb(51, 51, 51);
  218. font-size: 32rpx;
  219. font-weight: 500;
  220. line-height: 44rpx;
  221. white-space: nowrap;
  222. width: 140rpx;
  223. }
  224. .text_7 {
  225. margin-left: 18rpx;
  226. color: rgb(195, 195, 195);
  227. font-size: 28rpx;
  228. line-height: 44rpx;
  229. white-space: nowrap;
  230. max-width: 440rpx;
  231. overflow:hidden;
  232. text-overflow:ellipsis;
  233. }
  234. .flex-row{
  235. display: flex;
  236. align-items: center;
  237. }
  238. .black-color{
  239. color: #303133 !important;
  240. }
  241. </style>