division.vue 8.8 KB

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