autoSetting.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <template>
  2. <view class="auto-fertilization-container">
  3. <custom-card>
  4. <block slot="backText">自动施肥</block>
  5. </custom-card>
  6. <!-- 内容区域 -->
  7. <view class="content">
  8. <!-- 灌溉模式 -->
  9. <view class="setting-top-container">
  10. <!-- 轮灌次数 -->
  11. <view class="setting-item">
  12. <text class="setting-label">轮灌次数</text>
  13. <view class="number-input">
  14. <u-number-box v-model="IrrCnt" placeholder="请输入轮灌次数" min="1" max="9999999" @minus="irrChange(IrrCnt)" @plus="irrChange(IrrCnt)"></u-number-box>
  15. </view>
  16. </view>
  17. <!-- 轮灌间隔 -->
  18. <view class="setting-item">
  19. <text class="setting-label">轮灌间隔</text>
  20. <view class="time-input">
  21. <input type="number" v-model="IdleTim" class="time-input-field" min="0" max="1440" placeholder="请输入轮灌间隔(分钟)" @change="idleChange(IdleTim)" />
  22. <text class="time-unit">分钟</text>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 定时轮灌组 -->
  27. <view class="round-groups-section">
  28. <text class="section-title">定时轮灌组</text>
  29. <view class="round-groups-container">
  30. <!-- 左侧轮灌组列表 -->
  31. <view class="round-groups-list">
  32. <view
  33. v-for="(item,index) in group_list" :key="item.group"
  34. class="round-group-item"
  35. @click="selectGroup(index)"
  36. :class="{ active: selectedGroup === index }"
  37. >
  38. <text :class="{ 'green-text': selectedGroup === index }">{{ index + 1 }}组</text>
  39. </view>
  40. </view>
  41. <!-- 右侧轮灌组详情 -->
  42. <view class="round-group-detail">
  43. <view class="group-detail-item" v-for="(item,index) in group_list" :key="item.group" :id="'group-'+index">
  44. <view class="group-header">
  45. <text class="group-title">{{index + 1}}组</text>
  46. <view class="group-check" :class="item.selected?'active':''" @tap="()=>changeGroupStatus(index)">
  47. <u-icon class="check-icon" name="checkmark" size="24rpx" />
  48. </view>
  49. </view>
  50. <view class="group-settings">
  51. <view class="setting-row">
  52. <text class="setting-row-label">灌溉时长</text>
  53. <input
  54. type="number"
  55. v-model="item.PartTim"
  56. class="setting-row-input"
  57. min="0"
  58. max="1440"
  59. placeholder="请输入灌溉时长(分钟)"
  60. @change="(e) => PartTimChange(e,index)"
  61. />
  62. <text class="setting-row-unit">分钟</text>
  63. </view>
  64. <view class="setting-row">
  65. <text class="setting-row-label">施肥时长</text>
  66. <input
  67. type="number"
  68. v-model="item.FertTim"
  69. class="setting-row-input"
  70. min="0"
  71. max="1440"
  72. placeholder="请输入施肥时长(分钟)"
  73. @change="(e) => FertTimChange(e,index)"
  74. />
  75. <text class="setting-row-unit">分钟</text>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <script>
  86. export default {
  87. data() {
  88. return {
  89. devBid:'',
  90. selectedGroup: 0,
  91. FertType: -1,
  92. FertPidType: -1,
  93. IrrCnt: 0,
  94. IdleTim: 0,
  95. FrontClearWater: 0,
  96. UnderClearWater: 0,
  97. group_list:[],
  98. };
  99. },
  100. async onLoad(options) {
  101. const { devBid } = options;
  102. this.devBid = devBid;
  103. await this.getConfigInfo();
  104. },
  105. methods: {
  106. async refresh(){
  107. const params = {
  108. devBid: this.devBid,
  109. };
  110. await this.$myRequest({
  111. url:'/api/v2/iot/device/fkq/refresh/',
  112. method:'POST',
  113. data: params,
  114. header: {
  115. 'Content-Type': 'application/json',
  116. 'accept': 'application/json, text/plain, */*'
  117. }
  118. })
  119. },
  120. PartTimChange(e,index){
  121. const value = e.detail.value;
  122. const item = this.group_list[index];
  123. const deleteKey = Object.keys(item).find(key => key.endsWith(':Status'));
  124. const data = {
  125. ...this.excludeObjectKeys(item, ['selected', 'FertTim','PartTim','Formula','group_name',deleteKey]),
  126. }
  127. // 查找data中的key以:PartTim结尾的
  128. const key = Object.keys(data).find(key => key.endsWith(':PartTim'));
  129. this.$set(this.group_list[index],key,value);
  130. if(item.selected){
  131. data[key] = value;
  132. this.editGroupList(data);
  133. }
  134. },
  135. FertTimChange(e,index){
  136. const value = e.detail.value;
  137. const item = this.group_list[index];
  138. const deleteKey = Object.keys(item).find(key => key.endsWith(':Status'));
  139. const data = {
  140. ...this.excludeObjectKeys(item, ['selected','FertTim','PartTim','Formula','group_name',deleteKey]),
  141. }
  142. const key = Object.keys(data).find(key => key.endsWith(':FertTim'));
  143. this.$set(this.group_list[index],key,value);
  144. if(item.selected){
  145. // 查找data中的key以:FertTim结尾的
  146. data[key] = value;
  147. this.editGroupList(data);
  148. }
  149. },
  150. frontChange(val){
  151. this.FrontClearWater = val;
  152. this.editGroup({FrontClearWater: val});
  153. },
  154. idleChange(val){
  155. this.IdleTim = val;
  156. this.editGroup({IdleTim: val});
  157. },
  158. irrChange(val){
  159. this.IrrCnt = val;
  160. this.editGroup({IrrCnt: val});
  161. },
  162. async editGroupList(data){
  163. const params = {
  164. devBid: parseInt(this.devBid),
  165. data,
  166. }
  167. const res = await this.$myRequest({
  168. url:'/api/v2/iot/device/fkq/yunshang/auto/group/edit/',
  169. method:'POST',
  170. data: params,
  171. header: {
  172. 'Content-Type': 'application/json',
  173. 'accept': 'application/json, text/plain, */*'
  174. }
  175. })
  176. if(res?.code === '000000'){
  177. uni.showToast({
  178. title: '保存成功',
  179. icon: 'success',
  180. })
  181. this.refresh();
  182. }
  183. },
  184. // 实现排除对象中的某些属性的方法
  185. excludeObjectKeys(obj, keys) {
  186. return Object.keys(obj).reduce((acc, key) => {
  187. if (!keys.includes(key)) {
  188. acc[key] = obj[key];
  189. }
  190. return acc;
  191. }, {});
  192. },
  193. async editGroup(data){
  194. const params = {
  195. devBid: parseInt(this.devBid),
  196. data,
  197. }
  198. const res = await this.$myRequest({
  199. url:'/api/v2/iot/device/fkq/yunshang/auto/config/edit/',
  200. method:'POST',
  201. data: params,
  202. header: {
  203. 'Content-Type': 'application/json',
  204. 'accept': 'application/json, text/plain, */*'
  205. }
  206. })
  207. if(res?.code === '000000'){
  208. uni.showToast({
  209. title: '保存成功',
  210. icon: 'success',
  211. })
  212. this.refresh();
  213. }
  214. },
  215. async getConfigInfo(){
  216. const res = await this.$myRequest({
  217. url:'/api/v2/iot/device/fkq/yunshang/auto/config/info/',
  218. method:'post',
  219. data: {
  220. devBid: String(this.devBid),
  221. },
  222. })
  223. const resData = res || {};
  224. this.FertPidType = resData?.FertPidType;
  225. this.FertType = resData?.FertType;
  226. this.IrrCnt = resData?.IrrCnt;
  227. this.IdleTim = resData?.IdleTim;
  228. this.FrontClearWater = resData?.FrontClearWater;
  229. this.UnderClearWater = resData?.UnderClearWater;
  230. const group_list = resData.group_list || [];
  231. this.group_list = group_list.map((item, index) => {
  232. const selected = item.group_value == 1 ? true : false;
  233. for (let key in item) {
  234. if (key.includes('PartTim')) {
  235. item.PartTim = item[key];
  236. } else if (key.includes('FertTim')) {
  237. item.FertTim = item[key];
  238. } else if (key.includes('Formula')) {
  239. item.Formula = item[key];
  240. }
  241. }
  242. return {
  243. ...item,
  244. selected
  245. };
  246. });
  247. },
  248. changeGroupStatus(index) {
  249. const item = this.group_list[index];
  250. this.$set(this.group_list[index],'selected',!item.selected);
  251. this.$set(this.group_list[index],'group_value',this.group_list[index].selected? 1 :0);
  252. const deleteKey = Object.keys(item).find(key => key.endsWith(':Status'));
  253. const data = {
  254. ...this.excludeObjectKeys(item, ['selected', 'group_value','FertTim','PartTim','Formula','group_name',deleteKey]),
  255. group_value: this.group_list[index].selected? 1 :0,
  256. }
  257. this.editGroupList(data);
  258. },
  259. selectGroup(index) {
  260. this.selectedGroup = index;
  261. uni.createSelectorQuery().select('#group-' + index).boundingClientRect((data) => {
  262. if (data) {
  263. uni.pageScrollTo({
  264. scrollTop: data.top,
  265. duration: 300
  266. });
  267. }
  268. }).exec();
  269. },
  270. }
  271. };
  272. </script>
  273. <style scoped lang="scss">
  274. .auto-fertilization-container {
  275. width: 100%;
  276. min-height: 100vh;
  277. background: linear-gradient(180deg, #f5f6fa00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  278. font-family: 'Source Han Sans CN';
  279. }
  280. .group-check-container{
  281. display: flex;
  282. width: 120rpx;
  283. }
  284. .select-group{
  285. text-align:right;
  286. }
  287. .group-check-radius{
  288. width: 30rpx;
  289. height: 30rpx;
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. border-radius: 50%;
  294. background: #ffffff;
  295. border: 2rpx solid #E4E7ED;
  296. font-size: 24rpx;
  297. color: #14a478;
  298. margin-right: 10rpx;
  299. }
  300. .active{
  301. border-color: #0BBC58;
  302. }
  303. .text{
  304. color: #666666;
  305. font-family: "Source Han Sans CN VF";
  306. font-size: 28rpx;
  307. }
  308. .text-active{
  309. color: #0BBC58;
  310. }
  311. /* 内容区域 */
  312. .content {
  313. overflow-y: auto;
  314. width: calc(100% - 64rpx);
  315. margin-left: 32rpx;
  316. display:flex;
  317. flex-direction: column;
  318. }
  319. .setting-top-container{
  320. border: 2px solid #FFF;
  321. border-radius: 8px;
  322. padding: 32rpx;
  323. background: #FFF;
  324. }
  325. /* 设置项 */
  326. .setting-item {
  327. display: flex;
  328. align-items: center;
  329. justify-content: space-between;
  330. padding: 24rpx 0;
  331. border-bottom: 1rpx solid #e8e8e8;
  332. .setting-label {
  333. font-size: 28rpx;
  334. color: #042118;
  335. }
  336. /* 单选组 */
  337. .radio-group {
  338. display: flex;
  339. gap: 32rpx;
  340. .radio-item {
  341. display: flex;
  342. align-items: center;
  343. gap: 8rpx;
  344. font-size: 26rpx;
  345. color: #666;
  346. width: 120rpx;
  347. &.active {
  348. color: #14a478;
  349. }
  350. radio {
  351. transform: scale(0.8);
  352. }
  353. }
  354. }
  355. /* 数字输入 */
  356. .number-input {
  357. display: flex;
  358. align-items: center;
  359. gap: 16rpx;
  360. .number-btn {
  361. width: 40rpx;
  362. height: 40rpx;
  363. display: flex;
  364. align-items: center;
  365. justify-content: center;
  366. background: #f5f5f5;
  367. border-radius: 4rpx;
  368. font-size: 28rpx;
  369. color: #666;
  370. }
  371. .number-value {
  372. min-width: 60rpx;
  373. text-align: center;
  374. font-size: 26rpx;
  375. color: #042118;
  376. }
  377. }
  378. /* 时间输入 */
  379. .time-input {
  380. display: flex;
  381. align-items: center;
  382. gap: 8rpx;
  383. .time-input-field {
  384. flex:1;
  385. height: 52rpx;
  386. padding: 0 16rpx;
  387. font-size: 26rpx;
  388. text-align: right;
  389. color: #042118;
  390. }
  391. .time-unit {
  392. font-size: 24rpx;
  393. color: #666;
  394. }
  395. }
  396. }
  397. /* 轮灌组区域 */
  398. .round-groups-section {
  399. margin-top: 40rpx;
  400. flex:1;
  401. .section-title {
  402. font-size: 28rpx;
  403. font-weight: 500;
  404. color: #042118;
  405. }
  406. .round-groups-container {
  407. margin-top: 24rpx;
  408. display: flex;
  409. border-radius: 12rpx;
  410. flex:1;
  411. /* 左侧轮灌组列表 */
  412. .round-groups-list {
  413. width: 120rpx;
  414. background: #ffffff;
  415. border-radius: 8rpx;
  416. .round-group-item {
  417. height: 80rpx;
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. font-size: 26rpx;
  422. color: #666;
  423. border-left-top-radius: 16rpx;
  424. border-left-bottom-radius: 16rpx;
  425. &.active {
  426. background: #0bbc581a;
  427. color:#0BBC58;
  428. font-weight: 700;
  429. color: #0bbc58;
  430. font-family: "Source Han Sans CN VF";
  431. }
  432. &:last-child {
  433. border-bottom: none;
  434. }
  435. .green-text {
  436. color: #14a478;
  437. font-weight: 500;
  438. }
  439. }
  440. }
  441. /* 右侧轮灌组详情 */
  442. .round-group-detail {
  443. margin-left: 24rpx;
  444. border-radius: 16rpx;
  445. height: 600rpx;
  446. overflow-y: auto;
  447. .group-detail-item {
  448. margin-bottom: 32rpx;
  449. padding: 24rpx;
  450. background: #ffffff;
  451. border-radius: 8rpx;
  452. &:last-child {
  453. margin-bottom: 0;
  454. }
  455. .group-header {
  456. display: flex;
  457. align-items: center;
  458. justify-content: space-between;
  459. margin-bottom: 24rpx;
  460. .group-title {
  461. font-size: 28rpx;
  462. font-weight: 500;
  463. color: #042118;
  464. }
  465. .group-check {
  466. width: 38rpx;
  467. height: 38rpx;
  468. display: flex;
  469. align-items: center;
  470. justify-content: center;
  471. background: #C9CDD4;
  472. color: #ffffff;
  473. border-radius: 50%;
  474. font-size: 24rpx;
  475. .check-icon{
  476. font-size: 24rpx;
  477. }
  478. &.active {
  479. background: #0BBC58;
  480. color: #fff;
  481. }
  482. }
  483. }
  484. .group-settings {
  485. .setting-row {
  486. display: flex;
  487. align-items: center;
  488. justify-content: space-between;
  489. margin-bottom: 24rpx;
  490. .setting-row-label {
  491. width: 120rpx;
  492. font-size: 26rpx;
  493. color: #666;
  494. }
  495. .setting-row-input {
  496. flex: 1;
  497. height: 56rpx;
  498. padding: 0 16rpx;
  499. font-size: 26rpx;
  500. color: #042118;
  501. margin-right: 12rpx;
  502. text-align: right;
  503. }
  504. .setting-row-unit {
  505. font-size: 24rpx;
  506. color: #666;
  507. }
  508. }
  509. }
  510. }
  511. }
  512. }
  513. }
  514. /* 底部确定按钮 */
  515. .confirm-btn-container {
  516. padding: 32rpx;
  517. .confirm-btn {
  518. height: 88rpx;
  519. display: flex;
  520. align-items: center;
  521. justify-content: center;
  522. background: #14a478;
  523. border-radius: 12rpx;
  524. box-shadow: 0 4rpx 12rpx rgba(20, 164, 120, 0.3);
  525. .confirm-btn-text {
  526. font-size: 32rpx;
  527. font-weight: 500;
  528. color: #fff;
  529. }
  530. }
  531. }
  532. </style>