autoSetting.vue 16 KB

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