My_input.vue 8.9 KB

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