timingSetting.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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. <view
  9. class="setting-card"
  10. >
  11. <view class="setting-header">
  12. <text class="setting-title">定时设置</text>
  13. <u-switch
  14. size="40"
  15. space="4"
  16. activeColor="#0BBC58"
  17. inactiveColor="#C3CAD8"
  18. v-model="enabled"
  19. @change="onSwitchChange($event)"
  20. />
  21. </view>
  22. <view class="setting-item">
  23. <text class="setting-label">定时类型</text>
  24. <view class="number-input">
  25. <text style="color:#999999">{{ timeType }}</text>
  26. <u-icon name="arrow-right" color="#656565"></u-icon>
  27. </view>
  28. </view>
  29. <view class="setting-item">
  30. <text class="setting-label">选择时间</text>
  31. <view class="number-input">
  32. <text style="color:#999999">{{ selectTime }}</text>
  33. <u-icon name="arrow-right" color="#656565"></u-icon>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 灌溉模式 -->
  38. <view class="setting-top-container">
  39. <!-- 轮灌次数 -->
  40. <view class="setting-item">
  41. <text class="setting-label">轮灌次数</text>
  42. <view class="number-input">
  43. <u-number-box v-model="IrrCnt" placeholder="请输入轮灌次数" min="1" max="9999999" @minus="irrChange(IrrCnt)" @plus="irrChange(IrrCnt)"></u-number-box>
  44. </view>
  45. </view>
  46. <!-- 轮灌间隔 -->
  47. <view class="setting-item">
  48. <text class="setting-label">轮灌间隔</text>
  49. <view class="time-input">
  50. <input type="number" v-model="IdleTim" class="time-input-field" min="0" max="1440" placeholder="请输入轮灌间隔(分钟)" @change="idleChange(IdleTim)" />
  51. <text class="time-unit">分钟</text>
  52. </view>
  53. </view>
  54. </view>
  55. <u-picker v-model="show" mode="selector" :range="selector" range-key="label" @confirm="confirmHandler"></u-picker>
  56. <!-- 定时轮灌组 -->
  57. <view class="round-groups-section">
  58. <text class="section-title">选择轮灌组</text>
  59. <view class="round-groups-container">
  60. <!-- 左侧轮灌组列表 -->
  61. <view class="round-groups-list">
  62. <view
  63. v-for="(item,index) in group_list" :key="item.group"
  64. class="round-group-item"
  65. @click="selectGroup(index)"
  66. :class="{ active: selectedGroup === index }"
  67. >
  68. <text :class="{ 'green-text': selectedGroup === index }">{{ index + 1 }}组</text>
  69. </view>
  70. </view>
  71. <!-- 右侧轮灌组详情 -->
  72. <view class="round-group-detail">
  73. <view class="group-detail-item" v-for="(item,index) in group_list" :key="item.group" :id="'group-'+index">
  74. <view class="group-header">
  75. <text class="group-title">{{index + 1}}组</text>
  76. <view class="group-check" :class="{ active: item.selected }" @click="changeGroupStatus(item)">
  77. <u-icon class="check-icon" name="checkmark" size="24rpx" />
  78. </view>
  79. </view>
  80. <view class="group-settings">
  81. <view class="setting-row">
  82. <text class="setting-row-label">施肥配方</text>
  83. <view @click="selectFormula(index)" class="select-group">{{ getTitle(item) }}</view>
  84. </view>
  85. <view class="setting-row">
  86. <text class="setting-row-label">灌溉时长</text>
  87. <input
  88. type="number"
  89. v-model="item.PartTim"
  90. class="setting-row-input"
  91. min="0"
  92. max="1440"
  93. placeholder="请输入灌溉时长(分钟)"
  94. @change="(item) => PartTimChange(item)"
  95. />
  96. <text class="setting-row-unit">分钟</text>
  97. </view>
  98. <view class="setting-row">
  99. <text class="setting-row-label">施肥时长</text>
  100. <input
  101. type="number"
  102. v-model="item.FertTim"
  103. class="setting-row-input"
  104. min="0"
  105. max="1440"
  106. placeholder="请输入施肥时长(分钟)"
  107. @change="(item) => FertTimChange(item)"
  108. />
  109. <text class="setting-row-unit">分钟</text>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. </view>
  115. </view>
  116. </view>
  117. </view>
  118. </template>
  119. <script>
  120. export default {
  121. data() {
  122. return {
  123. show: false,
  124. devBid:'',
  125. title: '选择配方',
  126. selector: [],
  127. selectedGroup: 0,
  128. FertType: -1,
  129. FertPidType: -1,
  130. IrrCnt: 0,
  131. IdleTim: 0,
  132. FrontClearWater: 0,
  133. UnderClearWater: 0,
  134. group_list:[],
  135. enabled: false,
  136. currentIndex: -1,
  137. timeType: '请选择',
  138. selectTime: '请选择',
  139. };
  140. },
  141. async onLoad(options) {
  142. const { devBid } = options;
  143. this.devBid = devBid;
  144. await this.getInfoList();
  145. await this.getConfigInfo();
  146. },
  147. methods: {
  148. onSwitchChange(){},
  149. async refresh(){
  150. const params = {
  151. devBid: this.devBid,
  152. };
  153. await this.$myRequest({
  154. url:'/api/v2/iot/device/sf/refresh/',
  155. method:'POST',
  156. data: params,
  157. header: {
  158. 'Content-Type': 'application/json',
  159. 'accept': 'application/json, text/plain, */*'
  160. }
  161. })
  162. },
  163. getTitle(item){
  164. let value = '';
  165. if(item.labelText){
  166. return item.labelText;
  167. }
  168. for(let key in item){
  169. if(key.includes('Formula')){
  170. value = item[key];
  171. break;
  172. }
  173. }
  174. for(let i = 0;i< this.selector.length;i++){
  175. const item = this.selector[i];
  176. if(item.Formula == value){
  177. return item.label;
  178. }
  179. }
  180. return '选择配方';
  181. },
  182. confirmHandler(e){
  183. const currentItem = this.selector[e];
  184. const Formula = currentItem.Formula;
  185. const item = this.group_list[this.currentIndex];
  186. item.labelText = currentItem.label;
  187. if(item.selected){
  188. let keyLabel = '';
  189. for(let key in item){
  190. if(key.includes('Formula')){
  191. keyLabel = key
  192. break;
  193. }
  194. }
  195. const params = {
  196. [keyLabel]: Formula,
  197. group_value: 1,
  198. }
  199. this.editGroupList(params);
  200. }
  201. },
  202. async getInfoList(){
  203. this.recipeList = [];
  204. const params = {
  205. devBid: this.devBid
  206. }
  207. const res = await this.$myRequest({
  208. url:'/api/v2/iot/device/sf/yunshang/peifang/list/',
  209. method:'POST',
  210. data: params,
  211. header: {
  212. 'Content-Type': 'application/json',
  213. 'accept': 'application/json, text/plain, */*'
  214. }
  215. })
  216. const list = res?.data || [];
  217. list.forEach((item,index)=>{
  218. item.label = '配方' + (index + 1);
  219. })
  220. this.selector = list;
  221. },
  222. selectFertType(type){
  223. this.FertType = type;
  224. this.editGroup({
  225. FertType: type,
  226. });
  227. },
  228. selectFertPidType(type){
  229. this.FertPidType = type;
  230. this.editGroup({
  231. FertPidType: type,
  232. });
  233. },
  234. underChange(val){
  235. this.UnderClearWater = val;
  236. this.editGroup({UnderClearWater: val});
  237. },
  238. PartTimChange(item){
  239. if(item.selected){
  240. this.editGroupList({group_value: item.group_value, PartTim: item.PartTim});
  241. }
  242. },
  243. FertTimChange(item){
  244. if(item.selected){
  245. this.editGroupList({group_value: item.group_value, FertTim: item.FertTim});
  246. }
  247. },
  248. frontChange(val){
  249. this.FrontClearWater = val;
  250. this.editGroup({FrontClearWater: val});
  251. },
  252. idleChange(val){
  253. this.IdleTim = val;
  254. this.editGroup({IdleTim: val});
  255. },
  256. irrChange(val){
  257. this.IrrCnt = val;
  258. this.editGroup({IrrCnt: val});
  259. },
  260. selectFormula(index){
  261. this.show = true;
  262. this.currentIndex = index;
  263. },
  264. async editGroupList(data){
  265. const params = {
  266. devBid: parseInt(this.devBid),
  267. data,
  268. }
  269. const res = await this.$myRequest({
  270. url:'/api/v2/iot/device/sf/yunshang/auto/group/edit/',
  271. method:'POST',
  272. data: params,
  273. header: {
  274. 'Content-Type': 'application/json',
  275. 'accept': 'application/json, text/plain, */*'
  276. }
  277. })
  278. console.log(res,'resres')
  279. if(res?.code === '000000'){
  280. uni.showToast({
  281. title: '保存成功',
  282. icon: 'success',
  283. })
  284. this.refresh();
  285. }
  286. },
  287. async editGroup(data){
  288. const params = {
  289. devBid: parseInt(this.devBid),
  290. data,
  291. }
  292. const res = await this.$myRequest({
  293. url:'/api/v2/iot/device/sf/yunshang/auto/config/edit/',
  294. method:'POST',
  295. data: params,
  296. header: {
  297. 'Content-Type': 'application/json',
  298. 'accept': 'application/json, text/plain, */*'
  299. }
  300. })
  301. if(res?.code === '000000'){
  302. uni.showToast({
  303. title: '保存成功',
  304. icon: 'success',
  305. })
  306. this.refresh();
  307. }
  308. },
  309. async getConfigInfo(){
  310. const res = await this.$myRequest({
  311. url:'/api/v2/iot/device/sf/yunshang/auto/config/info/',
  312. method:'post',
  313. data: {
  314. devBid: String(this.devBid),
  315. },
  316. })
  317. const resData = res || {};
  318. this.FertPidType = resData?.FertPidType;
  319. this.FertType = resData?.FertType;
  320. this.IrrCnt = resData?.IrrCnt;
  321. this.IdleTim = resData?.IdleTim;
  322. this.FrontClearWater = resData?.FrontClearWater;
  323. this.UnderClearWater = resData?.UnderClearWater;
  324. const group_list = resData.group_list || [];
  325. this.group_list = group_list.map((item, index) => {
  326. const selected = item.group_value == 1 ? true : false;
  327. for (let key in item) {
  328. if (key.includes('PartTim')) {
  329. item.PartTim = item[key];
  330. } else if (key.includes('FertTim')) {
  331. item.FertTim = item[key];
  332. } else if (key.includes('Formula')) {
  333. item.Formula = item[key];
  334. }
  335. }
  336. return {
  337. ...item,
  338. selected
  339. };
  340. });
  341. },
  342. changeGroupStatus(item) {
  343. item.selected = !item.selected;
  344. this.editGroupList({group_value: item.group_value});
  345. },
  346. selectGroup(index) {
  347. this.selectedGroup = index;
  348. uni.createSelectorQuery().select('#group-' + index).boundingClientRect((data) => {
  349. if (data) {
  350. uni.pageScrollTo({
  351. scrollTop: data.top,
  352. duration: 300
  353. });
  354. }
  355. }).exec();
  356. },
  357. // 减少轮灌次数
  358. decreaseRoundCount() {
  359. if (this.roundCount > 1) {
  360. this.roundCount--;
  361. }
  362. },
  363. // 增加轮灌次数
  364. increaseRoundCount() {
  365. this.roundCount++;
  366. },
  367. // 确认按钮点击事件
  368. confirm() {
  369. // 这里可以添加确认逻辑
  370. console.log('确认设置');
  371. }
  372. }
  373. };
  374. </script>
  375. <style scoped lang="scss">
  376. .auto-fertilization-container {
  377. width: 100%;
  378. min-height: 100vh;
  379. background: linear-gradient(180deg, #f5f6fa00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  380. font-family: 'Source Han Sans CN';
  381. }
  382. .group-check-container{
  383. display: flex;
  384. width: 120rpx;
  385. }
  386. .select-group{
  387. text-align:right;
  388. }
  389. .setting-card {
  390. background: #ffffff;
  391. border-radius: 12rpx;
  392. padding: 24rpx;
  393. margin-bottom: 20rpx;
  394. // 卡片头部
  395. .setting-header {
  396. display: flex;
  397. justify-content: space-between;
  398. align-items: center;
  399. margin-bottom: 24rpx;
  400. .setting-title {
  401. font-size: 32rpx;
  402. font-weight: 600;
  403. color: #333333;
  404. font-family: 'Source Han Sans CN';
  405. }
  406. .setting-switch {
  407. transform: scale(0.9);
  408. }
  409. }
  410. }
  411. .group-check-radius{
  412. width: 30rpx;
  413. height: 30rpx;
  414. display: flex;
  415. align-items: center;
  416. justify-content: center;
  417. border-radius: 50%;
  418. background: #ffffff;
  419. border: 2rpx solid #E4E7ED;
  420. font-size: 24rpx;
  421. color: #14a478;
  422. margin-right: 10rpx;
  423. }
  424. .active{
  425. border-color: #0BBC58;
  426. }
  427. .text{
  428. color: #666666;
  429. font-family: "Source Han Sans CN VF";
  430. font-size: 28rpx;
  431. }
  432. .text-active{
  433. color: #0BBC58;
  434. }
  435. /* 内容区域 */
  436. .content {
  437. overflow-y: auto;
  438. width: calc(100% - 64rpx);
  439. margin-left: 32rpx;
  440. display:flex;
  441. flex-direction: column;
  442. }
  443. .setting-top-container{
  444. border: 2px solid #FFF;
  445. border-radius: 8px;
  446. padding: 32rpx;
  447. background: #FFF;
  448. }
  449. /* 设置项 */
  450. .setting-item {
  451. display: flex;
  452. align-items: center;
  453. justify-content: space-between;
  454. padding: 24rpx 0;
  455. border-bottom: 1rpx solid #e8e8e8;
  456. .setting-label {
  457. font-size: 28rpx;
  458. color: #042118;
  459. }
  460. /* 单选组 */
  461. .radio-group {
  462. display: flex;
  463. gap: 32rpx;
  464. .radio-item {
  465. display: flex;
  466. align-items: center;
  467. gap: 8rpx;
  468. font-size: 26rpx;
  469. color: #666;
  470. width: 120rpx;
  471. &.active {
  472. color: #14a478;
  473. }
  474. radio {
  475. transform: scale(0.8);
  476. }
  477. }
  478. }
  479. /* 数字输入 */
  480. .number-input {
  481. display: flex;
  482. align-items: center;
  483. gap: 16rpx;
  484. .number-btn {
  485. width: 40rpx;
  486. height: 40rpx;
  487. display: flex;
  488. align-items: center;
  489. justify-content: center;
  490. background: #f5f5f5;
  491. border-radius: 4rpx;
  492. font-size: 28rpx;
  493. color: #666;
  494. }
  495. .number-value {
  496. min-width: 60rpx;
  497. text-align: center;
  498. font-size: 26rpx;
  499. color: #042118;
  500. }
  501. }
  502. /* 时间输入 */
  503. .time-input {
  504. display: flex;
  505. align-items: center;
  506. gap: 8rpx;
  507. .time-input-field {
  508. flex:1;
  509. height: 52rpx;
  510. padding: 0 16rpx;
  511. font-size: 26rpx;
  512. text-align: right;
  513. color: #042118;
  514. }
  515. .time-unit {
  516. font-size: 24rpx;
  517. color: #666;
  518. }
  519. }
  520. }
  521. /* 轮灌组区域 */
  522. .round-groups-section {
  523. margin-top: 40rpx;
  524. flex:1;
  525. .section-title {
  526. font-size: 28rpx;
  527. font-weight: 500;
  528. color: #042118;
  529. }
  530. .round-groups-container {
  531. margin-top: 24rpx;
  532. display: flex;
  533. border-radius: 12rpx;
  534. flex:1;
  535. /* 左侧轮灌组列表 */
  536. .round-groups-list {
  537. width: 120rpx;
  538. background: #ffffff;
  539. border-radius: 8rpx;
  540. .round-group-item {
  541. height: 80rpx;
  542. display: flex;
  543. align-items: center;
  544. justify-content: center;
  545. font-size: 26rpx;
  546. color: #666;
  547. border-left-top-radius: 16rpx;
  548. border-left-bottom-radius: 16rpx;
  549. &.active {
  550. background: #0bbc581a;
  551. color:#0BBC58;
  552. font-weight: 700;
  553. color: #0bbc58;
  554. font-family: "Source Han Sans CN VF";
  555. }
  556. &:last-child {
  557. border-bottom: none;
  558. }
  559. .green-text {
  560. color: #14a478;
  561. font-weight: 500;
  562. }
  563. }
  564. }
  565. /* 右侧轮灌组详情 */
  566. .round-group-detail {
  567. margin-left: 24rpx;
  568. border-radius: 16rpx;
  569. height: 600rpx;
  570. overflow-y: auto;
  571. .group-detail-item {
  572. margin-bottom: 32rpx;
  573. padding: 24rpx;
  574. background: #ffffff;
  575. border-radius: 8rpx;
  576. &:last-child {
  577. margin-bottom: 0;
  578. }
  579. .group-header {
  580. display: flex;
  581. align-items: center;
  582. justify-content: space-between;
  583. margin-bottom: 24rpx;
  584. .group-title {
  585. font-size: 28rpx;
  586. font-weight: 500;
  587. color: #042118;
  588. }
  589. .group-check {
  590. width: 38rpx;
  591. height: 38rpx;
  592. display: flex;
  593. align-items: center;
  594. justify-content: center;
  595. background: #C9CDD4;
  596. color: #ffffff;
  597. border-radius: 50%;
  598. font-size: 24rpx;
  599. .check-icon{
  600. font-size: 24rpx;
  601. }
  602. &.active {
  603. background: #0BBC58;
  604. color: #fff;
  605. }
  606. }
  607. }
  608. .group-settings {
  609. .setting-row {
  610. display: flex;
  611. align-items: center;
  612. justify-content: space-between;
  613. margin-bottom: 24rpx;
  614. .setting-row-label {
  615. width: 120rpx;
  616. font-size: 26rpx;
  617. color: #666;
  618. }
  619. .setting-row-input {
  620. flex: 1;
  621. height: 56rpx;
  622. padding: 0 16rpx;
  623. font-size: 26rpx;
  624. color: #042118;
  625. margin-right: 12rpx;
  626. text-align: right;
  627. }
  628. .setting-row-unit {
  629. font-size: 24rpx;
  630. color: #666;
  631. }
  632. }
  633. }
  634. }
  635. }
  636. }
  637. }
  638. /* 底部确定按钮 */
  639. .confirm-btn-container {
  640. padding: 32rpx;
  641. .confirm-btn {
  642. height: 88rpx;
  643. display: flex;
  644. align-items: center;
  645. justify-content: center;
  646. background: #14a478;
  647. border-radius: 12rpx;
  648. box-shadow: 0 4rpx 12rpx rgba(20, 164, 120, 0.3);
  649. .confirm-btn-text {
  650. font-size: 32rpx;
  651. font-weight: 500;
  652. color: #fff;
  653. }
  654. }
  655. }
  656. </style>