project.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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('project.inputProName')"></el-input>
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" v-on:click="getProject">{{$t('base.query')}}</el-button>
  11. </el-form-item>
  12. <el-form-item style="float:right;" v-if="user.parentId == 1 && user.subordinateType == 0">
  13. <el-button type="primary" @click="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 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="$t('project.proName')" 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="$t('project.assName')" sortable>
  27. </el-table-column>
  28. <el-table-column prop="customCompaniesStr" :label="$t('project.cusName')" sortable>
  29. </el-table-column>
  30. <el-table-column prop="manager" :label="$t('project.manager')" width="100" align="center" sortable>
  31. </el-table-column>
  32. <el-table-column prop="indate" :label="$t('project.indate')" width="200" align="center" sortable>
  33. </el-table-column>
  34. <el-table-column :label="$t('base.operate')" width="150" align="center" v-if="user.parentId == 1 && user.subordinateType == 0">
  35. <template slot-scope="scope">
  36. <el-button type="danger" size="small" @click="invalid(scope.row.id)" v-if="scope.row.isDelete != 1">{{$t('project.invalid')}}</el-button>
  37. <span style="color:red" v-else>{{$t('project.expired')}}</span>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <!--工具条-->
  42. <el-col :span="24" class="toolbar">
  43. <el-pagination
  44. @size-change="handleSizeChange"
  45. @current-change="handleCurrentChange"
  46. :page-sizes="[20 , 50 , 80 , 100]"
  47. :page-size="20"
  48. layout="total, sizes, prev, pager, next"
  49. :total="total"
  50. style="float:right;">
  51. </el-pagination>
  52. </el-col>
  53. <!--新增界面-->
  54. <el-dialog :title="$t('project.addPro')" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  55. <el-form :model="addForm" label-width="120px" :rules="formRules" ref="addForm">
  56. <el-col :span="24">
  57. <el-form-item :label="$t('project.proName')" prop="projectName">
  58. <el-input v-model="addForm.projectName" autocomplete="off" :placeholder="$t('project.inputProName')" style="width:510px"></el-input>
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="24">
  62. <el-form-item :label="$t('project.moldName')" prop="mold">
  63. <el-select v-model="addForm.mold" @change="companyChange" clearable filterable multiple :placeholder="$t('project.inputMoldName')" value-key='id' style="width:510px">
  64. <el-option v-for="item in molds" :key="item.id" :label="item.modelName" :value="item">
  65. <span style="float: left">{{ item.modelName }}</span>
  66. <span style="float: right; color: #8492a6; font-size: 6px;margin-right:17px;">{{ item.produceCompany }}</span>
  67. </el-option>
  68. </el-select>
  69. </el-form-item>
  70. </el-col>
  71. <el-col :span="24">
  72. <el-form-item :label="$t('project.manager')" prop="managerId">
  73. <el-select v-model="addForm.managerId" clearable filterable :placeholder="$t('project.inputManager')" 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-option v-for="item in charger" :key="item.id" :label="item.username" :value="item">
  77. <span style="float: left">{{ item.username }}</span>
  78. <span style="float: right; color: #8492a6; font-size: 13px;">{{ item.companyName }}</span>
  79. </el-option>
  80. </el-select>
  81. </el-form-item>
  82. </el-col>
  83. </el-form>
  84. <div slot="footer" class="dialog-footer">
  85. <el-button @click.native="addFormVisible = false">{{$t('el.messagebox.cancel')}}</el-button>
  86. <el-button type="primary" @click.native="addSubmit" :loading="addLoading">{{$t('el.messagebox.confirm')}}</el-button>
  87. </div>
  88. </el-dialog>
  89. </section>
  90. </template>
  91. <script>
  92. import util from '../../common/js/util'
  93. export default {
  94. data() {
  95. const msg = (rule, value, callback) => {
  96. if (!value) {
  97. switch(rule.field) {
  98. case "projectName":
  99. return callback(new Error(this.$t('project.inputProName')));
  100. break;
  101. case "mold":
  102. return callback(new Error(this.$t('project.inputMoldName')));
  103. break;
  104. case "managerId":
  105. return callback(new Error(this.$t('project.inputManager')));
  106. break;
  107. default:
  108. callback();
  109. }
  110. } else {
  111. callback();
  112. }
  113. };
  114. return {
  115. filters: {
  116. keyName: ''
  117. },
  118. user: JSON.parse(sessionStorage.getItem('user')),
  119. charger: [],
  120. molds: [],
  121. list: [],
  122. total: 0,
  123. page: 1,
  124. size: 20,
  125. listLoading: false,
  126. tableHeight: 0,
  127. formRules: {
  128. projectName: [
  129. { required: true, validator: msg, trigger: 'blur' }
  130. ],
  131. mold: [
  132. { required: true, validator: msg, trigger: ['blur','change'] }
  133. ],
  134. managerId: [
  135. { required: true, validator: msg, trigger: ['blur','change'] }
  136. ]
  137. },
  138. addFormVisible: false, //新增界面是否显示
  139. addLoading: false,
  140. //新增界面数据
  141. addForm: {
  142. projectName: '',
  143. mold: [],
  144. managerId: ''
  145. }
  146. }
  147. },
  148. methods: {
  149. //获取基础数据
  150. getMsg(){
  151. this.http.post(this.port.project.getUserById, {
  152. companyIds: this.user.companyId,
  153. id: this.user.id
  154. } , res => {
  155. if (res.code == "ok") {
  156. this.charger = res.data;
  157. } else {
  158. this.$message({
  159. message: res.msg,
  160. type: 'error'
  161. });
  162. }
  163. }, error => {
  164. this.$message({
  165. message: error,
  166. type: 'error'
  167. });
  168. })
  169. //获取模具
  170. this.getMoulds();
  171. },
  172. //获取模具
  173. getMoulds(){
  174. this.http.post(this.port.mold.modelList, {
  175. parentId: this.user.parentId,
  176. id: this.user.id
  177. }, res => {
  178. if (res.code == "ok") {
  179. this.molds = res.data;
  180. } else {
  181. this.$message({
  182. message: res.msg,
  183. type: 'error'
  184. });
  185. }
  186. }, error => {
  187. this.$message({
  188. message: error,
  189. type: 'error'
  190. });
  191. })
  192. },
  193. //分页
  194. handleCurrentChange(val) {
  195. this.page = val;
  196. this.getProject();
  197. },
  198. handleSizeChange(val) {
  199. this.size = val;
  200. this.getProject();
  201. },
  202. //获取项目列表
  203. getProject() {
  204. this.listLoading = true;
  205. this.http.post(this.port.project.projectList, {
  206. keyName: this.filters.keyName,
  207. pageNum: this.page,
  208. pageSize: this.size,
  209. }, res => {
  210. this.listLoading = false;
  211. if (res.code == "ok") {
  212. var list = res.data.list;
  213. for(var i in list){
  214. var customCompaniesStr = "";
  215. for(var j in list[i].customCompanies){
  216. if(j == list[i].customCompanies.length -1){
  217. customCompaniesStr += list[i].customCompanies[j].companyName;
  218. } else {
  219. customCompaniesStr += list[i].customCompanies[j].companyName + "、";
  220. }
  221. }
  222. list[i].customCompaniesStr = customCompaniesStr;
  223. }
  224. this.list = list;
  225. this.total = res.data.total;
  226. } else {
  227. this.$message({
  228. message: res.msg,
  229. type: 'error'
  230. });
  231. }
  232. }, error => {
  233. this.listLoading = false;
  234. this.$message({
  235. message: error,
  236. type: 'error'
  237. });
  238. })
  239. },
  240. //详情
  241. toDetail(row) {
  242. this.$router.push('/project/' + row.id);
  243. },
  244. invalid(id) {
  245. this.http.post(this.port.project.invalidProject, {
  246. id: id,
  247. isDelete: 1,
  248. }, res => {
  249. if (res.code == "ok") {
  250. this.getProject();
  251. } else {
  252. this.$message({
  253. message: res.msg,
  254. type: 'error'
  255. });
  256. }
  257. }, error => {
  258. this.$message({
  259. message: error,
  260. type: 'error'
  261. });
  262. })
  263. },
  264. //选择公司切换人员
  265. companyChange() {
  266. var param = {} ,
  267. str = this.user.companyId;
  268. for(var i in this.addForm.mold){
  269. str += "," + this.addForm.mold[i].produceCompanyId;
  270. }
  271. param.companyIds = str;
  272. param.id = this.user.id
  273. this.http.post(this.port.project.getUserById, param , res => {
  274. if (res.code == "ok") {
  275. this.charger = res.data;
  276. } else {
  277. this.$message({
  278. message: res.msg,
  279. type: 'error'
  280. });
  281. }
  282. }, error => {
  283. this.$message({
  284. message: error,
  285. type: 'error'
  286. });
  287. })
  288. },
  289. //显示新增界面
  290. handleAdd() {
  291. //重新获取一下模具
  292. this.getMoulds();
  293. this.addFormVisible = true;
  294. this.addForm = {
  295. projectName: '',
  296. mold: [],
  297. managerId: ''
  298. };
  299. },
  300. //新增
  301. addSubmit() {
  302. this.$refs.addForm.validate((valid) => {
  303. if (valid) {
  304. var cId = "",
  305. cName = "",
  306. mId = "";
  307. for(var i in this.addForm.mold){
  308. if(cId.indexOf(this.addForm.mold[i].produceCompanyId) == -1){
  309. cId += this.addForm.mold[i].produceCompanyId + ",";
  310. cName += this.addForm.mold[i].produceCompanyName + ",";
  311. }
  312. mId += this.addForm.mold[i].id + ","
  313. }
  314. cId = cId.substring(0,cId.length-1);
  315. cName = cName.substring(0,cName.length-1);
  316. mId = mId.substring(0,mId.length-1);
  317. this.addLoading = true;
  318. this.http.post(this.port.project.addProject, {
  319. projectName: this.addForm.projectName,
  320. customerCompanyIds: cId,
  321. customerCompanyNames: cName,
  322. manager: this.addForm.managerId.username,
  323. managerId: this.addForm.managerId.id,
  324. modelIds: mId,
  325. flag: 0
  326. } , res => {
  327. this.addLoading = false;
  328. if (res.code == "ok") {
  329. this.addFormVisible = false;
  330. this.$message({
  331. message: this.$t('prompt.success2'),
  332. type: 'success'
  333. });
  334. this.getProject();
  335. } else {
  336. this.$message({
  337. message: res.msg,
  338. type: 'error'
  339. });
  340. }
  341. }, error => {
  342. this.addLoading = false;
  343. this.addFormVisible = false;
  344. this.$message({
  345. message: error,
  346. type: 'error'
  347. });
  348. })
  349. }
  350. });
  351. },
  352. },
  353. created() {
  354. let height = window.innerHeight;
  355. this.tableHeight = height - 210;
  356. const that = this;
  357. window.onresize = function temp() {
  358. that.tableHeight = window.innerHeight - 210;
  359. };
  360. },
  361. mounted() {
  362. this.getMsg();
  363. this.getProject();
  364. }
  365. }
  366. </script>