project.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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="请输入项目名称"></el-input>
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" v-on:click="getProject">查询</el-button>
  11. </el-form-item>
  12. <el-form-item style="float:right;" v-if="user.parentId == 1">
  13. <el-button type="primary" @click="handleAdd">新增</el-button>
  14. </el-form-item>
  15. </el-form>
  16. </el-col>
  17. <!--列表-->
  18. <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
  19. <el-table-column type="index" width="60">
  20. </el-table-column>
  21. <el-table-column prop="projectName" label="项目名称" width="250" sortable>
  22. <template slot-scope="scope">
  23. <el-link :underline="false" type="primary" @click="toDetail(scope.row)">{{scope.row.projectName}}</el-link>
  24. </template>
  25. </el-table-column>
  26. <el-table-column prop="ownerCompanyName" label="资产方公司" sortable>
  27. </el-table-column>
  28. <el-table-column prop="customCompaniesStr" label="生产方公司" width="500">
  29. </el-table-column>
  30. <el-table-column prop="manager" label="项目经理" width="100" align="center" sortable>
  31. </el-table-column>
  32. <el-table-column prop="indate" label="创建时间" width="250" align="center" sortable>
  33. </el-table-column>
  34. <!-- <el-table-column label="操作" width="250" align="center">
  35. <template slot-scope="scope">
  36. <el-button size="small" type="primary" @click="toDetail(scope.row.id)">详情</el-button>
  37. <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  38. <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</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="新增项目" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  56. <el-form :model="addForm" label-width="120px" :rules="formRules" ref="addForm">
  57. <el-col :span="24">
  58. <el-form-item label="项目名称" prop="projectName">
  59. <el-input v-model="addForm.projectName" autocomplete="off" placeholder="请输入项目名称" style="width:510px"></el-input>
  60. </el-form-item>
  61. </el-col>
  62. <el-col :span="24">
  63. <el-form-item label="生产方公司" prop="customerCompany">
  64. <el-select v-model="addForm.customerCompany" clearable filterable multiple placeholder="请选择生产方公司" @change="companyChange" value-key='id' style="width:510px">
  65. <!-- @change="companyChange(0)" -->
  66. <el-option v-for="item in company" :key="item.id" :label="item.companyName" :value="item">
  67. </el-option>
  68. </el-select>
  69. </el-form-item>
  70. </el-col>
  71. <el-col :span="24">
  72. <el-form-item label="项目经理" prop="managerId">
  73. <el-select v-model="addForm.managerId" clearable filterable placeholder="请选择项目经理" value-key='id' style="width:510px">
  74. <el-option v-for="item in charger" :key="item.id" :label="item.username" :value="item">
  75. </el-option>
  76. </el-select>
  77. </el-form-item>
  78. </el-col>
  79. </el-form>
  80. <div slot="footer" class="dialog-footer">
  81. <el-button @click.native="addFormVisible = false">取消</el-button>
  82. <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
  83. </div>
  84. </el-dialog>
  85. </section>
  86. </template>
  87. <script>
  88. import util from '../../common/js/util'
  89. export default {
  90. data() {
  91. return {
  92. filters: {
  93. keyName: ''
  94. },
  95. user: JSON.parse(sessionStorage.getItem('user')),
  96. company:[],
  97. charger: [],
  98. list: [],
  99. total: 0,
  100. page: 1,
  101. size: 20,
  102. listLoading: false,
  103. tableHeight: 0,
  104. formRules: {
  105. projectName: [
  106. { required: true, message: '请输入项目名称', trigger: 'blur' }
  107. ],
  108. customerCompany: [
  109. { required: true, message: '请选择客户公司', trigger: 'blur' }
  110. ],
  111. managerId: [
  112. { required: true, message: '请选择项目经理', trigger: ['blur','change'] }
  113. ]
  114. },
  115. addFormVisible: false,//新增界面是否显示
  116. addLoading: false,
  117. //新增界面数据
  118. addForm: {
  119. projectName: '',
  120. customerCompany: [],
  121. managerId: ''
  122. }
  123. }
  124. },
  125. methods: {
  126. // 获取基础数据
  127. getMsg(){
  128. this.http.post(this.port.project.getUserById, {
  129. companyIds: this.user.companyId,
  130. id: this.user.id
  131. } , res => {
  132. if (res.code == "ok") {
  133. this.charger = res.data;
  134. } else {
  135. this.$message({
  136. message: res.msg,
  137. type: 'error'
  138. });
  139. }
  140. }, error => {
  141. this.$message({
  142. message: error,
  143. type: 'error'
  144. });
  145. })
  146. this.http.post(this.port.base.addCompanyListToProject, {
  147. parentId: this.user.parentId,
  148. id: this.user.id
  149. }, res => {
  150. if (res.code == "ok") {
  151. var list = res.data , array = [];
  152. for(var i in list){
  153. if(list[i].id != this.user.companyId){
  154. array.push(list[i])
  155. }
  156. }
  157. this.company = array;
  158. } else {
  159. this.$message({
  160. message: res.msg,
  161. type: 'error'
  162. });
  163. }
  164. }, error => {
  165. this.$message({
  166. message: error,
  167. type: 'error'
  168. });
  169. })
  170. },
  171. //分页
  172. handleCurrentChange(val) {
  173. this.page = val;
  174. this.getProject();
  175. },
  176. handleSizeChange(val) {
  177. this.size = val;
  178. this.getProject();
  179. },
  180. //获取项目列表
  181. getProject() {
  182. this.listLoading = true;
  183. this.http.post(this.port.project.projectList, {
  184. keyName: this.filters.keyName,
  185. pageNum: this.page,
  186. pageSize: this.size,
  187. }, res => {
  188. this.listLoading = false;
  189. if (res.code == "ok") {
  190. var list = res.data.list;
  191. for(var i in list){
  192. var customCompaniesStr = "";
  193. for(var j in list[i].customCompanies){
  194. if(j == list[i].customCompanies.length -1){
  195. customCompaniesStr += list[i].customCompanies[j].companyName;
  196. } else {
  197. customCompaniesStr += list[i].customCompanies[j].companyName + "、";
  198. }
  199. }
  200. list[i].customCompaniesStr = customCompaniesStr;
  201. }
  202. this.list = res.data.list;
  203. this.total = res.data.total;
  204. } else {
  205. this.$message({
  206. message: res.msg,
  207. type: 'error'
  208. });
  209. }
  210. }, error => {
  211. this.listLoading = false;
  212. this.$message({
  213. message: error,
  214. type: 'error'
  215. });
  216. })
  217. },
  218. //详情
  219. toDetail(row) {
  220. this.$router.push('/project/' + row.id);
  221. },
  222. //选择公司切换人员
  223. companyChange() {
  224. var param = {} ,
  225. str = this.user.companyId;
  226. for(var i in this.addForm.customerCompany){
  227. str += "," + this.addForm.customerCompany[i].id;
  228. }
  229. param.companyIds = str;
  230. param.id = this.user.id
  231. this.http.post(this.port.project.getUserById, param , res => {
  232. if (res.code == "ok") {
  233. this.charger = res.data;
  234. } else {
  235. this.$message({
  236. message: res.msg,
  237. type: 'error'
  238. });
  239. }
  240. }, error => {
  241. this.$message({
  242. message: error,
  243. type: 'error'
  244. });
  245. })
  246. },
  247. //显示新增界面
  248. handleAdd() {
  249. this.addFormVisible = true;
  250. this.addForm = {
  251. projectName: '',
  252. customerCompany: '',
  253. managerId: ''
  254. };
  255. },
  256. //新增
  257. addSubmit() {
  258. this.$refs.addForm.validate((valid) => {
  259. if (valid) {
  260. var cId = "",
  261. cName = "";
  262. for(var i in this.addForm.customerCompany){
  263. cId += this.addForm.customerCompany[i].id + ",";
  264. cName += this.addForm.customerCompany[i].companyName + ",";
  265. }
  266. cId = cId.substring(0,cId.length-1);
  267. cName = cName.substring(0,cName.length-1);
  268. this.addLoading = true;
  269. this.http.post(this.port.project.addProject, {
  270. projectName: this.addForm.projectName,
  271. customerCompanyIds: cId,
  272. customerCompanyNames: cName,
  273. manager: this.addForm.managerId.username,
  274. managerId: this.addForm.managerId.id,
  275. flag: 0
  276. } , res => {
  277. this.addLoading = false;
  278. if (res.code == "ok") {
  279. this.addFormVisible = false;
  280. this.$message({
  281. message: '创建成功',
  282. type: 'success'
  283. });
  284. this.getProject();
  285. } else {
  286. this.$message({
  287. message: res.msg,
  288. type: 'error'
  289. });
  290. }
  291. }, error => {
  292. this.addLoading = false;
  293. this.addFormVisible = false;
  294. this.$message({
  295. message: error,
  296. type: 'error'
  297. });
  298. })
  299. }
  300. });
  301. },
  302. },
  303. created() {
  304. let height = window.innerHeight;
  305. this.tableHeight = height - 210;
  306. const that = this;
  307. window.onresize = function temp() {
  308. that.tableHeight = window.innerHeight - 210;
  309. };
  310. },
  311. mounted() {
  312. this.getMsg();
  313. this.getProject();
  314. }
  315. }
  316. </script>
  317. <style scoped>
  318. </style>