autoSetting.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. console.log(this.group_list[index],'indexindexdex')
  253. const deleteKey = Object.keys(item).find(key => key.endsWith(':Status'));
  254. const data = {
  255. ...this.excludeObjectKeys(item, ['selected', 'group_value','FertTim','PartTim','Formula','group_name',deleteKey]),
  256. group_value: this.group_list[index].selected? 1 :0,
  257. }
  258. this.editGroupList(data);
  259. },
  260. selectGroup(index) {
  261. this.selectedGroup = index;
  262. uni.createSelectorQuery().select('#group-' + index).boundingClientRect((data) => {
  263. if (data) {
  264. uni.pageScrollTo({
  265. scrollTop: data.top,
  266. duration: 300
  267. });
  268. }
  269. }).exec();
  270. },
  271. }
  272. };
  273. </script>
  274. <style scoped lang="scss">
  275. .auto-fertilization-container {
  276. width: 100%;
  277. min-height: 100vh;
  278. background: linear-gradient(180deg, #f5f6fa00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  279. font-family: 'Source Han Sans CN';
  280. }
  281. .group-check-container{
  282. display: flex;
  283. width: 120rpx;
  284. }
  285. .select-group{
  286. text-align:right;
  287. }
  288. .group-check-radius{
  289. width: 30rpx;
  290. height: 30rpx;
  291. display: flex;
  292. align-items: center;
  293. justify-content: center;
  294. border-radius: 50%;
  295. background: #ffffff;
  296. border: 2rpx solid #E4E7ED;
  297. font-size: 24rpx;
  298. color: #14a478;
  299. margin-right: 10rpx;
  300. }
  301. .active{
  302. border-color: #0BBC58;
  303. }
  304. .text{
  305. color: #666666;
  306. font-family: "Source Han Sans CN VF";
  307. font-size: 28rpx;
  308. }
  309. .text-active{
  310. color: #0BBC58;
  311. }
  312. /* 内容区域 */
  313. .content {
  314. overflow-y: auto;
  315. width: calc(100% - 64rpx);
  316. margin-left: 32rpx;
  317. display:flex;
  318. flex-direction: column;
  319. }
  320. .setting-top-container{
  321. border: 2px solid #FFF;
  322. border-radius: 8px;
  323. padding: 32rpx;
  324. background: #FFF;
  325. }
  326. /* 设置项 */
  327. .setting-item {
  328. display: flex;
  329. align-items: center;
  330. justify-content: space-between;
  331. padding: 24rpx 0;
  332. border-bottom: 1rpx solid #e8e8e8;
  333. .setting-label {
  334. font-size: 28rpx;
  335. color: #042118;
  336. }
  337. /* 单选组 */
  338. .radio-group {
  339. display: flex;
  340. gap: 32rpx;
  341. .radio-item {
  342. display: flex;
  343. align-items: center;
  344. gap: 8rpx;
  345. font-size: 26rpx;
  346. color: #666;
  347. width: 120rpx;
  348. &.active {
  349. color: #14a478;
  350. }
  351. radio {
  352. transform: scale(0.8);
  353. }
  354. }
  355. }
  356. /* 数字输入 */
  357. .number-input {
  358. display: flex;
  359. align-items: center;
  360. gap: 16rpx;
  361. .number-btn {
  362. width: 40rpx;
  363. height: 40rpx;
  364. display: flex;
  365. align-items: center;
  366. justify-content: center;
  367. background: #f5f5f5;
  368. border-radius: 4rpx;
  369. font-size: 28rpx;
  370. color: #666;
  371. }
  372. .number-value {
  373. min-width: 60rpx;
  374. text-align: center;
  375. font-size: 26rpx;
  376. color: #042118;
  377. }
  378. }
  379. /* 时间输入 */
  380. .time-input {
  381. display: flex;
  382. align-items: center;
  383. gap: 8rpx;
  384. .time-input-field {
  385. flex:1;
  386. height: 52rpx;
  387. padding: 0 16rpx;
  388. font-size: 26rpx;
  389. text-align: right;
  390. color: #042118;
  391. }
  392. .time-unit {
  393. font-size: 24rpx;
  394. color: #666;
  395. }
  396. }
  397. }
  398. /* 轮灌组区域 */
  399. .round-groups-section {
  400. margin-top: 40rpx;
  401. flex:1;
  402. .section-title {
  403. font-size: 28rpx;
  404. font-weight: 500;
  405. color: #042118;
  406. }
  407. .round-groups-container {
  408. margin-top: 24rpx;
  409. display: flex;
  410. border-radius: 12rpx;
  411. flex:1;
  412. /* 左侧轮灌组列表 */
  413. .round-groups-list {
  414. width: 120rpx;
  415. background: #ffffff;
  416. border-radius: 8rpx;
  417. .round-group-item {
  418. height: 80rpx;
  419. display: flex;
  420. align-items: center;
  421. justify-content: center;
  422. font-size: 26rpx;
  423. color: #666;
  424. border-left-top-radius: 16rpx;
  425. border-left-bottom-radius: 16rpx;
  426. &.active {
  427. background: #0bbc581a;
  428. color:#0BBC58;
  429. font-weight: 700;
  430. color: #0bbc58;
  431. font-family: "Source Han Sans CN VF";
  432. }
  433. &:last-child {
  434. border-bottom: none;
  435. }
  436. .green-text {
  437. color: #14a478;
  438. font-weight: 500;
  439. }
  440. }
  441. }
  442. /* 右侧轮灌组详情 */
  443. .round-group-detail {
  444. margin-left: 24rpx;
  445. border-radius: 16rpx;
  446. height: 600rpx;
  447. overflow-y: auto;
  448. .group-detail-item {
  449. margin-bottom: 32rpx;
  450. padding: 24rpx;
  451. background: #ffffff;
  452. border-radius: 8rpx;
  453. &:last-child {
  454. margin-bottom: 0;
  455. }
  456. .group-header {
  457. display: flex;
  458. align-items: center;
  459. justify-content: space-between;
  460. margin-bottom: 24rpx;
  461. .group-title {
  462. font-size: 28rpx;
  463. font-weight: 500;
  464. color: #042118;
  465. }
  466. .group-check {
  467. width: 38rpx;
  468. height: 38rpx;
  469. display: flex;
  470. align-items: center;
  471. justify-content: center;
  472. background: #C9CDD4;
  473. color: #ffffff;
  474. border-radius: 50%;
  475. font-size: 24rpx;
  476. .check-icon{
  477. font-size: 24rpx;
  478. }
  479. &.active {
  480. background: #0BBC58;
  481. color: #fff;
  482. }
  483. }
  484. }
  485. .group-settings {
  486. .setting-row {
  487. display: flex;
  488. align-items: center;
  489. justify-content: space-between;
  490. margin-bottom: 24rpx;
  491. .setting-row-label {
  492. width: 120rpx;
  493. font-size: 26rpx;
  494. color: #666;
  495. }
  496. .setting-row-input {
  497. flex: 1;
  498. height: 56rpx;
  499. padding: 0 16rpx;
  500. font-size: 26rpx;
  501. color: #042118;
  502. margin-right: 12rpx;
  503. text-align: right;
  504. }
  505. .setting-row-unit {
  506. font-size: 24rpx;
  507. color: #666;
  508. }
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. /* 底部确定按钮 */
  516. .confirm-btn-container {
  517. padding: 32rpx;
  518. .confirm-btn {
  519. height: 88rpx;
  520. display: flex;
  521. align-items: center;
  522. justify-content: center;
  523. background: #14a478;
  524. border-radius: 12rpx;
  525. box-shadow: 0 4rpx 12rpx rgba(20, 164, 120, 0.3);
  526. .confirm-btn-text {
  527. font-size: 32rpx;
  528. font-weight: 500;
  529. color: #fff;
  530. }
  531. }
  532. }
  533. </style>