factory.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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" placeholder="请输入生产方名称进行搜索" clearable></el-input>
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" @click.native="getFactory">查询</el-button>
  11. </el-form-item>
  12. <el-form-item style="float:right;">
  13. <el-button type="primary" @click.native="handleAdd">新增</el-button>
  14. </el-form-item>
  15. </el-form>
  16. </el-col>
  17. <!--列表-->
  18. <el-table :data="list" highlight-current-row :height="tableHeight" v-loading="listLoading" style="width: 100%;">
  19. <el-table-column type="index" width="60"></el-table-column>
  20. <el-table-column prop="companyName" label="生产方名称" width="250" sortable></el-table-column>
  21. <el-table-column prop="administrator" label="资产方管理员" width="150" sortable>
  22. </el-table-column>
  23. <el-table-column prop="relateCompanyList" label="关联资产方" width="400" sortable>
  24. <template slot-scope="scope">
  25. <span class="info" v-for="(item, index) in scope.row.relateCompanyList">
  26. {{item.companyName}}
  27. <span v-if="index != scope.row.relateCompanyList.length-1">、</span>
  28. </span>
  29. </template>
  30. </el-table-column>
  31. <el-table-column prop="companyAddress" label="生产方地址" sortable></el-table-column>
  32. <el-table-column label="操作" width="150">
  33. <template slot-scope="scope">
  34. <el-button size="small" @click.native="handleEdit(scope.$index, scope.row)">编辑</el-button>
  35. <el-button type="danger" size="small" @click.native.native="handleDel(scope.$index, scope.row)">删除</el-button>
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. <!--工具条-->
  40. <el-col :span="24" class="toolbar">
  41. <el-pagination
  42. @size-change="handleSizeChange"
  43. @current-change="handleCurrentChange"
  44. :page-sizes="[20 , 50 , 80 , 100]"
  45. :page-size="20"
  46. layout="total, sizes, prev, pager, next"
  47. :total="total"
  48. style="float:right;">
  49. </el-pagination>
  50. </el-col>
  51. <!--新增界面-->
  52. <el-dialog title="新增生产方" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  53. <el-form :model="addForm" label-width="100px" :rules="formRules" ref="addForm">
  54. <el-form-item label="生产方名称" prop="companyName" v-show="addState">
  55. <el-input v-model="addForm.companyName" autocomplete="off" placeholder="请输入生产方名称"></el-input>
  56. </el-form-item>
  57. <el-form-item label="关联资产方" v-show="addState">
  58. <el-select v-model="addForm.companyIds" clearable multiple filterable placeholder="请选择生产方" style="width:533px">
  59. <el-option v-for="item in companys" :key="item.id" :label="item.companyName" :value="item.id">
  60. </el-option>
  61. </el-select>
  62. </el-form-item>
  63. <el-form-item label="生产方地址" prop="companyAddress" v-show="addState">
  64. <el-input v-model.lazy="addForm.companyAddress" autocomplete="off" @change="changeFactoryArea('addContainer')" placeholder="请输入生产方地址"></el-input>
  65. </el-form-item>
  66. <div id="addContainer" class="formMap" v-show="addState"></div>
  67. <el-form-item label="姓名" prop="username" v-show="!addState">
  68. <el-input v-model="addForm.username" autocomplete="off" placeholder="请输入姓名"></el-input>
  69. </el-form-item>
  70. <el-form-item label="手机号" prop="account" v-show="!addState">
  71. <el-input v-model="addForm.account" autocomplete="off" placeholder="请输入手机号(登录账号)"></el-input>
  72. </el-form-item>
  73. <el-form-item label="角色" v-show="!addState">
  74. <el-input v-model="addForm.roleName" autocomplete="off" placeholder="请输入角色名称"></el-input>
  75. </el-form-item>
  76. </el-form>
  77. <div slot="footer" class="dialog-footer">
  78. <span v-if="!addState" style="color:#f00;float:left;margin-left:60px;">初始密码:000000</span>
  79. <el-button @click.native="addFormVisible = false">取消</el-button>
  80. <el-button v-if="addState" type="primary" @click.native="toNext(0)">下一步</el-button>
  81. <el-button v-if="!addState" type="primary" @click.native="toPart(0)">上一步</el-button>
  82. <el-button v-if="!addState" type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
  83. </div>
  84. </el-dialog>
  85. <!--编辑界面-->
  86. <el-dialog title="编辑生产方" v-if="editFormVisible" :visible.sync="editFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  87. <el-form :model="editForm" label-width="100px" :rules="formRules" ref="editForm">
  88. <el-form-item label="生产方名称" prop="companyName">
  89. <el-input v-model="editForm.companyName" autocomplete="off" placeholder="请输入生产方名称"></el-input>
  90. </el-form-item>
  91. <el-form-item label="关联资产方">
  92. <el-select v-model="editForm.companyIds" clearable multiple filterable placeholder="请选择生产方" style="width:533px">
  93. <el-option v-for="item in companys" :key="item.id" :label="item.companyName" :value="item.id">
  94. </el-option>
  95. </el-select>
  96. </el-form-item>
  97. <el-form-item label="生产方地址" prop="companyAddress">
  98. <el-input v-model="editForm.companyAddress" autocomplete="off" :change="changeFactoryArea('editContainer')" placeholder="请输入生产方地址"></el-input>
  99. </el-form-item>
  100. <div id="editContainer" class="formMap"></div>
  101. </el-form>
  102. <div slot="footer" class="dialog-footer">
  103. <el-button @click.native="editFormVisible = false">取消</el-button>
  104. <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
  105. </div>
  106. </el-dialog>
  107. </section>
  108. </template>
  109. <script>
  110. import Vue from 'vue';
  111. import util from '../../common/js/util'
  112. export default {
  113. data() {
  114. var checkPhone = (rule, value, callback) => {
  115. if (!value) {
  116. return callback(new Error('请输入联系方式'));
  117. } else {
  118. const reg = /^1[0-9]\d{9}$/
  119. if (reg.test(value)) {
  120. callback();
  121. } else {
  122. return callback(new Error('请输入正确的联系方式'));
  123. }
  124. }
  125. };
  126. return {
  127. filters: {
  128. keyName: ''
  129. },
  130. user: JSON.parse(sessionStorage.getItem('user')),
  131. companys:[],
  132. list: [],
  133. total: 0,
  134. page: 1,
  135. size: 20,
  136. listLoading: false,
  137. tableHeight: 0,
  138. formRules: {
  139. companyName: [
  140. { required: true, message: '请输入生产方名称', trigger: 'blur' }
  141. ],
  142. companyAddress: [
  143. { required: true, message: '请输入生产方地址', trigger: 'blur' }
  144. ],
  145. username: [
  146. { required: true, message: '请输入姓名', trigger: 'blur' }
  147. ],
  148. account: [
  149. { required: true, validator: checkPhone, trigger: 'blur'}
  150. ]
  151. },
  152. // 地图
  153. map: '',
  154. marker: '',
  155. // 新增界面
  156. addFormVisible: false,
  157. addLoading: false,
  158. addState: true,
  159. addTitle: '新增生产方',
  160. addForm: {
  161. companyName: '',
  162. companyType: 1,
  163. companyAddress: '',
  164. yLng: 116.397511,
  165. xLat: 39.907545,
  166. companyIds: [],
  167. username: '',
  168. account: '',
  169. companyId: '',
  170. roleName: "系统管理员",
  171. flag: 0
  172. },
  173. // 编辑界面
  174. editFormVisible: false,
  175. editLoading: false,
  176. editForm: {
  177. id: 0,
  178. companyName: '',
  179. companyType: 1,
  180. companyAddress: '',
  181. yLng: 0,
  182. xLat: 0,
  183. companyIds: [],
  184. flag: 1
  185. }
  186. }
  187. },
  188. methods: {
  189. // 分页
  190. handleCurrentChange(val) {
  191. this.page = val;
  192. this.getFactory();
  193. },
  194. handleSizeChange(val) {
  195. this.size = val;
  196. this.getFactory();
  197. },
  198. //获取基础数据
  199. getMsg() {
  200. this.http.post(this.port.base.relationList, {
  201. companyType: 0
  202. }, res => {
  203. if (res.code == "ok") {
  204. this.companys = res.data;
  205. } else {
  206. this.$message({
  207. message: res.msg,
  208. type: 'error'
  209. });
  210. }
  211. }, error => {
  212. this.$message({
  213. message: error,
  214. type: 'error'
  215. });
  216. })
  217. },
  218. //获取列表
  219. getFactory() {
  220. this.listLoading = true;
  221. this.http.post(this.port.base.companyList, {
  222. keyName: this.filters.keyName,
  223. pageNum: this.page,
  224. pageSize: this.size,
  225. companyType: 1
  226. }, res => {
  227. this.listLoading = false;
  228. if (res.code == "ok") {
  229. this.list = res.data.list;
  230. this.total = res.data.total;
  231. } else {
  232. this.$message({
  233. message: res.msg,
  234. type: 'error'
  235. });
  236. }
  237. }, error => {
  238. this.listLoading = false;
  239. this.$message({
  240. message: error,
  241. type: 'error'
  242. });
  243. })
  244. },
  245. //地址输入切换
  246. changeFactoryArea(mapId) {
  247. if(mapId == "addContainer"){
  248. this.markLocation(this.addForm.companyAddress, mapId);
  249. } else {
  250. this.markLocation(this.editForm.companyAddress, mapId);
  251. }
  252. },
  253. toNext(i) {
  254. if(i == 0) {
  255. this.addState = false;
  256. this.addTitle = '新增生产方管理员';
  257. }
  258. },
  259. toPart(i) {
  260. if(i == 0) {
  261. this.addState = true;
  262. this.addTitle = '新增生产方';
  263. }
  264. var _this = this
  265. setTimeout(function(){ _this.setMap('addContainer'); }, 100);
  266. },
  267. //显示新增界面
  268. handleAdd() {
  269. this.addFormVisible = true;
  270. this.addState = true;
  271. this.addTitle = '新增资产方';
  272. this.addForm = {
  273. companyName: '',
  274. companyAddress: '',
  275. yLng: 116.397511,
  276. xLat: 39.907545,
  277. companyIds: [],
  278. username: '',
  279. account: '',
  280. companyId: '',
  281. roleName: "系统管理员",
  282. flag: 0
  283. };
  284. },
  285. //新增
  286. addSubmit() {
  287. this.$refs.addForm.validate((valid) => {
  288. if (valid) {
  289. this.addLoading = true;
  290. var str = "";
  291. for(var i in this.addForm.companyIds){
  292. if(i == this.addForm.companyIds.length-1){
  293. str += this.addForm.companyIds
  294. } else {
  295. str += this.addForm.companyIds + ","
  296. }
  297. }
  298. this.http.post(this.port.base.addCompany, {
  299. companyName: this.addForm.companyName,
  300. companyType: 1,
  301. companyAddress: this.addForm.companyAddress,
  302. yLng: this.addForm.yLng,
  303. xLat: this.addForm.xLat,
  304. companyIds: str,
  305. flag: 0
  306. } , res => {
  307. this.addLoading = false;
  308. if (res.code == "ok") {
  309. this.addPeo(res.data.id);
  310. } else {
  311. this.$message({
  312. message: res.msg,
  313. type: 'error'
  314. });
  315. }
  316. }, error => {
  317. this.addLoading = false;
  318. this.addFormVisible = false;
  319. this.$message({
  320. message: error,
  321. type: 'error'
  322. });
  323. })
  324. }
  325. });
  326. },
  327. //添加人员
  328. addPeo(companyId) {
  329. this.$refs.addForm.validate((valid) => {
  330. if (valid) {
  331. this.http.post(this.port.project.addUser, {
  332. username: this.addForm.username,
  333. account: this.addForm.account,
  334. companyId: companyId,
  335. roleName: this.addForm.roleName,
  336. parentId: this.user.id,
  337. addType: 0,
  338. flag: 0
  339. } , res => {
  340. this.addLoading = false;
  341. if (res.code == "ok") {
  342. this.addFormVisible = false;
  343. this.$message({
  344. message: '创建成功',
  345. type: 'success'
  346. });
  347. this.getFactory();
  348. } else {
  349. this.$message({
  350. message: res.msg,
  351. type: 'error'
  352. });
  353. }
  354. }, error => {
  355. this.addLoading = false;
  356. this.addFormVisible = false;
  357. this.$message({
  358. message: error,
  359. type: 'error'
  360. });
  361. })
  362. }
  363. });
  364. },
  365. //删除
  366. handleDel(index, row) {
  367. this.$confirm('确认删除该生产方吗?', '提示', {
  368. type: 'warning'
  369. }).then(() => {
  370. this.http.post(this.port.base.delCompany, {
  371. id: row.id
  372. }, res => {
  373. if (res.code == "ok") {
  374. this.$message({
  375. message: '删除成功',
  376. type: 'success'
  377. });
  378. this.getFactory();
  379. } else {
  380. this.$message({
  381. message: res.msg,
  382. type: 'error'
  383. });
  384. }
  385. }, error => {
  386. this.$message({
  387. message: error,
  388. type: 'error'
  389. });
  390. })
  391. });
  392. },
  393. //显示编辑界面
  394. handleEdit(index, row) {
  395. this.editFormVisible = true;
  396. var array = [];
  397. for(var i in row.relateCompanyList){
  398. array.push(row.relateCompanyList[i].id)
  399. }
  400. this.editForm = {
  401. id: row.id,
  402. companyName: row.companyName,
  403. companyType: 1,
  404. companyAddress: row.companyAddress,
  405. yLng: row.ylng,
  406. xLat: row.xlat,
  407. companyIds: array,
  408. flag: 1
  409. };
  410. console.log(this.editForm.companyIds)
  411. },
  412. //编辑
  413. editSubmit() {
  414. this.$refs.editForm.validate((valid) => {
  415. if (valid) {
  416. this.editLoading = true;
  417. var str = "";
  418. console.log(this.editForm.companyIds.length)
  419. for(var i in this.editForm.companyIds){
  420. if(i == this.editForm.companyIds.length-1){
  421. str += this.editForm.companyIds[i]
  422. } else {
  423. str += this.editForm.companyIds[i] + ","
  424. }
  425. }
  426. this.http.post(this.port.base.addCompany, {
  427. id: this.editForm.id,
  428. companyName: this.editForm.companyName,
  429. companyType: 1,
  430. companyAddress: this.editForm.companyAddress,
  431. yLng: this.editForm.yLng,
  432. xLat: this.editForm.xLat,
  433. companyIds: str,
  434. flag: 1
  435. } , res => {
  436. this.editLoading = false;
  437. if (res.code == "ok") {
  438. this.editFormVisible = false;
  439. this.$message({
  440. message: '修改成功',
  441. type: 'success'
  442. });
  443. this.getFactory();
  444. } else {
  445. this.$message({
  446. message: res.msg,
  447. type: 'error'
  448. });
  449. }
  450. }, error => {
  451. this.editLoading = false;
  452. this.editFormVisible = false;
  453. this.$message({
  454. message: error,
  455. type: 'error'
  456. });
  457. })
  458. }
  459. });
  460. },
  461. //获取地图
  462. setMap(mapId) {
  463. if(mapId == 'addContainer') {
  464. this.map = new AMap.Map('addContainer', {
  465. resizeEnable: true, // 允许缩放
  466. center:[ this.addForm.yLng , this.addForm.xLat ],
  467. zoom:10
  468. })
  469. this.marker = new AMap.Marker({
  470. map: this.map,
  471. position: new AMap.LngLat(this.addForm.yLng , this.addForm.xLat), // 经纬度
  472. });
  473. } else {
  474. this.map = new AMap.Map('editContainer', {
  475. resizeEnable: true, // 允许缩放
  476. center:[this.editForm.yLng , this.editForm.xLat],
  477. zoom:10
  478. })
  479. this.marker = new AMap.Marker({
  480. map: this.map,
  481. position: new AMap.LngLat(this.editForm.yLng , this.editForm.xLat), // 经纬度
  482. });
  483. }
  484. var _this = this;
  485. this.map.on('click', function(e) {
  486. if(_this.map){
  487. _this.map.remove(_this.marker);
  488. }
  489. var Lng = e.lnglat.getLng(),
  490. Lat = e.lnglat.getLat();
  491. if(mapId == 'addContainer') {
  492. _this.addForm.yLng = Lng;
  493. _this.addForm.xLat = Lat;
  494. } else {
  495. _this.editForm.yLng = Lng;
  496. _this.editForm.xLat = Lat;
  497. }
  498. _this.marker = new AMap.Marker({
  499. map: _this.map,
  500. position: new AMap.LngLat(Lng , Lat), // 经纬度
  501. });
  502. });
  503. },
  504. // 获取经纬度
  505. markLocation(address,mapId) {
  506. var _this = this;
  507. AMap.plugin('AMap.Geocoder', function() {
  508. var geocoder = new AMap.Geocoder();
  509. geocoder.getLocation(address, function(status, result) {
  510. if (status === 'complete' && result.info === 'OK') {
  511. // 经纬度
  512. var lng = result.geocodes[0].location.lng;
  513. var lat = result.geocodes[0].location.lat;
  514. _this.noSub = false;
  515. if(mapId == "addContainer") {
  516. _this.addForm.yLng = lng;
  517. _this.addForm.xLat = lat;
  518. } else {
  519. _this.editForm.yLng = lng;
  520. _this.editForm.xLat = lat;
  521. }
  522. // 添加标记
  523. if(_this.map){
  524. _this.map.remove(_this.marker);
  525. _this.map.setZoomAndCenter(10, [lng, lat]);
  526. _this.marker = new AMap.Marker({
  527. map: _this.map,
  528. position: new AMap.LngLat(lng, lat), // 经纬度
  529. });
  530. }
  531. } else {
  532. //console.log('定位失败!');
  533. }
  534. });
  535. });
  536. }
  537. },
  538. created() {
  539. let height = window.innerHeight;
  540. this.tableHeight = height - 210;
  541. const that = this;
  542. window.onresize = function temp() {
  543. that.tableHeight = window.innerHeight - 210;
  544. };
  545. },
  546. watch: {
  547. addFormVisible(val) {
  548. if(val){
  549. var _this = this
  550. setTimeout(function(){ _this.setMap('addContainer'); }, 300);
  551. }
  552. },
  553. editFormVisible(val) {
  554. if(val){
  555. var _this = this
  556. setTimeout(function(){ _this.setMap('editContainer'); }, 300);
  557. }
  558. }
  559. },
  560. mounted() {
  561. this.getMsg();
  562. this.getFactory();
  563. }
  564. }
  565. </script>
  566. <style scoped>
  567. .formMap {
  568. height: 400px;
  569. }
  570. </style>