condition.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="condition">
  3. <view class="title">请选择追踪条件(可多选)</view>
  4. <view class="select-btn">
  5. <text>选择门诊或急诊</text>
  6. <view>
  7. <button :class="{active: condition.depType === 1}"
  8. @click="selectBtnHandle(1)">门诊</button>
  9. <button :class="{active: condition.depType === 2}"
  10. @click="selectBtnHandle(2)">急诊</button>
  11. </view>
  12. </view>
  13. <tm-trees :options="condition.options"
  14. :defaultOpen="condition.defaultOpen"
  15. :defaultChecked="condition.conditionIds"
  16. v-on:checked-keys="checkedHandle"></tm-trees>
  17. </view>
  18. </template>
  19. <script>
  20. import { mapState } from "vuex";
  21. import {conditionOptions,editCondition} from "./utils.js";
  22. export default {
  23. computed: {
  24. ...mapState({
  25. condition: state => state.creatingSituations.condition,
  26. needReload: state => state.creatingSituations.needReload,
  27. theme: state => state.creatingSituations.theme,
  28. editConfig: state => state.creatingSituations.editConfig
  29. })
  30. },
  31. created: function(){
  32. // 编辑的时候不用获取数据
  33. if(this.editConfig && this.editConfig.theme.id === this.theme.id) {
  34. this.$store.commit({
  35. type: 'creatingSituations/comChangeState',
  36. key: 'condition',
  37. data: this.editConfig.condition
  38. });
  39. } else if(this.needReload) {
  40. this.getOptions(this.condition.depType);
  41. }
  42. },
  43. methods: {
  44. checkedHandle: function(keys) {
  45. this.myCommit('conditionIds', keys);
  46. },
  47. selectBtnHandle: function(depType) {
  48. this.myCommit('depType', depType);
  49. this.getOptions(depType);
  50. },
  51. /**
  52. * 获取树形节点数据
  53. */
  54. getOptions: function(depType) {
  55. this.checkedHandle([]); // 切换后清空选中
  56. const {id} = this.theme;
  57. if(id || id === 0) {
  58. this.$store.dispatch({
  59. type: 'creatingSituations/commActions',
  60. key: 'conditions',
  61. data: { depType, type: id }
  62. }).then((data)=> {
  63. if(data) {
  64. if(data.length > 0) {
  65. this.myCommit('defaultOpen', [data[0].id]);
  66. }
  67. this.myCommit('options', conditionOptions(data));
  68. }
  69. });
  70. } else {
  71. uni.showModal({
  72. title: '温馨提示',
  73. content: '请先选择主题!',
  74. showCancel: false
  75. });
  76. }
  77. },
  78. /**
  79. * 更新condition数据
  80. * @param {Object} key 要更新的属性
  81. * @param {Object} value 值
  82. */
  83. myCommit: function(key, value) {
  84. let data = {...this.condition};
  85. data[key] = value;
  86. this.$store.commit({
  87. type: 'creatingSituations/comChangeState',
  88. key: 'condition',
  89. data
  90. });
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="less">
  96. .select-btn {
  97. display: flex;
  98. flex-direction: row;
  99. justify-content: space-between;
  100. align-items: center;
  101. margin-bottom: 15rpx;
  102. padding: 0 25rpx;
  103. width: 100%;
  104. height: 87.5rpx;
  105. font-size: 22.5rpx;
  106. line-height: 33.75rpx;
  107. color: #525866;
  108. background-color: #fff;
  109. view {
  110. display: flex;
  111. flex-direction: row;
  112. button {
  113. border: 0;
  114. border-radius: 25rpx;
  115. padding: 0 46.25rpx;
  116. height: 50rpx;
  117. line-height: 50rpx;
  118. color: #292C33;
  119. background-color: #EBEFF7;
  120. &:first-child {
  121. margin-right: 20rpx;
  122. }
  123. &::after {
  124. border: 0;
  125. }
  126. &.active {
  127. color: #fff;
  128. background-color: #3377FF;
  129. }
  130. }
  131. }
  132. }
  133. </style>