project.vue 14 KB

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