autoSetting.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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: 160rpx;">
  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: 160rpx;">
  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 || [];
  247. console.log(list,'listliustlist')
  248. list.forEach((item,index)=>{
  249. item.label = '配方' + (index + 1);
  250. })
  251. this.selector = list;
  252. },
  253. selectFertType(type){
  254. this.FertType = type;
  255. this.editGroup({
  256. FertType: type,
  257. });
  258. },
  259. selectFertPidType(type){
  260. this.FertPidType = type;
  261. this.editGroup({
  262. FertPidType: type,
  263. });
  264. },
  265. underChange(val){
  266. this.UnderClearWater = val;
  267. this.editGroup({UnderClearWater: val});
  268. },
  269. PartTimChange(item){
  270. if(item.selected){
  271. this.editGroupList({group_value: item.group_value, PartTim: item.PartTim});
  272. }
  273. },
  274. FertTimChange(item){
  275. if(item.selected){
  276. this.editGroupList({group_value: item.group_value, FertTim: item.FertTim});
  277. }
  278. },
  279. frontChange(val){
  280. this.FrontClearWater = val;
  281. this.editGroup({FrontClearWater: val});
  282. },
  283. idleChange(val){
  284. this.IdleTim = val;
  285. this.editGroup({IdleTim: val});
  286. },
  287. irrChange(val){
  288. this.IrrCnt = val;
  289. this.editGroup({IrrCnt: val});
  290. },
  291. selectFormula(index){
  292. this.show = true;
  293. this.currentIndex = index;
  294. },
  295. async editGroupList(data){
  296. const params = {
  297. devBid: parseInt(this.devBid),
  298. data,
  299. }
  300. const res = await this.$myRequest({
  301. url:'/api/v2/iot/device/sf/yunshang/auto/group/edit/',
  302. method:'POST',
  303. data: params,
  304. header: {
  305. 'Content-Type': 'application/json',
  306. 'accept': 'application/json, text/plain, */*'
  307. }
  308. })
  309. console.log(res,'resres')
  310. if(res?.code === '000000'){
  311. uni.showToast({
  312. title: '保存成功',
  313. icon: 'success',
  314. })
  315. this.refresh();
  316. }
  317. },
  318. async editGroup(data){
  319. const params = {
  320. devBid: parseInt(this.devBid),
  321. data,
  322. }
  323. const res = await this.$myRequest({
  324. url:'/api/v2/iot/device/sf/yunshang/auto/config/edit/',
  325. method:'POST',
  326. data: params,
  327. header: {
  328. 'Content-Type': 'application/json',
  329. 'accept': 'application/json, text/plain, */*'
  330. }
  331. })
  332. if(res?.code === '000000'){
  333. uni.showToast({
  334. title: '保存成功',
  335. icon: 'success',
  336. })
  337. this.refresh();
  338. }
  339. },
  340. async getConfigInfo(){
  341. const res = await this.$myRequest({
  342. url:'/api/v2/iot/device/sf/yunshang/auto/config/info/',
  343. method:'post',
  344. data: {
  345. devBid: String(this.devBid),
  346. },
  347. })
  348. const resData = res || {};
  349. this.FertPidType = resData?.FertPidType;
  350. this.FertType = resData?.FertType;
  351. this.IrrCnt = resData?.IrrCnt;
  352. this.IdleTim = resData?.IdleTim;
  353. this.FrontClearWater = resData?.FrontClearWater;
  354. this.UnderClearWater = resData?.UnderClearWater;
  355. const group_list = resData.group_list || [];
  356. this.group_list = group_list.map((item, index) => {
  357. const selected = item.group_value == 1 ? true : false;
  358. for (let key in item) {
  359. if (key.includes('PartTim')) {
  360. item.PartTim = item[key];
  361. } else if (key.includes('FertTim')) {
  362. item.FertTim = item[key];
  363. } else if (key.includes('Formula')) {
  364. item.Formula = item[key];
  365. }
  366. }
  367. return {
  368. ...item,
  369. selected
  370. };
  371. });
  372. },
  373. changeGroupStatus(item) {
  374. item.selected = !item.selected;
  375. this.editGroupList({group_value: item.group_value});
  376. },
  377. selectGroup(index) {
  378. this.selectedGroup = index;
  379. uni.createSelectorQuery().select('#group-' + index).boundingClientRect((data) => {
  380. if (data) {
  381. uni.pageScrollTo({
  382. scrollTop: data.top,
  383. duration: 300
  384. });
  385. }
  386. }).exec();
  387. },
  388. // 减少轮灌次数
  389. decreaseRoundCount() {
  390. if (this.roundCount > 1) {
  391. this.roundCount--;
  392. }
  393. },
  394. // 增加轮灌次数
  395. increaseRoundCount() {
  396. this.roundCount++;
  397. },
  398. // 确认按钮点击事件
  399. confirm() {
  400. // 这里可以添加确认逻辑
  401. console.log('确认设置');
  402. }
  403. }
  404. };
  405. </script>
  406. <style scoped lang="scss">
  407. .auto-fertilization-container {
  408. width: 100%;
  409. min-height: 100vh;
  410. background: linear-gradient(180deg, #f5f6fa00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  411. font-family: 'Source Han Sans CN';
  412. }
  413. .group-check-container{
  414. display: flex;
  415. width: 120rpx;
  416. }
  417. .select-group{
  418. text-align:right;
  419. }
  420. .group-check-radius{
  421. width: 30rpx;
  422. height: 30rpx;
  423. display: flex;
  424. align-items: center;
  425. justify-content: center;
  426. border-radius: 50%;
  427. background: #ffffff;
  428. border: 2rpx solid #E4E7ED;
  429. font-size: 24rpx;
  430. color: #14a478;
  431. margin-right: 10rpx;
  432. }
  433. .active{
  434. border-color: #0BBC58;
  435. }
  436. .text{
  437. color: #666666;
  438. font-family: "Source Han Sans CN VF";
  439. font-size: 28rpx;
  440. }
  441. .text-active{
  442. color: #0BBC58;
  443. }
  444. /* 内容区域 */
  445. .content {
  446. overflow-y: auto;
  447. width: calc(100% - 64rpx);
  448. margin-left: 32rpx;
  449. display:flex;
  450. flex-direction: column;
  451. }
  452. .setting-top-container{
  453. border: 2px solid #FFF;
  454. border-radius: 8px;
  455. padding: 32rpx;
  456. background: #FFF;
  457. }
  458. /* 设置项 */
  459. .setting-item {
  460. display: flex;
  461. align-items: center;
  462. justify-content: space-between;
  463. padding: 24rpx 0;
  464. border-bottom: 1rpx solid #e8e8e8;
  465. .setting-label {
  466. font-size: 28rpx;
  467. color: #042118;
  468. }
  469. /* 单选组 */
  470. .radio-group {
  471. display: flex;
  472. gap: 32rpx;
  473. .radio-item {
  474. display: flex;
  475. align-items: center;
  476. gap: 8rpx;
  477. font-size: 26rpx;
  478. color: #666;
  479. width: 120rpx;
  480. &.active {
  481. color: #14a478;
  482. }
  483. radio {
  484. transform: scale(0.8);
  485. }
  486. }
  487. }
  488. /* 数字输入 */
  489. .number-input {
  490. display: flex;
  491. align-items: center;
  492. gap: 16rpx;
  493. .number-btn {
  494. width: 40rpx;
  495. height: 40rpx;
  496. display: flex;
  497. align-items: center;
  498. justify-content: center;
  499. background: #f5f5f5;
  500. border-radius: 4rpx;
  501. font-size: 28rpx;
  502. color: #666;
  503. }
  504. .number-value {
  505. min-width: 60rpx;
  506. text-align: center;
  507. font-size: 26rpx;
  508. color: #042118;
  509. }
  510. }
  511. /* 时间输入 */
  512. .time-input {
  513. display: flex;
  514. align-items: center;
  515. gap: 8rpx;
  516. .time-input-field {
  517. flex:1;
  518. height: 52rpx;
  519. padding: 0 16rpx;
  520. font-size: 26rpx;
  521. text-align: right;
  522. color: #042118;
  523. }
  524. .time-unit {
  525. font-size: 24rpx;
  526. color: #666;
  527. }
  528. }
  529. }
  530. /* 轮灌组区域 */
  531. .round-groups-section {
  532. margin-top: 40rpx;
  533. flex:1;
  534. .section-title {
  535. font-size: 28rpx;
  536. font-weight: 500;
  537. color: #042118;
  538. }
  539. .round-groups-container {
  540. margin-top: 24rpx;
  541. display: flex;
  542. border-radius: 12rpx;
  543. flex:1;
  544. /* 左侧轮灌组列表 */
  545. .round-groups-list {
  546. width: 120rpx;
  547. background: #ffffff;
  548. border-radius: 8rpx;
  549. .round-group-item {
  550. height: 80rpx;
  551. display: flex;
  552. align-items: center;
  553. justify-content: center;
  554. font-size: 26rpx;
  555. color: #666;
  556. border-left-top-radius: 16rpx;
  557. border-left-bottom-radius: 16rpx;
  558. &.active {
  559. background: #0bbc581a;
  560. color:#0BBC58;
  561. font-weight: 700;
  562. color: #0bbc58;
  563. font-family: "Source Han Sans CN VF";
  564. }
  565. &:last-child {
  566. border-bottom: none;
  567. }
  568. .green-text {
  569. color: #14a478;
  570. font-weight: 500;
  571. }
  572. }
  573. }
  574. /* 右侧轮灌组详情 */
  575. .round-group-detail {
  576. margin-left: 24rpx;
  577. border-radius: 16rpx;
  578. height: 600rpx;
  579. overflow-y: auto;
  580. .group-detail-item {
  581. margin-bottom: 32rpx;
  582. padding: 24rpx;
  583. background: #ffffff;
  584. border-radius: 8rpx;
  585. &:last-child {
  586. margin-bottom: 0;
  587. }
  588. .group-header {
  589. display: flex;
  590. align-items: center;
  591. justify-content: space-between;
  592. margin-bottom: 24rpx;
  593. .group-title {
  594. font-size: 28rpx;
  595. font-weight: 500;
  596. color: #042118;
  597. }
  598. .group-check {
  599. width: 38rpx;
  600. height: 38rpx;
  601. display: flex;
  602. align-items: center;
  603. justify-content: center;
  604. background: #C9CDD4;
  605. color: #ffffff;
  606. border-radius: 50%;
  607. font-size: 24rpx;
  608. .check-icon{
  609. font-size: 24rpx;
  610. }
  611. &.active {
  612. background: #0BBC58;
  613. color: #fff;
  614. }
  615. }
  616. }
  617. .group-settings {
  618. .setting-row {
  619. display: flex;
  620. align-items: center;
  621. justify-content: space-between;
  622. margin-bottom: 24rpx;
  623. .setting-row-label {
  624. width: 120rpx;
  625. font-size: 26rpx;
  626. color: #666;
  627. }
  628. .setting-row-input {
  629. flex: 1;
  630. height: 56rpx;
  631. padding: 0 16rpx;
  632. font-size: 26rpx;
  633. color: #042118;
  634. margin-right: 12rpx;
  635. text-align: right;
  636. }
  637. .setting-row-unit {
  638. font-size: 24rpx;
  639. color: #666;
  640. }
  641. }
  642. }
  643. }
  644. }
  645. }
  646. }
  647. /* 底部确定按钮 */
  648. .confirm-btn-container {
  649. padding: 32rpx;
  650. .confirm-btn {
  651. height: 88rpx;
  652. display: flex;
  653. align-items: center;
  654. justify-content: center;
  655. background: #14a478;
  656. border-radius: 12rpx;
  657. box-shadow: 0 4rpx 12rpx rgba(20, 164, 120, 0.3);
  658. .confirm-btn-text {
  659. font-size: 32rpx;
  660. font-weight: 500;
  661. color: #fff;
  662. }
  663. }
  664. }
  665. </style>