change-add.vue 8.4 KB

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