1
0

change-add.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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'>{{response.data.list[0].address ? '确认修改地址' : '确定'}}</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. if(!response.data.list[0].address) {
  106. uni.setNavigationBarTitle({
  107. title: '添加收货地址'
  108. });
  109. return false;
  110. }
  111. let arr = response.data.list[0].address.trim().split(" ");
  112. that.detail = arr[arr.length - 1];
  113. let firstList = that.list;
  114. that.ids = [];
  115. firstList.forEach(function(row){
  116. if (row.name == arr[0]) {
  117. that.ids[0] = row.id;
  118. let secList = row
  119. secList.list.forEach(function(res){
  120. if (res.name == arr[1]) {
  121. that.ids[1] = res.id;
  122. let thirList = res;
  123. thirList.list.forEach(function (e) {
  124. if (e.name == arr[2]) {
  125. that.ids[2] = e.id;
  126. }
  127. })
  128. }
  129. })
  130. }
  131. })
  132. }else {
  133. uni.showToast({
  134. title: response.msg,
  135. icon: 'none',
  136. duration: 1000
  137. });
  138. }
  139. }).catch(response => {
  140. that.$hideLoading();
  141. });
  142. },
  143. saveAddress: function (e) {
  144. let that = this;
  145. if (!that.province) {
  146. uni.showToast({
  147. title: '地区不能为空',
  148. icon: 'none',
  149. duration: 1000,
  150. });
  151. return;
  152. }
  153. uni.showLoading({
  154. title: '提交中...'
  155. });
  156. that.$request({
  157. url: that.$api.app_admin.update_address,
  158. method: "POST",
  159. data: {
  160. order_id: that.order.id,
  161. name: that.name,
  162. mobile: that.mobile,
  163. province: that.province,
  164. city: that.city,
  165. district: that.district,
  166. address: that.detail,
  167. }
  168. }).then(response => {
  169. uni.hideLoading();
  170. if (response.code == 0) {
  171. uni.showToast({
  172. title: response.msg,
  173. duration: 1000,
  174. icon: 'success',
  175. mask: false
  176. });
  177. setTimeout(function(){
  178. uni.navigateBack();
  179. },500)
  180. } else {
  181. uni.showToast({
  182. title: response.msg,
  183. icon: 'none',
  184. duration: 1000
  185. });
  186. }
  187. }).catch(response => {
  188. uni.hideLoading();
  189. uni.showToast({
  190. title: response,
  191. icon: 'none',
  192. duration: 1000
  193. });
  194. });
  195. },
  196. },
  197. onLoad(options) {
  198. let that = this;
  199. if (options.order_no) {
  200. that.order_no = options.order_no
  201. that.getDistrict();
  202. }
  203. }
  204. }
  205. </script>
  206. <style scoped lang="scss">
  207. .address-bottom {
  208. width: #{702rpx};
  209. height: #{80rpx};
  210. line-height: #{80rpx};
  211. border-radius: #{40rpx};
  212. padding: 0;
  213. text-align: center;
  214. margin: #{40rpx} auto;
  215. color: #fff;
  216. z-index: 7;
  217. font-size: #{28rpx};
  218. background-color: #446dfd;
  219. }
  220. .input-list {
  221. background-color: #fff;
  222. padding-left: #{30rpx};
  223. }
  224. .input-item {
  225. border-bottom: #{1rpx} solid #eee;
  226. padding: #{24rpx} #{30rpx} #{24rpx} 0;
  227. height: #{96rpx};
  228. font-size: #{28rpx};
  229. color: #495060;
  230. }
  231. .input-item:last-of-type {
  232. border-bottom: 0;
  233. }
  234. .input-item .label {
  235. width: 20%;
  236. height: #{48rpx};
  237. line-height: #{48rpx};
  238. }
  239. .input-item input {
  240. width: 80%;
  241. height: #{48rpx};
  242. line-height: #{48rpx};
  243. font-size: #{28rpx};
  244. }
  245. </style>