edit-add.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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} = obj;
  108. return {value:dorm_id + '',text:name};
  109. });
  110. }
  111. })
  112. },
  113. save() {
  114. console.log(this.fromData);
  115. return
  116. if(this.isAJAX){
  117. return
  118. }
  119. this.isAJAX = true;
  120. saveAddress(this.fromData).then((res)=>{
  121. if(res.code === 1){
  122. tools.success('操作成功');
  123. this.isAJAX = false;
  124. setTimeout(()=>{
  125. uni.navigateBack({
  126. delta: 1
  127. });
  128. uni.setStorageSync('isConfirmAddressFlag',true);
  129. },1500)
  130. }else{
  131. tools.success('操作失败');
  132. this.isAJAX = false;
  133. }
  134. })
  135. },
  136. del(){
  137. if(this.isAJAX){
  138. return
  139. }
  140. this.isAJAX = true;
  141. delAddress({id:this.fromData.id}).then((res)=>{
  142. if(res.code === 1){
  143. tools.success('操作成功');
  144. this.isAJAX = false;
  145. setTimeout(()=>{
  146. uni.reLaunch({
  147. url: '/pages-address/address'
  148. })
  149. },1500)
  150. }else{
  151. tools.success('操作失败');
  152. this.isAJAX = false;
  153. }
  154. })
  155. },
  156. },
  157. }
  158. </script>
  159. <style scoped lang="scss">
  160. .edit-add-index {
  161. .add-box {
  162. width: 100%;
  163. height: 80rpx;
  164. line-height: 80rpx;
  165. background-color: #2F80ED;
  166. border-radius: 200rpx;
  167. }
  168. .add-box-1{
  169. width: 100%;
  170. height: 88rpx;
  171. line-height: 88rpx;
  172. background: #FFFFFF;
  173. border-radius: 200rpx 200rpx 200rpx 200rpx;
  174. box-sizing: border-box;
  175. border: 2rpx solid #41ABF5;
  176. }
  177. .box-card{
  178. width: 1005;
  179. min-height: 152rpx;
  180. background: #FFFFFF;
  181. border-radius: 20rpx;
  182. }
  183. .r-right{
  184. margin-top: 24rpx;
  185. width: 88rpx;
  186. height: 52rpx;
  187. border-radius: 200rpx;
  188. position: relative;
  189. .r-y{
  190. width: 44rpx;
  191. height: 44rpx;
  192. background: #FFFFFF;
  193. border-radius: 200rpx;
  194. position: absolute;
  195. top: 4rpx;
  196. }
  197. }
  198. .s-r{
  199. background-color: #41ABF5;
  200. transition: all 1s;
  201. .r-y{
  202. right: 4rpx !important;
  203. transition: all 1s;
  204. }
  205. }
  206. .n-r{
  207. background-color: #ccc;
  208. transition: all 1s;
  209. .r-y{
  210. left: 4rpx !important;
  211. transition: all 1s;
  212. }
  213. }
  214. }
  215. </style>