瀏覽代碼

fix(prodInfo): backend alignment

furffico 1 年之前
父節點
當前提交
341cdc7f0c

+ 13 - 4
src/avue/form/prodinfo.ts

@@ -51,14 +51,23 @@ export default {
       label: "库存(件)",
       prop: "stockAmount",
       ...number_input_props("请输入库存数"),
+      // }, {
+      //   label: "售出(件)",
+      //   prop: "soldAmount",
+      //   ...number_input_props("请输入售出量"),
+      row: true,
+    }, {
+      label: "商品类型",
+      prop: "kind",
+      span: 8,
     }, {
-      label: "售出(件)",
-      prop: "soldAmount",
-      ...number_input_props("请输入售出量"),
+      label: "商品平台",
+      prop: "platform",
+      span: 8,
       row: true,
     }, {
       label: "商品分类",
-      prop: "kind",
+      prop: "goodsTypeList",
       formslot: true,
       span: 24,
       row: true,

+ 5 - 0
src/utils/currency.ts

@@ -0,0 +1,5 @@
+
+// 因为数据库表内价格是以分为单位的整数,因此在展示与请求时需要转换
+// 以下为转换函数
+export const database2real = (n: number) => n / 100
+export const real2database = (n: number) => n * 100

+ 3 - 3
src/utils/formatters.ts

@@ -1,4 +1,4 @@
+import { database2real } from "./currency"
 
-
-export const currencyFormatter = (v:number) => "¥"+v.toFixed(2)
-export const row_currencyFormatter = (_:any, v:number|null) => v?("¥"+v.toFixed(2)):"-"
+export const currencyFormatter = (v: number) => "¥" + database2real(v).toFixed(2)
+export const row_currencyFormatter = (_: any, v: number | null) => v ? ("¥" + database2real(v).toFixed(2)) : "-"

+ 32 - 3
src/utils/httpx.ts

@@ -1,7 +1,13 @@
-import axios from 'axios'
+import axios, { AxiosInstance } from 'axios'
 import { Message } from 'element-ui'
 
-export const httpx = axios.create({
+const BASEURL = process.env.VUE_APP_BASE_API || ""
+
+interface Utilities {
+  makeurl(path: string, query?: Record<string, any>): string
+}
+
+const httpx_request = axios.create({
   timeout: 1000 * 5,
   // withCredentials: true,
   headers: {
@@ -9,11 +15,34 @@ export const httpx = axios.create({
   }
 })
 
+const httpx_utility: Utilities = {
+  makeurl(path, query = {}): string {
+    if (!query) {
+      return BASEURL + path
+    } else {
+      const query_str = new URLSearchParams(query).toString()
+      return BASEURL + path + "?" + query_str
+    }
+  }
+}
+
+export const httpx = Object.assign(httpx_request, httpx_utility)
+
 httpx.interceptors.response.use(
   (response) => {
+    console.log(response.status, response.data)
     if (response.data.code >= 0) {
       response.statusText = response.data.msg;
       response.data = response.data.data;
+      if ((response.data?.retCode || "0000") !== "0000") {
+        //! 如果后端能更规范一些就好了
+        Message({
+          message: response.data.retMsg,
+          type: 'error',
+          duration: 1500,
+          customClass: 'element-error-message-zindex',
+        })
+      }
       return response;
     } else {
       Message({
@@ -33,7 +62,7 @@ httpx.interceptors.response.use(
           duration: 1500,
           customClass: 'element-error-message-zindex'
         })
-                break
+        break
       case 401:
         // clearLoginInfo()
         // router.push({ name: 'login' })

+ 0 - 1
src/views/main-sidebar.vue

@@ -63,7 +63,6 @@ export default {
   methods: {
     // 路由操作
     routeHandle(route) {
-      console.log(route)
       if (route.meta.isTab) {
         // tab选中, 不存在先添加
         var tab = this.mainTabs.filter(item => item.name === route.name)[0]

+ 70 - 8
src/views/modules/prod/prodInfo.vue

@@ -1,7 +1,8 @@
 <template>
   <avue-form :option="option" v-model="form" @submit="onSubmit">
-    <template slot="kind">
-      <el-transfer v-model="form.kind" filterable :data="categories_selections" :titles="['备选项', '已选项']"></el-transfer>
+    <template slot="goodsTypeList">
+      <el-transfer v-model="form.goodsTypeList" filterable :data="categories_selections"
+        :titles="['备选项', '已选项']"></el-transfer>
     </template>
   </avue-form>
 </template>
@@ -11,6 +12,8 @@ import Vue from 'vue'
 import httpx, { AxiosResponse } from '@/utils/httpx'
 import formOption from "@/avue/form/prodinfo"
 import { ICategory } from '@/utils/vo'
+import { isInteger } from 'lodash'
+import { database2real, real2database } from "@/utils/currency"
 // import TransferBox from '@/components/transfer-box'
 
 interface ISelection {
@@ -29,25 +32,64 @@ export default Vue.extend({
         price: 0,
         deliverPrice: 0,
         stockAmount: 0,
-        soldAmount: 0,
-        cover: "",
-        kind: [] as number[],
+        // soldAmount: 0,
+        cover: [] as string[],
+        kind: "",
+        platform: "",
+        goodsTypeList: [] as number[],
+        adminId: null,
       },
       option: formOption,
       categories: [] as ICategory[],
+      new: false,
+      id: 0,
     }
   },
   // components: {
   //   TransferBox
   // },
-
   mounted() {
     this.getCategoryList("")
+    const id_str = this.$route.params.id
+    const id = parseInt(id_str)
+    if (isNaN(id) || !isInteger(id)) {
+      if (id_str === "new") {
+        this.new = true
+      } else {
+        this.notFound()
+      }
+    } else {
+      this.new = false
+      this.id = id
+      httpx.post(
+        httpx.makeurl("/goods/editGood"),
+        id
+      ).then(({ data }) => {
+        if ((data?.goodList?.length || 0) === 0) {
+          this.notFound()
+        }
+        const item = data.goodList[0]
+        const categories = data?.goodsGoodsTypesEntityList || []
+        this.form = {
+          name: item.name,
+          desc: item.desc,
+          price: database2real(item.price),  // 数据库内单位为分
+          deliverPrice: database2real(item.deliverPrice),  // 数据库内单位为分
+          stockAmount: item.stockAmount,
+          // soldAmount: item.soldAmount,
+          platform: item.platform,
+          cover: [item.cover],
+          kind: item.kind,
+          goodsTypeList: categories,
+          adminId: item.adminId,
+        }
+      })
+    }
   },
 
   methods: {
     getCategoryList(name: string = "") {
-      return httpx.post("/goodsTypes/queryGoodsTypeList", {
+      return httpx.post(httpx.makeurl("/goodsTypes/queryGoodsTypeList"), {
         name: name, limit: 1000, page: 1
       }).then(({ data }: AxiosResponse<{ goodsTypeList: ICategory[], total: number }>) => {
         this.categories = data.goodsTypeList
@@ -56,9 +98,29 @@ export default Vue.extend({
     // @ts-ignore
     onSubmit(form: typeof this.form, done: Function) {
       console.log(form)
-      // TODO
+      const path = this.new ? "/goods/addGood" : "/goods/updateGood"
+      const id_form: { id?: number } = this.new ? {} : { id: this.id }
+      const data = Object.assign(form, id_form)
+      data.price = real2database(data.price)
+      data.deliverPrice = real2database(data.deliverPrice)
+      // @ts-ignore
+      data.cover = data.cover[0] || ""
+
+      console.log(data)
+
+      httpx.post(path, data).then((data) => {
+        // TODO: AddGood 返回新项目id
+        this.$message({
+          message: '操作成功',
+          type: 'success',
+          duration: 1500
+        })
+      })
       done()
     },
+    notFound() {
+      this.$router.replace("/404")
+    }
   },
 
   computed: {

+ 32 - 32
src/views/modules/prod/prodList.vue

@@ -4,8 +4,8 @@
     <template slot="menuLeft">
       <el-button type="primary" icon="el-icon-plus" size="small" v-if="isAuth('shop:pickAddr:save')"
         @click.stop="addOrUpdateHandle()">新增</el-button>
-      <el-button type="danger" @click="deleteHandle()" size="small" v-if="isAuth('shop:pickAddr:delete')"
-        :disabled="dataListSelections.length <= 0">批量删除</el-button>
+      <!--el-button type="danger" @click="deleteHandle()" size="small" v-if="isAuth('shop:pickAddr:delete')"
+        :disabled="dataListSelections.length <= 0">批量删除</el-button-->
     </template>
 
     <template slot-scope="scope" slot="menu">
@@ -20,6 +20,8 @@
 <script>
 import { tableOption } from '@/avue/crud/prodList.js'
 import Axios from 'axios'
+import httpx from '@/utils/httpx'
+
 export default {
   data() {
     return {
@@ -45,15 +47,14 @@ export default {
     // 获取数据列表
     getDataList(page, params, done) {
       this.dataListLoading = true
-      Axios.post(this.$http.adornUrl('/goods/queryGoodList'), {
+      httpx.post(httpx.makeurl('/goods/queryGoodList'), {
         name: params?.name || "",
         limit: page == null ? this.page.pageSize : page.pageSize,
         page: page == null ? this.page.currentPage : page.currentPage,
       }).then(({ data }) => {
-        console.log(data)
-        const items = data.data.goodList
+        const items = data.goodList
         this.dataList = items
-        // this.page.total = data.total
+        this.page.total = data.total
         this.dataListLoading = false
         if (done) {
           done()
@@ -67,9 +68,8 @@ export default {
         type: 'warning'
       }).then(() => {
         console.log(id)
-        Axios.post("/goods/deleteGood", { id }
+        httpx.post("/goods/deleteGood", { id }
         ).then(({ data }) => {
-          console.log(data)
           this.$message({
             message: '操作成功',
             type: 'success',
@@ -89,30 +89,30 @@ export default {
       })
     },
     // 删除和批量删除
-    deleteHandle(id) {
-      let prodIds = this.getSeleProdIds()
-      if (id) {
-        prodIds.push(id)
-      }
-      this.$confirm(`确定进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(() => {
-        this.$http({
-          url: this.$http.adornUrl(`/prod/prod`),
-          method: 'delete',
-          data: this.$http.adornData(prodIds, false)
-        }).then(({ data }) => {
-          this.getDataList(this.page)
-          this.$message({
-            message: '操作成功',
-            type: 'success',
-            duration: 1500
-          })
-        })
-      })
-    },
+    // deleteHandle(id) {
+    // let prodIds = this.getSeleProdIds()
+    // if (id) {
+    //   prodIds.push(id)
+    // }
+    // this.$confirm(`确定进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
+    //   confirmButtonText: '确定',
+    //   cancelButtonText: '取消',
+    //   type: 'warning'
+    // }).then(() => {
+    //   this.$http({
+    //     url: this.$http.adornUrl(`/prod/prod`),
+    //     method: 'delete',
+    //     data: this.$http.adornData(prodIds, false)
+    //   }).then(({ data }) => {
+    //     this.getDataList(this.page)
+    //     this.$message({
+    //       message: '操作成功',
+    //       type: 'success',
+    //       duration: 1500
+    //     })
+    //   })
+    // })
+    // },
     // 条件查询
     searchChange(params, done) {
       this.getDataList(this.page, params, done)