SelectProject.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. res.forEach(function(item,index,array){
  28. that.$set(that.projectList,index,item);
  29. });
  30. //console.info(that.projectList);
  31. });
  32. },
  33. onClick:function(index,item) {
  34. //console.info(index);
  35. //console.info(item);
  36. let unitCode=item.unitCode; //获取项目编码
  37. this.$store.commit('setProjectCode',unitCode); //赋值
  38. uni.setStorage({
  39. key:'storage_state',
  40. data:this.$store.state,
  41. success:function(){
  42. console.info("setProjectCode选择项目后状态缓存成功");
  43. },
  44. fail: () => {
  45. console.error("setProjectCode选择项目后状态缓存失败");
  46. }
  47. });
  48. //导向到首页
  49. uni.navigateTo({
  50. url: "/pages/index/index"
  51. });
  52. // uni.showToast({
  53. // title: '点击反馈'
  54. // });
  55. }
  56. }
  57. }
  58. </script>
  59. <style>
  60. </style>