factory.vue 25 KB

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