@salen
2017-11-06T03:05:40.000000Z
字数 1921
阅读 324
未分类
// 引入查询城市接口(接口统一放到service/index.js方便管理维护)import {searchCity,searchProduct,} from "../../service"
// 始发站<el-form-item label="始发站" class="grid-content" prop="departure"><el-select size="mini"filterableremotedefault-first-optionallow-create placeholder=""v-model="detailInfo.departure":remote-method="getDepartures":loading="loading"><el-optionv-for="item in departures" // 根据departures数据展示下拉框显示项:key="item.value":label="item.label":value="item.value"></el-option></el-select></el-form-item>// 目的站<el-form-item label="目的站" class="grid-content" prop="destination"><el-select size="mini"filterableremotedefault-first-optionallow-create placeholder=""v-model="detailInfo.destination":remote-method="getDestination":loading="loading"><el-optionv-for="item in destinations":key="item.value":label="item.label":value="item.value"></el-option></el-select></el-form-item>
methods: {getCity(query) { // 获取城市if(query !== '') { // 查询前显示loadingthis.loading = true}return searchCity({code: query}).then(res => {if(res.data.status === 200) {this.loading = false // 查询出后隐藏loadingreturn res.data.data.map(item => {// label为下拉框显示项,value为显示项对应值return {value: item.cn_name, label: item.cn_name}})}})},getDepartures(query) { // 获取始发站this.getCity(query).then(res => {this.departures = res})},getDestination(query) { // 获取目的站this.getCity(query).then(res => {this.destinations = res})}}
methods: {getProduct(query) {if(query !== '') {this.loading = true}return searchProduct({code: query}).then(res => {if(res.data.status === 200) {this.loading = falsereturn res.data.data}})},renderProduct(query) {this.getProduct(query).then(res => {this.products = res.map(item => {return {value: item.name, label: item.name}})})},fillProductAbout(query) { // 填充反写项this.getProduct(query).then(res => {if(Array.isArray(res)) {let o = res[0]if(o) {this.detailInfo.product_category = o.start_product_categorythis.detailInfo.packaging = o.pkgthis.$refs['your_category'].focus()}}})}}
无反写项时参考始发站、目的站,有反写项时参考品名
具体代码参考 src ->pages ->receive ->detail