personnel.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view>
  3. <!-- 顶部 -->
  4. <cu-custom bgColor="bg-blue" :isBack="true">
  5. <block slot="backText">{{titleName}}</block>
  6. <block slot="content"></block>
  7. <block slot="right">
  8. <view class=" flex justify-center">
  9. <button @click="navTo()" class="cu-btn round line-blue text-white" style="width: 160rpx;height: 66rpx;padding: 0;">确定({{num}})</button>
  10. </view>
  11. </block>
  12. </cu-custom>
  13. <!-- 内容 -->
  14. <checkboxTree v-if="type==0" :selectList="selectList"></checkboxTree>
  15. <radioTree v-else :selectList="selectList"></radioTree>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. titleName:"选择施工员",
  23. num:0,
  24. selectList:[
  25. {name: '施工方',checked:false,show:true,children:[]},
  26. {name: '监理',checked:false,show:false,children:[]},
  27. {name: '业主',checked:false,show:false,children:[]}],
  28. type:0
  29. }
  30. },
  31. deep:true,
  32. methods: {
  33. navTo(){
  34. //刷新确定的选择的数据
  35. let choose =[];
  36. if(this.type!=0){//单选类型
  37. this.selectList.forEach(item => {
  38. item.children.forEach((items)=>{
  39. if(items.checked){
  40. choose.push(items)
  41. }
  42. })
  43. });
  44. if(choose.length>=2){
  45. choose =choose[choose.length-1];
  46. let index = [];
  47. index.push(choose)
  48. choose=index.concat();
  49. }
  50. }else{//多选类型
  51. this.selectList.forEach(item => {
  52. item.children.forEach((items)=>{
  53. if(items.checked){
  54. choose.push(items)
  55. }
  56. })
  57. });
  58. }
  59. if(choose.length==0){
  60. this.$prompt.none("请选择人员");
  61. return;
  62. }
  63. if(this.type==1 && this.titleName=="选择施工员"){//施工
  64. uni.$emit("handleFun",choose);
  65. }
  66. else if(this.type==2 && this.titleName=="选择监理员"){//监理
  67. uni.$emit("handleFunBy",choose);
  68. }
  69. else if(this.titleName=="选择负责人" && this.type==0){
  70. //console.log(this.selectList);
  71. uni.$emit("principal",choose)
  72. }
  73. else if(this.titleName=="选择审批人" && this.type==1){
  74. uni.$emit("approve",choose)
  75. }
  76. uni.navigateBack({
  77. delta:1
  78. })
  79. },
  80. /* 获取施工员和监理员 */
  81. findUserType(type){
  82. var that =this;
  83. that.selectList=[];
  84. var contractId = uni.getStorageSync("porject"+"_"+uni.getStorageSync("userInfo").id).contractId;
  85. that.http.request('/app/diary/listByType', {type:type,contractId:contractId}).then((result)=>{
  86. if(result.datas!=null){
  87. if(type==1){//施工员
  88. that.selectList=[{name: '施工方',checked:false,show:true,children:[]}];
  89. }else{//监理员
  90. that.selectList=[{name: '监理方',checked:false,show:true,children:[]}];
  91. }
  92. result.datas.forEach((item,index,arr)=>{
  93. item.checked=false;
  94. })
  95. that.selectList[0].children=result.datas;
  96. }
  97. })
  98. },
  99. /* 获取负责人(获取1为施工方、 2为监理方 3、为业主方)*/
  100. findUserTypeOne(){
  101. var that=this;
  102. var contractId = uni.getStorageSync("porject"+"_"+uni.getStorageSync("userInfo").id).contractId;
  103. that.http.request("/app/task/listByTask",{contractId:contractId}).then((res)=>{
  104. res.datas.forEach((item,index,arr)=>{
  105. item.checked=false;
  106. if(item.type==1){
  107. that.selectList[0].children.push(item)
  108. }else if(item.type==2){
  109. that.selectList[1].children.push(item)
  110. }else if(item.type==3){
  111. that.selectList[2].children.push(item)
  112. }
  113. })
  114. //把已选的添加上
  115. if(that.titleName=="选择负责人"){
  116. let selects = getApp().globalData.principal;
  117. this.num = selects.length;
  118. selects.forEach((sele)=>{
  119. let index = 0;
  120. if(sele.type==1){
  121. index = 0;
  122. }else if(sele.type==2){
  123. index = 1;
  124. }else if(sele.type==3){
  125. index = 2;
  126. }
  127. that.selectList[index].children.forEach((person)=>{
  128. if(person.id == sele.id){
  129. person.checked = true;
  130. }
  131. })
  132. })
  133. }
  134. })
  135. }
  136. },
  137. onLoad(e) {
  138. if(e.type){
  139. if(e.type==1){
  140. this.titleName ="选择施工员";
  141. this.findUserType(e.type);
  142. }
  143. if(e.type==2){
  144. this.titleName ="选择监理员";
  145. this.findUserType(e.type);
  146. }
  147. this.type=e.type
  148. }else{
  149. this.titleName =e.name;
  150. if(this.titleName=="选择负责人"){
  151. this.findUserTypeOne();
  152. }else{//选择审批人
  153. this.type=1;//单选
  154. this.findUserTypeOne();
  155. }
  156. }
  157. /* 全局事件订阅,只要订阅了事件就可以收到值 */
  158. uni.$on("num",(rel)=>{
  159. this.num=rel
  160. })
  161. }
  162. }
  163. </script>
  164. <style>
  165. </style>