division.vue 9.3 KB

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