formulaSetting.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <view class="formula-setting-page">
  3. <custom-card>
  4. <block slot="backText">配方设置</block>
  5. <block slot="right">
  6. <view class="right-icons">
  7. <u-icon name="more-dot-fill" color="#333333" size="36rpx" style="margin-right: 16rpx;" />
  8. <u-icon name="camera" color="#333333" size="36rpx" />
  9. </view>
  10. </block>
  11. </custom-card>
  12. <view class="formula-content">
  13. <!-- 选择肥源 -->
  14. <view class="form-section">
  15. <text class="section-label">选择肥源</text>
  16. <picker
  17. mode="selector"
  18. :range="fertilizerSources"
  19. :value="selectedSourceIndex"
  20. @change="onSourceChange"
  21. >
  22. <view class="picker-wrapper">
  23. <text class="picker-text" :class="{ placeholder: selectedSourceIndex === -1 }">
  24. {{ selectedSourceIndex === -1 ? '请选择肥源' : fertilizerSources[selectedSourceIndex] }}
  25. </text>
  26. <u-icon name="arrow-down" color="#999999" size="24rpx" />
  27. </view>
  28. </picker>
  29. </view>
  30. <!-- 配方名称 -->
  31. <view class="form-section">
  32. <text class="section-label">配方名称</text>
  33. <input
  34. class="formula-name-input"
  35. v-model="formulaName"
  36. placeholder="请输入配方名称"
  37. placeholder-style="color: #999999;"
  38. />
  39. </view>
  40. <!-- 肥料配置表格 -->
  41. <view class="fertilizer-table">
  42. <view class="table-header">
  43. <text class="header-cell">肥料名称</text>
  44. <text class="header-cell">EC值</text>
  45. <text class="header-cell">占比</text>
  46. <text class="header-cell action">操作</text>
  47. </view>
  48. <view
  49. v-for="(item, index) in fertilizerList"
  50. :key="index"
  51. class="table-row"
  52. >
  53. <view class="row-cell">
  54. <input
  55. class="cell-input"
  56. v-model="item.name"
  57. placeholder="输入名称"
  58. placeholder-style="color: #999999;"
  59. />
  60. </view>
  61. <view class="row-cell">
  62. <input
  63. class="cell-input"
  64. v-model="item.ec"
  65. type="digit"
  66. placeholder="EC"
  67. placeholder-style="color: #999999;"
  68. />
  69. </view>
  70. <view class="row-cell">
  71. <input
  72. class="cell-input"
  73. v-model="item.proportion"
  74. type="digit"
  75. placeholder="%"
  76. placeholder-style="color: #999999;"
  77. />
  78. </view>
  79. <view class="row-cell action">
  80. <text class="delete-btn" @click="deleteFertilizer(index)">删除</text>
  81. </view>
  82. </view>
  83. </view>
  84. <!-- 添加按钮 -->
  85. <view class="add-btn-wrapper">
  86. <view class="add-fertilizer-btn" @click="addFertilizer">
  87. <u-icon name="plus" color="#00c853" size="28rpx" />
  88. <text class="add-btn-text">添加肥料</text>
  89. </view>
  90. </view>
  91. <!-- 保存按钮 -->
  92. <view class="save-btn-wrapper">
  93. <view class="save-btn" @click="handleSave">
  94. <text class="save-text">保存</text>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. </template>
  100. <script>
  101. export default {
  102. data() {
  103. return {
  104. fertilizerSources: ['肥源1', '肥源2', '肥源3'],
  105. selectedSourceIndex: -1,
  106. formulaName: '',
  107. fertilizerList: [
  108. { name: '', ec: '', proportion: '' },
  109. { name: '', ec: '', proportion: '' },
  110. { name: '', ec: '', proportion: '' },
  111. ],
  112. };
  113. },
  114. methods: {
  115. // 肥源选择改变
  116. onSourceChange(e) {
  117. this.selectedSourceIndex = e.detail.value;
  118. },
  119. // 添加肥料
  120. addFertilizer() {
  121. if (this.fertilizerList.length >= 10) {
  122. uni.showToast({
  123. title: '最多添加10种肥料',
  124. icon: 'none'
  125. });
  126. return;
  127. }
  128. this.fertilizerList.push({ name: '', ec: '', proportion: '' });
  129. },
  130. // 删除肥料
  131. deleteFertilizer(index) {
  132. if (this.fertilizerList.length <= 1) {
  133. uni.showToast({
  134. title: '至少保留一种肥料',
  135. icon: 'none'
  136. });
  137. return;
  138. }
  139. uni.showModal({
  140. title: '确认删除',
  141. content: '确定要删除该肥料吗?',
  142. success: (res) => {
  143. if (res.confirm) {
  144. this.fertilizerList.splice(index, 1);
  145. }
  146. }
  147. });
  148. },
  149. // 保存
  150. handleSave() {
  151. // 验证
  152. if (this.selectedSourceIndex === -1) {
  153. uni.showToast({
  154. title: '请选择肥源',
  155. icon: 'none'
  156. });
  157. return;
  158. }
  159. if (!this.formulaName.trim()) {
  160. uni.showToast({
  161. title: '请输入配方名称',
  162. icon: 'none'
  163. });
  164. return;
  165. }
  166. // 验证肥料列表
  167. const validFertilizers = this.fertilizerList.filter(item => {
  168. return item.name.trim() || item.ec || item.proportion;
  169. });
  170. if (validFertilizers.length === 0) {
  171. uni.showToast({
  172. title: '请至少添加一种肥料',
  173. icon: 'none'
  174. });
  175. return;
  176. }
  177. // 构建保存数据
  178. const saveData = {
  179. fertilizerSource: this.fertilizerSources[this.selectedSourceIndex],
  180. formulaName: this.formulaName,
  181. fertilizers: validFertilizers
  182. };
  183. console.log('保存配方设置:', saveData);
  184. // TODO: 调用接口保存
  185. uni.showToast({
  186. title: '保存成功',
  187. icon: 'success'
  188. });
  189. },
  190. },
  191. };
  192. </script>
  193. <style scoped lang="scss">
  194. uni-page-body {
  195. position: relative;
  196. height: 100%;
  197. }
  198. .formula-setting-page {
  199. min-height: 100%;
  200. background: linear-gradient(180deg, #e6f7f0 0%, #ffffff 100%);
  201. overflow-x: hidden;
  202. overflow-y: auto;
  203. .right-icons {
  204. display: flex;
  205. align-items: center;
  206. }
  207. .formula-content {
  208. padding: 24rpx 32rpx;
  209. }
  210. // 表单区域
  211. .form-section {
  212. background: #ffffff;
  213. border-radius: 12rpx;
  214. padding: 24rpx;
  215. margin-bottom: 20rpx;
  216. .section-label {
  217. display: block;
  218. font-size: 28rpx;
  219. font-weight: 500;
  220. color: #333333;
  221. margin-bottom: 20rpx;
  222. font-family: 'Source Han Sans CN';
  223. }
  224. .picker-wrapper {
  225. display: flex;
  226. justify-content: space-between;
  227. align-items: center;
  228. padding: 20rpx 24rpx;
  229. background: #f5f5f5;
  230. border-radius: 8rpx;
  231. .picker-text {
  232. font-size: 28rpx;
  233. color: #333333;
  234. font-family: 'Source Han Sans CN';
  235. &.placeholder {
  236. color: #999999;
  237. }
  238. }
  239. }
  240. .formula-name-input {
  241. width: 100%;
  242. padding: 20rpx 24rpx;
  243. background: #f5f5f5;
  244. border-radius: 8rpx;
  245. font-size: 28rpx;
  246. color: #333333;
  247. font-family: 'Source Han Sans CN';
  248. }
  249. }
  250. // 肥料表格
  251. .fertilizer-table {
  252. background: #ffffff;
  253. border-radius: 12rpx;
  254. padding: 24rpx;
  255. margin-bottom: 20rpx;
  256. .table-header {
  257. display: flex;
  258. padding-bottom: 20rpx;
  259. border-bottom: 1rpx solid #f0f0f0;
  260. .header-cell {
  261. flex: 1;
  262. font-size: 26rpx;
  263. font-weight: 500;
  264. color: #666666;
  265. text-align: center;
  266. font-family: 'Source Han Sans CN';
  267. &.action {
  268. flex: 0.8;
  269. }
  270. }
  271. }
  272. .table-row {
  273. display: flex;
  274. padding: 24rpx 0;
  275. border-bottom: 1rpx solid #f0f0f0;
  276. &:last-child {
  277. border-bottom: none;
  278. }
  279. .row-cell {
  280. flex: 1;
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. .cell-input {
  285. width: 100%;
  286. padding: 12rpx 16rpx;
  287. background: #f5f5f5;
  288. border-radius: 6rpx;
  289. font-size: 26rpx;
  290. color: #333333;
  291. text-align: center;
  292. font-family: 'Source Han Sans CN';
  293. }
  294. &.action {
  295. flex: 0.8;
  296. .delete-btn {
  297. font-size: 26rpx;
  298. color: #ff4d4f;
  299. font-family: 'Source Han Sans CN';
  300. }
  301. }
  302. }
  303. }
  304. }
  305. // 添加按钮区域
  306. .add-btn-wrapper {
  307. margin-bottom: 20rpx;
  308. .add-fertilizer-btn {
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. height: 80rpx;
  313. background: #ffffff;
  314. border: 2rpx dashed #00c853;
  315. border-radius: 12rpx;
  316. .add-btn-text {
  317. margin-left: 8rpx;
  318. font-size: 28rpx;
  319. color: #00c853;
  320. font-family: 'Source Han Sans CN';
  321. }
  322. }
  323. }
  324. // 保存按钮
  325. .save-btn-wrapper {
  326. .save-btn {
  327. width: 100%;
  328. height: 88rpx;
  329. background: #00c853;
  330. border-radius: 12rpx;
  331. display: flex;
  332. align-items: center;
  333. justify-content: center;
  334. .save-text {
  335. font-size: 32rpx;
  336. font-weight: 500;
  337. color: #ffffff;
  338. font-family: 'Source Han Sans CN';
  339. }
  340. }
  341. }
  342. }
  343. </style>