SelectProject.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view>
  3. <uni-list >
  4. <uni-list-item v-for="(item,index) in projectList" :title="item.unitCode" :key="index" :rightText="item.unitName" @click="onClick(index,item)" clickable style="cursor: pointer;"/>
  5. </uni-list>
  6. </view>
  7. </template>
  8. <script>
  9. import {selectProject} from "@/common/api/commonApi.js";
  10. export default {
  11. data() {
  12. return {
  13. projectList:[]
  14. }
  15. },
  16. onLoad:function(){
  17. this.$util.persistLogin(this);
  18. },
  19. created:function(){
  20. this.getProjectList();
  21. },
  22. methods: {
  23. getProjectList:function(){
  24. var that=this;
  25. selectProject().then((res)=>{
  26. console.info('getProjectList',res);
  27. if(!res.isSuccess){
  28. uni.showToast({
  29. title:res.errMsg,
  30. duration:3000,
  31. icon:"none"
  32. });
  33. }
  34. res.data.forEach(function(item,index,array){
  35. that.$set(that.projectList,index,item);
  36. });
  37. //console.info(that.projectList);
  38. });
  39. },
  40. onClick:function(index,item) {
  41. //console.info(index);
  42. //console.info(item);
  43. let unitCode=item.unitCode; //获取项目编码
  44. this.$store.commit('setProjectCode',unitCode); //赋值
  45. uni.setStorage({
  46. key:'storage_state',
  47. data:this.$store.state,
  48. success:function(){
  49. console.info("setProjectCode选择项目后状态缓存成功");
  50. console.info('storage_state',uni.getStorageSync('storage_state'));
  51. },
  52. fail: () => {
  53. console.error("setProjectCode选择项目后状态缓存失败");
  54. }
  55. });
  56. //导向到首页
  57. uni.navigateTo({
  58. url: "/pages/index/index"
  59. });
  60. // uni.showToast({
  61. // title: '点击反馈'
  62. // });
  63. }
  64. }
  65. }
  66. </script>
  67. <style>
  68. </style>