condition.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. export default {
  22. computed: {
  23. ...mapState({
  24. condition: state => state.creatingSituations.condition,
  25. needReload: state => state.creatingSituations.needReload,
  26. theme: state => state.creatingSituations.theme
  27. })
  28. },
  29. created: function(){
  30. if(this.needReload) // 点击上一步不用获取数据
  31. this.getOptions(this.condition.depType);
  32. },
  33. methods: {
  34. checkedHandle: function(keys) {
  35. this.myCommit('conditionIds', keys);
  36. },
  37. selectBtnHandle: function(depType) {
  38. this.myCommit('depType', depType);
  39. this.getOptions(depType);
  40. },
  41. /**
  42. * 获取树形节点数据
  43. */
  44. getOptions: function(depType) {
  45. this.checkedHandle([]); // 切换后清空选中
  46. const {id} = this.theme;
  47. if(id || id === 0) {
  48. this.$store.dispatch({
  49. type: 'creatingSituations/commActions',
  50. key: 'conditions',
  51. data: { depType, type: id }
  52. }).then((data)=> {
  53. if(data) {
  54. if(data.length > 0) {
  55. this.myCommit('defaultOpen', [data[0].id]);
  56. }
  57. this.myCommit('options', this.optionsHandle(data));
  58. }
  59. });
  60. } else {
  61. uni.showModal({
  62. title: '温馨提示',
  63. content: '请先选择主题!',
  64. showCancel: false
  65. });
  66. }
  67. },
  68. /**
  69. * 增加树形数据字段,以适配公共组件
  70. * @param {Object} data
  71. */
  72. optionsHandle: function(data) {
  73. let options = data.map((item)=>{
  74. return {
  75. ...item,
  76. key: item.id,
  77. label: item.name,
  78. children: this.optionsHandle(item.child)
  79. }
  80. });
  81. return options;
  82. },
  83. /**
  84. * 更新condition数据
  85. * @param {Object} key 要更新的属性
  86. * @param {Object} value 值
  87. */
  88. myCommit: function(key, value) {
  89. let data = {...this.condition};
  90. data[key] = value;
  91. this.$store.commit({
  92. type: 'creatingSituations/comChangeState',
  93. key: 'condition',
  94. data
  95. });
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="less">
  101. .select-btn {
  102. display: flex;
  103. flex-direction: row;
  104. justify-content: space-between;
  105. align-items: center;
  106. margin-bottom: 15rpx;
  107. padding: 0 25rpx;
  108. width: 100%;
  109. height: 87.5rpx;
  110. font-size: 22.5rpx;
  111. line-height: 33.75rpx;
  112. color: #525866;
  113. background-color: #fff;
  114. view {
  115. display: flex;
  116. flex-direction: row;
  117. button {
  118. border: 0;
  119. border-radius: 25rpx;
  120. padding: 0 46.25rpx;
  121. height: 50rpx;
  122. line-height: 50rpx;
  123. color: #292C33;
  124. background-color: #EBEFF7;
  125. &:first-child {
  126. margin-right: 20rpx;
  127. }
  128. &::after {
  129. border: 0;
  130. }
  131. &.active {
  132. color: #fff;
  133. background-color: #3377FF;
  134. }
  135. }
  136. }
  137. }
  138. </style>