order-address.php 8.3 KB

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