formulaSetting.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <view class="formula-setting-container">
  3. <custom-card>
  4. <block slot="backText">{{ title }}</block>
  5. </custom-card>
  6. <!-- 内容区域 -->
  7. <view class="content">
  8. <!-- 配方列表 -->
  9. <view class="formula-list">
  10. <!-- 配方1 -->
  11. <view class="formula-item" v-for="(recipe,index) in recipeList" :key="recipe.id">
  12. <view class="formula-header">
  13. <text class="formula-name">配方{{index + 1}}</text>
  14. </view>
  15. <view class="formula-details">
  16. <view class="detail-row">
  17. <text class="detail-label">目标EC</text>
  18. <view class="detail-value">
  19. <input
  20. v-model="recipe.ec"
  21. type="number"
  22. placeholder="请输入EC值"
  23. class="input"
  24. @blur="(e)=>peifangEditHandle(index, -1, 'ec', e.detail.value)"
  25. />
  26. <text class="detail-unit">us/cm</text>
  27. </view>
  28. </view>
  29. <view class="detail-row">
  30. <text class="detail-label">目标PH</text>
  31. <view class="detail-value">
  32. <input
  33. v-model="recipe.ph"
  34. type="number"
  35. placeholder="请输入PH值"
  36. class="input"
  37. @blur="(e)=>peifangEditHandle(index, -1, 'ph', e.detail.value)"
  38. />
  39. </view>
  40. </view>
  41. <view class="detail-row">
  42. <text class="detail-label">目标水肥比</text>
  43. <view class="detail-value">
  44. <input
  45. v-model="recipe.wfratio"
  46. type="number"
  47. placeholder="请输入水肥比值"
  48. class="input"
  49. @blur="(e)=>peifangEditHandle(index, -1, 'wfratio', e.detail.value)"
  50. />
  51. </view>
  52. </view>
  53. <view class="detail-row">
  54. <text class="detail-label">吸肥通道比例</text>
  55. <view class="detail-value">
  56. <input
  57. v-model="channel.percentage"
  58. type="number"
  59. placeholder="请输入吸肥通道比例值"
  60. class="input1"
  61. v-for="(channel,channelIndex) in recipe.channels"
  62. :key="channelIndex"
  63. @blur="(e)=>peifangEditHandle(index, channelIndex, 'fertratio', e.detail.value)"
  64. />
  65. <text class="detail-unit">%</text>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. export default {
  76. data() {
  77. return {
  78. title: '配方设置',
  79. devBid: '',
  80. recipeList: [],
  81. };
  82. },
  83. onLoad(options) {
  84. const { devBid } = options;
  85. this.devBid = devBid;
  86. this.getInfoList();
  87. },
  88. methods: {
  89. async peifangEditHandle(index, channelIndex, type, value) {
  90. // 判断value 是否是数字
  91. if (isNaN(value)) {
  92. uni.showToast({
  93. title: '请输入数字',
  94. icon: 'none',
  95. })
  96. return;
  97. }
  98. let key = '';
  99. if (type == 'fertratio') {
  100. // 4个加一起不能超过100
  101. const sum = this.recipeList[index].channels.reduce(
  102. (acc, cur) => Number(acc) + Number(cur.percentage),
  103. 0
  104. );
  105. if (sum > 100) {
  106. uni.showToast({
  107. title: '吸肥通道比例加起来不能超过100',
  108. icon: 'none',
  109. })
  110. // 如果超过了100,恢复原来的值
  111. this.recipeList[index].channels[channelIndex].percentage = +value;
  112. return;
  113. }
  114. }
  115. if (channelIndex == -1) {
  116. key = `ValveFormula:VF0${index}:${type}`;
  117. } else {
  118. key = `ValveFormula:VF0${index}:${type}${channelIndex}`;
  119. }
  120. const peifang = {
  121. [key]: +value
  122. };
  123. const params = {
  124. devBid: Number(this.devBid),
  125. peifang: peifang
  126. }
  127. const res = await this.$myRequest({
  128. url:'/api/v2/iot/device/sf/yunshang/peifang/edit/',
  129. method:'POST',
  130. data: params,
  131. header: {
  132. 'Content-Type': 'application/json',
  133. 'accept': 'application/json, text/plain, */*'
  134. }
  135. })
  136. const resData = res
  137. console.log(resData,'resDataresData')
  138. if (resData.code === '000000') {
  139. uni.showToast({
  140. title: '配方保存成功',
  141. icon: 'success',
  142. })
  143. } else {
  144. uni.showToast({
  145. title: '配方保存失败',
  146. icon: 'none',
  147. })
  148. }
  149. },
  150. async getInfoList(){
  151. this.recipeList = [];
  152. const params = {
  153. devBid: this.devBid
  154. }
  155. const res = await this.$myRequest({
  156. url:'/api/v2/iot/device/sf/yunshang/peifang/list/',
  157. method:'POST',
  158. data: params,
  159. header: {
  160. 'Content-Type': 'application/json',
  161. 'accept': 'application/json, text/plain, */*'
  162. }
  163. })
  164. const resData = res.data || [];
  165. for (let i = 0; i < resData.length; i++) {
  166. const item = resData[i];
  167. const recipe = {
  168. ec: item[`ValveFormula:VF0${i}:ec`],
  169. ph: item[`ValveFormula:VF0${i}:ph`],
  170. wfratio: item[`ValveFormula:VF0${i}:wfratio`],
  171. channels: []
  172. };
  173. if (
  174. item[`ValveFormula:VF0${i}:fertratio0`] !== null &&
  175. item[`ValveFormula:VF0${i}:fertratio0`] !== undefined
  176. ) {
  177. recipe.channels.push({
  178. percentage: item[`ValveFormula:VF0${i}:fertratio0`]
  179. });
  180. }
  181. if (
  182. item[`ValveFormula:VF0${i}:fertratio1`] !== null &&
  183. item[`ValveFormula:VF0${i}:fertratio1`] !== undefined
  184. ) {
  185. recipe.channels.push({
  186. percentage: item[`ValveFormula:VF0${i}:fertratio1`]
  187. });
  188. }
  189. if (
  190. item[`ValveFormula:VF0${i}:fertratio2`] !== null &&
  191. item[`ValveFormula:VF0${i}:fertratio2`] !== undefined
  192. ) {
  193. recipe.channels.push({
  194. percentage: item[`ValveFormula:VF0${i}:fertratio2`]
  195. });
  196. }
  197. if (
  198. item[`ValveFormula:VF0${i}:fertratio3`] !== null &&
  199. item[`ValveFormula:VF0${i}:fertratio3`] !== undefined
  200. ) {
  201. recipe.channels.push({
  202. percentage: item[`ValveFormula:VF0${i}:fertratio3`]
  203. });
  204. }
  205. this.recipeList.push(recipe);
  206. }
  207. },
  208. // 确认按钮点击事件
  209. confirm() {
  210. // 这里可以添加确认逻辑
  211. console.log('确认设置');
  212. }
  213. }
  214. };
  215. </script>
  216. <style scoped lang="scss">
  217. .formula-setting-container {
  218. width: 100%;
  219. min-height: 100vh;
  220. background: linear-gradient(180deg, #f5f6fa00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  221. font-family: 'Source Han Sans CN';
  222. ::v-deep .u-input{
  223. text-align:right !important;
  224. }
  225. }
  226. .input{
  227. width: 100%;
  228. height: 80rpx;
  229. text-align:right;
  230. color:#020305;
  231. }
  232. .input1{
  233. width: 25%;
  234. color:#020305;
  235. }
  236. /* 顶部导航栏 */
  237. .nav-bar {
  238. display: flex;
  239. align-items: center;
  240. justify-content: space-between;
  241. padding: 20rpx 32rpx;
  242. background: linear-gradient(180deg, #14a478 0%, #0f8a64 100%);
  243. color: #fff;
  244. .nav-left {
  245. .back-icon {
  246. font-size: 32rpx;
  247. }
  248. }
  249. .nav-center {
  250. .nav-title {
  251. font-size: 32rpx;
  252. font-weight: 500;
  253. }
  254. }
  255. .nav-right {
  256. display: flex;
  257. gap: 24rpx;
  258. .nav-icon {
  259. font-size: 28rpx;
  260. }
  261. }
  262. }
  263. /* 内容区域 */
  264. .content {
  265. padding: 32rpx;
  266. }
  267. /* 配方管理 */
  268. .formula-management {
  269. display: flex;
  270. align-items: center;
  271. justify-content: space-between;
  272. background: #fff;
  273. padding: 24rpx;
  274. border-radius: 12rpx;
  275. margin-bottom: 24rpx;
  276. .management-title {
  277. font-size: 28rpx;
  278. font-weight: 500;
  279. color: #042118;
  280. }
  281. .add-formula-btn {
  282. width: 40rpx;
  283. height: 40rpx;
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. background: #14a478;
  288. color: #fff;
  289. border-radius: 50%;
  290. font-size: 28rpx;
  291. font-weight: bold;
  292. }
  293. }
  294. /* 配方列表 */
  295. .formula-list {
  296. display: flex;
  297. flex-direction: column;
  298. gap: 24rpx;
  299. }
  300. /* 配方项 */
  301. .formula-item {
  302. background: #fff;
  303. border-radius: 12rpx;
  304. padding: 24rpx;
  305. .formula-header {
  306. display: flex;
  307. align-items: center;
  308. justify-content: space-between;
  309. margin-bottom: 24rpx;
  310. .formula-name {
  311. font-size: 28rpx;
  312. font-weight: 500;
  313. color: #020305;
  314. }
  315. .delete-formula-btn {
  316. width: 32rpx;
  317. height: 32rpx;
  318. display: flex;
  319. align-items: center;
  320. justify-content: center;
  321. background: #f5f5f5;
  322. color: #666;
  323. border-radius: 50%;
  324. font-size: 24rpx;
  325. font-weight: bold;
  326. }
  327. }
  328. .formula-details {
  329. .detail-row {
  330. display: flex;
  331. align-items: center;
  332. padding: 16rpx 0;
  333. border-bottom: 1rpx solid #f0f0f0;
  334. &:last-child {
  335. border-bottom: none;
  336. }
  337. .detail-label {
  338. width: 150rpx;
  339. font-size: 26rpx;
  340. color: #333333;
  341. }
  342. .detail-value {
  343. display: flex;
  344. flex:1;
  345. align-items: center;
  346. justify-content: flex-end;
  347. height: 60rpx;
  348. font-size: 26rpx;
  349. color: #042118;
  350. text-align: right;
  351. }
  352. .detail-unit {
  353. margin-left: 8rpx;
  354. font-size: 24rpx;
  355. color: #333333;
  356. }
  357. }
  358. }
  359. }
  360. </style>