edit-add.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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="请选择收货学校"
  9. v-model="fromData.dorm_school_id" :localData="schoolList" :valueType="'1'" @upValue=upValue>
  10. </EnSelect>
  11. <EnSelect label="楼栋" placeholder="请选择楼栋" v-if="isDorm" v-model="fromData.dorm_id" :localData="builList"
  12. :valueType="'1'"></EnSelect>
  13. <EnInput label="详细地址" placeholder="请输入详细地址" v-model="fromData.address"></EnInput>
  14. </view>
  15. <view class="box-card box-border-box p-24 flex-justify-space">
  16. <view class="">
  17. <view class="fs-30 mb-16">设为默认地址</view>
  18. <view class="fs-24 fc-9">提醒:下单会优先使用该地址</view>
  19. </view>
  20. <view class="r-right" @click="fromData.is_default == 1?fromData.is_default=0:fromData.is_default=1"
  21. :class="fromData.is_default == 0?'n-r':'s-r'">
  22. <view class="r-y"></view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="box-border-box p-24 bgc-f ">
  27. <view class="add-box text-align-center fs-34 fc-f mb-20" @click="save()">确定</view>
  28. <view v-if="fromData.id" class="add-box-1 text-align-center fs-34 fc-41ABF5" @click="del()">删除</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. getAddressInfo,
  35. saveAddress,
  36. delAddress,
  37. getAddressSchool,
  38. getAddressDorm
  39. } from '@/api/member.js'
  40. import tools from "@/service/tools.js";
  41. import EnSelect from "@/components/en-from/en-select/en-select";
  42. import EnInput from "@/components/en-from/en-input/en-input";
  43. export default {
  44. components: {
  45. EnInput,
  46. EnSelect,
  47. },
  48. data() {
  49. return {
  50. radioData: [{
  51. 'id': '0',
  52. 'name': '否'
  53. },
  54. {
  55. 'id': '1',
  56. 'name': '是'
  57. }
  58. ],
  59. fromData: {
  60. id: '',
  61. address: '',
  62. is_default: 0,
  63. consignee: '',
  64. phone: '',
  65. dorm_id: '',
  66. dorm_school_id: '',
  67. school_name: '',
  68. },
  69. schoolList: [],
  70. builList: [],
  71. isAJAX: false,
  72. isDorm: false,
  73. time: '',
  74. selectId: false,
  75. a: 1
  76. }
  77. },
  78. onLoad(e) {
  79. if (e.id) {
  80. this.selectId = true
  81. this.getInfo(e.id)
  82. } else {
  83. this.fromData.id = '';
  84. this.getAddressSchool();
  85. }
  86. },
  87. watch: {
  88. 'fromData.dorm_school_id': {
  89. handler(newval, old) {
  90. console.log(old, 'old');
  91. console.log(newval, 'newval');
  92. if (newval != old && !this.selectId) {
  93. this.fromData.dorm_id = ''
  94. }
  95. this.getAddressDorm()
  96. },
  97. immediate: true, // 立即执行
  98. }
  99. },
  100. methods: {
  101. upValue(val) {
  102. // if (this.selectId) {
  103. // this.fromData.dorm_id = ''
  104. // this.fromData.dorm_id = val+ ''
  105. // }
  106. // this.getAddressDorm()
  107. },
  108. getInfo(id) {
  109. getAddressInfo({
  110. id: id
  111. }).then((res) => {
  112. if (res.code === 1) {
  113. this.fromData.id = res.data.id;
  114. this.fromData.address = res.data.address;
  115. this.fromData.consignee = res.data.consignee;
  116. this.fromData.is_default = res.data.is_default;
  117. this.fromData.phone = res.data.phone;
  118. this.fromData.school_name = res.data.school_name;
  119. this.fromData.dorm_school_id = res.data.school_id + '';
  120. this.fromData.dorm_id = res.data.dorm_id + '';
  121. this.getAddressSchool();
  122. }
  123. })
  124. },
  125. getAddressSchool() {
  126. let operate_id = uni.getStorageSync('operate_id');
  127. getAddressSchool({
  128. operate_id: operate_id
  129. }).then((res) => {
  130. if (res.code === 1) {
  131. this.schoolList = res.data.map(obj => {
  132. const {
  133. school_id,
  134. school_name
  135. } = obj;
  136. return {
  137. value: school_id + '',
  138. text: school_name
  139. };
  140. });
  141. }
  142. })
  143. },
  144. getAddressDorm() {
  145. getAddressDorm({
  146. dorm_school_id: this.fromData.dorm_school_id
  147. }).then((res) => {
  148. if (res.code === 1) {
  149. this.builList = res.data.map(obj => {
  150. const {
  151. dorm_id,
  152. name,
  153. type_str
  154. } = obj;
  155. return {
  156. value: dorm_id + '',
  157. text: name + '(' + type_str + ')'
  158. };
  159. });
  160. this.isDorm = true
  161. this.selectId = false
  162. }
  163. })
  164. },
  165. save() {
  166. if (this.isAJAX) {
  167. return
  168. }
  169. this.isAJAX = true;
  170. saveAddress(this.fromData).then((res) => {
  171. if (res.code === 1) {
  172. tools.success('操作成功');
  173. this.isAJAX = false;
  174. setTimeout(() => {
  175. uni.navigateBack({
  176. delta: 1
  177. });
  178. let addressData = {
  179. flag: true,
  180. is_default: this.fromData.is_default,
  181. id: this.fromData.id
  182. }
  183. uni.setStorageSync('isConfirmAddressFlag', addressData);
  184. }, 1500)
  185. } else {
  186. tools.error(res.msg);
  187. this.isAJAX = false;
  188. }
  189. })
  190. },
  191. del() {
  192. if (this.isAJAX) {
  193. return
  194. }
  195. this.isAJAX = true;
  196. delAddress({
  197. id: this.fromData.id
  198. }).then((res) => {
  199. if (res.code === 1) {
  200. tools.success('操作成功');
  201. this.isAJAX = false;
  202. setTimeout(() => {
  203. uni.reLaunch({
  204. url: '/pages-address/address'
  205. })
  206. }, 1500)
  207. } else {
  208. tools.error(res.msg);
  209. this.isAJAX = false;
  210. }
  211. })
  212. },
  213. },
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. .edit-add-index {
  218. .add-box {
  219. width: 100%;
  220. height: 80rpx;
  221. line-height: 80rpx;
  222. background-color: #2F80ED;
  223. border-radius: 200rpx;
  224. }
  225. .add-box-1 {
  226. width: 100%;
  227. height: 88rpx;
  228. line-height: 88rpx;
  229. background: #FFFFFF;
  230. border-radius: 200rpx 200rpx 200rpx 200rpx;
  231. box-sizing: border-box;
  232. border: 2rpx solid #41ABF5;
  233. }
  234. .box-card {
  235. width: 1005;
  236. min-height: 152rpx;
  237. background: #FFFFFF;
  238. border-radius: 20rpx;
  239. }
  240. .r-right {
  241. margin-top: 24rpx;
  242. width: 88rpx;
  243. height: 52rpx;
  244. border-radius: 200rpx;
  245. position: relative;
  246. .r-y {
  247. width: 44rpx;
  248. height: 44rpx;
  249. background: #FFFFFF;
  250. border-radius: 200rpx;
  251. position: absolute;
  252. top: 4rpx;
  253. }
  254. }
  255. .s-r {
  256. background-color: #41ABF5;
  257. transition: all 1s;
  258. .r-y {
  259. right: 4rpx !important;
  260. transition: all 1s;
  261. }
  262. }
  263. .n-r {
  264. background-color: #ccc;
  265. transition: all 1s;
  266. .r-y {
  267. left: 4rpx !important;
  268. transition: all 1s;
  269. }
  270. }
  271. }
  272. </style>