[关闭]
@salen 2017-11-06T03:05:40.000000Z 字数 1921 阅读 290

关联查询

未分类


始发站 目的站(无需要反写项)

  1. // 引入查询城市接口(接口统一放到service/index.js方便管理维护)
  2. import {
  3. searchCity,
  4. searchProduct,
  5. } from "../../service"

模板

  1. // 始发站
  2. <el-form-item label="始发站" class="grid-content" prop="departure">
  3. <el-select size="mini"
  4. filterable
  5. remote
  6. default-first-option
  7. allow-create placeholder=""
  8. v-model="detailInfo.departure"
  9. :remote-method="getDepartures"
  10. :loading="loading">
  11. <el-option
  12. v-for="item in departures" // 根据departures数据展示下拉框显示项
  13. :key="item.value"
  14. :label="item.label"
  15. :value="item.value">
  16. </el-option>
  17. </el-select>
  18. </el-form-item>
  19. // 目的站
  20. <el-form-item label="目的站" class="grid-content" prop="destination">
  21. <el-select size="mini"
  22. filterable
  23. remote
  24. default-first-option
  25. allow-create placeholder=""
  26. v-model="detailInfo.destination"
  27. :remote-method="getDestination"
  28. :loading="loading">
  29. <el-option
  30. v-for="item in destinations"
  31. :key="item.value"
  32. :label="item.label"
  33. :value="item.value">
  34. </el-option>
  35. </el-select>
  36. </el-form-item>

交互

  1. methods: {
  2. getCity(query) { // 获取城市
  3. if(query !== '') { // 查询前显示loading
  4. this.loading = true
  5. }
  6. return searchCity({code: query}).then(res => {
  7. if(res.data.status === 200) {
  8. this.loading = false // 查询出后隐藏loading
  9. return res.data.data.map(item => {
  10. // label为下拉框显示项,value为显示项对应值
  11. return {value: item.cn_name, label: item.cn_name}
  12. })
  13. }
  14. })
  15. },
  16. getDepartures(query) { // 获取始发站
  17. this.getCity(query).then(res => {
  18. this.departures = res
  19. })
  20. },
  21. getDestination(query) { // 获取目的站
  22. this.getCity(query).then(res => {
  23. this.destinations = res
  24. })
  25. }
  26. }

品名(存在需要反写项)

  1. methods: {
  2. getProduct(query) {
  3. if(query !== '') {
  4. this.loading = true
  5. }
  6. return searchProduct({code: query}).then(res => {
  7. if(res.data.status === 200) {
  8. this.loading = false
  9. return res.data.data
  10. }
  11. })
  12. },
  13. renderProduct(query) {
  14. this.getProduct(query).then(res => {
  15. this.products = res.map(item => {
  16. return {value: item.name, label: item.name}
  17. })
  18. })
  19. },
  20. fillProductAbout(query) { // 填充反写项
  21. this.getProduct(query).then(res => {
  22. if(Array.isArray(res)) {
  23. let o = res[0]
  24. if(o) {
  25. this.detailInfo.product_category = o.start_product_category
  26. this.detailInfo.packaging = o.pkg
  27. this.$refs['your_category'].focus()
  28. }
  29. }
  30. })
  31. }
  32. }

无反写项时参考始发站、目的站,有反写项时参考品名
具体代码参考 src ->pages ->receive ->detail

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注