order-address.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template id="order-address">
  2. <div class="">
  3. <el-dialog :title="title" :visible.sync="isShowChangeAddress" @close="dialogClose">
  4. <el-form :model="form" ref="address" label-width="80px" :rules="rules" size="small" label-position="top">
  5. <el-form-item label="收货人" prop="receiver_name">
  6. <el-input v-model="form.receiver_name"></el-input>
  7. </el-form-item>
  8. <el-form-item label="收货人手机号" prop="mobile">
  9. <el-input v-model="form.mobile"></el-input>
  10. </el-form-item>
  11. <el-form-item label="收货人邮编" prop="zip">
  12. <el-input v-model="form.zip"></el-input>
  13. </el-form-item>
  14. <el-form-item label="" prop="region_name">
  15. <el-row :gutter="20">
  16. <el-col :span="8">
  17. <div>省</div>
  18. </el-col>
  19. <el-col :span="8">
  20. <div>市</div>
  21. </el-col>
  22. <el-col :span="8">
  23. <div>区</div>
  24. </el-col>
  25. </el-row>
  26. <el-row :gutter="20">
  27. <el-col :span="8">
  28. <el-select v-model="regionArr[0]" size="small" placeholder="请选择" @change="getCity">
  29. <el-option v-for="item in province" :key="item.id" :label="item.name" :value="item.name"></el-option>
  30. </el-select>
  31. </el-col>
  32. <el-col :span="8">
  33. <el-select v-model="regionArr[1]" size="small" placeholder="请选择" @change="getDistrict">
  34. <el-option v-for="item in city" :key="item.id" :label="item.name" :value="item.name"></el-option>
  35. </el-select>
  36. </el-col>
  37. <el-col :span="8">
  38. <el-select v-model="regionArr[2]" size="small" placeholder="请选择" @change="getArea">
  39. <el-option v-for="item in district" :key="item.id" :label="item.name" :value="item.name"></el-option>
  40. </el-select>
  41. </el-col>
  42. </el-row>
  43. </el-form-item>
  44. <el-form-item label="详细地址" prop="address">
  45. <el-input v-model="form.address"></el-input>
  46. </el-form-item>
  47. </el-form>
  48. <div slot="footer" class="dialog-footer">
  49. <el-button @click="isShowChangeAddress = false">取 消</el-button>
  50. <el-button type="primary" @click="comfirm('address')" :loading="changeAddressLoading">确 定</el-button>
  51. </div>
  52. </el-dialog>
  53. </div>
  54. </template>
  55. <script>
  56. Vue.component('order-address', {
  57. template: '#order-address',
  58. props: {
  59. is_show: {
  60. type: Boolean,
  61. default: false
  62. },
  63. order_info: {
  64. type: Object,
  65. default: function() {
  66. return {};
  67. }
  68. },
  69. changeAddressLoading:{
  70. type:Boolean,
  71. default:false
  72. },
  73. title: {
  74. type: String,
  75. default: '修改地址'
  76. }
  77. },
  78. data() {
  79. return {
  80. isShowChangeAddress: false,
  81. regionArr: [],
  82. province: [],
  83. city: [],
  84. district: [],
  85. addressInfo: '',
  86. form: {
  87. name: '',
  88. mobile: '',
  89. address: '',
  90. region_name: ''
  91. },
  92. rules: {
  93. receiver_name: [{
  94. required: true,
  95. message: '请填写收货人姓名',
  96. trigger: 'change'
  97. }],
  98. mobile: [{
  99. required: true,
  100. message: '请填写收货人手机号',
  101. trigger: 'change'
  102. }],
  103. region_name: [{
  104. required: true,
  105. message: '请填写所在区域',
  106. trigger: 'change'
  107. }],
  108. address: [{
  109. required: true,
  110. message: '请填写详细地址',
  111. trigger: 'change'
  112. }],
  113. },
  114. }
  115. },
  116. watch: {
  117. is_show: function(newVal) {
  118. if (newVal) {
  119. this.openAddress();
  120. }
  121. this.isShowChangeAddress = newVal
  122. },
  123. order_info(val) {
  124. this.form = {
  125. id:val.id,
  126. receiver_name: val.receiver_name,
  127. mobile: val.mobile,
  128. address: val.address,
  129. zip: val.zip,
  130. province: val.province,
  131. city: val.city,
  132. area: val.area,
  133. }
  134. let region_name = val.region_name
  135. this.regionArr = region_name.split(' ')
  136. console.log(this.regionArr)
  137. },
  138. regionArr(val) {
  139. this.form.region_name = val[0] + ' ' + val[1] + ' ' + val[2]
  140. }
  141. },
  142. methods: {
  143. openAddress() {
  144. request({
  145. params: {
  146. r: 'common/region/list',
  147. level: 3
  148. },
  149. }).then(res => {
  150. // console.log(res)
  151. this.province = res.data.data.list
  152. for (let i = 0; i < this.province.length; i++) {
  153. if (this.regionArr[0] == this.province[i].name) {
  154. this.city = this.province[i].children
  155. }
  156. }
  157. for (let i = 0; i < this.city.length; i++) {
  158. if (this.regionArr[1] == this.city[i].name) {
  159. this.district = this.city[i].children
  160. }
  161. }
  162. // this.getDistrict();
  163. })
  164. },
  165. // 获取城市列表
  166. getCity() {
  167. for (let i = 0; i < this.province.length; i++) {
  168. if (this.regionArr[0] == this.province[i].name) {
  169. this.city = this.province[i].children
  170. this.regionArr[1] = this.city[0].name
  171. this.district = this.city[0].children
  172. this.regionArr[2] = this.district[0].name
  173. this.form.province = this.province[i].id
  174. this.form.city = this.city[0].id
  175. this.form.area = this.district[0].id
  176. }
  177. }
  178. },
  179. // 获取区县
  180. getDistrict() {
  181. for (let i = 0; i < this.city.length; i++) {
  182. if (this.regionArr[1] == this.city[i].name) {
  183. this.district = this.city[i].children
  184. this.regionArr[2] = this.district[0].name
  185. this.form.city = this.city[i].id
  186. this.form.area = this.district[0].id
  187. }
  188. }
  189. },
  190. getArea(e) {
  191. this.district.forEach((it, i) => {
  192. if (it.name == e) {
  193. this.form.area = it.id
  194. }
  195. })
  196. },
  197. comfirm(formName) { // 确定
  198. // console.log('ok')
  199. this.$refs[formName].validate((valid) => {
  200. if (valid) {
  201. console.log(this.form);
  202. this.$emit('sure',this.form)
  203. } else {
  204. console.log('error submit!!');
  205. }
  206. });
  207. },
  208. dialogClose() {
  209. this.$emit('close')
  210. }
  211. }
  212. });
  213. </script>
  214. <style>
  215. </style>