formulaSetting.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. if (resData.code === '000000') {
  138. uni.showToast({
  139. title: '配方保存成功',
  140. icon: 'success',
  141. })
  142. } else {
  143. uni.showToast({
  144. title: resData.msg || '配方保存失败',
  145. icon: 'none',
  146. })
  147. }
  148. },
  149. async getInfoList(){
  150. this.recipeList = [];
  151. const params = {
  152. devBid: this.devBid
  153. }
  154. const res = await this.$myRequest({
  155. url:'/api/v2/iot/device/sf/yunshang/peifang/list/',
  156. method:'POST',
  157. data: params,
  158. header: {
  159. 'Content-Type': 'application/json',
  160. 'accept': 'application/json, text/plain, */*'
  161. }
  162. })
  163. const resData = res || [];
  164. for (let i = 0; i < resData.length; i++) {
  165. const item = resData[i];
  166. const recipe = {
  167. ec: item[`ValveFormula:VF0${i}:ec`],
  168. ph: item[`ValveFormula:VF0${i}:ph`],
  169. wfratio: item[`ValveFormula:VF0${i}:wfratio`],
  170. channels: []
  171. };
  172. if (
  173. item[`ValveFormula:VF0${i}:fertratio0`] !== null &&
  174. item[`ValveFormula:VF0${i}:fertratio0`] !== undefined
  175. ) {
  176. recipe.channels.push({
  177. percentage: item[`ValveFormula:VF0${i}:fertratio0`]
  178. });
  179. }
  180. if (
  181. item[`ValveFormula:VF0${i}:fertratio1`] !== null &&
  182. item[`ValveFormula:VF0${i}:fertratio1`] !== undefined
  183. ) {
  184. recipe.channels.push({
  185. percentage: item[`ValveFormula:VF0${i}:fertratio1`]
  186. });
  187. }
  188. if (
  189. item[`ValveFormula:VF0${i}:fertratio2`] !== null &&
  190. item[`ValveFormula:VF0${i}:fertratio2`] !== undefined
  191. ) {
  192. recipe.channels.push({
  193. percentage: item[`ValveFormula:VF0${i}:fertratio2`]
  194. });
  195. }
  196. if (
  197. item[`ValveFormula:VF0${i}:fertratio3`] !== null &&
  198. item[`ValveFormula:VF0${i}:fertratio3`] !== undefined
  199. ) {
  200. recipe.channels.push({
  201. percentage: item[`ValveFormula:VF0${i}:fertratio3`]
  202. });
  203. }
  204. this.recipeList.push(recipe);
  205. }
  206. },
  207. // 确认按钮点击事件
  208. confirm() {
  209. // 这里可以添加确认逻辑
  210. console.log('确认设置');
  211. }
  212. }
  213. };
  214. </script>
  215. <style scoped lang="scss">
  216. .formula-setting-container {
  217. width: 100%;
  218. min-height: 100vh;
  219. background: linear-gradient(180deg, #f5f6fa00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  220. font-family: 'Source Han Sans CN';
  221. ::v-deep .u-input{
  222. text-align:right !important;
  223. }
  224. }
  225. .input{
  226. width: 100%;
  227. height: 80rpx;
  228. text-align:right;
  229. color:#020305;
  230. }
  231. .input1{
  232. width: 25%;
  233. color:#020305;
  234. }
  235. /* 顶部导航栏 */
  236. .nav-bar {
  237. display: flex;
  238. align-items: center;
  239. justify-content: space-between;
  240. padding: 20rpx 32rpx;
  241. background: linear-gradient(180deg, #14a478 0%, #0f8a64 100%);
  242. color: #fff;
  243. .nav-left {
  244. .back-icon {
  245. font-size: 32rpx;
  246. }
  247. }
  248. .nav-center {
  249. .nav-title {
  250. font-size: 32rpx;
  251. font-weight: 500;
  252. }
  253. }
  254. .nav-right {
  255. display: flex;
  256. gap: 24rpx;
  257. .nav-icon {
  258. font-size: 28rpx;
  259. }
  260. }
  261. }
  262. /* 内容区域 */
  263. .content {
  264. padding: 32rpx;
  265. }
  266. /* 配方管理 */
  267. .formula-management {
  268. display: flex;
  269. align-items: center;
  270. justify-content: space-between;
  271. background: #fff;
  272. padding: 24rpx;
  273. border-radius: 12rpx;
  274. margin-bottom: 24rpx;
  275. .management-title {
  276. font-size: 28rpx;
  277. font-weight: 500;
  278. color: #042118;
  279. }
  280. .add-formula-btn {
  281. width: 40rpx;
  282. height: 40rpx;
  283. display: flex;
  284. align-items: center;
  285. justify-content: center;
  286. background: #14a478;
  287. color: #fff;
  288. border-radius: 50%;
  289. font-size: 28rpx;
  290. font-weight: bold;
  291. }
  292. }
  293. /* 配方列表 */
  294. .formula-list {
  295. display: flex;
  296. flex-direction: column;
  297. gap: 24rpx;
  298. }
  299. /* 配方项 */
  300. .formula-item {
  301. background: #fff;
  302. border-radius: 12rpx;
  303. padding: 24rpx;
  304. .formula-header {
  305. display: flex;
  306. align-items: center;
  307. justify-content: space-between;
  308. margin-bottom: 24rpx;
  309. .formula-name {
  310. font-size: 28rpx;
  311. font-weight: 500;
  312. color: #020305;
  313. }
  314. .delete-formula-btn {
  315. width: 32rpx;
  316. height: 32rpx;
  317. display: flex;
  318. align-items: center;
  319. justify-content: center;
  320. background: #f5f5f5;
  321. color: #666;
  322. border-radius: 50%;
  323. font-size: 24rpx;
  324. font-weight: bold;
  325. }
  326. }
  327. .formula-details {
  328. .detail-row {
  329. display: flex;
  330. align-items: center;
  331. padding: 16rpx 0;
  332. border-bottom: 1rpx solid #f0f0f0;
  333. &:last-child {
  334. border-bottom: none;
  335. }
  336. .detail-label {
  337. width: 150rpx;
  338. font-size: 26rpx;
  339. color: #333333;
  340. }
  341. .detail-value {
  342. display: flex;
  343. flex:1;
  344. align-items: center;
  345. justify-content: flex-end;
  346. height: 60rpx;
  347. font-size: 26rpx;
  348. color: #042118;
  349. text-align: right;
  350. }
  351. .detail-unit {
  352. margin-left: 8rpx;
  353. font-size: 24rpx;
  354. color: #333333;
  355. }
  356. }
  357. }
  358. }
  359. </style>