operate.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="content">
  3. <view class="row b-b">
  4. <text class="tit">{{$L('联系人')}}</text>
  5. <input class="input" maxlength='10' type="text" v-model="addressData.memberName" :placeholder="$L('请输入收货人姓名')"
  6. placeholder-class="placeholder" />
  7. </view>
  8. <view class="row b-b">
  9. <text class="tit">{{$L('联系电话')}}</text>
  10. <input class="input" maxlength='11' type="number" v-model="addressData.telMobile" :placeholder="$L('请输入手机号')"
  11. placeholder-class="placeholder" />
  12. </view>
  13. <view class="row b-b">
  14. <text class="tit">{{$L('所在地区')}}</text>
  15. <text @click="chooseArea" :class="addressData.addressAll==$L(`请选择所在地区`)? 'input placeholder1':'input'">
  16. {{addressData.addressAll}}
  17. </text>
  18. </view>
  19. <view class="row b-b">
  20. <text class="tit">{{$L('详细地址')}}</text>
  21. <input class="input" type="text" v-model="addressData.detailAddress" :placeholder="$L('请输入详细地址,建议5~60字')" maxlength='60'
  22. placeholder-class="placeholder" />
  23. </view>
  24. <view class="row default_row">
  25. <text class="tit">{{$L('设为默认地址')}}</text>
  26. <switch style="transform: scale(0.8,0.8)" :checked="addressData.isDefault" color="#FC1C1C" @change="switchChange" />
  27. </view>
  28. <button class="add_btn flex_row_center_center" @click="confirm" :style="{top:windowHeight - 80 + 'px'}">{{$L('提交')}}</button>
  29. <selectAddress ref='selectAddress' :sel_data='selAddressData' @selectAddress="successSelectAddress"></selectAddress>
  30. </view>
  31. </template>
  32. <script>
  33. import selectAddress from '@/components/yixuan-selectAddress/yixuan-selectAddress';
  34. import {
  35. mapState,mapMutations
  36. } from 'vuex';
  37. export default {
  38. components: {
  39. selectAddress,
  40. },
  41. data() {
  42. return {
  43. addressData: {
  44. memberName: '',
  45. telMobile: '',
  46. addressAll: '请选择所在地区',
  47. detailAddress: '',
  48. isDefault: false,
  49. addressId: '', //编辑收货地址时的id
  50. },
  51. selAddressData: [],
  52. windowHeight:''
  53. }
  54. },
  55. onLoad(option) {
  56. let title = '新增收货地址';
  57. if (option.type === 'edit') {
  58. title = '编辑收货地址'
  59. this.addressData.addressId = option.addressId;
  60. this.getAddressDetail();
  61. }
  62. this.manageType = option.type;
  63. uni.setNavigationBarTitle({
  64. title
  65. });
  66. uni.getSystemInfo({
  67. success:(res)=>{
  68. this.windowHeight = res.windowHeight;
  69. }
  70. });
  71. },
  72. computed: {
  73. ...mapState(['userInfo','addressList'])
  74. },
  75. methods: {
  76. ...mapMutations(['operateAddressData']),
  77. switchChange(e) {
  78. this.addressData.isDefault = e.detail.value;
  79. },
  80. chooseArea() {
  81. this.$refs.selectAddress.show()
  82. },
  83. successSelectAddress(address) { //选择成功回调
  84. this.selAddressData = address;
  85. this.addressData.addressAll = ''
  86. address.map((item) => {
  87. this.addressData.addressAll += item.name;
  88. })
  89. },
  90. //获取收货地址详情
  91. getAddressDetail() {
  92. this.$request({
  93. url: 'v3/member/front/memberAddress/detail',
  94. data: {
  95. addressId: this.addressData.addressId,
  96. },
  97. method:'GET',
  98. }).then(res => {
  99. if (res.state == 200) {
  100. let result = res.data;
  101. this.addressData.memberName = result.memberName;
  102. this.addressData.telMobile = result.telMobile;
  103. this.addressData.addressAll = result.addressAll;
  104. this.addressData.detailAddress = result.detailAddress;
  105. this.addressData.isDefault = result.isDefault ? true : false;
  106. this.selAddressData = [{
  107. code: result.provinceCode,
  108. name: ''
  109. }, {
  110. code: result.cityCode,
  111. name: ''
  112. }, {
  113. code: result.districtCode,
  114. name: ''
  115. }, ];
  116. //初始化地址选择组件
  117. } else {
  118. this.$api.msg(res.msg);
  119. }
  120. }).catch((e) => {
  121. //异常处理
  122. })
  123. },
  124. //提交
  125. confirm() {
  126. let data = this.addressData;
  127. if (!data.memberName) {
  128. this.$api.msg('请填写收货人姓名');
  129. return;
  130. }
  131. if (!this.$checkMobile(data.telMobile)) {
  132. return;
  133. }
  134. if (data.addressAll=='请选择所在地区') {
  135. this.$api.msg('请选择所在地区');
  136. return;
  137. }
  138. if (!data.detailAddress) {
  139. this.$api.msg('请填写详细地址');
  140. return;
  141. } else if (data.detailAddress.length < 5) {
  142. this.$api.msg('详细地址至少填写5个字');
  143. return;
  144. }
  145. let param = {};
  146. param.url = data.addressId ? 'v3/member/front/memberAddress/edit' : 'v3/member/front/memberAddress/add';
  147. param.data = {};
  148. param.data.key = this.userInfo.access_token;
  149. param.data.memberName = data.memberName; //收货人
  150. param.data.provinceCode = this.selAddressData[0].code; //省份编码
  151. param.data.cityCode = this.selAddressData[1].code; //城市编码
  152. param.data.districtCode = this.selAddressData[2]?this.selAddressData[2].code:0; //区县编码
  153. param.data.addressAll = data.addressAll; //所在地区
  154. param.data.detailAddress = data.detailAddress; //详细地址
  155. param.data.telMobile = data.telMobile; //联系电话
  156. param.data.isDefault = data.isDefault ? 1 : 0; //是否设为默认地址(0非默认地址 1默认地址)
  157. if (data.addressId) {
  158. param.data.addressId = data.addressId;
  159. }
  160. param.method = 'POST';
  161. this.$request(param).then(res => {
  162. this.$api.msg(res.msg);
  163. if (res.state == 200) {
  164. //更新上一页的数据
  165. const pages = getCurrentPages(); //当前页面栈
  166. if (pages.length > 1) {
  167. const beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
  168. beforePage.$vm.getAddressList(); //触发上个面中的方法获取地址列表的方法
  169. }
  170. setTimeout(() => {
  171. uni.navigateBack()
  172. }, 800)
  173. } else {
  174. //错误提示
  175. this.$api.msg(res.msg);
  176. }
  177. }).catch((e) => {
  178. })
  179. },
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. page {
  185. background: $bg-color-split;
  186. padding-top: 20rpx;
  187. width: 750rpx;
  188. margin: 0 auto;
  189. }
  190. .content{
  191. position: relative;
  192. }
  193. .b_b {
  194. &:after {
  195. position: absolute;
  196. z-index: 3;
  197. left: 20rpx;
  198. right: 0;
  199. height: 0;
  200. content: '';
  201. -webkit-transform: scaleY(0.5);
  202. transform: scaleY(0.5);
  203. border-bottom: 1px solid rgba(0, 0, 0, .1);
  204. }
  205. }
  206. .row {
  207. display: flex;
  208. align-items: center;
  209. position: relative;
  210. padding: 0 30rpx;
  211. height: 100rpx;
  212. background: #fff;
  213. &.b-b {
  214. &:after {
  215. position: absolute;
  216. z-index: 3;
  217. left: 20rpx;
  218. right: 0;
  219. height: 0;
  220. content: '';
  221. -webkit-transform: scaleY(0.5);
  222. transform: scaleY(0.5);
  223. border-bottom: 1px solid rgba(0, 0, 0, .1);
  224. }
  225. }
  226. .tit {
  227. flex-shrink: 0;
  228. width: 130rpx;
  229. font-size: 28rpx;
  230. color: #333;
  231. }
  232. .input {
  233. flex: 1;
  234. font-size: 30rpx;
  235. color: #333;
  236. font-weight: 600;
  237. }
  238. }
  239. .default_row {
  240. margin-top: 20rpx;
  241. .tit {
  242. flex: 1;
  243. }
  244. switch {
  245. transform: translateX(16rpx) scale(.9);
  246. }
  247. }
  248. .add_btn {
  249. position: absolute;
  250. font-size: 34rpx;
  251. color: #fff;
  252. width: 668rpx;
  253. height: 88rpx;
  254. background: #F30300;
  255. border-radius: 44rpx;
  256. right: 0;
  257. left: 0;
  258. margin: 0 auto;
  259. }
  260. .placeholder1{
  261. color: #949494!important;
  262. font-size: 26rpx!important;
  263. }
  264. </style>