project.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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="200" 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="customCompaniesStr" label="生产方" width="250" sortable>
  27. </el-table-column>
  28. <el-table-column prop="charger" label="生产方负责人" width="200" align="center" sortable>
  29. </el-table-column>
  30. <el-table-column prop="creator" label="项目创建人" width="180" align="center" sortable>
  31. </el-table-column>
  32. <el-table-column prop="indate" label="创建时间" width="200" 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. // userA: [],
  99. // userB: [],
  100. list: [],
  101. total: 0,
  102. page: 1,
  103. size: 20,
  104. listLoading: false,
  105. tableHeight: 0,
  106. formRules: {
  107. projectName: [
  108. { required: true, message: '请输入项目名称', trigger: 'blur' }
  109. ],
  110. customerCompany: [
  111. { required: true, message: '请选择客户公司', trigger: 'blur' }
  112. ],
  113. managerId: [
  114. { required: true, message: '请选择项目经理', trigger: ['blur','change'] }
  115. ]
  116. },
  117. addFormVisible: false,//新增界面是否显示
  118. addLoading: false,
  119. //新增界面数据
  120. addForm: {
  121. projectName: '',
  122. customerCompany: [],
  123. managerId: '',
  124. // userA: [],
  125. // userB: []
  126. }
  127. }
  128. },
  129. methods: {
  130. // 获取基础数据
  131. getMsg(){
  132. this.http.post(this.port.project.getUserById, {
  133. companyIds: this.user.companyId,
  134. id: this.user.id
  135. } , res => {
  136. if (res.code == "ok") {
  137. this.charger = res.data;
  138. } else {
  139. this.$message({
  140. message: res.msg,
  141. type: 'error'
  142. });
  143. }
  144. }, error => {
  145. this.$message({
  146. message: error,
  147. type: 'error'
  148. });
  149. })
  150. this.http.post(this.port.base.companys, {
  151. parentId: this.user.parentId,
  152. id: this.user.id
  153. }, res => {
  154. if (res.code == "ok") {
  155. var list = res.data , array = [];
  156. for(var i in list){
  157. if(list[i].id != this.user.companyId){
  158. array.push(list[i])
  159. }
  160. }
  161. this.company = array;
  162. } else {
  163. this.$message({
  164. message: res.msg,
  165. type: 'error'
  166. });
  167. }
  168. }, error => {
  169. this.$message({
  170. message: error,
  171. type: 'error'
  172. });
  173. })
  174. },
  175. //分页
  176. handleCurrentChange(val) {
  177. this.page = val;
  178. this.getProject();
  179. },
  180. handleSizeChange(val) {
  181. this.size = val;
  182. this.getProject();
  183. },
  184. //获取项目列表
  185. getProject() {
  186. this.listLoading = true;
  187. this.http.post(this.port.project.projectList, {
  188. keyName: this.filters.keyName,
  189. currentPage: this.page,
  190. pageSize: this.size,
  191. }, res => {
  192. this.listLoading = false;
  193. if (res.code == "ok") {
  194. var list = res.data.list;
  195. for(var i in list){
  196. var customCompaniesStr = "";
  197. for(var j in list[i].customCompanies){
  198. if(j == list[i].customCompanies.length -1){
  199. customCompaniesStr += list[i].customCompanies[j].companyName;
  200. } else {
  201. customCompaniesStr += list[i].customCompanies[j].companyName + ",";
  202. }
  203. console.log(list[i].customCompanies[j])
  204. }
  205. list[i].customCompaniesStr = customCompaniesStr;
  206. }
  207. this.list = res.data.list;
  208. this.total = res.data.total;
  209. } else {
  210. this.$message({
  211. message: res.msg,
  212. type: 'error'
  213. });
  214. }
  215. }, error => {
  216. this.listLoading = false;
  217. this.$message({
  218. message: error,
  219. type: 'error'
  220. });
  221. })
  222. },
  223. //详情
  224. toDetail(row) {
  225. this.$router.push('/project/' + row.id);
  226. },
  227. //选择公司切换人员
  228. companyChange() {
  229. var param = {} ,
  230. str = this.user.companyId;
  231. for(var i in this.addForm.customerCompany){
  232. str += "," + this.addForm.customerCompany[i].id;
  233. }
  234. param.companyIds = str;
  235. param.id = this.user.id
  236. this.http.post(this.port.project.getUserById, param , res => {
  237. if (res.code == "ok") {
  238. this.charger = res.data;
  239. } else {
  240. this.$message({
  241. message: res.msg,
  242. type: 'error'
  243. });
  244. }
  245. }, error => {
  246. this.$message({
  247. message: error,
  248. type: 'error'
  249. });
  250. })
  251. },
  252. //显示新增界面
  253. handleAdd() {
  254. this.addFormVisible = true;
  255. this.addForm = {
  256. projectName: '',
  257. customerCompany: '',
  258. managerId: ''
  259. };
  260. },
  261. //新增
  262. addSubmit() {
  263. this.$refs.addForm.validate((valid) => {
  264. if (valid) {
  265. var cId = "",
  266. cName = "";
  267. for(var i in this.addForm.customerCompany){
  268. cId += this.addForm.customerCompany[i].id + ",";
  269. cName += this.addForm.customerCompany[i].companyName + ",";
  270. }
  271. cId = cId.substring(0,cId.length-1);
  272. cName = cName.substring(0,cName.length-1);
  273. this.addLoading = true;
  274. this.http.post(this.port.project.addProject, {
  275. projectName: this.addForm.projectName,
  276. customerCompanyIds: cId,
  277. customerCompanyNames: cName,
  278. manager: this.addForm.managerId.username,
  279. managerId: this.addForm.managerId.id,
  280. flag: 0
  281. } , res => {
  282. this.addLoading = false;
  283. this.addFormVisible = false;
  284. if (res.code == "ok") {
  285. this.$message({
  286. message: '创建成功',
  287. type: 'success'
  288. });
  289. this.getProject();
  290. } else {
  291. this.$message({
  292. message: res.msg,
  293. type: 'error'
  294. });
  295. }
  296. }, error => {
  297. this.addLoading = false;
  298. this.addFormVisible = false;
  299. this.$message({
  300. message: error,
  301. type: 'error'
  302. });
  303. })
  304. }
  305. });
  306. },
  307. },
  308. created() {
  309. let height = window.innerHeight;
  310. this.tableHeight = height - 210;
  311. const that = this;
  312. window.onresize = function temp() {
  313. that.tableHeight = window.innerHeight - 210;
  314. };
  315. },
  316. mounted() {
  317. this.getMsg();
  318. this.getProject();
  319. }
  320. }
  321. </script>
  322. <style scoped>
  323. </style>