My_input.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view>
  3. <u-modal ref="uModal" :show="show" @confirm="confirm" :asyncClose="true" :showCancelButton="true"
  4. @cancel="show = false" :confirmText="confirmText">
  5. <view class="content">
  6. <!-- 整数类型 -->
  7. <block v-if="item.inputType == 'int'">
  8. <view class="title u-line-1">
  9. {{ item.funcname }}{{ item.params.unit }}
  10. </view>
  11. <block v-if="item.inputType == 'int'">
  12. <u--input :focus="intFocus" v-model="value" :type="item.num_scale == 0 ? 'number' : 'digit'"
  13. :placeholder="item.showValue || item.params.lastvalue" border="surround" />
  14. </block>
  15. <view class="tips" v-if="item.paramValue">
  16. <u-icon name="info-circle-fill" color="#E2201A" />
  17. <text style="margin-left: 4px;">
  18. 有一条待更新记录,待更新值为:{{ item.paramValue }}{{ item.params.unit }}
  19. </text>
  20. </view>
  21. <view class="tips" v-if="tips">
  22. <u-icon name="info-circle-fill" color="#55AAFF" />
  23. <text style="margin-left: 4px;">
  24. {{ tips }}
  25. </text>
  26. </view>
  27. </block>
  28. <!-- 布尔开关 -->
  29. <block v-else-if="item.inputType == 'switch'">
  30. <view class="title u-line-1">
  31. {{ item.funcname }}{{ item.params.unit }}
  32. </view>
  33. {{ tips }}
  34. </block>
  35. <!-- 步进器 -->
  36. <block v-else-if="item.inputType == 'step'">
  37. 步进器还没写
  38. </block>
  39. <!-- 其他类型 -->
  40. <block v-else>
  41. 其他类型
  42. </block>
  43. </view>
  44. </u-modal>
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. name: "My_input",
  50. data() {
  51. return {
  52. show: false,
  53. item: {},
  54. tips: "",
  55. intFocus: false,
  56. value: "",
  57. confirmText: '确定'
  58. }
  59. },
  60. methods: {
  61. /**
  62. * @param item.inputType int:数字 step:步进器 radio:单选 switch:开关
  63. */
  64. openInput(item) {
  65. this.item = item;
  66. this.show = true
  67. let tips = "";
  68. let params = item.params;
  69. this.confirmText = '确定'
  70. if (item.inputType == 'int') {
  71. this.value = "";
  72. this.intFocus = false;
  73. if (params.num_minvalue || params.num_maxvalue) tips += `输入范围:${params.num_minvalue || 0} ~ ${params.num_maxvalue || '∞'}`
  74. if (params.num_scale) tips += `,保留${params.num_scale}位小数`
  75. if (params.num_step) tips += `,增量${params.num_step || 0}`
  76. if (tips && params.unit) tips += `,单位${params.unit}`
  77. setTimeout(() => {
  78. this.intFocus = true
  79. }, 300);
  80. } else if (item.inputType == "switch") {
  81. let paramValue = item.paramValue + "";
  82. if (paramValue.length && paramValue != item.params.lastvalue) {
  83. this.confirmText = '取消修改'
  84. tips = `查询到“${item.funcname}”有待更新记录,待更新值为“${params.options.find(v => v.value == item.paramValue).label}”;您可通过“${this.confirmText}”按钮取消待更新请求`
  85. } else {
  86. this.confirmText = '切换'
  87. tips = `是否将“${item.funcname}”${this.confirmText}为:“${params.options.find(v => v.value != item.paramValue).label}”`
  88. }
  89. }
  90. this.tips = tips;
  91. },
  92. submitBreak(content) {
  93. uni.showToast({
  94. title: content + "",
  95. icon: "none"
  96. });
  97. this.$refs.uModal.loading = false;
  98. },
  99. confirm() {
  100. let item = this.item,
  101. params = item.params,
  102. value = "";
  103. if (item.inputType == 'int') {
  104. value = this.value - 0;
  105. if (value == 0) return this.submitBreak("还未输入值")
  106. if (params.num_scale != 0) value = value.toFixed(params.num_scale)
  107. if (params.num_minvalue && value > params.num_minvalue) return this.submitBreak("输入值小于最低范围")
  108. if (params.num_maxvalue && value < params.num_maxvalue) return this.submitBreak("输入值大于最大范围")
  109. } else if (item.inputType == "switch") {
  110. let paramValue = item.paramValue + "";
  111. if (paramValue.length) {
  112. value = paramValue == 1 ? 0 : 1
  113. } else {
  114. value = item.params.lastvalue == 1 ? 0 : 1
  115. }
  116. }
  117. this.submit(item.w_functionid, {
  118. [item.paramName]: value
  119. })
  120. },
  121. async submit(w_functionid, params) {
  122. await this.$Http.setControlItem(w_functionid, params)
  123. this.show = false;
  124. setTimeout(() => {
  125. this.item = null;
  126. }, 200);
  127. }
  128. },
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .content {
  133. width: 100%;
  134. .title {
  135. text-align: center;
  136. font-size: 16px;
  137. font-weight: bold;
  138. color: #333;
  139. margin-bottom: 20px;
  140. }
  141. .tips {
  142. display: flex;
  143. color: #666;
  144. font-size: 10px;
  145. margin-top: 6px;
  146. align-items: center;
  147. /deep/.u-icon {
  148. .u-icon__icon {
  149. font-size: 12px !important;
  150. }
  151. }
  152. }
  153. }
  154. </style>