edit-add.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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="isDorm" 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 {
  33. getAddressInfo,
  34. saveAddress,
  35. delAddress,
  36. getAddressSchool,
  37. getAddressDorm
  38. } from '@/api/member.js'
  39. import tools from "@/service/tools.js";
  40. import EnSelect from "@/components/en-from/en-select/en-select";
  41. import EnInput from "@/components/en-from/en-input/en-input";
  42. export default {
  43. components: {
  44. EnInput,
  45. EnSelect,
  46. },
  47. data() {
  48. return {
  49. radioData: [{
  50. 'id': '0',
  51. 'name': '否'
  52. },
  53. {
  54. 'id': '1',
  55. 'name': '是'
  56. }
  57. ],
  58. fromData: {
  59. id: '',
  60. address: '',
  61. is_default: 0,
  62. consignee: '',
  63. phone: '',
  64. dorm_id: '',
  65. school_id: '',
  66. dorm_name: '',
  67. school_name: '',
  68. },
  69. schoolList: [],
  70. builList: [],
  71. isAJAX: false,
  72. isDorm: false,
  73. time: '',
  74. selectId: false
  75. }
  76. },
  77. onLoad(e) {
  78. if (e.id) {
  79. this.selectId = true
  80. this.getInfo(e.id)
  81. } else {
  82. this.fromData.id = '';
  83. this.getAddressSchool();
  84. }
  85. },
  86. watch: {
  87. 'fromData.school_id'(newval,old) {
  88. console.log(old, 'old');
  89. console.log(newval, 'newval');
  90. if(newval != old && !this.selectId) {
  91. this.fromData.dorm_id = ''
  92. }
  93. this.getAddressDorm()
  94. },
  95. },
  96. methods: {
  97. getInfo(id) {
  98. getAddressInfo({
  99. id: id
  100. }).then((res) => {
  101. if (res.code === 1) {
  102. this.fromData = res.data;
  103. this.fromData.school_id = res.data.school_id + '';
  104. this.fromData.dorm_id = res.data.dorm_id + '';
  105. this.getAddressSchool();
  106. }
  107. })
  108. },
  109. getAddressSchool() {
  110. let operate_id = uni.getStorageSync('operate_id');
  111. getAddressSchool({
  112. operate_id: operate_id
  113. }).then((res) => {
  114. if (res.code === 1) {
  115. this.schoolList = res.data.map(obj => {
  116. const {
  117. school_id,
  118. school_name
  119. } = obj;
  120. return {
  121. value: school_id + '',
  122. text: school_name
  123. };
  124. });
  125. }
  126. })
  127. },
  128. getAddressDorm() {
  129. getAddressDorm({
  130. school_id: this.fromData.school_id
  131. }).then((res) => {
  132. if (res.code === 1) {
  133. this.builList = res.data.map(obj => {
  134. const {
  135. dorm_id,
  136. name,
  137. type_str
  138. } = obj;
  139. return {
  140. value: dorm_id + '',
  141. text: name + '(' + type_str + ')'
  142. };
  143. });
  144. this.isDorm = true
  145. this.selectId = false
  146. }
  147. })
  148. },
  149. save() {
  150. if (this.isAJAX) {
  151. return
  152. }
  153. this.isAJAX = true;
  154. saveAddress(this.fromData).then((res) => {
  155. if (res.code === 1) {
  156. tools.success('操作成功');
  157. this.isAJAX = false;
  158. setTimeout(() => {
  159. uni.navigateBack({
  160. delta: 1
  161. });
  162. let addressData = {
  163. flag: true,
  164. is_default: this.fromData.is_default,
  165. id: this.fromData.id
  166. }
  167. uni.setStorageSync('isConfirmAddressFlag', addressData);
  168. }, 1500)
  169. } else {
  170. tools.error(res.msg);
  171. this.isAJAX = false;
  172. }
  173. })
  174. },
  175. del() {
  176. if (this.isAJAX) {
  177. return
  178. }
  179. this.isAJAX = true;
  180. delAddress({
  181. id: this.fromData.id
  182. }).then((res) => {
  183. if (res.code === 1) {
  184. tools.success('操作成功');
  185. this.isAJAX = false;
  186. setTimeout(() => {
  187. uni.reLaunch({
  188. url: '/pages-address/address'
  189. })
  190. }, 1500)
  191. } else {
  192. tools.error(res.msg);
  193. this.isAJAX = false;
  194. }
  195. })
  196. },
  197. },
  198. }
  199. </script>
  200. <style scoped lang="scss">
  201. .edit-add-index {
  202. .add-box {
  203. width: 100%;
  204. height: 80rpx;
  205. line-height: 80rpx;
  206. background-color: #2F80ED;
  207. border-radius: 200rpx;
  208. }
  209. .add-box-1 {
  210. width: 100%;
  211. height: 88rpx;
  212. line-height: 88rpx;
  213. background: #FFFFFF;
  214. border-radius: 200rpx 200rpx 200rpx 200rpx;
  215. box-sizing: border-box;
  216. border: 2rpx solid #41ABF5;
  217. }
  218. .box-card {
  219. width: 1005;
  220. min-height: 152rpx;
  221. background: #FFFFFF;
  222. border-radius: 20rpx;
  223. }
  224. .r-right {
  225. margin-top: 24rpx;
  226. width: 88rpx;
  227. height: 52rpx;
  228. border-radius: 200rpx;
  229. position: relative;
  230. .r-y {
  231. width: 44rpx;
  232. height: 44rpx;
  233. background: #FFFFFF;
  234. border-radius: 200rpx;
  235. position: absolute;
  236. top: 4rpx;
  237. }
  238. }
  239. .s-r {
  240. background-color: #41ABF5;
  241. transition: all 1s;
  242. .r-y {
  243. right: 4rpx !important;
  244. transition: all 1s;
  245. }
  246. }
  247. .n-r {
  248. background-color: #ccc;
  249. transition: all 1s;
  250. .r-y {
  251. left: 4rpx !important;
  252. transition: all 1s;
  253. }
  254. }
  255. }
  256. </style>