edit-add.vue 5.5 KB

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