condition.vue 3.6 KB

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