|
|
@@ -1,240 +1,113 @@
|
|
|
-import { getApiUrl } from '@/utils/utils'
|
|
|
-import {baseUrl, baseImgPath} from '@/config/env'
|
|
|
-import {cityGuess, getResturants, getResturantsCount, foodCategory, updateResturant, searchplace, deleteResturant} from '@/api/getData'
|
|
|
+import { getList } from '@/api/business/order'
|
|
|
+import { getResturantDetail } from '@/api/business/shop'
|
|
|
+import { getUserInfo } from '@/api/business/user'
|
|
|
+import { getAddressById } from '@/api/business/address'
|
|
|
+
|
|
|
export default {
|
|
|
- data(){
|
|
|
+ data() {
|
|
|
return {
|
|
|
- baseUrl,
|
|
|
- baseImgPath,
|
|
|
- city: {},
|
|
|
-
|
|
|
- // offset: 0,
|
|
|
- // limit: 20,
|
|
|
- count: 0,
|
|
|
- tableData: [],
|
|
|
- currentPage: 1,
|
|
|
- selectTable: {},
|
|
|
- dialogFormVisible: false,
|
|
|
- categoryOptions: [],
|
|
|
- selectedCategory: [],
|
|
|
- address: {},
|
|
|
- total:0,
|
|
|
listQuery: {
|
|
|
page: 1,
|
|
|
- limit: 20
|
|
|
+ limit: 20,
|
|
|
+ id: undefined,
|
|
|
+ restaurant_id:undefined
|
|
|
},
|
|
|
+ total: 0,
|
|
|
+ list: null,
|
|
|
+ listLoading: true,
|
|
|
+ selRow: {},
|
|
|
+ expandRowData: []
|
|
|
}
|
|
|
},
|
|
|
- created(){
|
|
|
- this.initData();
|
|
|
+ created() {
|
|
|
+ this.init()
|
|
|
},
|
|
|
-
|
|
|
methods: {
|
|
|
- async initData(){
|
|
|
- try{
|
|
|
- cityGuess().then(response =>{
|
|
|
- console.log('city',response)
|
|
|
- this.city = response.data
|
|
|
- console.log(this.city)
|
|
|
- getResturantsCount().then(response2 => {
|
|
|
- console.log(response2)
|
|
|
- this.count = response2.count;
|
|
|
- this.fetchData();
|
|
|
- })
|
|
|
- });
|
|
|
+ init() {
|
|
|
+ this.fetchData()
|
|
|
+ },
|
|
|
+ fetchData() {
|
|
|
+ this.list = []
|
|
|
+ this.listLoading = true
|
|
|
+ getList(this.listQuery).then(response => {
|
|
|
+ let list = response.data.records
|
|
|
+ list.forEach((item,index) =>{
|
|
|
+ item.index = index
|
|
|
+ })
|
|
|
+ this.list = list
|
|
|
+ console.log('list',list)
|
|
|
+ this.listLoading = false
|
|
|
+ this.total = response.data.total
|
|
|
+ })
|
|
|
+ },
|
|
|
+ search() {
|
|
|
+ this.fetchData()
|
|
|
+ },
|
|
|
+ reset() {
|
|
|
+ this.listQuery.id = ''
|
|
|
+ this.listQuery.restaurant_id = ''
|
|
|
+ this.fetchData()
|
|
|
+ },
|
|
|
+ async expandRow(row, status){
|
|
|
+ if(status.length>0) {
|
|
|
+ const restaurant = await getResturantDetail(row.restaurant_id);
|
|
|
+ const userInfo = await getUserInfo(row.user_id);
|
|
|
+ const addressInfo = await getAddressById(row.address_id);
|
|
|
+ this.list.splice(row.index, 1, {
|
|
|
+ ...row, ...{
|
|
|
+ restaurant_name: restaurant.data.name,
|
|
|
+ restaurant_address: restaurant.data.address,
|
|
|
+ address: addressInfo.data.address,
|
|
|
+ user_name: userInfo.data.username
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.expandRowData = []
|
|
|
+ this.expandRowData.push(row.index);
|
|
|
+ }else{
|
|
|
+ this.expandRowData = []
|
|
|
+ }
|
|
|
|
|
|
- // const countData = await getResturantsCount();
|
|
|
|
|
|
- }catch(err){
|
|
|
- console.log('获取数据失败', err);
|
|
|
- }
|
|
|
-},
|
|
|
-async getCategory(){
|
|
|
- try{
|
|
|
- const response = await foodCategory();
|
|
|
- const categories = response.data
|
|
|
- categories.forEach(item => {
|
|
|
- if (item.sub_categories.length) {
|
|
|
- const addnew = {
|
|
|
- value: item.name,
|
|
|
- label: item.name,
|
|
|
- children: []
|
|
|
- }
|
|
|
- item.sub_categories.forEach((subitem, index) => {
|
|
|
- if (index == 0) {
|
|
|
- return
|
|
|
- }
|
|
|
- addnew.children.push({
|
|
|
- value: subitem.name,
|
|
|
- label: subitem.name,
|
|
|
- })
|
|
|
- })
|
|
|
- this.categoryOptions.push(addnew)
|
|
|
- }
|
|
|
- })
|
|
|
- }catch(err){
|
|
|
- console.log('获取商铺种类失败', err);
|
|
|
- }
|
|
|
-},
|
|
|
-async fetchData(){
|
|
|
- console.log(111)
|
|
|
- console.log(this.city)
|
|
|
- // const {latitude, longitude} = this.city;
|
|
|
- const latitude = ''
|
|
|
- const longitude = ''
|
|
|
- getResturants({page: this.listQuery.page, limit: this.listQuery.limit}).then( response=> {
|
|
|
- console.log(response)
|
|
|
- const restaurants = response.data.records
|
|
|
- this.total = response.data.total
|
|
|
- this.tableData = [];
|
|
|
- restaurants.forEach(item => {
|
|
|
- const tableData = {};
|
|
|
- tableData.name = item.name;
|
|
|
- tableData.address = item.address;
|
|
|
- tableData.description = item.description;
|
|
|
- tableData.id = item.id;
|
|
|
- tableData.phone = item.phone;
|
|
|
- tableData.rating = item.rating;
|
|
|
- tableData.recent_order_num = item.recent_order_num;
|
|
|
- tableData.category = item.category;
|
|
|
- tableData.image_path = item.image_path;
|
|
|
- this.tableData.push(tableData);
|
|
|
-})
|
|
|
-})
|
|
|
- // const restaurants = await getResturants({latitude, longitude, page: this.listQuery.page, limit: this.listQuery.limit});
|
|
|
- // this.tableData = [];
|
|
|
- // restaurants.forEach(item => {
|
|
|
- // const tableData = {};
|
|
|
- // tableData.name = item.name;
|
|
|
- // tableData.address = item.address;
|
|
|
- // tableData.description = item.description;
|
|
|
- // tableData.id = item.id;
|
|
|
- // tableData.phone = item.phone;
|
|
|
- // tableData.rating = item.rating;
|
|
|
- // tableData.recent_order_num = item.recent_order_num;
|
|
|
- // tableData.category = item.category;
|
|
|
- // tableData.image_path = item.image_path;
|
|
|
- // this.tableData.push(tableData);
|
|
|
- // })
|
|
|
-},
|
|
|
-handleSizeChange(val) {
|
|
|
- console.log(`每页 ${val} 条`);
|
|
|
-},
|
|
|
-handleCurrentChange(val) {
|
|
|
- this.currentPage = val;
|
|
|
- this.offset = (val - 1)*this.limit;
|
|
|
- this.getResturants()
|
|
|
-},
|
|
|
-fetchNext() {
|
|
|
- this.listQuery.page = this.listQuery.page + 1
|
|
|
- this.fetchData()
|
|
|
-},
|
|
|
-fetchPrev() {
|
|
|
- this.listQuery.page = this.listQuery.page - 1
|
|
|
- this.fetchData()
|
|
|
-},
|
|
|
-fetchPage(page) {
|
|
|
- this.listQuery.page = page
|
|
|
- this.fetchData()
|
|
|
-},
|
|
|
-changeSize(limit) {
|
|
|
- this.listQuery.limit = limit
|
|
|
- this.fetchData()
|
|
|
-},
|
|
|
-handleEdit(index, row) {
|
|
|
- this.selectTable = row;
|
|
|
- this.selectTable.image = getApiUrl() + '/file/getImgStream?fileName=' + row.image_path
|
|
|
- console.log(this.selectTable)
|
|
|
- this.address.address = row.address;
|
|
|
- this.dialogFormVisible = true;
|
|
|
- this.selectedCategory = row.category.split('/');
|
|
|
- if (!this.categoryOptions.length) {
|
|
|
- this.getCategory();
|
|
|
- }
|
|
|
-},
|
|
|
-addFood(index, row){
|
|
|
- this.$router.push({ path: 'addGoods', query: { restaurant_id: row.id }})
|
|
|
-},
|
|
|
-async handleDelete(index, row) {
|
|
|
- try{
|
|
|
- const res = await deleteResturant(row.id);
|
|
|
- if (res.status == 1) {
|
|
|
- this.$message({
|
|
|
- type: 'success',
|
|
|
- message: '删除店铺成功'
|
|
|
- });
|
|
|
- this.tableData.splice(index, 1);
|
|
|
- }else{
|
|
|
- throw new Error(res.message)
|
|
|
- }
|
|
|
- }catch(err){
|
|
|
- this.$message({
|
|
|
- type: 'error',
|
|
|
- message: err.message
|
|
|
- });
|
|
|
- console.log('删除店铺失败')
|
|
|
- }
|
|
|
-},
|
|
|
-async querySearchAsync(queryString, cb) {
|
|
|
- if (queryString) {
|
|
|
- try{
|
|
|
- const cityList = await searchplace(this.city.id, queryString);
|
|
|
- if (cityList instanceof Array) {
|
|
|
- cityList.map(item => {
|
|
|
- item.value = item.address;
|
|
|
- return item;
|
|
|
+ },
|
|
|
+ getRowKeys(row){
|
|
|
+ return row.index
|
|
|
+ },
|
|
|
+ handleFilter() {
|
|
|
+ this.listQuery.page = 1
|
|
|
+ this.getList()
|
|
|
+ },
|
|
|
+ fetchNext() {
|
|
|
+ this.listQuery.page = this.listQuery.page + 1
|
|
|
+ this.fetchData()
|
|
|
+ },
|
|
|
+ fetchPrev() {
|
|
|
+ this.listQuery.page = this.listQuery.page - 1
|
|
|
+ this.fetchData()
|
|
|
+ },
|
|
|
+ fetchPage(page) {
|
|
|
+ this.listQuery.page = page
|
|
|
+ this.fetchData()
|
|
|
+ },
|
|
|
+ changeSize(limit) {
|
|
|
+ this.listQuery.limit = limit
|
|
|
+ this.fetchData()
|
|
|
+ },
|
|
|
+ clear() {
|
|
|
+ this.$confirm('确定清空数据?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ clear().then(response => {
|
|
|
+ this.$message({
|
|
|
+ message: '清空成功',
|
|
|
+ type: 'sucess'
|
|
|
+ })
|
|
|
+ this.fetchData()
|
|
|
+ })
|
|
|
+ }).catch(() => {
|
|
|
})
|
|
|
- cb(cityList)
|
|
|
- }
|
|
|
- }catch(err){
|
|
|
- console.log(err)
|
|
|
}
|
|
|
- }
|
|
|
-},
|
|
|
-addressSelect(vale){
|
|
|
- const {address, latitude, longitude} = vale;
|
|
|
- this.address = {address, latitude, longitude};
|
|
|
-},
|
|
|
-handleServiceAvatarScucess(res, file) {
|
|
|
- if (res.status == 1) {
|
|
|
- this.selectTable.image_path = res.image_path;
|
|
|
- }else{
|
|
|
- this.$message.error('上传图片失败!');
|
|
|
- }
|
|
|
-},
|
|
|
-beforeAvatarUpload(file) {
|
|
|
- const isRightType = (file.type === 'image/jpeg') || (file.type === 'image/png');
|
|
|
- const isLt2M = file.size / 1024 / 1024 < 2;
|
|
|
-
|
|
|
- if (!isRightType) {
|
|
|
- this.$message.error('上传头像图片只能是 JPG 格式!');
|
|
|
- }
|
|
|
- if (!isLt2M) {
|
|
|
- this.$message.error('上传头像图片大小不能超过 2MB!');
|
|
|
- }
|
|
|
- return isRightType && isLt2M;
|
|
|
-},
|
|
|
-async updateShop(){
|
|
|
- this.dialogFormVisible = false;
|
|
|
- try{
|
|
|
- Object.assign(this.selectTable, this.address);
|
|
|
- this.selectTable.category = this.selectedCategory.join('/');
|
|
|
- console.log(this.selectTable)
|
|
|
- updateResturant(this.selectTable).then( response=> {
|
|
|
- this.$message({
|
|
|
- type: 'success',
|
|
|
- message: '更新店铺信息成功'
|
|
|
- });
|
|
|
- this.getResturants();
|
|
|
- })
|
|
|
|
|
|
- }catch(err){
|
|
|
- console.log('更新餐馆信息失败', err);
|
|
|
- this.$message({
|
|
|
- type: 'error',
|
|
|
- message: err
|
|
|
- });
|
|
|
}
|
|
|
-},
|
|
|
-},
|
|
|
}
|