comp.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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.inputAss')" clearable></el-input>
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" @click.native="getComp">{{$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.assName')" width="250" sortable>
  21. </el-table-column>
  22. <el-table-column prop="administrator" :label="$t('basic.assManager')" width="150" sortable>
  23. <template slot-scope="scope">
  24. <router-link to="/staff" tag="span" style="cursor: pointer; color: #409eff;">{{scope.row.administrator}}</router-link>
  25. </template>
  26. </el-table-column>
  27. <el-table-column prop="relateCompanyList" :label="$t('basic.assProducer')" sortable>
  28. <template slot-scope="scope">
  29. <span class="info" v-for="(item, index) in scope.row.relateCompanyList">
  30. {{item.companyName}}
  31. <span v-if="index != scope.row.relateCompanyList.length-1">、</span>
  32. </span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="companyAddress" :label="$t('basic.assAddress')" sortable></el-table-column>
  36. <el-table-column :label="$t('base.operate')" width="200">
  37. <template slot-scope="scope">
  38. <el-button size="small" @click.native="handleEdit(scope.$index, scope.row)">{{$t('base.edit')}}</el-button>
  39. <el-button type="danger" size="small" @click.native.native="handleDel(scope.$index, scope.row)">{{$t('el.upload.delete')}}</el-button>
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <!--工具条-->
  44. <el-col :span="24" class="toolbar">
  45. <el-pagination
  46. @size-change="handleSizeChange"
  47. @current-change="handleCurrentChange"
  48. :page-sizes="[20 , 50 , 80 , 100]"
  49. :page-size="20"
  50. layout="total, sizes, prev, pager, next"
  51. :total="total"
  52. style="float:right;">
  53. </el-pagination>
  54. </el-col>
  55. <!--新增界面-->
  56. <el-dialog :title="addTitle" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  57. <el-form :model="addForm" :rules="formRules" ref="addForm">
  58. <el-form-item label-width="150px" :label="$t('basic.assName')" prop="companyName" v-show="addState">
  59. <el-input v-model="addForm.companyName" autocomplete="off" :placeholder="$t('basic.inputAssName')" style="width:485px"></el-input>
  60. </el-form-item>
  61. <el-form-item label-width="150px" :label="$t('basic.assProducer')" v-show="addState">
  62. <el-select v-model="addForm.companyIds" clearable multiple filterable :placeholder="$t('basic.inputAssProducer')" style="width:485px">
  63. <el-option v-for="item in companys" :key="item.id" :label="item.companyName" :value="item.id">
  64. </el-option>
  65. </el-select>
  66. </el-form-item>
  67. <el-form-item label-width="150px" :label="$t('basic.assAddress')" prop="companyAddress" v-show="addState">
  68. <el-input v-model="addForm.companyAddress" autocomplete="off" :placeholder="$t('basic.inputAssAddress')" style="width:485px"></el-input>
  69. </el-form-item>
  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.editAsset')" v-if="editFormVisible" :visible.sync="editFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  90. <el-form :model="editForm" label-width="150px" :rules="formRules" ref="editForm">
  91. <el-form-item :label="$t('basic.assName')" prop="companyName">
  92. <el-input v-model="editForm.companyName" autocomplete="off" :placeholder="$t('basic.inputAssName')" style="width:485px"></el-input>
  93. </el-form-item>
  94. <el-form-item :label="$t('basic.assProducer')">
  95. <el-select v-model="editForm.companyIds" clearable multiple filterable :placeholder="$t('basic.inputAssProducer')" 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.assAddress')" prop="companyAddress">
  101. <el-input v-model="editForm.companyAddress" autocomplete="off" :placeholder="$t('basic.inputAssAddress')" style="width:485px"></el-input>
  102. </el-form-item>
  103. </el-form>
  104. <div slot="footer" class="dialog-footer">
  105. <el-button @click.native="editFormVisible = false">{{$t('el.messagebox.cancel')}}</el-button>
  106. <el-button type="primary" @click.native="editSubmit" :loading="editLoading">{{$t('el.messagebox.confirm')}}</el-button>
  107. </div>
  108. </el-dialog>
  109. </section>
  110. </template>
  111. <script>
  112. import util from '../../common/js/util'
  113. export default {
  114. data() {
  115. const checkPhone = (rule, value, callback) => {
  116. if (!value) {
  117. return callback(new Error(this.$t('project.inputMobile')));
  118. } else {
  119. const reg = /^1[0-9]\d{9}$/
  120. if (reg.test(value)) {
  121. callback();
  122. } else {
  123. return callback(new Error(this.$t('project.inputTrueMobile')));
  124. }
  125. }
  126. };
  127. const msg = (rule, value, callback) => {
  128. if (!value) {
  129. switch(rule.field) {
  130. case "companyName":
  131. return callback(new Error(this.$t('basic.inputAssName')));
  132. break;
  133. case "companyAddress":
  134. return callback(new Error(this.$t('basic.inputAssAddress')));
  135. break;
  136. case "username":
  137. return callback(new Error(this.$t('project.inputName')));
  138. break;
  139. default:
  140. callback();
  141. }
  142. } else {
  143. callback();
  144. }
  145. };
  146. return {
  147. filters: {
  148. keyName: ''
  149. },
  150. user: JSON.parse(sessionStorage.getItem('user')),
  151. companys:[],
  152. list: [],
  153. total: 0,
  154. page: 1,
  155. size: 20,
  156. listLoading: false,
  157. tableHeight: 0,
  158. formRules: {
  159. companyName: [
  160. { required: true, validator: msg , trigger: 'blur' }
  161. ],
  162. companyAddress: [
  163. { required: true, validator: msg , trigger: 'blur' }
  164. ],
  165. username: [
  166. { required: true, validator: msg , trigger: 'blur' }
  167. ],
  168. account: [
  169. { required: true, validator: checkPhone, trigger: 'blur'}
  170. ]
  171. },
  172. team: [{label:this.$t('basic.asset'),value:0},{label:this.$t('basic.producer'),value:1}],
  173. // 新增界面
  174. addFormVisible: false,
  175. addLoading: false,
  176. addState: true,
  177. addTitle: this.$t('basic.addAsset'),
  178. addForm: {
  179. companyName: '',
  180. companyAddress: '',
  181. companyIds: [],
  182. username: '',
  183. account: '',
  184. companyId: '',
  185. roleName: this.$t('basic.system'),
  186. flag: 0
  187. },
  188. // 编辑界面
  189. editFormVisible: false,
  190. editLoading: false,
  191. editForm: {
  192. id: 0,
  193. companyName: '',
  194. companyType: 0,
  195. companyAddress: '',
  196. companyIds: [],
  197. flag: 1
  198. }
  199. }
  200. },
  201. methods: {
  202. // 分页
  203. handleCurrentChange(val) {
  204. this.page = val;
  205. this.getComp();
  206. },
  207. handleSizeChange(val) {
  208. this.size = val;
  209. this.getComp();
  210. },
  211. //获取基础数据
  212. getMsg() {
  213. this.http.post(this.port.base.relationList, {
  214. companyType: 1
  215. }, res => {
  216. if (res.code == "ok") {
  217. this.companys = res.data;
  218. } else {
  219. this.$message({
  220. message: res.msg,
  221. type: 'error'
  222. });
  223. }
  224. }, error => {
  225. this.$message({
  226. message: error,
  227. type: 'error'
  228. });
  229. })
  230. },
  231. //获取资产方列表
  232. getComp() {
  233. this.listLoading = true;
  234. this.http.post(this.port.base.companyList, {
  235. keyName: this.filters.keyName,
  236. pageNum: this.page,
  237. pageSize: this.size,
  238. companyType: 0
  239. }, res => {
  240. this.listLoading = false;
  241. if (res.code == "ok") {
  242. this.list = res.data.list;
  243. this.total = res.data.total;
  244. } else {
  245. this.$message({
  246. message: res.msg,
  247. type: 'error'
  248. });
  249. }
  250. }, error => {
  251. this.listLoading = false;
  252. this.$message({
  253. message: error,
  254. type: 'error'
  255. });
  256. })
  257. },
  258. toNext(i) {
  259. if(i == 0) {
  260. this.addState = false;
  261. this.addTitle = this.$t('basic.addSystem');
  262. }
  263. },
  264. toPart(i) {
  265. if(i == 0) {
  266. this.addState = true;
  267. this.addTitle = this.$t('basic.addAsset');
  268. }
  269. },
  270. //显示新增界面
  271. handleAdd() {
  272. this.addFormVisible = true;
  273. this.addState = true;
  274. this.addTitle = this.$t('basic.addAsset');
  275. this.addForm = {
  276. companyName: '',
  277. companyAddress: '',
  278. companyIds: [],
  279. username: '',
  280. account: '',
  281. companyId: '',
  282. roleName: this.$t('basic.system'),
  283. flag: 0
  284. };
  285. },
  286. //新增
  287. addSubmit() {
  288. this.$refs.addForm.validate((valid) => {
  289. if (valid) {
  290. this.addLoading = true;
  291. var str = "";
  292. for(var i in this.addForm.companyIds){
  293. if(i == this.addForm.companyIds.length-1){
  294. str += this.addForm.companyIds
  295. } else {
  296. str += this.addForm.companyIds + ","
  297. }
  298. }
  299. this.http.post(this.port.base.addCompany, {
  300. companyName: this.addForm.companyName,
  301. companyType: 0,
  302. companyAddress: this.addForm.companyAddress,
  303. companyIds: str,
  304. flag: 0
  305. } , res => {
  306. if (res.code == "ok") {
  307. this.addPeo(res.data.id);
  308. } else {
  309. this.$message({
  310. message: res.msg,
  311. type: 'error'
  312. });
  313. }
  314. }, error => {
  315. this.addLoading = false;
  316. this.addFormVisible = false;
  317. this.$message({
  318. message: error,
  319. type: 'error'
  320. });
  321. })
  322. }
  323. });
  324. },
  325. //添加人员
  326. addPeo(companyId) {
  327. this.$refs.addForm.validate((valid) => {
  328. if (valid) {
  329. this.http.post(this.port.project.addUser, {
  330. username: this.addForm.username,
  331. account: this.addForm.account,
  332. companyId: companyId,
  333. roleName: this.addForm.roleName,
  334. parentId: this.user.id,
  335. addType: 0,
  336. flag: 0
  337. } , res => {
  338. this.addLoading = false;
  339. if (res.code == "ok") {
  340. this.addFormVisible = false;
  341. this.$message({
  342. message: this.$t('prompt.success2'),
  343. type: 'success'
  344. });
  345. this.getComp();
  346. } else {
  347. this.$message({
  348. message: res.msg,
  349. type: 'error'
  350. });
  351. }
  352. }, error => {
  353. this.addLoading = false;
  354. this.addFormVisible = false;
  355. this.$message({
  356. message: error,
  357. type: 'error'
  358. });
  359. })
  360. }
  361. });
  362. },
  363. //删除
  364. handleDel(index, row) {
  365. this.$confirm(this.$t('basic.delAss'), this.$t('el.messagebox.title'), {
  366. confirmButtonText: this.$t('el.messagebox.confirm'),
  367. cancelButtonText: this.$t('el.messagebox.cancel'),
  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: this.$t('prompt.success3'),
  376. type: 'success'
  377. });
  378. this.getComp();
  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: 0,
  404. companyAddress: row.companyAddress,
  405. companyIds: array,
  406. flag: 1
  407. };
  408. },
  409. //编辑
  410. editSubmit() {
  411. this.$refs.editForm.validate((valid) => {
  412. if (valid) {
  413. this.editLoading = true;
  414. var str = "";
  415. for(var i in this.editForm.companyIds){
  416. if(i == this.editForm.companyIds.length-1){
  417. str += this.editForm.companyIds
  418. } else {
  419. str += this.editForm.companyIds + ","
  420. }
  421. }
  422. this.http.post(this.port.base.addCompany, {
  423. id: this.editForm.id,
  424. companyName: this.editForm.companyName,
  425. companyType: 0,
  426. companyAddress: this.editForm.companyAddress,
  427. companyIds: str,
  428. flag: 1
  429. } , res => {
  430. this.editLoading = false;
  431. if (res.code == "ok") {
  432. this.editFormVisible = false;
  433. this.$message({
  434. message: this.$t("prompt.success"),
  435. type: 'success'
  436. });
  437. this.getComp();
  438. } else {
  439. this.$message({
  440. message: res.msg,
  441. type: 'error'
  442. });
  443. }
  444. }, error => {
  445. this.editLoading = false;
  446. this.editFormVisible = false;
  447. this.$message({
  448. message: error,
  449. type: 'error'
  450. });
  451. })
  452. }
  453. });
  454. }
  455. },
  456. created() {
  457. let height = window.innerHeight;
  458. this.tableHeight = height - 210;
  459. const that = this;
  460. window.onresize = function temp() {
  461. that.tableHeight = window.innerHeight - 210;
  462. };
  463. },
  464. mounted() {
  465. this.getMsg();
  466. this.getComp();
  467. }
  468. }
  469. </script>
  470. <style scoped>
  471. </style>