edit-add.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 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. }
  67. },
  68. onLoad(e) {
  69. if (e.id) {
  70. this.getInfo(e.id)
  71. } else {
  72. this.fromData.id = '';
  73. }
  74. this.getAddressSchool();
  75. },
  76. watch:{
  77. 'fromData.school_id'(val){
  78. this.getAddressDorm()
  79. },
  80. },
  81. methods: {
  82. getInfo(id) {
  83. getAddressInfo({id:id}).then((res)=>{
  84. if(res.code === 1){
  85. this.fromData = res.data;
  86. this.fromData.school_id = res.data.school_id + ''
  87. this.fromData.dorm_id = res.data.dorm_id + ''
  88. }
  89. })
  90. },
  91. getAddressSchool(){
  92. let operate_id = uni.getStorageSync('operate_id');
  93. getAddressSchool({operate_id:operate_id}).then((res)=>{
  94. if(res.code === 1){
  95. this.schoolList = res.data.map(obj =>{
  96. const {school_id,school_name} = obj;
  97. return {value:school_id,text:school_name};
  98. });
  99. }
  100. })
  101. },
  102. getAddressDorm(){
  103. getAddressDorm({school_id:this.fromData.school_id}).then((res)=>{
  104. if(res.code === 1){
  105. this.builList = res.data.map(obj =>{
  106. const {dorm_id,name} = obj;
  107. return {value:dorm_id,text:name};
  108. });
  109. }
  110. })
  111. },
  112. save() {
  113. if(this.isAJAX){
  114. return
  115. }
  116. this.isAJAX = true;
  117. saveAddress(this.fromData).then((res)=>{
  118. if(res.code === 1){
  119. tools.success('操作成功');
  120. this.isAJAX = false;
  121. setTimeout(()=>{
  122. uni.reLaunch({
  123. url: '/pages-address/address'
  124. })
  125. },1500)
  126. }else{
  127. tools.success('操作失败');
  128. this.isAJAX = false;
  129. }
  130. })
  131. },
  132. del(){
  133. if(this.isAJAX){
  134. return
  135. }
  136. this.isAJAX = true;
  137. delAddress({id:this.fromData.id}).then((res)=>{
  138. if(res.code === 1){
  139. tools.success('操作成功');
  140. this.isAJAX = false;
  141. setTimeout(()=>{
  142. uni.reLaunch({
  143. url: '/pages-address/address'
  144. })
  145. },1500)
  146. }else{
  147. tools.success('操作失败');
  148. this.isAJAX = false;
  149. }
  150. })
  151. },
  152. },
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. .edit-add-index {
  157. .add-box {
  158. width: 100%;
  159. height: 80rpx;
  160. line-height: 80rpx;
  161. background-color: #2F80ED;
  162. border-radius: 200rpx;
  163. }
  164. .add-box-1{
  165. width: 100%;
  166. height: 88rpx;
  167. line-height: 88rpx;
  168. background: #FFFFFF;
  169. border-radius: 200rpx 200rpx 200rpx 200rpx;
  170. box-sizing: border-box;
  171. border: 2rpx solid #41ABF5;
  172. }
  173. .box-card{
  174. width: 1005;
  175. min-height: 152rpx;
  176. background: #FFFFFF;
  177. border-radius: 20rpx;
  178. }
  179. .r-right{
  180. margin-top: 24rpx;
  181. width: 88rpx;
  182. height: 52rpx;
  183. border-radius: 200rpx;
  184. position: relative;
  185. .r-y{
  186. width: 44rpx;
  187. height: 44rpx;
  188. background: #FFFFFF;
  189. border-radius: 200rpx;
  190. position: absolute;
  191. top: 4rpx;
  192. }
  193. }
  194. .s-r{
  195. background-color: #41ABF5;
  196. transition: all 1s;
  197. .r-y{
  198. right: 4rpx !important;
  199. transition: all 1s;
  200. }
  201. }
  202. .n-r{
  203. background-color: #ccc;
  204. transition: all 1s;
  205. .r-y{
  206. left: 4rpx !important;
  207. transition: all 1s;
  208. }
  209. }
  210. }
  211. </style>