123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <template>
- <div>
- <van-nav-bar title="项目管理" left-text="返回" @click-left="back" :right-text="canEdit?'新增项目':''" @click-right="openDialog(-1)" fixed left-arrow/>
-
- <div class="login_form">
- <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
- <van-list v-model="loading" :finished="finished" finished-text="没有更多了" :error.sync="error" error-text="请求失败,点击重新加载" @load="getProject">
- <van-swipe-cell v-for="(item,index) in list" :key="index">
- <van-cell :border="false" :title="item.projectName" :value="item.projectCode"/>
- <template slot="right" v-if="canEdit">
- <van-button square type="info" text="编辑" @click="openDialog(index)"/>
- <van-button square type="danger" text="删除" @click="delPro(index)"/>
- </template>
- </van-swipe-cell>
- </van-list>
- </van-pull-refresh>
- <van-dialog v-model="show" :title="title" show-cancel-button :beforeClose="chargeBtn">
- <van-form style="margin: 0.4rem 0;">
- <van-field v-model="form.projectCode" name="项目编号" label="项目编号" placeholder="请填写项目编号" />
- <van-field v-model="form.projectName" name="项目名称" label="项目名称" placeholder="请填写项目名称" :rules="[{ required: true, message: '请填写项目名称' }]"/>
- <van-field readonly clickable name="userNames" v-model="form.userNames" label="参与人"
- placeholder="请选择参与人" @click="clickPicker()" />
- <van-field readonly clickable v-model="form.inchargerName" label="负责人"
- placeholder="请选择负责人" @click="showPickerIncharger = true" />
- <!-- 研究中心 -->
- <van-field v-if="user.timeType.customDegreeActive == 1" readonly clickable name="userNames" v-model="form.associateDegreeNames" label="研究中心"
- placeholder="请选择" @click="clikls()"/>
- </van-form>
- </van-dialog>
- <van-popup v-model="showPickerUser" position="bottom">
- <van-search v-model="userName" placeholder="输入员工姓名搜索" @search="onSearch"></van-search>
- <div style="minHeight:300px;">
- <van-checkbox class="userCheckbox" v-for="(item) in userList" :key="item.id" v-model="item.isChecked" >{{item.name}}</van-checkbox>
- <van-button style="width:100%;" @click="refreshParticipate();showPickerUser=false">确定</van-button>
- </div>
- </van-popup>
- <van-popup v-model="showPickerIncharger" position="bottom">
- <van-picker show-toolbar :columns="inchargerUserList" value-key="name" @confirm="choseIncharger" @cancel="showPickerIncharger = false" />
- </van-popup>
- <!-- 研究中心 -->
- <van-popup v-model="cliklss" position="bottom">
- <div style="minHeight:300px;">
- <van-checkbox class="userCheckbox" v-for="(item) in ause" :key="item.id" v-model="item.isChecked" @change="fuxuan()" @click="ddd()">{{item.name}}</van-checkbox>
- <van-button style="width:100%;" @click="refreshParticipatess();cliklss=false">确定</van-button>
- </div>
- </van-popup>
- </div>
- </div>
- </template>
- <script>
- export default {
- data() {
- return {
- canEdit:false,
- user: JSON.parse(localStorage.userInfo),
- showPickerUser: false,
- showPickerIncharger: false,
- userName:null,
- total: 0,
- page: 1,
- size: 1000,
- list: [],
- loading: false,
- finished: false,
- error: false,
- refreshing: false,
- allUserList:[],
- userList:[],
- inchargerUserList:[],
- show: false,
- title: "修改项目",
- form: {
- id: null,
- projectName: "",
- },
- cliklss: false,
- ause: []
- };
- },
- created() {
- },
- methods: {
- fuxuan() {
- console.log(this.ause)
- },
- ddd() {
- let aes = this.ause
- this.ause = aes
- console.log(this.ause, '12345')
- },
- yanjiuzx() {
- this.$axios.post("/report-extra-degree/getAll", {})
- .then(res => {
- if(res.code == "ok") {
- for(var i in res.data) {
- res.data[i].isChecked = false
- }
- this.ause = res.data
- } else {
- this.$toast.fail('获取失败');
- }
- }).catch(err=> {toast.clear();});
- },
- choseIncharger(value, index) {
- this.showPickerIncharger = false;
- this.form.inchargerName = value.name;
- this.form.inchargerId = value.id;
- },
- onSearch(val) {
- console.log(val);
- this.userList = [];
- this.allUserList.forEach(u=>{if (u.name.startsWith(val)) {
- this.userList.push(u);
- }})
-
- },
- //刷新参与人
- refreshParticipate() {
- this.form.userNames = '';
- var that = this;
- that.inchargerUserList = [];
- that.form.userId = [];
- this.userList.filter(u=>u.isChecked).forEach(u=>{
- that.form.userNames+=(u.name+',');
- that.form.userId.push(u.id);
- that.inchargerUserList.push(u);
- });
- if (this.form.userNames.length > 0) {
- this.form.userNames = this.form.userNames.substring(0, this.form.userNames.length-1);
- }
- },
- // 刷新研究中心
- refreshParticipatess() {
- var auseNme = []
- var auseList = []
- for(var i in this.ause) {
- if(this.ause[i].isChecked) {
- if(this.ause[i].isChecked == true) {
- auseNme.push(this.ause[i].name)
- auseList.push(this.ause[i].id)
- }
- }
- }
- this.form.associateDegreeNames = auseNme.toString()
- this.form.associateDegrees = auseList
- console.log(this.form, '刷新')
- },
- onChange() {
- console.log('===');
- },
- choseUsers() {
- },
- clickPicker() {
- this.showPickerUser = true;
- },
- clikls() {
- this.cliklss = true
- for(var i in this.ause) {
- if(this.form.associateDegrees.length > 0) {
- for(var j in this.form.associateDegrees) {
- if(this.form.associateDegrees[j] == this.ause[i].id) {
- this.ause[i].isChecked = true
- }
- }
- }
- }
- this.ause = this.ause
- console.log(this.ause)
- },
- // 返回
- back() {
- history.back();
- },
- //获取用户列表
- getUsers() {
- this.$axios.post("/user/getEmployeeList", {
- departmentId: -1,
- pageIndex: 1,
- pageSize: 99999
- })
- .then(res => {
- if(res.code == "ok") {
- this.loading = false;
- var sj = res.data.records
- for (var i in sj) {
- sj[i].isChecked = false
- }
- // this.userList = res.data.records;
- this.userList = sj;
- this.allUserList = res.data.records;
- } else {
- this.$toast.fail('获取失败');
- }
- }).catch(err=> {toast.clear();});
- },
- // 获取项目
- getProject() {
- if (this.refreshing) {
- this.list = [];
- this.refreshing = false;
- }
- if(this.total == this.list.length && this.list.length != 0) {
- this.loading = false;
- this.finished = true;
- return false;
- }
- this.$axios.post("/project/getProjectPage", {
- pageIndex: this.page,
- pageSize: this.size,
- })
- .then(res => {
- if(res.code == "ok") {
- this.loading = false;
- if (this.list.length == 0) {
- this.finished = true;
- }
- this.list = [];
- for(var i in res.data.records) {
- this.list.push(res.data.records[i])
- }
- this.total = res.data.total;
- this.page++;
- } else {
- this.$toast.fail('获取失败:'+res.msg);
- }
- }).catch(err=> {toast.clear();});
- },
- onRefresh() {
- this.finished = false;
- this.loading = true;
- this.page = 1;
- this.getProject();
- },
- // 新增、编辑项目
- openDialog(i) {
- if(i == -1) {
- this.title = "新增项目";
- this.form = {
- id: null,
- projectName: "",
- projectCode:null,
- inchargerName:null,
- inchargerId:null,
- userId:null,
- userNames:null,
- associateDegreeNames: null,
- associateDegrees: null
- }
- // this.userList.forEach(u=>u.isChecked=false);
- // this.refreshParticipate();
- } else {
- this.title = "修改项目";
- var arrs
- if(this.list[i].associateDegrees) {
- arrs = this.list[i].associateDegrees.split(',')
- for(var j in arrs) {
- arrs[j] = +arrs[j] + 0
- }
- } else {
- arrs = []
- }
- var name
- if(this.list[i].associateDegreeNames != null && this.list[i].associateDegreeNames != 'null') {
- name = this.list[i].associateDegreeNames
- } else {
- name = ''
- }
- console.log(name, '看看')
- this.form = {
- id: this.list[i].id,
- projectName: this.list[i].projectName,
- projectCode: this.list[i].projectCode,
- inchargerId: this.list[i].inchargerId,
- inchargerName: this.list[i].inchargerName,
- associateDegreeNames: name,
- associateDegrees: arrs
- }
- var part = this.list[i].participator;
-
- if (part.length>0) {
- for (var j in part) {
- this.userList.filter(u=>u.id == part[j].id)[0].isChecked = true;
- }
- this.refreshParticipate();
- }
- }
- this.show = true;
- },
- chargeBtn(action, done) {
- if (action === 'confirm') {
- this.show = false;
- const toast = this.$toast.loading({
- forbidClick: true,
- duration: 0
- });
- let formData = new FormData();
- formData.append("name", this.form.projectName);
- formData.append("code", this.form.projectCode);
- formData.append("inchargerId", this.form.inchargerId);
- for (var j in this.form.userId) {
- formData.append("userId", this.form.userId[j]);
- }
-
- let form = {
- name: this.form.projectName,
- code:this.form.projectCode,
- inchargerId: this.form.inchargerId,
- userId:this.form.userId
- }
- if(this.form.id != null) {
- // form.id = this.form.id;
- formData.append("id", this.form.id);
- }
- if(this.form.associateDegreeNames != '' && this.form.associateDegreeNames != null) {
- formData.append("associateDegreeNames", this.form.associateDegreeNames);
- } else {
- formData.append("associateDegreeNames", null);
- }
- if(this.form.associateDegrees.length > 0) {
- var sss = this.form.associateDegrees.toString()
- formData.append("associateDegrees", sss);
- } else {
- formData.append("associateDegrees", null);
- }
- const config = {
- headers: {
- 'Content-Type': 'multipart/form-data'
- }
- }
- this.$axios.post("/project/editProject", formData, config)
- .then(res => {
- if(res.code == "ok") {
- toast.clear();
- this.$toast.success(this.form.id==null?'新增成功':'修改成功');
- this.list = [];
- this.page = 1;
- this.getProject();
- this.yanjiuzx()
- } else {
- toast.clear();
- this.$toast.fail(this.form.id==null?'新增失败':'修改失败');
- }
- }).catch(err=> {toast.clear();});
- } else {
- this.show = false;
- this.yanjiuzx()
- }
- done();
- },
- // 删除项目
- delPro(i) {
- this.$dialog.confirm({
- title: '删除项目',
- message: '确定要项目'+this.list[i].projectName+'吗?'
- }).then(() => {
- const toast = this.$toast.loading({
- forbidClick: true,
- duration: 0
- });
- this.$axios.post("/project/deleteProject", {id: this.list[i].id})
- .then(res => {
- if(res.code == "ok") {
- toast.clear();
- this.$toast.success('删除成功');
- this.list = [];
- this.page = 1;
- this.getProject();
- } else {
- toast.clear();
- this.$toast.fail(res.msg);
- }
- }).catch(err=> {toast.clear();});
- }).catch(() => {});
- },
- },
- mounted() {
- this.getUsers();
- this.yanjiuzx()
- this.canEdit = (this.user.role==1||this.user.role==2||this.user.role==5);
- }
- };
- </script>
- <style lang="less" scoped>
- .login_form {
- margin-top: 46px;
- }
- .one_report {
- margin-bottom: 15px;
- }
- .form_text {
- margin: 15px 0 30px;
- padding: 0 12px;
- }
-
- .form_btn {
- text-align: right;
- }
- .form_btn button {
- margin-left: 10px;
- }
- .one_report_data {
- margin-bottom: 20px;
- padding: 0 22px;
- div {
- line-height: 30px;
- }
- }
- .userCheckbox {
- padding: 10px;;
- }
- </style>
- <style lang="less">
- .van-nav-bar .van-icon , .van-nav-bar__text {
- color: #20a0ff;
- }
- </style>
|