condition.vue 3.2 KB

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