change-add.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <app-layout>
  3. <view>
  4. <view class="input-list">
  5. <view class="dir-left-nowrap input-item">
  6. <view class='label'>收货人</view>
  7. <input name="name" v-model="name"></input>
  8. </view>
  9. <view class="dir-left-nowrap input-item">
  10. <view class='label'>联系电话</view>
  11. <input name="mobile" type="number" v-model="mobile"></input>
  12. </view>
  13. <view class="main-between input-item">
  14. <text class="label">所在地区</text>
  15. <app-area-picker @customevent="areaEvent"
  16. :ids="ids"></app-area-picker>
  17. </view>
  18. <view class="dir-left-nowrap input-item">
  19. <view class='label'>详细地址</view>
  20. <input name="detail" placeholder="请输入详细地址(最多50字)" maxlength="50" v-model="detail"></input>
  21. </view>
  22. </view>
  23. <button @click="saveAddress" class='address-bottom'>{{!changeAddress ? '确认修改地址' : '确定'}}</button>
  24. </view>
  25. </app-layout>
  26. </template>
  27. <script>
  28. import appAreaPicker from '../../../components/page-component/app-area-picker/app-area-picker.vue';
  29. import { mapState } from "vuex";
  30. export default {
  31. data() {
  32. return {
  33. ids: [0],
  34. list: [],
  35. name: '',
  36. mobile: '',
  37. detail: '',
  38. order_no: '',
  39. province: '',
  40. city: '',
  41. district: '',
  42. order: {},
  43. changeAddress: false
  44. }
  45. },
  46. components: {
  47. "app-area-picker": appAreaPicker
  48. },
  49. computed: {
  50. ...mapState({
  51. userInfo: state => state.user.info,
  52. adminImg: state => state.mallConfig.__wxapp_img.app_admin,
  53. })
  54. },
  55. methods: {
  56. areaEvent(data) {
  57. if (data) {
  58. this.province = data.province.name;
  59. this.city = data.city.name;
  60. this.district = data.district.name;
  61. }
  62. },
  63. getDistrict() {
  64. let that = this;
  65. that.$showLoading({
  66. text: '加载中...'
  67. });
  68. that.$request({
  69. url: that.$api.default.district
  70. }).then(response=>{
  71. if(response.code == 0) {
  72. that.list = response.data.list;
  73. that.getList();
  74. }else {
  75. that.$hideLoading();
  76. uni.showToast({
  77. title: response.msg,
  78. icon: 'none',
  79. duration: 1000
  80. });
  81. }
  82. }).catch(response => {
  83. that.$hideLoading();
  84. });
  85. },
  86. getList() {
  87. let that = this;
  88. that.$request({
  89. url: that.$api.app_admin.order,
  90. data: {
  91. status: '-1',
  92. keyword: that.order_no
  93. },
  94. method: 'post'
  95. }).then(response=>{
  96. that.$hideLoading();
  97. if(response.code == 0) {
  98. that.order = response.data.list[0];
  99. that.name = response.data.list[0].name;
  100. that.mobile = response.data.list[0].mobile;
  101. if(!response.data.list[0].address) {
  102. that.changeAddress = true;
  103. uni.setNavigationBarTitle({
  104. title: '添加收货地址'
  105. });
  106. return false;
  107. }
  108. let arr = response.data.list[0].address.trim().split(" ");
  109. that.detail = arr[arr.length - 1];
  110. let firstList = that.list;
  111. that.ids = [];
  112. firstList.forEach(function(row){
  113. if (row.name == arr[0]) {
  114. that.ids[0] = row.id;
  115. let secList = row
  116. secList.list.forEach(function(res){
  117. if (res.name == arr[1]) {
  118. that.ids[1] = res.id;
  119. let thirList = res;
  120. thirList.list.forEach(function (e) {
  121. if (e.name == arr[2]) {
  122. that.ids[2] = e.id;
  123. }
  124. })
  125. }
  126. })
  127. }
  128. })
  129. }else {
  130. uni.showToast({
  131. title: response.msg,
  132. icon: 'none',
  133. duration: 1000
  134. });
  135. }
  136. }).catch(response => {
  137. that.$hideLoading();
  138. });
  139. },
  140. saveAddress: function (e) {
  141. let that = this;
  142. if (!that.province) {
  143. uni.showToast({
  144. title: '地区不能为空',
  145. icon: 'none',
  146. duration: 1000,
  147. });
  148. return;
  149. }
  150. uni.showLoading({
  151. mask: true,
  152. title: '提交中...'
  153. });
  154. that.$request({
  155. url: that.$api.app_admin.update_address,
  156. method: "POST",
  157. data: {
  158. order_id: that.order.id,
  159. name: that.name,
  160. mobile: that.mobile,
  161. province: that.province,
  162. city: that.city,
  163. district: that.district,
  164. address: that.detail,
  165. }
  166. }).then(response => {
  167. uni.hideLoading();
  168. if (response.code == 0) {
  169. uni.showToast({
  170. title: response.msg,
  171. duration: 1000,
  172. icon: 'success',
  173. mask: false
  174. });
  175. setTimeout(function(){
  176. uni.navigateBack();
  177. },500)
  178. } else {
  179. uni.showToast({
  180. title: response.msg,
  181. icon: 'none',
  182. duration: 1000
  183. });
  184. }
  185. }).catch(response => {
  186. uni.hideLoading();
  187. uni.showToast({
  188. title: response,
  189. icon: 'none',
  190. duration: 1000
  191. });
  192. });
  193. },
  194. },
  195. onLoad(options) { this.$commonLoad.onload(options);
  196. let that = this;
  197. if (options.order_no) {
  198. that.order_no = options.order_no
  199. that.getDistrict();
  200. }
  201. }
  202. }
  203. </script>
  204. <style scoped lang="scss">
  205. .address-bottom {
  206. width: #{702rpx};
  207. height: #{80rpx};
  208. line-height: #{80rpx};
  209. border-radius: #{40rpx};
  210. padding: 0;
  211. text-align: center;
  212. margin: #{40rpx} auto;
  213. color: #fff;
  214. z-index: 7;
  215. font-size: #{28rpx};
  216. background-color: #446dfd;
  217. }
  218. .input-list {
  219. background-color: #fff;
  220. padding-left: #{30rpx};
  221. }
  222. .input-item {
  223. border-bottom: #{1rpx} solid #eee;
  224. padding: #{24rpx} #{30rpx} #{24rpx} 0;
  225. height: #{96rpx};
  226. font-size: #{28rpx};
  227. color: #495060;
  228. }
  229. .input-item:last-of-type {
  230. border-bottom: 0;
  231. }
  232. .input-item .label {
  233. width: 20%;
  234. height: #{48rpx};
  235. line-height: #{48rpx};
  236. }
  237. .input-item input {
  238. width: 80%;
  239. height: #{48rpx};
  240. line-height: #{48rpx};
  241. font-size: #{28rpx};
  242. }
  243. </style>