autoSetting.vue 19 KB

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