My_input.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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-if="item.inputType == 'dayParting'">
  41. <view class="title u-line-1">
  42. {{ item.funcname }}{{ item.params[item.key + 'P'].unit || '' }}
  43. </view>
  44. <view class="day-parting">
  45. <picker mode="time" :value="item.params[item.key + 'T'].lastvalue" @change="changeT_T">
  46. <view class="row">
  47. <view class="label">
  48. 时间:
  49. </view>
  50. {{ item.params[item.key + 'T'].lastvalue }}
  51. </view>
  52. </picker>
  53. <view class="row" style="margin-top: 20px">
  54. <view class="label">压力:</view>
  55. <u--input :focus="dayPartingFocus" v-model="value" type="digit"
  56. :placeholder="item.params[item.key + 'P'].lastvalue" border="surround" />
  57. </view>
  58. <view class="tips" v-if="toBeUpdated">
  59. <u-icon name="info-circle-fill" color="#E2201A" />
  60. <text style="margin-left: 4px;">
  61. {{ toBeUpdated }}
  62. </text>
  63. </view>
  64. <view class="tips" v-if="tips">
  65. <u-icon name="info-circle-fill" color="#55AAFF" />
  66. <text style="margin-left: 4px;">
  67. {{ tips }}
  68. </text>
  69. </view>
  70. </view>
  71. </block>
  72. <!-- 其他类型 -->
  73. <block v-else>
  74. 其他类型
  75. </block>
  76. </view>
  77. </u-modal>
  78. </view>
  79. </template>
  80. <script>
  81. export default {
  82. name: "My_input",
  83. data() {
  84. return {
  85. show: false,
  86. item: {},
  87. tips: "",
  88. toBeUpdated: "",
  89. intFocus: false,
  90. dayPartingFocus: false,
  91. value: "",
  92. confirmText: '确定',
  93. loading: false
  94. }
  95. },
  96. methods: {
  97. /**
  98. * @param item.inputType int:数字 step:步进器 radio:单选 switch:开关 dayParting:分时段
  99. */
  100. openInput(item) {
  101. this.item = item;
  102. this.show = true
  103. let tips = "";
  104. let params = item.params;
  105. this.confirmText = '确定'
  106. if (item.inputType == 'int') {
  107. this.value = "";
  108. this.intFocus = false;
  109. if (params.num_minvalue || params.num_maxvalue) tips += `输入范围:${params.num_minvalue || 0} ~ ${params.num_maxvalue || '∞'}`
  110. if (params.num_scale) tips += `,保留${params.num_scale}位小数`
  111. if (params.num_step) tips += `,增量${params.num_step || 0}`
  112. if (tips && params.unit) tips += `,单位${params.unit}`
  113. setTimeout(() => {
  114. this.intFocus = true
  115. }, 300);
  116. } else if (item.inputType == "switch") {
  117. let paramValue = item.paramValue + "";
  118. if (paramValue.length && paramValue != item.params.lastvalue) {
  119. this.confirmText = '取消修改'
  120. tips = `查询到“${item.funcname}”有待更新记录,待更新值为“${params.options.find(v => v.value == item.paramValue).label}”;您可通过“${this.confirmText}”按钮取消待更新请求`
  121. } else {
  122. this.confirmText = '切换'
  123. tips = `是否将“${item.funcname}”${this.confirmText}为:“${params.options.find(v => v.value != item.paramValue).label}”`
  124. }
  125. } else if (item.inputType == "dayParting") {
  126. this.value = item.params[item.key + 'p'];
  127. this.dayPartingFocus = false;
  128. this.item = JSON.parse(JSON.stringify(item))
  129. this.toBeUpdated = item.paramValue.time || item.paramValue.value ? `查询到一条待更新指令,更新内容为时间:${item.paramValue.time.split("_").join(":")},压力:${item.paramValue.value}MPA` : ""
  130. let p = item.params[item.key + 'P'];
  131. if (p.num_minvalue || p.num_maxvalue) tips += `输入范围:${p.num_minvalue || 0} ~ ${p.num_maxvalue || '∞'}`
  132. if (p.num_scale) tips += `,保留${p.num_scale}位小数`
  133. if (p.num_step) tips += `,增量${p.num_step || 0}`
  134. if (tips && p.unit) tips += `,单位${p.unit}`
  135. setTimeout(() => {
  136. this.dayPartingFocus = true
  137. }, 300);
  138. }
  139. this.tips = tips;
  140. },
  141. /* 时段修改 */
  142. changeT_T(e) {
  143. this.item.params[this.item.key + 'T'].lastvalue = e.detail.value;
  144. },
  145. submitBreak(content) {
  146. uni.showToast({
  147. title: content + "",
  148. icon: "none"
  149. });
  150. this.$refs.uModal.loading = false;
  151. },
  152. confirm() {
  153. if (this.loading) return;
  154. let item = this.item,
  155. params = item.params,
  156. value = "";
  157. if (item.inputType == 'int') {
  158. value = this.value - 0;
  159. if (value == 0) return this.submitBreak("还未输入值")
  160. if (params.num_scale != 0) value = value.toFixed(params.num_scale)
  161. if (params.num_minvalue && value > params.num_minvalue) return this.submitBreak("输入值小于最低范围")
  162. if (params.num_maxvalue && value < params.num_maxvalue) return this.submitBreak("输入值大于最大范围")
  163. } else if (item.inputType == "switch") {
  164. let paramValue = item.paramValue + "";
  165. if (paramValue.length) {
  166. value = paramValue == 1 ? 0 : 1
  167. } else {
  168. value = item.params.lastvalue == 1 ? 0 : 1
  169. }
  170. } else if (item.inputType == "dayParting") {
  171. value = this.value - 0;
  172. if (value == 0) return this.submitBreak("还未输入值")
  173. if (params.num_scale != 0) value = value.toFixed(params.num_scale)
  174. if (params.num_minvalue && value > params.num_minvalue) return this.submitBreak("输入值小于最低范围")
  175. if (params.num_maxvalue && value < params.num_maxvalue) return this.submitBreak("输入值大于最大范围")
  176. return this.submit(item.w_functionid, {
  177. [item.key + 'P']: value,
  178. [item.key + 'T']: params[item.key + 'T'].lastvalue.split(":").join("_")
  179. })
  180. }
  181. this.submit(item.w_functionid, {
  182. [item.paramName]: value
  183. })
  184. },
  185. async submit(w_functionid, params) {
  186. this.loading = true;
  187. let res = await this.$Http.setControlItem(w_functionid, params)
  188. this.loading = false;
  189. if (res) {
  190. this.show = false;
  191. setTimeout(() => {
  192. this.item = null;
  193. }, 200);
  194. } else {
  195. this.$refs.uModal.loading = false;
  196. }
  197. }
  198. },
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .content {
  203. width: 100%;
  204. .title {
  205. text-align: center;
  206. font-size: 16px;
  207. font-weight: bold;
  208. color: #333;
  209. margin-bottom: 20px;
  210. }
  211. .tips {
  212. display: flex;
  213. color: #666;
  214. font-size: 10px;
  215. margin-top: 6px;
  216. align-items: center;
  217. /deep/.u-icon {
  218. .u-icon__icon {
  219. font-size: 12px !important;
  220. }
  221. }
  222. }
  223. .day-parting {
  224. .row {
  225. display: flex;
  226. align-items: center;
  227. .label {
  228. width: 50px;
  229. }
  230. }
  231. }
  232. /deep/.u-input {
  233. .uni-input-input {
  234. font-size: 12px;
  235. }
  236. }
  237. }
  238. </style>