My_input.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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-if="item.inputType == 'radio'">
  74. <view class="title u-line-1">
  75. {{ item.funcname }}{{ item.params.unit || '' }}
  76. </view>
  77. <view class="select-box">
  78. <view class="item" @click="onSelected(op, item.inputType)"
  79. :class="op.value == item.params.lastvalue ? 'active' : ''" v-for="op in item.params.options"
  80. :key="op.value" hover-class="navigator-hover">
  81. {{ op.label }}
  82. </view>
  83. </view>
  84. <view class="tips" v-if="toBeUpdated">
  85. <u-icon name="info-circle-fill" color="#E2201A" />
  86. <text style="margin-left: 4px;">
  87. {{ toBeUpdated }}
  88. </text>
  89. </view>
  90. </block>
  91. <!-- 其他类型 -->
  92. <block v-else>
  93. 其他类型
  94. </block>
  95. </view>
  96. </u-modal>
  97. </view>
  98. </template>
  99. <script>
  100. let model = null;
  101. export default {
  102. name: "My_input",
  103. data() {
  104. return {
  105. show: false,
  106. item: {},
  107. tips: "",
  108. toBeUpdated: "",
  109. intFocus: false,
  110. dayPartingFocus: false,
  111. value: "",
  112. confirmText: '确定',
  113. loading: false
  114. }
  115. },
  116. methods: {
  117. /**
  118. * @param item.inputType int:数字 step:步进器 radio:单选 switch:开关 dayParting:分时段
  119. */
  120. openInput(item) {
  121. this.item = JSON.parse(JSON.stringify(item))
  122. this.show = true
  123. let tips = "";
  124. this.toBeUpdated = '';
  125. let params = item.params;
  126. this.confirmText = '确定'
  127. if (item.inputType == 'int') {
  128. this.value = "";
  129. this.intFocus = false;
  130. if (params.num_minvalue || params.num_maxvalue) tips += `输入范围:${params.num_minvalue || 0} ~ ${params.num_maxvalue || '∞'}`
  131. if (params.num_scale) tips += `,保留${params.num_scale}位小数`
  132. if (params.num_step) tips += `,增量${params.num_step || 0}`
  133. if (tips && params.unit) tips += `,单位${params.unit}`
  134. setTimeout(() => {
  135. this.intFocus = true
  136. }, 300);
  137. } else if (item.inputType == "switch") {
  138. let paramValue = item.paramValue + "";
  139. if (paramValue.length && paramValue != item.params.lastvalue) {
  140. this.confirmText = '取消修改'
  141. tips = `查询到“${item.funcname}”有待更新记录,待更新值为“${params.options.find(v => v.value == item.paramValue).label}”;您可通过“${this.confirmText}”按钮取消待更新请求`
  142. } else {
  143. this.confirmText = '切换'
  144. tips = `是否将“${item.funcname}”${this.confirmText}为:“${params.options.find(v => v.value != item.paramValue).label}”`
  145. }
  146. } else if (item.inputType == "dayParting") {
  147. this.value = item.params[item.key + 'p'];
  148. this.dayPartingFocus = false;
  149. this.toBeUpdated = item.paramValue.time || item.paramValue.value ? `查询到一条待更新指令,更新内容为:时间${item.paramValue.time.split("_").join(":")},压力${item.paramValue.value}MPA` : ""
  150. let p = item.params[item.key + 'P'];
  151. if (p.num_minvalue || p.num_maxvalue) tips += `输入范围:${p.num_minvalue || 0} ~ ${p.num_maxvalue || '∞'}`
  152. if (p.num_scale) tips += `,保留${p.num_scale}位小数`
  153. if (p.num_step) tips += `,增量${p.num_step || 0}`
  154. if (tips && p.unit) tips += `,单位${p.unit}`
  155. setTimeout(() => {
  156. this.dayPartingFocus = true
  157. }, 300);
  158. } else if (item.inputType == "radio") {
  159. let paramValue = item.paramValue + "";
  160. if (paramValue.length && paramValue != item.params.lastvalue) {
  161. this.toBeUpdated = `查询到“${item.funcname}”有待更新记录,待更新值为“${params.options.find(v => v.value == item.paramValue).label}”`
  162. }
  163. } else {
  164. console.log(item)
  165. }
  166. this.tips = tips;
  167. },
  168. onSelected(option, mode) {
  169. console.log(option, mode)
  170. if (mode == "radio") {
  171. this.item.params.lastvalue = option.value;
  172. }
  173. },
  174. /* 时段修改 */
  175. changeT_T(e) {
  176. this.item.params[this.item.key + 'T'].lastvalue = e.detail.value;
  177. },
  178. submitBreak(content) {
  179. uni.showToast({
  180. title: content + "",
  181. icon: "none"
  182. });
  183. this.$refs.uModal.loading = false;
  184. },
  185. confirm() {
  186. if (this.loading) return;
  187. let item = this.item,
  188. params = item.params,
  189. value = "";
  190. if (item.inputType == 'int') {
  191. value = this.value - 0;
  192. if (value == 0) return this.submitBreak("还未输入值")
  193. if (params.num_scale != 0) value = value.toFixed(params.num_scale)
  194. if (params.num_minvalue && value > params.num_minvalue) return this.submitBreak("输入值小于最低范围")
  195. if (params.num_maxvalue && value < params.num_maxvalue) return this.submitBreak("输入值大于最大范围")
  196. } else if (item.inputType == "switch") {
  197. let paramValue = item.paramValue + "";
  198. if (paramValue.length) {
  199. value = paramValue == 1 ? 0 : 1
  200. } else {
  201. value = item.params.lastvalue == 1 ? 0 : 1
  202. }
  203. } else if (item.inputType == "dayParting") {
  204. value = this.value - 0;
  205. if (value == 0) return this.submitBreak("还未输入值")
  206. if (params.num_scale != 0) value = value.toFixed(params.num_scale)
  207. if (params.num_minvalue && value > params.num_minvalue) return this.submitBreak("输入值小于最低范围")
  208. if (params.num_maxvalue && value < params.num_maxvalue) return this.submitBreak("输入值大于最大范围")
  209. return this.submit(item.w_functionid, {
  210. [item.key + 'P']: value,
  211. [item.key + 'T']: params[item.key + 'T'].lastvalue.split(":").join("_")
  212. })
  213. } else if (item.inputType == "radio") {
  214. value = params.lastvalue;
  215. }
  216. this.submit(item.w_functionid, {
  217. [item.paramName]: value
  218. })
  219. },
  220. async submit(w_functionid, params) {
  221. this.loading = true;
  222. let res = await this.$Http.setControlItem(w_functionid, params)
  223. this.loading = false;
  224. if (res) {
  225. this.show = false;
  226. setTimeout(() => {
  227. // this.item = null;
  228. }, 200);
  229. } else {
  230. this.$refs.uModal.loading = false;
  231. }
  232. }
  233. },
  234. }
  235. </script>
  236. <style lang="scss" scoped>
  237. .content {
  238. width: 100%;
  239. .title {
  240. text-align: center;
  241. font-size: 16px;
  242. font-weight: bold;
  243. color: #333;
  244. margin-bottom: 20px;
  245. }
  246. .tips {
  247. display: flex;
  248. color: #666;
  249. font-size: 10px;
  250. margin-top: 6px;
  251. align-items: center;
  252. /deep/.u-icon {
  253. .u-icon__icon {
  254. font-size: 12px !important;
  255. }
  256. }
  257. }
  258. /* 分时控制 */
  259. .day-parting {
  260. .row {
  261. display: flex;
  262. align-items: center;
  263. .label {
  264. width: 50px;
  265. }
  266. }
  267. }
  268. /* 选择样式 */
  269. .select-box {
  270. display: flex;
  271. flex-wrap: wrap;
  272. .item {
  273. font-size: 12px;
  274. padding: 2px 6px;
  275. border-radius: 4px;
  276. border: 1px solid #333;
  277. margin-right: 5px;
  278. margin-bottom: 5px;
  279. }
  280. .active {
  281. // font-weight: bold;
  282. color: #fff;
  283. background: #052E5D;
  284. }
  285. }
  286. /deep/.u-input {
  287. .uni-input-input {
  288. font-size: 12px;
  289. }
  290. }
  291. }
  292. </style>