Demo.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div>
  3. <div class="crumbs">
  4. <el-breadcrumb separator="/">
  5. <el-breadcrumb-item><i class="el-icon-lx-calendar"></i> 表单</el-breadcrumb-item>
  6. <el-breadcrumb-item>图片上传</el-breadcrumb-item>
  7. </el-breadcrumb>
  8. </div>
  9. <div class="container">
  10. <div class="crop-demo">
  11. <el-input v-model="fileName" style="width:200px"></el-input>
  12. <div class="crop-demo-btn">选择文件
  13. <input class="crop-input" type="file" name="image" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" @change="setImage"/>
  14. </div>
  15. <div class="crop-demo-btn1">
  16. <el-button @click="upload" :disabled="disabled">上传</el-button>
  17. </div>
  18. </div>
  19. <div class="el-upload__tip" slot="tip">只能上传excel文件,且不超过500kb</div>
  20. </div>
  21. <div class="container">
  22. <div class="linkage">
  23. <el-select v-model="sheng" @change="choseProvince" placeholder="省级地区">
  24. <el-option v-for="item in province" :key="item.id" :label="item.value" :value="item.id"></el-option>
  25. </el-select>
  26. <el-select v-model="shi" @change="choseCity" placeholder="市级地区">
  27. <el-option v-for="item in shi1" :key="item.id" :label="item.value" :value="item.id"></el-option>
  28. </el-select>
  29. <el-select v-model="qu" @change="choseBlock" placeholder="区级地区">
  30. <el-option v-for="item in qu1" :key="item.id" :label="item.value" :value="item.id"></el-option>
  31. </el-select>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. export default {
  38. name: 'upload',
  39. data: function(){
  40. return {
  41. fileName: '',
  42. imgSrc: '',
  43. cropImg: '',
  44. disabled: true,
  45. mapJson:'../../static/json/map.json',
  46. province:'',
  47. sheng: '',
  48. shi: '',
  49. shi1: [],
  50. qu: '',
  51. qu1: [],
  52. city:'',
  53. block:''
  54. }
  55. },
  56. methods:{
  57. setImage(e){
  58. const file = e.target.files[0];
  59. if (!file.type.includes('application/')) {
  60. this.$message.error('文件格式错误!');
  61. this.disabled = true;
  62. return;
  63. }
  64. if (file.size > 500) {
  65. this.$message.error('文件不能超过500字节!');
  66. this.disabled = true;
  67. return;
  68. };
  69. this.fileName = file.name;
  70. this.disabled = false;
  71. },
  72. upload() {
  73. this.$message.success('ok');
  74. },
  75. // 加载china地点数据,三级
  76. getCityData:function(){
  77. var that = this
  78. this.$axios.get(this.mapJson).then(function(response){
  79. if (response.status==200) {
  80. var data = response.data
  81. that.province = []
  82. that.city = []
  83. that.block = []
  84. // 省市区数据分类
  85. for (var item in data) {
  86. if (item.match(/0000$/)) {//省
  87. that.province.push({id: item, value: data[item], children: []})
  88. } else if (item.match(/00$/)) {//市
  89. that.city.push({id: item, value: data[item], children: []})
  90. } else {//区
  91. that.block.push({id: item, value: data[item]})
  92. }
  93. }
  94. // 分类市级
  95. for (var index in that.province) {
  96. for (var index1 in that.city) {
  97. if (that.province[index].id.slice(0, 2) === that.city[index1].id.slice(0, 2)) {
  98. that.province[index].children.push(that.city[index1])
  99. }
  100. }
  101. }
  102. // 分类区级
  103. for(var item1 in that.city) {
  104. for(var item2 in that.block) {
  105. if (that.block[item2].id.slice(0, 4) === that.city[item1].id.slice(0, 4)) {
  106. that.city[item1].children.push(that.block[item2])
  107. }
  108. }
  109. }
  110. }
  111. else{
  112. console.log(response.status)
  113. }
  114. }).catch(function(error){console.log(typeof+ error)})
  115. },
  116. // 选省
  117. choseProvince:function(e) {
  118. for (var index2 in this.province) {
  119. if (e === this.province[index2].id) {
  120. this.shi1 = this.province[index2].children
  121. this.shi = this.province[index2].children[0].value
  122. this.qu1 =this.province[index2].children[0].children
  123. this.qu = this.province[index2].children[0].children[0].value
  124. this.E = this.qu1[0].id
  125. }
  126. }
  127. },
  128. // 选市
  129. choseCity:function(e) {
  130. for (var index3 in this.city) {
  131. if (e === this.city[index3].id) {
  132. this.qu1 = this.city[index3].children
  133. this.qu = this.city[index3].children[0].value
  134. this.E = this.qu1[0].id
  135. // console.log(this.E)
  136. }
  137. }
  138. },
  139. // 选区
  140. choseBlock:function(e) {
  141. this.E=e;
  142. // console.log(this.E)
  143. },
  144. },
  145. created:function(){
  146. this.getCityData()
  147. }
  148. }
  149. </script>
  150. <style scoped>
  151. .content-title{
  152. font-weight: 400;
  153. line-height: 50px;
  154. margin: 10px 0;
  155. font-size: 22px;
  156. color: #1f2f3d;
  157. }
  158. .pre-img{
  159. width: 100px;
  160. height: 100px;
  161. background: #f8f8f8;
  162. border: 1px solid #eee;
  163. border-radius: 5px;
  164. }
  165. .crop-demo{
  166. display: flex;
  167. align-items: flex-end;
  168. }
  169. .crop-demo-btn{
  170. position: relative;
  171. width: 100px;
  172. height: 33px;
  173. line-height: 33px;
  174. padding: 0 20px;
  175. margin-left: 10px;
  176. background-color: #409eff;
  177. color: #fff;
  178. font-size: 14px;
  179. border-radius: 4px;
  180. box-sizing: border-box;
  181. }
  182. .crop-demo-btn1{
  183. position: relative;
  184. width: 33px;
  185. height: 33px;
  186. line-height: 33px;
  187. padding: 0 20px;
  188. margin-left: 10px;
  189. /* border-radius: 4px; */
  190. /* box-sizing: border-box; */
  191. }
  192. .crop-input{
  193. position: absolute;
  194. width: 100px;
  195. height: 40px;
  196. left: 0;
  197. top: 0;
  198. opacity: 0;
  199. cursor: pointer;
  200. }
  201. </style>