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

241 lines
5.9 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 } from '@/service/address.js';
  46. export default {
  47. data() {
  48. return {
  49. id: null,
  50. address: {
  51. name: '',
  52. phone: '',
  53. region: [],
  54. desc: '',
  55. default: true
  56. }
  57. };
  58. },
  59. computed: {
  60. regionNotEmpty(){
  61. return this.address.region.length > 0;
  62. }
  63. },
  64. onLoad(options){
  65. this.id = options.id || null;
  66. this.id && this.getAddressDetail();
  67. },
  68. onReady(){
  69. let title = '新增收货地址';
  70. if(this.id){
  71. title = '编辑收货地址';
  72. }
  73. uni.setNavigationBarTitle({
  74. title: title
  75. })
  76. },
  77. methods: {
  78. // 编辑进入,根据地址id查询后做修改 todo
  79. getAddressDetail(){
  80. this.address = {
  81. name: '邓平艺',
  82. phone: '1878455554',
  83. region: ['北京市','北京市','东城区'],
  84. desc: '北京北京市海淀区钻石大厦C座',
  85. default: false
  86. }
  87. },
  88. pickerChnage(event){
  89. console.log(event);
  90. this.address.region = event.detail.value;
  91. },
  92. // 新增/编辑 保存
  93. save(){
  94. console.log(this.address)
  95. let address = this.address;
  96. if(!address.name) return this.$msg('请填写收货人');
  97. if(!address.phone) return this.$msg('请填写手机号');
  98. if(address.region.length === 0) return this.$msg('请选择地区');
  99. if(!address.desc) return this.$msg('请填写详细信息');
  100. let data = {
  101. tel: address.phone,
  102. name: address.name,
  103. desc: address.desc,
  104. default: Number(address.default),
  105. area_id: '' // todo 地区id ???
  106. }
  107. if(this.id){ // 编辑地址,多传入原地址id
  108. data.addr_id = this.id;
  109. }
  110. addNewAddress(data).then(res => {
  111. console.log(res);
  112. this.$msg('操作成功', {icon: 'success'}).then(() => {
  113. this.$toBack();
  114. })
  115. });
  116. }
  117. }
  118. };
  119. </script>
  120. <style scoped lang="css">
  121. .top-group {
  122. padding: 40rpx 0 38rpx;
  123. border-bottom: solid 2rpx rgb(239, 239, 239);
  124. }
  125. .page {
  126. background-color: #f6f6f6;
  127. width: 100%;
  128. overflow-y: auto;
  129. height: 100%;
  130. }
  131. .group_4 {
  132. padding-top: 2rpx;
  133. flex: 1 1 auto;
  134. overflow-y: auto;
  135. }
  136. .section_2 {
  137. padding: 0 32rpx;
  138. background-color: rgb(255, 255, 255);
  139. }
  140. .group_8 {
  141. margin-top: 64rpx;
  142. padding: 16rpx 32rpx;
  143. color: rgb(231, 162, 63);
  144. font-size: 32rpx;
  145. font-weight: 600;
  146. line-height: 44rpx;
  147. white-space: nowrap;
  148. }
  149. .group_5 {
  150. padding-top: 2rpx;
  151. }
  152. .button {
  153. padding: 24rpx 0;
  154. border-radius: 10rpx;
  155. border: solid 2rpx rgb(231, 162, 63);
  156. }
  157. .text_2 {
  158. color: rgb(51, 51, 51);
  159. font-size: 32rpx;
  160. font-weight: 500;
  161. line-height: 44rpx;
  162. white-space: nowrap;
  163. width: 140rpx;
  164. }
  165. .text_3 {
  166. margin-left: 72rpx;
  167. color: rgb(195, 195, 195);
  168. font-size: 32rpx;
  169. line-height: 44rpx;
  170. white-space: nowrap;
  171. }
  172. .text_4 {
  173. color: rgb(51, 51, 51);
  174. font-size: 32rpx;
  175. font-weight: 500;
  176. line-height: 44rpx;
  177. white-space: nowrap;
  178. width: 140rpx;
  179. }
  180. .text_5 {
  181. margin-left: 40rpx;
  182. color: rgb(195, 195, 195);
  183. font-size: 32rpx;
  184. line-height: 44rpx;
  185. white-space: nowrap;
  186. }
  187. .group_7 {
  188. margin-right: 6rpx;
  189. padding: 40rpx 0;
  190. }
  191. .image_6 {
  192. width: 44rpx;
  193. height: 44rpx;
  194. }
  195. .text_8 {
  196. color: rgb(51, 51, 51);
  197. font-size: 32rpx;
  198. font-weight: 500;
  199. line-height: 44rpx;
  200. white-space: nowrap;
  201. width: 140rpx;
  202. }
  203. .text_9 {
  204. margin-left: 40rpx;
  205. flex: 1 1 auto;
  206. color: rgb(195, 195, 195);
  207. font-size: 32rpx;
  208. line-height: 44rpx;
  209. text-align: left;
  210. }
  211. .text_6 {
  212. color: rgb(51, 51, 51);
  213. font-size: 32rpx;
  214. font-weight: 500;
  215. line-height: 44rpx;
  216. white-space: nowrap;
  217. width: 140rpx;
  218. }
  219. .text_7 {
  220. margin-left: 18rpx;
  221. color: rgb(195, 195, 195);
  222. font-size: 28rpx;
  223. line-height: 44rpx;
  224. white-space: nowrap;
  225. max-width: 440rpx;
  226. overflow:hidden;
  227. text-overflow:ellipsis;
  228. }
  229. .flex-row{
  230. display: flex;
  231. align-items: center;
  232. }
  233. .black-color{
  234. color: #303133 !important;
  235. }
  236. </style>