division.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view class="control">
  3. <view class="control-title"> 分时控制 </view>
  4. <view
  5. class="item-box"
  6. v-for="(item, index) in list"
  7. :key="item.w_functionid"
  8. >
  9. <view
  10. class="TR-state"
  11. hover-class="navigator-hover"
  12. @click.stop="changTR(index)"
  13. >{{
  14. (TRList[index].showValue.includes("投入") ? "切出" : "投入") ||
  15. "暂未设置"
  16. }}</view
  17. >
  18. <view class="item" hover-class="navigator-hover" @click="onClick(item)">
  19. <view class="title">
  20. <view>{{ item.funcname }}</view>
  21. <view class="pilotLamp">
  22. <pilotLamp :trItem="TRList[index]" />
  23. </view>
  24. </view>
  25. <view class="row">
  26. <view class="box">
  27. <view class=""> 开始时间 </view>
  28. <view class="content">
  29. <view class="value">{{ item.showValue.begin || "--" }}</view>
  30. </view>
  31. </view>
  32. <view class="box">
  33. <view class=""> 结束时间 </view>
  34. <view class="content">
  35. <view class="value">{{ item.showValue.end || "--" }}</view>
  36. </view>
  37. </view>
  38. <view class="box">
  39. <view class=""> 压力设定 </view>
  40. <view class="content">
  41. <view class="value">{{ item.showValue.value || "--" }}</view>
  42. <view class="unit">{{
  43. item.params[item.funcname + "压力设定"].unit || ""
  44. }}</view>
  45. </view>
  46. </view>
  47. </view>
  48. <view v-if="item.isfeedback" class="dot" />
  49. </view>
  50. </view>
  51. <My_input ref="MyInput" @customMethod="customMethod">
  52. <view class="change-item" v-if="changeItem.funcname">
  53. <!-- :end="endTime" -->
  54. <!-- :start="changeItem.showValue.begin" -->
  55. <picker
  56. mode="time"
  57. :value="changeItem.showValue.begin"
  58. data-name="begin"
  59. @change="timeChange"
  60. >
  61. <view class="row">
  62. <view class="label"> 开始时间: </view>
  63. <view class="value day-parting-row"
  64. >{{ changeItem.showValue.begin || " --" }}
  65. </view>
  66. </view>
  67. </picker>
  68. <picker
  69. mode="time"
  70. :value="changeItem.showValue.end"
  71. data-name="end"
  72. @change="timeChange"
  73. >
  74. <view class="row">
  75. <view class="label"> 结束时间: </view>
  76. <view class="value day-parting-row">{{
  77. changeItem.showValue.end || " --"
  78. }}</view>
  79. </view>
  80. </picker>
  81. <view class="row">
  82. <view class="label"> 压力设定: </view>
  83. <view class="value">
  84. <u-input
  85. :placeholder="changeItem.showValue.value || '压力设定'"
  86. v-model="changeItem.showValue.value"
  87. :type="
  88. changeItem.params[changeItem.funcname1 + '压力设定']
  89. .num_scale == 0
  90. ? 'number'
  91. : 'digit'
  92. "
  93. >
  94. <template slot="suffix">
  95. {{
  96. changeItem.params[changeItem.funcname1 + "压力设定"].unit ||
  97. ""
  98. }}
  99. </template>
  100. </u-input>
  101. </view>
  102. </view>
  103. </view>
  104. </My_input>
  105. </view>
  106. </template>
  107. <script>
  108. import pilotLamp from "./pilotLamp";
  109. export default {
  110. name: "division",
  111. components: { pilotLamp },
  112. data() {
  113. return {
  114. list: [],
  115. TRList: [],
  116. changeItem: {},
  117. endTime: "",
  118. };
  119. },
  120. methods: {
  121. loadData(newVal, Chinese = false) {
  122. let reg = /^时段\d{1,5}$/,
  123. count = 0,
  124. list = [];
  125. for (const key in newVal.function) {
  126. if (reg.test(key)) count++;
  127. }
  128. let Nzh = require("nzh");
  129. let nzhcn = require("nzh/cn"); //直接使用简体中文
  130. function formattingKey(num, prefix = "T") {
  131. let res = "";
  132. switch (String(num).length) {
  133. case 1:
  134. res = prefix + "00" + num;
  135. break;
  136. case 2:
  137. res = prefix + "0" + num;
  138. break;
  139. case 3:
  140. res = prefix + num;
  141. break;
  142. }
  143. return res;
  144. }
  145. let key1 = 1,
  146. key2 = 49,
  147. TRList = [];
  148. for (let i = 1; i <= count; i++) {
  149. let name = Chinese ? nzhcn.encodeS(i) : i;
  150. let obj = newVal.function[`时段${i}`],
  151. keyList = [];
  152. for (let index = 0; index < 4; index++) {
  153. keyList.push(formattingKey(key1));
  154. key1++;
  155. if (index == 3) {
  156. keyList.push(formattingKey(key2));
  157. key2++;
  158. TRList.push(
  159. this.__proto__.getControlItem([`时间段${i}`], newVal)[0]
  160. );
  161. }
  162. }
  163. let item = {
  164. keyList,
  165. index: i,
  166. inputType: "slot",
  167. paramValue: {
  168. begin:
  169. newVal.paramcmdvalues[keyList[0]] +
  170. ":" +
  171. newVal.paramcmdvalues[keyList[2]],
  172. end:
  173. newVal.paramcmdvalues[keyList[1]] +
  174. ":" +
  175. newVal.paramcmdvalues[keyList[3]],
  176. value: newVal.paramcmdvalues[keyList[4]],
  177. },
  178. showValue: {
  179. begin:
  180. newVal.paramvalues[keyList[0]] +
  181. ":" +
  182. newVal.paramvalues[keyList[2]],
  183. end:
  184. newVal.paramvalues[keyList[1]] +
  185. ":" +
  186. newVal.paramvalues[keyList[3]],
  187. value: newVal.paramvalues[keyList[4]],
  188. },
  189. params: {},
  190. };
  191. keyList.forEach((key) => {
  192. item.params[key] = newVal.params[key];
  193. });
  194. obj.funcname1 = "时段" + nzhcn.encodeS(i);
  195. item.isfeedback =
  196. newVal.isfeedback &&
  197. (obj.paramValue.begin || obj.paramValue.end || obj.paramValue.value)
  198. ? true
  199. : false;
  200. list.push(Object.assign(obj, item));
  201. }
  202. this.TRList = TRList;
  203. this.list = list;
  204. },
  205. onClick(item) {
  206. this.changeItem = JSON.parse(JSON.stringify(item));
  207. this.endTime =
  208. this.changeItem.showValue.end == "0:0"
  209. ? ""
  210. : this.changeItem.showValue.end;
  211. let toBeUpdated = [];
  212. if (item.paramValue.begin)
  213. toBeUpdated.push(`开始时间:${item.paramValue.begin}`);
  214. if (item.paramValue.end)
  215. toBeUpdated.push(`结束时间:${item.paramValue.begin}`);
  216. if (item.paramValue.value)
  217. toBeUpdated.push(`压力设定:${item.paramValue.value}`);
  218. if (toBeUpdated.length) {
  219. item.toBeUpdated = "待更新记录:" + toBeUpdated.join(",");
  220. }
  221. this.$refs.MyInput.openInput(item, item.inputType != "switch");
  222. },
  223. changTR(index) {
  224. this.$refs.MyInput.openInput(this.TRList[index]);
  225. },
  226. timeChange(e) {
  227. const name = e.currentTarget.dataset.name;
  228. this.changeItem.showValue[name] = e.detail.value;
  229. },
  230. customMethod() {
  231. const { showValue, w_functionid, params, index } = this.changeItem,
  232. MyInput = this.$refs.MyInput;
  233. if (!showValue.begin) return MyInput.submitBreak("还未填写开始时间");
  234. if (!showValue.end) return MyInput.submitBreak("还未填写结束时间");
  235. if ((showValue.value + "").length == 0)
  236. return MyInput.submitBreak("还未设定压力");
  237. let item = this.list[index - 1];
  238. showValue.value = (showValue.value - 0).toFixed(
  239. params[item.keyList[4]].num_scale
  240. );
  241. let obj = {
  242. [item.keyList[0]]: showValue.begin.split(":")[0],
  243. [item.keyList[1]]: showValue.end.split(":")[0],
  244. [item.keyList[2]]: showValue.begin.split(":")[1],
  245. [item.keyList[3]]: showValue.end.split(":")[1],
  246. [item.keyList[4]]: showValue.value,
  247. };
  248. console.log("发送请求", obj);
  249. MyInput.submit(w_functionid, obj);
  250. },
  251. },
  252. };
  253. </script>
  254. <style lang="scss" scoped>
  255. /* 边框 */
  256. .day-parting-row {
  257. display: flex;
  258. align-items: center;
  259. flex: 1;
  260. width: 0;
  261. border: 1px solid #dadbde;
  262. border-radius: 4px;
  263. padding: 6px 9px;
  264. height: 35px;
  265. font-size: 14px;
  266. box-sizing: border-box;
  267. }
  268. .item-box {
  269. position: relative;
  270. .TR-state {
  271. position: absolute;
  272. top: 4px;
  273. right: 6px;
  274. font-size: 12px;
  275. background: #004a92;
  276. color: #fff;
  277. padding: 4px 6px;
  278. border-radius: 4px;
  279. z-index: 2;
  280. }
  281. .item {
  282. position: relative;
  283. padding: 4px 6px 6px;
  284. box-sizing: border-box;
  285. background: #fff;
  286. border-radius: 4px;
  287. margin-bottom: 5px;
  288. .title {
  289. display: flex;
  290. margin-bottom: 6px;
  291. font-weight: bold;
  292. .pilotLamp {
  293. margin-left: 10px;
  294. }
  295. }
  296. .row {
  297. display: flex;
  298. .box {
  299. width: 33.33%;
  300. .content {
  301. display: flex;
  302. margin-top: 6px;
  303. align-items: flex-end;
  304. .value {
  305. width: 0;
  306. flex: 1;
  307. color: #333;
  308. font-size: 16px;
  309. flex-shrink: 0;
  310. font-weight: bold;
  311. }
  312. .unit {
  313. font-size: 10px;
  314. color: #666;
  315. flex-shrink: 0;
  316. max-width: 50px;
  317. }
  318. }
  319. }
  320. }
  321. .dot {
  322. position: absolute;
  323. right: 2px;
  324. top: 2px;
  325. width: 10px;
  326. height: 10px;
  327. background: #d9001b;
  328. border-radius: 50%;
  329. }
  330. }
  331. }
  332. .change-item {
  333. .row {
  334. display: flex;
  335. align-items: center;
  336. line-height: 35px;
  337. width: 100%;
  338. margin-top: 4px;
  339. .label {
  340. width: 80px;
  341. flex-shrink: 0;
  342. }
  343. }
  344. }
  345. </style>