总结

  1. 终止循环的条件判断,单独写
  2. 表单赋值可以用es6的解构赋值
  3. 当条件为真假时,可用赋值的形式
  4. 定义全局变量,便于后期维护
  5. 写代码之前,需要考虑是否拆分组件(原因:计算属性默认只有getter,没有setter,所以计算属性不支持数据的修改,只能对data中的数据进行引用计算。)

修改之前
image.png
修改之后
image.png
修改之前
image.png
修改之后
image.png

修改之前
image.png
修改之后
image.png
没拆分组件之前
image.png
拆分组件之后
image.png
image.png
image.png
image.png

  1. <template>
  2. <view class="pi-pd-lr-32 pi-bg-white pi-pd-top-30 pi-pd-bottom-32 pi-mg-top-2">
  3. <view class="pi-flex pi-justify-between">
  4. <view class="pi-fz-28 pi-fw-400">{{ item.title }}</view>
  5. <pi-radio-group
  6. v-model="status"
  7. shape="round"
  8. style="width: auto;"
  9. size="32"
  10. icon-size="22"
  11. @change="handleSelectStatus(status, item.key)"
  12. >
  13. <pi-radio active-color="#FF8A24" active-mode="fill" :name="0">无</pi-radio>
  14. <pi-radio active-color="#FF8A24" active-mode="fill" :name="1">
  15. 有
  16. </pi-radio>
  17. </pi-radio-group>
  18. </view>
  19. <view v-if="status === 1 && !item.isSingle">
  20. <pi-input
  21. v-model="content"
  22. placeholder="请补充您的确诊疾病名称"
  23. placeholder-style="font-size:28rpx;color:#cccccc"
  24. maxlength="200"
  25. type="textarea"
  26. class="textarea pi-pd-lr-24 pi-pd-top-32 pi-mg-top-38"
  27. style="background: #f4f4f4;"
  28. :custom-style="{ height: '180rpx' }"
  29. />
  30. <view class="pi-flex pi-flex-wrap">
  31. <view
  32. v-for="(text, tipsIndex) in item.tips"
  33. :key="tipsIndex"
  34. class="tips pi-mg-top-32 pi-flex pi-justify-center pi-align-center pi-fz-24 pi-gray pi-mg-right-16"
  35. @click="handleAppendTips(text, item.key)"
  36. >
  37. {{ text }}
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. const TAG_NAME = 'PatientHistoryInfo'
  45. export default {
  46. name: TAG_NAME,
  47. components: {},
  48. filters: {},
  49. props: {
  50. item: {
  51. type: Object,
  52. default: () => {}
  53. }
  54. },
  55. data() {
  56. return {
  57. content: '', // 文本域输入的内容
  58. status: 0 // 选择的状态
  59. }
  60. },
  61. computed: {},
  62. watch: {
  63. content: {
  64. handler: function(content) {
  65. this.$emit('add', content, this.item.key, this.status, this.item.isSingle)
  66. },
  67. deep: true
  68. },
  69. status: {
  70. handler: function(status) {
  71. this.$emit('add', this.content, this.item.key, status, this.item.isSingle)
  72. },
  73. deep: true
  74. },
  75. item: {
  76. handler: function(item) {
  77. if (item.isSingle) {
  78. // 单选操作
  79. this.status = item.status
  80. } else if (item.content && !item.isSingle) {
  81. // 内容不为空,赋值
  82. this.status = 1
  83. this.content = item.content
  84. }
  85. },
  86. deep: true
  87. }
  88. },
  89. methods: {
  90. // 追加提示
  91. handleAppendTips(text, key) {
  92. this.content += (this.content && ',') + text
  93. },
  94. // 选择状态
  95. handleSelectStatus(status, key) {
  96. this.status = status
  97. if (this.status === 0) this.content = ''
  98. }
  99. }
  100. }
  101. </script>