agencyList.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true" :model="filters">
  6. <el-form-item>
  7. <el-input v-model="filters.keyName" size="small" clearable placeholder="请输入机构名称"></el-input>
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" size="small" v-on:click="getList">查询</el-button>
  11. </el-form-item>
  12. <el-form-item style="float:right;">
  13. <!-- v-if="user.parentId == 1 && user.subordinateType == 0" -->
  14. <el-button type="primary" size="small" @click="handleAdd">新增</el-button>
  15. </el-form-item>
  16. </el-form>
  17. </el-col>
  18. <!--列表-->
  19. <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
  20. <el-table-column type="index" width="60"></el-table-column>
  21. <el-table-column prop="name" label="机构名称" width="300" sortable></el-table-column>
  22. <el-table-column prop="phone" label="联系方式" width="200" sortable></el-table-column>
  23. <el-table-column prop="address" label="机构位置" sortable></el-table-column>
  24. <el-table-column label="操作" width="160" align="center">
  25. <template slot-scope="scope">
  26. <el-button type="primary" size="small" @click="toDetail(scope.row.id)">详情</el-button>
  27. <el-button type="danger" size="small" @click="toDelete(scope.row.id)">删除</el-button>
  28. </template>
  29. </el-table-column>
  30. </el-table>
  31. <!--工具条-->
  32. <el-col :span="24" class="toolbar">
  33. <el-pagination
  34. @size-change="handleSizeChange"
  35. @current-change="handleCurrentChange"
  36. :page-sizes="[20 , 50 , 80 , 100]"
  37. :page-size="20"
  38. layout="total, sizes, prev, pager, next"
  39. :total="total"
  40. style="float:right;">
  41. </el-pagination>
  42. </el-col>
  43. <!--新增界面-->
  44. <el-dialog title="新增培训机构" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  45. <el-form :model="addForm" label-width="100px" :rules="formRules" ref="addForm">
  46. <el-form-item label="机构名称" prop="name">
  47. <el-input v-model="addForm.name" autocomplete="off" placeholder="请输入机构名称"></el-input>
  48. </el-form-item>
  49. <el-form-item label="联系方式" prop="phone">
  50. <el-input v-model="addForm.phone" autocomplete="off" placeholder="请输入联系方式"></el-input>
  51. </el-form-item>
  52. <el-form-item label="机构地址" prop="address">
  53. <el-input v-model="addForm.address" autocomplete="off" :change="changeFactoryArea('addContainer')" placeholder="请输入机构地址"></el-input>
  54. </el-form-item>
  55. <div id="addContainer" class="formMap"></div>
  56. </el-form>
  57. <div slot="footer" class="dialog-footer">
  58. <el-button @click.native="addFormVisible = false">取消</el-button>
  59. <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
  60. </div>
  61. </el-dialog>
  62. </section>
  63. </template>
  64. <script>
  65. import Vue from 'vue';
  66. import util from '../../common/js/util'
  67. export default {
  68. data() {
  69. return {
  70. filters: {
  71. keyName: ''
  72. },
  73. user: JSON.parse(sessionStorage.getItem('user')),
  74. charger: [],
  75. molds: [],
  76. list: [],
  77. total: 0,
  78. page: 1,
  79. size: 20,
  80. listLoading: false,
  81. tableHeight: 0,
  82. formRules: {
  83. name: [
  84. { required: true, message: '请输入机构名称', trigger: 'blur' }
  85. ]
  86. },
  87. // 地图
  88. map: '',
  89. marker: '',
  90. // 新增界面
  91. addFormVisible: false,
  92. addLoading: false,
  93. addForm: {
  94. name: '',
  95. address: '',
  96. phone: '',
  97. yLng: 116.397511,
  98. xLat: 39.907545,
  99. }
  100. }
  101. },
  102. methods: {
  103. //分页
  104. handleCurrentChange(val) {
  105. this.page = val;
  106. this.getList();
  107. },
  108. handleSizeChange(val) {
  109. this.size = val;
  110. this.getList();
  111. },
  112. //获取项目列表
  113. getList() {
  114. this.listLoading = true;
  115. this.http.post(this.port.agency.list, {
  116. // keyName: this.filters.keyName,
  117. pageNum: this.page,
  118. pageSize: this.size,
  119. }, res => {
  120. this.listLoading = false;
  121. if (res.code == "ok") {
  122. this.list = res.data.list;
  123. this.total = res.data.total;
  124. } else {
  125. this.$message({
  126. message: res.msg,
  127. type: 'error'
  128. });
  129. }
  130. }, error => {
  131. this.listLoading = false;
  132. this.$message({
  133. message: error,
  134. type: 'error'
  135. });
  136. })
  137. },
  138. //详情
  139. toDetail(id) {
  140. this.$router.push('/agency/' + id);
  141. },
  142. //删除
  143. toDelete(id) {
  144. this.$confirm('确认删除该培训机构吗?', '提示', {
  145. type: 'warning'
  146. }).then(() => {
  147. this.http.post(this.port.agency.delete, {
  148. id: row.id
  149. }, res => {
  150. if (res.code == "ok") {
  151. this.$message({
  152. message: '删除成功',
  153. type: 'success'
  154. });
  155. this.getList();
  156. } else {
  157. this.$message({
  158. message: res.msg,
  159. type: 'error'
  160. });
  161. }
  162. }, error => {
  163. this.$message({
  164. message: error,
  165. type: 'error'
  166. });
  167. })
  168. });
  169. },
  170. //显示新增界面
  171. handleAdd() {
  172. this.addFormVisible = true;
  173. this.addForm = {
  174. name: '',
  175. address: '',
  176. phone: '',
  177. yLng: 116.397511,
  178. xLat: 39.907545,
  179. };
  180. },
  181. //新增
  182. addSubmit() {
  183. this.$refs.addForm.validate((valid) => {
  184. if (valid) {
  185. this.addLoading = true;
  186. this.http.post(this.port.agency.add, {
  187. name: this.addForm.name,
  188. address: this.addForm.address,
  189. lng: this.addForm.address==''?null:this.addForm.yLng,
  190. lat: this.addForm.address==''?null:this.addForm.xLat,
  191. } , res => {
  192. this.addLoading = false;
  193. if (res.code == "ok") {
  194. this.addFormVisible = false;
  195. this.$message({
  196. message: '创建成功',
  197. type: 'success'
  198. });
  199. this.getList();
  200. } else {
  201. this.$message({
  202. message: res.msg,
  203. type: 'error'
  204. });
  205. }
  206. }, error => {
  207. this.addLoading = false;
  208. this.addFormVisible = false;
  209. this.$message({
  210. message: error,
  211. type: 'error'
  212. });
  213. })
  214. }
  215. });
  216. },
  217. //地址输入切换
  218. changeFactoryArea(mapId) {
  219. if(mapId == "addContainer"){
  220. this.markLocation(this.addForm.address, mapId);
  221. } else {
  222. this.markLocation(this.editForm.address, mapId);
  223. }
  224. },
  225. //获取地图
  226. setMap(mapId) {
  227. if(mapId == 'addContainer') {
  228. this.map = new AMap.Map('addContainer', {
  229. resizeEnable: true, // 允许缩放
  230. center:[ this.addForm.yLng , this.addForm.xLat ],
  231. zoom:10
  232. })
  233. this.marker = new AMap.Marker({
  234. map: this.map,
  235. position: new AMap.LngLat(this.addForm.yLng , this.addForm.xLat), // 经纬度
  236. });
  237. } else {
  238. this.map = new AMap.Map('editContainer', {
  239. resizeEnable: true, // 允许缩放
  240. center:[this.editForm.yLng , this.editForm.xLat],
  241. zoom:10
  242. })
  243. this.marker = new AMap.Marker({
  244. map: this.map,
  245. position: new AMap.LngLat(this.editForm.yLng , this.editForm.xLat), // 经纬度
  246. });
  247. }
  248. var _this = this;
  249. this.map.on('click', function(e) {
  250. if(_this.map){
  251. _this.map.remove(_this.marker);
  252. }
  253. var Lng = e.lnglat.getLng(),
  254. Lat = e.lnglat.getLat();
  255. if(mapId == 'addContainer') {
  256. _this.addForm.yLng = Lng;
  257. _this.addForm.xLat = Lat;
  258. } else {
  259. _this.editForm.yLng = Lng;
  260. _this.editForm.xLat = Lat;
  261. }
  262. _this.marker = new AMap.Marker({
  263. map: _this.map,
  264. position: new AMap.LngLat(Lng , Lat), // 经纬度
  265. });
  266. });
  267. },
  268. // 获取经纬度
  269. markLocation(address,mapId) {
  270. var _this = this;
  271. AMap.plugin('AMap.Geocoder', function() {
  272. var geocoder = new AMap.Geocoder();
  273. geocoder.getLocation(address, function(status, result) {
  274. if (status === 'complete' && result.info === 'OK') {
  275. // 经纬度
  276. var lng = result.geocodes[0].location.lng;
  277. var lat = result.geocodes[0].location.lat;
  278. _this.noSub = false;
  279. if(mapId == "addContainer") {
  280. _this.addForm.yLng = lng;
  281. _this.addForm.xLat = lat;
  282. } else {
  283. _this.editForm.yLng = lng;
  284. _this.editForm.xLat = lat;
  285. }
  286. // 添加标记
  287. if(_this.map){
  288. _this.map.remove(_this.marker);
  289. _this.map.setZoomAndCenter(10, [lng, lat]);
  290. _this.marker = new AMap.Marker({
  291. map: _this.map,
  292. position: new AMap.LngLat(lng, lat), // 经纬度
  293. });
  294. }
  295. } else {
  296. //console.log('定位失败!');
  297. }
  298. });
  299. });
  300. }
  301. },
  302. created() {
  303. let height = window.innerHeight;
  304. this.tableHeight = height - 210;
  305. const that = this;
  306. window.onresize = function temp() {
  307. that.tableHeight = window.innerHeight - 210;
  308. };
  309. },
  310. watch: {
  311. addFormVisible(val) {
  312. if(val){
  313. var _this = this
  314. setTimeout(function(){ _this.setMap('addContainer'); }, 300);
  315. }
  316. },
  317. editFormVisible(val) {
  318. if(val){
  319. var _this = this
  320. setTimeout(function(){ _this.setMap('editContainer'); }, 300);
  321. }
  322. }
  323. },
  324. mounted() {
  325. this.getList();
  326. }
  327. }
  328. </script>
  329. <style scoped>
  330. .formMap {
  331. height: 400px;
  332. }
  333. </style>