condition.vue 3.9 KB

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