nutrient.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container" style="position: relative">
  4. <floating-window :class="{'is_fixed': isFixed}" >
  5. <el-dropdown @command="handleCommand">
  6. <img width="50px" height="50px" src="@/assets/navigation.png" alt="导航.png" />
  7. <el-dropdown-menu slot="dropdown">
  8. <el-dropdown-item command="detail">食物更新</el-dropdown-item>
  9. <el-dropdown-item command="unit">单位管理</el-dropdown-item>
  10. <el-dropdown-item command="modifier">规格管理</el-dropdown-item>
  11. <el-dropdown-item command="list">食物列表</el-dropdown-item>
  12. </el-dropdown-menu>
  13. </el-dropdown>
  14. </floating-window>
  15. <el-row>
  16. 营养素:
  17. <el-select
  18. ref="nutrientSelect"
  19. v-model="params.nutrientId"
  20. filterable
  21. remote
  22. reserve-keyword
  23. :default-first-option="true"
  24. style="width: 200px;margin-left: 10px;"
  25. placeholder="请输入营养素关键词"
  26. :remote-method="queryNutrients"
  27. :loading="loading"
  28. @change="nutrientChanged"
  29. >
  30. <el-option v-for="item in nutrients" :key="item.id" :label="item.name" :value="item.id" />
  31. </el-select>
  32. 计量:
  33. <el-radio v-model="params.radio" :label="0" @change="radioChange(params)">值</el-radio>
  34. <el-radio v-model="params.radio" :label="1" @change="radioChange(params)">范围</el-radio>
  35. <el-radio v-model="params.radio" :label="2" @change="radioChange(params)">误差</el-radio>
  36. <div v-if="params.radio === 1" style="display: inline-block">
  37. 大于等于:
  38. <el-input v-model="params.quantityMin" style="width: 80px;" class="filter-item" @focus="getInputFocus" />
  39. 小于等于:
  40. <el-input v-model="params.quantityMax" style="width: 80px;" class="filter-item" @focus="getInputFocus" />
  41. </div>
  42. <div v-else-if="params.radio === 2" style="display: inline-block">
  43. 基准:
  44. <el-input v-model="params.quantity" style="width: 80px;" class="filter-item" @focus="getInputFocus" />
  45. ±:
  46. <el-input v-model="params.stdError" style="width: 80px;" class="filter-item" @focus="getInputFocus" />
  47. </div>
  48. <el-input
  49. v-else
  50. v-model="params.quantity"
  51. style="width: 80px;"
  52. class="filter-item"
  53. @focus="getInputFocus"
  54. />
  55. <el-autocomplete
  56. class="inline-input"
  57. v-model="params.unit"
  58. :fetch-suggestions="(query, cb) => {queryNutrientUnits(query, params.nutrientId, cb)}"
  59. @input="handleUnitChanged"
  60. placeholder="单位关键词"
  61. />
  62. <div v-show="showNutrientSource" style="display: inline-block">
  63. <el-select
  64. v-model="params.nutrientSource"
  65. placeholder="请选择营养素来源"
  66. >
  67. <el-option v-for="item in nutrientSources" :key="item" :label="item" :value="item" />
  68. </el-select>
  69. </div>
  70. <div v-show="showNRV" style="display: inline-block">
  71. NRV%:
  72. <el-input
  73. v-model="params.nrvPercent"
  74. style="width: 80px;"
  75. class="filter-item"
  76. />
  77. </div>
  78. </el-row>
  79. <el-row style="margin-top: 10px">
  80. <div v-show="!isPercentByVolumeUnit(params)" style="display: inline-block">
  81. Nv_Spec计量:
  82. <el-input
  83. v-model="params.nvSpec"
  84. style="width: 80px;"
  85. class="filter-item"
  86. @focus="getInputFocus"
  87. />
  88. <el-autocomplete
  89. class="inline-input"
  90. v-model="params.nvSpecUnit"
  91. :fetch-suggestions="queryUnits"
  92. placeholder="单位关键词"
  93. />
  94. </div>
  95. 信息来源:
  96. <el-autocomplete
  97. v-model="params.source"
  98. :fetch-suggestions="querySources"
  99. placeholder="请输入信息来源"
  100. />
  101. <el-button
  102. class="filter-item"
  103. style="margin-left: 10px;"
  104. type="primary"
  105. :disabled="!canEdit"
  106. @click="addNutrient">
  107. 添加
  108. </el-button>
  109. <el-button
  110. class="filter-item"
  111. style="margin-left: 10px;"
  112. type="success"
  113. :disabled="!canEdit"
  114. @click="handleImport">
  115. 导入营养素
  116. </el-button>
  117. </el-row>
  118. </div>
  119. <el-table
  120. :key="tableKey"
  121. v-loading="listLoading"
  122. :data="list"
  123. border
  124. fit
  125. highlight-current-row
  126. style="width: 100%;margin-top: 10px"
  127. @cell-dblclick="handleEdit"
  128. >
  129. <el-table-column type="index" label="序号" align="center" width="60px" />
  130. <el-table-column label="营养素名称" align="center">
  131. <template slot-scope="{row}">
  132. <span>{{ row.nutrientName }}</span>
  133. </template>
  134. </el-table-column>
  135. <el-table-column label="营养素计量" align="center" :width="150">
  136. <template slot-scope="{row}">
  137. <template v-if="row.edit">
  138. <el-radio v-model="row.radio" :label="0" @change="radioChange(row)">值</el-radio>
  139. <el-radio v-model="row.radio" :label="1" @change="radioChange(row)">范围</el-radio>
  140. <el-radio v-model="row.radio" :label="2" @change="radioChange(row)">误差</el-radio>
  141. <div v-if="row.radio === 1" style="display: inline-block">
  142. 大于等于:
  143. <el-input v-model="row.quantityMin" @focus="getInputFocus" />
  144. 小于等于:
  145. <el-input v-model="row.quantityMax" @focus="getInputFocus" />
  146. </div>
  147. <div v-else-if="row.radio === 2" style="display: inline-block">
  148. 基准:
  149. <el-input v-model="row.quantity" @focus="getInputFocus" />
  150. ±:
  151. <el-input v-model="row.stdError" @focus="getInputFocus" />
  152. </div>
  153. <el-input
  154. v-else
  155. v-model="row.quantity"
  156. style="width: 80px;"
  157. class="filter-item"
  158. @focus="getInputFocus"
  159. />
  160. </template>
  161. <span v-else>{{ row | nutrientQuantityFilter }}</span>
  162. </template>
  163. </el-table-column>
  164. <el-table-column label="计量单位" align="center" width="150">
  165. <template slot-scope="{row}">
  166. <template v-if="row.edit">
  167. <el-autocomplete
  168. v-model="row.unit"
  169. @input="handleRowUnitChanged(row)"
  170. :fetch-suggestions="(query, cb) => {queryNutrientUnits(query, row.nutrientId, cb)}"
  171. placeholder="单位关键词"
  172. />
  173. <el-select
  174. clearable
  175. v-show="showRowNutrientSource"
  176. v-model="row.nutrientSource"
  177. placeholder="请选择营养素来源"
  178. >
  179. <el-option v-for="item in nutrientSources" :key="item" :label="item" :value="item" />
  180. </el-select>
  181. </template>
  182. <span v-else>{{ row.nutrientSource ? `${row.unit}(${row.nutrientSource})` : row.unit }}</span>
  183. </template>
  184. </el-table-column>
  185. <el-table-column label="NRV%" align="center" width="80">
  186. <template slot-scope="{row}">
  187. <template v-if="row.edit">
  188. <el-input v-show="!isPercentByVolumeUnit(row)" v-model="row.nrvPercent"/>
  189. </template>
  190. <span v-else>{{ row.nrvPercent }}</span>
  191. </template>
  192. </el-table-column>
  193. <el-table-column label="Nv_Spec" align="center" width="80">
  194. <template slot-scope="{row}" v-if="!isPercentByVolumeUnit(row)">
  195. <template v-if="row.edit">
  196. <el-input v-model="row.nvSpec" class="filter-item" @focus="getInputFocus" />
  197. </template>
  198. <span v-else>{{ row.nvSpec }}</span>
  199. </template>
  200. </el-table-column>
  201. <el-table-column label="计量单位" align="center" width="150">
  202. <template slot-scope="{row}" v-if="!isPercentByVolumeUnit(row)">
  203. <template v-if="row.edit">
  204. <el-autocomplete v-model="row.nvSpecUnit" :fetch-suggestions="queryUnits" placeholder="单位关键词" />
  205. </template>
  206. <span v-else>{{ row.nvSpecUnit }}</span>
  207. </template>
  208. </el-table-column>
  209. <el-table-column label="信息来源" align="center" width="200">
  210. <template slot-scope="{row}">
  211. <template v-if="row.edit">
  212. <el-autocomplete
  213. v-model="row.source"
  214. :fetch-suggestions="querySources"
  215. placeholder="请输入信息来源"
  216. />
  217. </template>
  218. <span v-else>{{ row.source }}</span>
  219. </template>
  220. </el-table-column>
  221. <el-table-column label="信息来源备注" align="center" width="200">
  222. <template slot-scope="{row}">
  223. <template v-if="row.edit">
  224. <el-input type="text" :rows="2" v-model="row.sourceNote" @focus="getInputFocus" />
  225. </template>
  226. <span v-else>{{ row.sourceNote }}</span>
  227. </template>
  228. </el-table-column>
  229. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="320" fixed="right">
  230. <template slot-scope="{row}">
  231. <template v-if="row.edit">
  232. <el-button
  233. type="success"
  234. size="mini"
  235. @click="confirmEdit(row)"
  236. >
  237. 提交
  238. </el-button>
  239. <el-button
  240. type="danger"
  241. size="mini"
  242. @click="fetchData"
  243. >
  244. 取消
  245. </el-button>
  246. </template>
  247. <template v-else>
  248. <el-button size="mini" type="primary" :disabled="!canEdit" @click="handleEdit(row)">编辑</el-button>
  249. <el-button size="mini" type="primary" :disabled="!canEdit" @click="updateSort(row, 0)">上移</el-button>
  250. <el-button size="mini" type="primary" :disabled="!canEdit" @click="updateSort(row, 1)">下移</el-button>
  251. <el-button size="mini" type="danger" :disabled="!canEdit" @click="confirmRemoveNutrient(row)">
  252. 删除
  253. </el-button>
  254. </template>
  255. </template>
  256. </el-table-column>
  257. </el-table>
  258. <el-dialog title="导入营养素" :visible.sync="dialogFormVisible" v-loading="importLoading">
  259. <el-form ref="dialogForm" label-position="left" style="width: 80%; margin-left:50px;">
  260. <el-radio :label="0" v-model="importType" @change="handleImportTypeChange" >从模板导入</el-radio>
  261. <el-radio :label="1" v-model="importType" @change="handleImportTypeChange" style="margin-bottom: 10px">从食物导入</el-radio>
  262. <el-form-item prop="importId">
  263. <el-select
  264. v-model="importId"
  265. class="filter-item"
  266. filterable
  267. remote
  268. reserve-keyword
  269. placeholder="请输入关键词"
  270. :loading="importLoading"
  271. :remote-method="queryImportItems"
  272. style="width: 100%"
  273. >
  274. <el-option v-for="item in importItems" :key="`import${item.id}`" :label="item.name" :value="item.id" />
  275. </el-select>
  276. </el-form-item>
  277. </el-form>
  278. <div slot="footer" class="dialog-footer">
  279. <el-button @click="dialogFormVisible = false">
  280. 取消
  281. </el-button>
  282. <el-button type="primary" @click="submitImport">
  283. 提交
  284. </el-button>
  285. </div>
  286. </el-dialog>
  287. </div>
  288. </template>
  289. <script>
  290. import { getNutrientList, addFoodNutrient, updateFoodNutrient, removeFoodNutrient,
  291. updateFoodNutrientSort, confirmDeleteFoodNutrient, importNutrientsFromTemplate,
  292. getList as getFoodList, importNutrientFromSimilarFood, getDetail } from '@/api/food'
  293. import FloatingWindow from '@/components/FloatingWindow'
  294. import { getList, getNutrientUnits, getNutrientSources } from '@/api/nutrient'
  295. import { getList as getUnits } from '@/api/unit'
  296. import { getNutrientTemplates } from '@/api/nutrientTemplate'
  297. import store from '@/store'
  298. // 特殊营养素 若单位不为baseUnit,则需要填写来源
  299. const SPECIAL_NUTRIENT_NAMES = ['维生素A', '维生素D', '维生素E', '烟酸', '叶酸']
  300. export default {
  301. name: 'AddNutrient',
  302. components: { FloatingWindow },
  303. mounted() {
  304. window.addEventListener('scroll', this.initHeight);
  305. },
  306. //回调中移除监听
  307. destroyed() {
  308. window.removeEventListener('scroll', this.handleScroll)
  309. },
  310. created() {
  311. this.foodId = this.$route.params && this.$route.params.id
  312. this.fetchData()
  313. this.queryNutrients()
  314. },
  315. filters: {
  316. nutrientQuantityFilter(row) {
  317. if (row.stdError) {
  318. return `${row.quantity} ± ${row.stdError}`
  319. }else if (row.quantityMin && row.quantityMax) {
  320. return `${row.quantityMin} ~ ${row.quantityMax}`
  321. } else if (row.quantityMin) {
  322. return `≥${row.quantityMin}`
  323. } else if (row.quantityMax) {
  324. return `≤${row.quantityMax}`
  325. } else {
  326. return row.quantity
  327. }
  328. }
  329. },
  330. data() {
  331. return {
  332. tableKey: 0,
  333. listLoading: false,
  334. units: [],
  335. foodId: '',
  336. list: [],
  337. nutrients: [],
  338. params: { source: '营养标签', radio: 0, nvSpec: 100, nvSpecUnit: '克' },
  339. loading: false,
  340. unitLoading: false,
  341. sources: [{ value: "营养标签" }, { value: "食品官方资料" }, { value: "计算值" }],
  342. dialogFormVisible: false,
  343. importType: 0,
  344. importId: '',
  345. importLoading: false,
  346. importItems: [],
  347. isFixed: false,
  348. offsetTop: 0,
  349. showNutrientSource: false,
  350. showRowNutrientSource: false,
  351. nutrientSources: [],
  352. showNRV: false,
  353. canEdit: true
  354. }
  355. },
  356. methods: {
  357. fetchData() {
  358. this.listLoading = true
  359. getNutrientList(this.foodId).then(res => {
  360. this.list = res.data
  361. this.listLoading = false
  362. if (this.list.length > 0) {
  363. this.$set(this.params, "nvSpec", this.list[0].nvSpec)
  364. this.$set(this.params, "nvSpecUnit", this.list[0].nvSpecUnit)
  365. } else {
  366. this.$set(this.params, 'nvSpec', 100)
  367. this.$set(this.params, 'nvSpecUnit', '克')
  368. }
  369. })
  370. getDetail(this.foodId).then(res => {
  371. if (!store.getters.isAdmin && res.data.userId !== store.getters.userId) {
  372. this.canEdit = false
  373. }
  374. })
  375. },
  376. addNutrient() {
  377. this.params.foodId = this.foodId
  378. addFoodNutrient(this.foodId, this.params).then(res => {
  379. this.params = { source: '营养标签', radio: 0 }
  380. this.fetchData()
  381. this.$notify.success('添加营养素成功')
  382. this.$refs.nutrientSelect.focus()
  383. }).catch(res => {
  384. this.$message.error(res.data.message)
  385. })
  386. },
  387. confirmEdit(row) {
  388. updateFoodNutrient(this.foodId, row.nutrientId, row).then(res => {
  389. this.fetchData()
  390. this.$notify.success('提交成功')
  391. }).catch(res => {
  392. this.$message.error(res.data.message)
  393. })
  394. },
  395. confirmRemoveNutrient(row) {
  396. confirmDeleteFoodNutrient(row.foodId, row.nutrientId).then(res => {
  397. if (!res.data) {
  398. this.$confirm('由于单位转换的原因,删除此条营养素关联数据,将会导致该食物被删除,是否继续?', '提示', {
  399. confirmButtonText: '确定',
  400. cancelButtonText: '取消',
  401. type: 'warning'
  402. }).then(() => {
  403. this.removeNutrient(row)
  404. })
  405. } else {
  406. this.removeNutrient(row)
  407. }
  408. }).catch(res => {
  409. this.$message.error(res.data.message)
  410. })
  411. },
  412. removeNutrient(row) {
  413. removeFoodNutrient(row.foodId, row.nutrientId).then(res => {
  414. this.fetchData()
  415. this.$notify.success('删除营养素成功')
  416. this.$refs.nutrientSelect.focus()
  417. }).catch(res => {
  418. this.$message.error(res.data.message)
  419. })
  420. },
  421. queryNutrients(query) {
  422. getList({ query }).then(res => {
  423. this.nutrients = res.data.list
  424. }).catch(() => {
  425. this.nutrients = []
  426. })
  427. },
  428. queryNutrientUnits(query, nutrientId, cb) {
  429. let units = []
  430. getNutrientUnits(nutrientId, { query }).then(res => {
  431. res.data.forEach(item => units.push({ value: item }))
  432. cb(units)
  433. })
  434. },
  435. queryUnits(query, cb) {
  436. let units = []
  437. getUnits({ query }).then(res => {
  438. res.data.list.forEach(item => units.push({ value: item.name }))
  439. cb(units)
  440. })
  441. },
  442. updateSort(row, type) {
  443. updateFoodNutrientSort(this.foodId, row.nutrientId, { type }).then(res => {
  444. this.$notify.success('提交成功')
  445. this.fetchData()
  446. }).catch(res => {
  447. this.$message.error(res.data.message)
  448. })
  449. },
  450. querySources(query, cb) {
  451. let sources = this.sources
  452. let results = query ? sources.filter(this.sourcesFilter(query)) : sources;
  453. cb(results)
  454. },
  455. sourcesFilter(query) {
  456. return (restaurant) => {
  457. return (restaurant.value.toLowerCase().indexOf(query.toLowerCase()) === 0);
  458. };
  459. },
  460. handleEdit(row) {
  461. if (!this.canEdit) {
  462. return
  463. }
  464. this.$set(row, 'edit', true)
  465. if (row.quantityMax || row.quantityMin) {
  466. this.$set(row, 'radio', 1)
  467. } else if (row.stdError) {
  468. this.$set(row, 'radio', 2)
  469. } else {
  470. this.$set(row, 'radio', 0)
  471. }
  472. this.handleRowUnitChanged(row)
  473. },
  474. radioChange(row) {
  475. this.$set(row, 'stdError', '')
  476. this.$set(row, 'quantityMin', '')
  477. this.$set(row, 'quantityMax', '')
  478. this.$set(row, 'quantity', '')
  479. },
  480. nutrientChanged(value) {
  481. for (let nutrient of this.nutrients) {
  482. if (nutrient.id === value) {
  483. this.$set(this.params, 'unit', nutrient.baseUnit)
  484. if (nutrient.nrvUnit) {
  485. this.showNRV = true
  486. } else {
  487. this.showNRV = false
  488. }
  489. break
  490. }
  491. }
  492. },
  493. getInputFocus(event) {
  494. event.currentTarget.select();
  495. },
  496. handleImport() {
  497. this.query = ''
  498. this.importId = ''
  499. this.importType = 0
  500. this.importItems = []
  501. this.queryImportItems()
  502. this.dialogFormVisible = true
  503. },
  504. handleImportTypeChange() {
  505. this.importId = ''
  506. this.importItems = []
  507. this.queryImportItems()
  508. },
  509. queryImportItems(query=''){
  510. this.importType === 0 ? this.queryTemplates(query) : this.queryFoods(query)
  511. },
  512. queryTemplates(query='') {
  513. this.importLoading = true
  514. getNutrientTemplates({ query }).then(res => {
  515. this.importItems = res.data.list
  516. if (this.importItems.length > 0) {
  517. this.importId = this.importItems[0].id
  518. }
  519. this.importLoading = false
  520. }).catch(() => {
  521. this.importItems = []
  522. this.importLoading = false
  523. })
  524. },
  525. queryFoods(query='') {
  526. this.importLoading = true
  527. getFoodList({ query: query, orderBy: 0, pageNum: 1, pageSize: 20 }).then(res => {
  528. this.importItems = res.data.list
  529. this.importLoading = false
  530. }).catch(() => {
  531. this.importItems = []
  532. this.importLoading = false
  533. })
  534. },
  535. submitImport() {
  536. this.importLoading = true
  537. const resPromise = this.importType === 0 ?
  538. importNutrientsFromTemplate(this.foodId, { templateId: this.importId }) :
  539. importNutrientFromSimilarFood(this.foodId, { foodId: this.importId })
  540. resPromise.then(res => {
  541. this.fetchData()
  542. this.$notify.success("提交成功")
  543. this.dialogFormVisible = false
  544. this.importLoading = false
  545. }).catch(res => {
  546. this.$message.error(res.data.message)
  547. this.importLoading = false
  548. this.dialogFormVisible = false
  549. })
  550. },
  551. initHeight() {
  552. // 设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 (被卷曲的高度)
  553. const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
  554. //如果被卷曲的高度大于吸顶元素到顶端位置 的距离
  555. this.isFixed = scrollTop > this.offsetTop;
  556. },
  557. handleCommand(value) {
  558. let path = ''
  559. if (value === 'detail') {
  560. path = `/food/edit/${this.foodId}`
  561. } else if (value === 'unit') {
  562. path = `/food/${this.foodId}/unit`
  563. } else if (value === 'nutrient') {
  564. path = `/food/${this.foodId}/nutrient`
  565. } else if (value === 'modifier') {
  566. path = `/food/${this.foodId}/modifier`
  567. } else if (value === 'list') {
  568. path = store.getters.isAdmin ? '/food' : '/food/entry'
  569. }
  570. if (path) {
  571. this.$router.push({ path: path })
  572. }
  573. },
  574. isPercentByVolumeUnit(row) {
  575. return row && row.unit === '%Vol'
  576. },
  577. isSpecialNutrient(nutrientId) {
  578. let nutrient = null
  579. for (let i = 0; i < this.nutrients.length; i++) {
  580. if (this.nutrients[i].id === nutrientId) {
  581. nutrient = this.nutrients[i]
  582. break
  583. }
  584. }
  585. // 如果特殊营养素单位不等于baseUnit,则显示来源
  586. return nutrient && SPECIAL_NUTRIENT_NAMES.indexOf(nutrient.name) > -1
  587. },
  588. handleUnitChanged() {
  589. if (this.isSpecialNutrient(this.params.nutrientId)) {
  590. getNutrientSources(this.params.nutrientId, { unit: this.params.unit }).then(res => {
  591. this.nutrientSources = res.data
  592. if (this.nutrientSources.length > 0){
  593. this.params.nutrientSource = this.nutrientSources[0]
  594. this.showNutrientSource = true
  595. } else {
  596. this.showNutrientSource = false
  597. this.params.nutrientSource = null
  598. }
  599. })
  600. } else {
  601. this.showNutrientSource = false
  602. this.params.nutrientSource = null
  603. }
  604. },
  605. handleRowUnitChanged(row) {
  606. if (SPECIAL_NUTRIENT_NAMES.indexOf(row.nutrientName) > -1) {
  607. getNutrientSources(row.nutrientId, { unit: row.unit }).then(res => {
  608. this.nutrientSources = res.data
  609. if (this.nutrientSources.length > 0){
  610. if (!row.nutrientSource) {
  611. row.nutrientSource = this.nutrientSources[0]
  612. }
  613. this.showRowNutrientSource = true
  614. } else {
  615. this.showRowNutrientSource = false
  616. row.nutrientSource = null
  617. }
  618. })
  619. } else {
  620. this.showRowNutrientSource = false
  621. row.nutrientSource = null
  622. }
  623. }
  624. }
  625. }
  626. </script>
  627. <style scoped>
  628. </style>