addressManager.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <div class='m-container'>
  3. <h2>分部教学点</h2>
  4. <div class="m-core">
  5. <div @click="teachingStatus = true" class='newBand'>新建</div>
  6. <!-- 搜索类型 -->
  7. <!-- <el-form :inline="true"
  8. class="searchForm"
  9. v-model="searchForm">
  10. <el-form-item>
  11. <el-select v-model="searchForm.status"
  12. placeholder="工作类型">
  13. <el-option label="哈哈哈"
  14. value="1"></el-option>
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-input suffix-icon="el-icon-search"
  19. placeholder="请输入搜索内容"></el-input>
  20. </el-form-item>
  21. </el-form> -->
  22. <!-- 查询列表 -->
  23. <!-- <div class="searchWrap">
  24. <p>查询条件:</p>
  25. <div class="searchItem"
  26. @click="closeSearch(item)"
  27. v-for="(item,index) in searchLsit" :key="index">
  28. {{ item.key }}
  29. <i class="el-icon-close"></i>
  30. </div>
  31. </div> -->
  32. <!-- 列表 -->
  33. <div class="tableWrap">
  34. <el-table :data='tableList'>
  35. <el-table-column align='center' width="55" prop="id"
  36. label="编号">
  37. </el-table-column>
  38. <el-table-column align='center' prop="name"
  39. label="教学点名称">
  40. </el-table-column>
  41. <el-table-column align='center'
  42. label="教学点来源"
  43. :formatter="filterOrgan">
  44. <!-- <template slot-scope="scope">
  45. {{ scope.row.cooperationOrganId ? scope.row.cooperationOrganId : '租赁' }}
  46. </template> -->
  47. </el-table-column>
  48. <el-table-column align='center'
  49. label="费用">
  50. <template slot-scope="scope">
  51. {{ scope.row.cooperationOrganId ? '免费' : scope.row.remark }}
  52. </template>
  53. </el-table-column>
  54. <el-table-column align='center'
  55. label="上课地点详情">
  56. <template slot-scope="scope">
  57. {{ scope.row.address.split(',').join('') }}
  58. </template>
  59. </el-table-column>
  60. <el-table-column align='center' prop="delFlag"
  61. label="状态">
  62. <template slot-scope="scope">
  63. <el-tag effect="dark" type="danger" v-if="scope.row.delFlag == 2" key="delFlag"> 停用</el-tag>
  64. <el-tag effect="dark" v-else key="delFlag">启用</el-tag>
  65. </template>
  66. </el-table-column>
  67. <el-table-column align='center'
  68. label="课酬补贴">
  69. <template slot-scope="scope">
  70. {{ scope.row.subsidy ? scope.row.subsidy : '无' }}
  71. </template>
  72. </el-table-column>
  73. <el-table-column align='center'
  74. label="操作">
  75. <template slot-scope="scope">
  76. <el-button @click="openTeaching('update', scope.row)" type="text">修改</el-button>
  77. <el-button v-if="scope.row.delFlag == 0" @click="onUpdateSubmit(scope.row, 2)" type="text">停用</el-button>
  78. <el-button v-if="scope.row.delFlag == 2" @click="onUpdateSubmit(scope.row, 0)" type="text">启用</el-button>
  79. <el-button @click="onUpdateSubmit(scope.row, 1)" type="text">删除</el-button>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. <pagination :total="pageInfo.total"
  84. :page.sync="pageInfo.page"
  85. :limit.sync="pageInfo.limit"
  86. :page-sizes="pageInfo.page_size"
  87. @pagination="getList" />
  88. </div>
  89. </div>
  90. <el-dialog :title="formTitle[formActionTitle]" :visible.sync="teachingStatus" @close="onFormClose('ruleForm')" width="500px">
  91. <el-form :model="form" :rules="rules" ref="ruleForm">
  92. <el-form-item label="教学点名称" prop="name" :label-width="formLabelWidth">
  93. <el-input v-model="form.name" autocomplete="off"></el-input>
  94. </el-form-item>
  95. <el-form-item label="教学点来源" prop="source" :label-width="formLabelWidth">
  96. <el-select v-model="form.source">
  97. <el-option label="合作单位" value="1"></el-option>
  98. <el-option label="租赁" value="2"></el-option>
  99. </el-select>
  100. </el-form-item>
  101. <el-form-item v-if="form.source == 1" prop="cooperationOrganId" label="合作单位" :label-width="formLabelWidth">
  102. <el-select v-model="form.cooperationOrganId">
  103. <el-option v-for="item in breachList" :key="item.value"
  104. :label="item.label" :value="item.value"></el-option>
  105. </el-select>
  106. </el-form-item>
  107. <el-form-item v-if="form.source == 2" prop="remark" label="费用" :label-width="formLabelWidth">
  108. <el-input v-model="form.remark" autocomplete="off"></el-input>
  109. </el-form-item>
  110. <el-form-item prop="address" :show-message="addressMessage" label="上课地点" :label-width="formLabelWidth">
  111. <el-input class="text-address" v-model="form.address" :disabled="true">
  112. <el-button slot="append" @click="addMap" type="primary" icon="el-icon-plus">选择</el-button>
  113. </el-input>
  114. </el-form-item>
  115. <el-form-item label="课酬补贴" prop="subsidy" :label-width="formLabelWidth">
  116. <el-input v-model.number="form.subsidy" type="number" autocomplete="off"></el-input>
  117. </el-form-item>
  118. </el-form>
  119. <span slot="footer" class="dialog-footer">
  120. <el-button @click="onTeachingCancel('ruleForm')">取 消</el-button>
  121. <el-button type="primary" @click="onTeachingSubmit('ruleForm')">确 定</el-button>
  122. </span>
  123. </el-dialog>
  124. <el-dialog title="选择地图" custom-class="map-container" :visible.sync="mapStatus" width="800px">
  125. <el-amap-search-box class="search-box" :search-option="searchOption" :on-search-result="onSearchResult"></el-amap-search-box>
  126. <el-amap :zoom="zoom" :plugin="plugin" :center="center">
  127. <el-amap-marker :events="markerEvents()" v-for="(marker, index) in markers" :key="index" :position="marker" ></el-amap-marker>
  128. </el-amap>
  129. </el-dialog>
  130. </div>
  131. </template>
  132. <script>
  133. import pagination from '@/components/Pagination/index'
  134. // 地图
  135. (function () {
  136. let func = EventTarget.prototype.addEventListener;
  137. let supportsPassive = false
  138. try {
  139. let opts = Object.defineProperty({}, 'passive', {
  140. get: function() {
  141. supportsPassive = true;
  142. }
  143. })
  144. document.addEventListener("testPassive", null, opts);
  145. document.removeEventListener('testPassive', null, opts);
  146. } catch(e) {}
  147. EventTarget.prototype.addEventListener = function (type, fn, capture) {
  148. this.func = func;
  149. capture = capture instanceof Object ? capture : {};
  150. capture.passive = supportsPassive;
  151. this.func(type, fn, capture);
  152. };
  153. }());
  154. import { schoolQueryPage, schoolAdd, schoolUpdate, queryByOrganId, schoolDel } from '@/api/systemManage'
  155. import store from '@/store'
  156. export default {
  157. components: { pagination },
  158. name: 'adminManager',
  159. data () {
  160. let self = this
  161. return {
  162. searchForm: {
  163. status: ''
  164. },
  165. searchLsit: [],
  166. tableList: [],
  167. pageInfo: {
  168. // 分页规则
  169. limit: 10, // 限制显示条数
  170. page: 1, // 当前页
  171. total: 0, // 总条数
  172. page_size: [10, 20, 40, 50] // 选择限制显示条数
  173. },
  174. formActionTitle: 'create',
  175. formTitle: {
  176. create: '添加教学点',
  177. update: '修改教学点'
  178. },
  179. teachingStatus: false, // 添加教学点
  180. formLabelWidth: '100px',
  181. addressDetail: {},
  182. form: {
  183. name: null, // 教学点名称
  184. source: null, // 来源
  185. cooperationOrganId: null, // 合作单位
  186. remark: null, // 费用
  187. address: null, // 上课地点
  188. subsidy: null, // 课酬补贴
  189. organId: store.getters.organ
  190. },
  191. rules: {
  192. name: [{ required: true, message: '请输入教学点名称', trigger: 'blur' }],
  193. source: [{required: true, message: '请选择教学点来源', trigger: 'change'}],
  194. remark: [{ required: true, message: '请输入教学点名称', trigger: 'blur'}],
  195. address: [{required: true, message: '请选择上课地点', trigger: 'blur'}],
  196. cooperationOrganId: [{required: true, message: '请选择合作单位', trigger: 'change'}],
  197. subsidy: [{ type: 'number', message: '课酬补贴只能为数字', trigger: 'blur'}]
  198. },
  199. addressMessage: true,
  200. mapStatus: false,
  201. zoom: 16,
  202. center: [114.34371, 30.55939],
  203. markers: [],
  204. plugin: [],
  205. searchOption: {
  206. city: '',
  207. citylimit: true,
  208. pageSize: 1, // 单页显示结果条数
  209. pageIndex: 1, // 页码
  210. autoFitView: true // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
  211. },
  212. breachList: [], // 分部列表
  213. }
  214. },
  215. mounted() {
  216. this.getList()
  217. this.getBreachList()
  218. },
  219. methods: {
  220. onTeachingSubmit(formName) { // 添加数据
  221. this.$refs[formName].validate((valid) => {
  222. if (valid) {
  223. this.form.address = this.addressDetail.address
  224. this.form.longitudeLatitude = this.addressDetail.poi
  225. if(this.formActionTitle == 'create') {
  226. schoolAdd(this.form).then(res => {
  227. if(res.code == 200) {
  228. this.$message({
  229. message: '添加成功',
  230. type: 'success'
  231. })
  232. this.teachingStatus = false
  233. this.getList()
  234. } else {
  235. this.$message.error(res.msg)
  236. }
  237. })
  238. } else if(this.formActionTitle == 'update') {
  239. schoolUpdate(this.form).then(res => {
  240. if(res.code == 200) {
  241. this.$message({
  242. message: '修改成功',
  243. type: 'success'
  244. })
  245. this.teachingStatus = false
  246. this.getList()
  247. } else {
  248. this.$message.error(res.msg)
  249. }
  250. })
  251. }
  252. } else {
  253. return false;
  254. }
  255. })
  256. },
  257. onTeachingCancel(formName) {
  258. this.teachingStatus = false
  259. this.$refs[formName].clearValidate()
  260. },
  261. addMap() { //
  262. this.mapStatus = true
  263. let poi = this.addressDetail.poi
  264. // 获取经纬度
  265. if(poi) {
  266. this.markers = []
  267. this.center = [poi.split(',')[0], poi.split(',')[1]];
  268. this.markers.push([poi.split(',')[0], poi.split(',')[1]])
  269. }
  270. },
  271. onSearchResult(pois) { // 搜索出来的Marker
  272. let latSum = 0
  273. let lngSum = 0
  274. if (pois.length > 0) {
  275. pois.forEach(poi => {
  276. let {lng, lat} = poi;
  277. lngSum += lng;
  278. latSum += lat;
  279. this.markers.push([poi.lng, poi.lat]);
  280. });
  281. let center = {
  282. lng: lngSum / pois.length,
  283. lat: latSum / pois.length
  284. };
  285. this.center = [center.lng, center.lat];
  286. }
  287. },
  288. markerEvents() { // marker 事件添加
  289. let that = this
  290. return {
  291. click: (e) => {
  292. let geocoder = new AMap.Geocoder()
  293. geocoder.getAddress(e.lnglat, function(status, result) {
  294. if(status === 'complete' && result.regeocode) {
  295. result.regeocode.lnglat = e.lnglat
  296. let ct = result.regeocode.addressComponent
  297. that.addressDetail = {
  298. address: ct.province + ',' + ct.city + ',' + ct.district + ','+ ct.township + ct.street + ct.streetNumber,
  299. poi: e.lnglat.lng + ',' + e.lnglat.lat
  300. }
  301. that.form.address = result.regeocode.formattedAddress
  302. that.mapStatus = false
  303. that.addressMessage = false
  304. } else {
  305. that.$message.error('请重新选择地址')
  306. }
  307. })
  308. }
  309. }
  310. },
  311. getList() {
  312. schoolQueryPage({
  313. organId: this.form.organId,
  314. rows: this.pageInfo.limit,
  315. page: this.pageInfo.page
  316. }).then(res => {
  317. if(res.code == 200 && res.data) {
  318. this.tableList = res.data.rows
  319. this.pageInfo.total = res.data.total
  320. }
  321. })
  322. },
  323. getBreachList() { // 获取分部列表
  324. queryByOrganId({
  325. organId: this.form.organId
  326. }).then(res => {
  327. if(res.code == 200) {
  328. // 判断是否有数据
  329. if(!res.data && res.data.length <= 0) return
  330. res.data.forEach(r => {
  331. this.breachList.push({
  332. value: r.id,
  333. label: r.name
  334. })
  335. })
  336. }
  337. })
  338. },
  339. openTeaching(type, row) {
  340. // 重置数据
  341. this.form = {
  342. id: null,
  343. name: null, // 教学点名称
  344. linkman: null, // 来源
  345. job: null, // 费用
  346. mobileNo: null, // 合作单位
  347. }
  348. this.teachingStatus = true
  349. this.formActionTitle = type
  350. // 修改的时候赋值
  351. if(type == 'update') {
  352. this.addressDetail = {
  353. address: row.address,
  354. poi: row.longitudeLatitude
  355. }
  356. this.form = {
  357. id: row.id,
  358. name: row.name, // 教学点名称
  359. source: row.cooperationOrganId ? "1" : "2", // 来源
  360. cooperationOrganId: row.cooperationOrganId, // 合作单位
  361. remark: row.remark, // 费用
  362. address: row.address.split(',').join(''), // 上课地点
  363. subsidy: row.subsidy, // 课酬补贴
  364. organId: store.getters.organ
  365. }
  366. }
  367. },
  368. onFormClose(formName) { // 关闭弹窗重置验证
  369. this.$refs[formName].clearValidate()
  370. },
  371. filterOrgan(val) {
  372. let result = ''
  373. if(val.cooperationOrganId) {
  374. this.breachList.forEach(res => {
  375. if(res.value == val.cooperationOrganId) {
  376. result = res.label
  377. }
  378. })
  379. } else {
  380. result = '租赁'
  381. }
  382. return result
  383. },
  384. onUpdateSubmit(row, type) {
  385. let msg
  386. if(type == 2) {
  387. msg = '停用'
  388. } else if(type == 0) {
  389. msg = '启用'
  390. } else {
  391. msg = '删除'
  392. }
  393. this.$confirm(`您确定${msg}吗?`, '提示', {
  394. confirmButtonText: '确定',
  395. cancelButtonText: '取消',
  396. type: 'warning'
  397. }).then(() => {
  398. schoolUpdate({
  399. id: row.id,
  400. delFlag: type
  401. }).then(res => {
  402. if(res.code == 200) {
  403. this.$message({
  404. message: '修改成功',
  405. type: 'success'
  406. })
  407. this.teachingStatus = false
  408. if(type == 2 || type == 0) {
  409. row.delFlag = type
  410. } else {
  411. this.getList()
  412. }
  413. } else {
  414. this.$message.error(res.msg)
  415. }
  416. })
  417. })
  418. }
  419. }
  420. }
  421. </script>
  422. <style lang="scss">
  423. .el-select {
  424. width: auto !important;
  425. }
  426. .el-vue-amap-container {
  427. width: 100%;
  428. height: 50vh !important;
  429. }
  430. * {
  431. // touch-action: pan-y;
  432. touch-action: none;
  433. }
  434. .map-container {
  435. .el-dialog__body {
  436. padding: 0;
  437. }
  438. }
  439. .el-input-group__append, .el-button--primary {
  440. background: #14928a;
  441. border-color: #14928a;
  442. color: #fff;
  443. &:hover, &:active, &:focus {
  444. background: #14928a;
  445. border-color: #14928a;
  446. color: #FFF;
  447. }
  448. }
  449. .el-vue-search-box-container {
  450. position: absolute !important;
  451. left: 10px;
  452. margin-top: 10px;
  453. z-index: 99999 !important;
  454. }
  455. </style>