edit-add.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="edit-add-index flex-common-css box-border-box iPhone-bottom">
  3. <Nav :title="fromData.id?'编辑地址':'新增地址'"></Nav>
  4. <view class="scroll-view-css box-border-box p-24">
  5. <view class="box-card box-border-box p-24 mb-20">
  6. <EnInput label="收货人" placeholder="请输入收货人姓名" v-model="fromData.consignee"></EnInput>
  7. <EnInput label="电话号码" type="number" placeholder="请输入电话号码" v-model="fromData.phone"></EnInput>
  8. <EnSelect v-if="schoolList.length > 0" label="收货学校" placeholder="请选择收货学校" v-model="fromData.school_id"
  9. :localData="schoolList" :valueType="'1'" ></EnSelect>
  10. <EnSelect label="楼栋" placeholder="请选择楼栋" v-if="fromData.school_id" v-model="fromData.dorm_id"
  11. :localData="builList" :valueType="'1'" ></EnSelect>
  12. <EnInput label="详细地址" placeholder="请输入详细地址" v-model="fromData.address"></EnInput>
  13. </view>
  14. <view class="box-card box-border-box p-24 flex-justify-space">
  15. <view class="">
  16. <view class="fs-30 mb-16">设为默认地址</view>
  17. <view class="fs-24 fc-9">提醒:下单会优先使用该地址</view>
  18. </view>
  19. <view class="r-right" @click="fromData.is_default == 1?fromData.is_default=0:fromData.is_default=1"
  20. :class="fromData.is_default == 0?'n-r':'s-r'">
  21. <view class="r-y"></view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="box-border-box p-24 bgc-f " >
  26. <view class="add-box text-align-center fs-34 fc-f mb-20" @click="save()">确定</view>
  27. <view v-if="fromData.id" class="add-box-1 text-align-center fs-34 fc-41ABF5" @click="del()">删除</view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import {getAddressInfo,saveAddress,delAddress,getAddressSchool,getAddressDorm} from '@/api/member.js'
  33. import tools from "@/service/tools.js";
  34. import EnSelect from "@/components/en-from/en-select/en-select";
  35. import EnInput from "@/components/en-from/en-input/en-input";
  36. export default {
  37. components: {
  38. EnInput,
  39. EnSelect,
  40. },
  41. data() {
  42. return {
  43. radioData: [{
  44. 'id': '0',
  45. 'name': '否'
  46. },
  47. {
  48. 'id': '1',
  49. 'name': '是'
  50. }
  51. ],
  52. fromData: {
  53. id: '',
  54. address: '',
  55. is_default: 0,
  56. consignee: '',
  57. phone: '',
  58. dorm_id:'',
  59. school_id:'',
  60. dorm_name:'',
  61. school_name:'',
  62. },
  63. schoolList: [],
  64. builList:[],
  65. isAJAX: false,
  66. time:'',
  67. }
  68. },
  69. onLoad(e) {
  70. if (e.id) {
  71. this.getInfo(e.id)
  72. } else {
  73. this.fromData.id = '';
  74. }
  75. this.getAddressSchool();
  76. },
  77. watch:{
  78. 'fromData.school_id'(val){
  79. this.getAddressDorm()
  80. },
  81. },
  82. methods: {
  83. getInfo(id) {
  84. getAddressInfo({id:id}).then((res)=>{
  85. if(res.code === 1){
  86. this.fromData = res.data;
  87. this.fromData.school_id = res.data.school_id + '';
  88. this.fromData.dorm_id = res.data.dorm_id + '';
  89. }
  90. })
  91. },
  92. getAddressSchool(){
  93. let operate_id = uni.getStorageSync('operate_id');
  94. getAddressSchool({operate_id:operate_id}).then((res)=>{
  95. if(res.code === 1){
  96. this.schoolList = res.data.map(obj =>{
  97. const {school_id,school_name} = obj;
  98. return {value:school_id + '',text:school_name};
  99. });
  100. }
  101. })
  102. },
  103. getAddressDorm(){
  104. getAddressDorm({school_id:this.fromData.school_id}).then((res)=>{
  105. if(res.code === 1){
  106. this.builList = res.data.map(obj =>{
  107. const {dorm_id,name,type_str} = obj;
  108. return {value:dorm_id + '',text:name + '('+ type_str +')'};
  109. });
  110. }
  111. })
  112. },
  113. save() {
  114. if(this.isAJAX){
  115. return
  116. }
  117. this.isAJAX = true;
  118. saveAddress(this.fromData).then((res)=>{
  119. if(res.code === 1){
  120. tools.success('操作成功');
  121. this.isAJAX = false;
  122. setTimeout(()=>{
  123. uni.navigateBack({
  124. delta: 1
  125. });
  126. uni.setStorageSync('isConfirmAddressFlag',true);
  127. },1500)
  128. }else{
  129. tools.success('操作失败');
  130. this.isAJAX = false;
  131. }
  132. })
  133. },
  134. del(){
  135. if(this.isAJAX){
  136. return
  137. }
  138. this.isAJAX = true;
  139. delAddress({id:this.fromData.id}).then((res)=>{
  140. if(res.code === 1){
  141. tools.success('操作成功');
  142. this.isAJAX = false;
  143. setTimeout(()=>{
  144. uni.reLaunch({
  145. url: '/pages-address/address'
  146. })
  147. },1500)
  148. }else{
  149. tools.success('操作失败');
  150. this.isAJAX = false;
  151. }
  152. })
  153. },
  154. },
  155. }
  156. </script>
  157. <style scoped lang="scss">
  158. .edit-add-index {
  159. .add-box {
  160. width: 100%;
  161. height: 80rpx;
  162. line-height: 80rpx;
  163. background-color: #2F80ED;
  164. border-radius: 200rpx;
  165. }
  166. .add-box-1{
  167. width: 100%;
  168. height: 88rpx;
  169. line-height: 88rpx;
  170. background: #FFFFFF;
  171. border-radius: 200rpx 200rpx 200rpx 200rpx;
  172. box-sizing: border-box;
  173. border: 2rpx solid #41ABF5;
  174. }
  175. .box-card{
  176. width: 1005;
  177. min-height: 152rpx;
  178. background: #FFFFFF;
  179. border-radius: 20rpx;
  180. }
  181. .r-right{
  182. margin-top: 24rpx;
  183. width: 88rpx;
  184. height: 52rpx;
  185. border-radius: 200rpx;
  186. position: relative;
  187. .r-y{
  188. width: 44rpx;
  189. height: 44rpx;
  190. background: #FFFFFF;
  191. border-radius: 200rpx;
  192. position: absolute;
  193. top: 4rpx;
  194. }
  195. }
  196. .s-r{
  197. background-color: #41ABF5;
  198. transition: all 1s;
  199. .r-y{
  200. right: 4rpx !important;
  201. transition: all 1s;
  202. }
  203. }
  204. .n-r{
  205. background-color: #ccc;
  206. transition: all 1s;
  207. .r-y{
  208. left: 4rpx !important;
  209. transition: all 1s;
  210. }
  211. }
  212. }
  213. </style>