Procházet zdrojové kódy

对接产品分类

chenrui před 4 roky
rodič
revize
25ad3be126

+ 16 - 0
src/api/productType.js

@@ -16,3 +16,19 @@ export const productTypeQuery = (params) => {
     method: 'post'
   })
 }
+// 产品分类  新增/编辑
+export const productTypeSave = params => {
+  return axios({
+    url: '/productType/save',
+    data: params,
+    method: 'post'
+  })
+}
+// 产品分类  删除
+export const productTypeDel = params => {
+  return axios({
+    url: `/productType/delete/${params.sn}`,
+    data: {},
+    method: 'get'
+  })
+}

+ 31 - 11
src/views/productManagement/productCategory/editModal.vue

@@ -22,7 +22,13 @@
           {{ parentType }}
         </a-form-model-item>
         <a-form-model-item label="产品分类名称" prop="productTypeName">
-          <a-input v-model.trim="form.productTypeName" id="productCategoryEdit-name" :maxLength="30" allowClear placeholder="请输入产品分类名称(最多30个字符)" />
+          <a-input
+            v-model.trim="form.productTypeName"
+            @change="filterEmpty"
+            id="productCategoryEdit-name"
+            :maxLength="30"
+            allowClear
+            placeholder="请输入产品分类名称(最多30个字符)" />
         </a-form-model-item>
       </a-form-model>
       <div class="btn-cont">
@@ -35,7 +41,7 @@
 
 <script>
 import { STable } from '@/components'
-// import { dealerProductTypeSave } from '@/api/dealerProductType'
+import { productTypeSave } from '@/api/productType'
 export default {
   name: 'ProductCategoryEditModal',
   components: { STable },
@@ -44,7 +50,7 @@ export default {
       type: Boolean,
       default: false
     },
-    itemId: {
+    itemSn: {
       type: [Number, String],
       default: ''
     },
@@ -55,7 +61,7 @@ export default {
   },
   computed: {
     modalTit () {
-      return (this.itemId ? '编辑' : '新增') + '产品分类'
+      return (this.itemSn ? '编辑' : '新增') + '产品分类'
     }
   },
   data () {
@@ -77,15 +83,25 @@ export default {
     }
   },
   methods: {
+    filterEmpty () {
+      let str = this.form.productTypeName
+      str = str.replace(/\ +/g, '')
+      str = str.replace(/[ ]/g, '')
+      str = str.replace(/[\r\n]/g, '')
+      this.form.productTypeName = str
+    },
     //  保存
     handleSave () {
       const _this = this
       _this.$refs.ruleForm.validate(valid => {
         if (valid) {
           const formData = JSON.parse(JSON.stringify(_this.form))
-          formData.id = _this.itemId ? _this.itemId : undefined
-          formData.psn = _this.nowData && _this.nowData.psn ? _this.nowData.psn : undefined
-          dealerProductTypeSave(formData).then(res => {
+          if (_this.itemSn) { //  编辑
+            formData.productTypeSn = _this.nowData && _this.nowData.productTypeSn ? _this.nowData.productTypeSn : undefined
+          } else { //  新增子级
+            formData.parentSn = _this.nowData && _this.nowData.productTypeSn ? _this.nowData.productTypeSn : undefined
+          }
+          productTypeSave(formData).then(res => {
             if (res.status == 200) {
               _this.$message.success(res.message)
               _this.$emit('ok')
@@ -107,11 +123,15 @@ export default {
     isShow (newValue, oldValue) {
       if (!newValue) {
         this.$emit('close')
+        this.$refs.ruleForm.resetFields()
       } else {
         //  获取父级分类 名称
         if (this.nowData && this.nowData.namePaths) {
           let namePathsArr = []
           namePathsArr = this.nowData.namePaths.split(',')
+          if (this.itemSn) { //  编辑    编辑时不显示当前分类
+            namePathsArr = namePathsArr.slice(0, namePathsArr.length - 1)
+          }
           this.parentType = ''
           namePathsArr.map((item, index) => {
             this.parentType += item + ' > '
@@ -122,7 +142,7 @@ export default {
         }
       }
     },
-    itemId (newValue, oldValue) {
+    itemSn (newValue, oldValue) {
       if (this.isShow && newValue) {
         this.form.productTypeName = this.nowData && this.nowData.productTypeName ? this.nowData.productTypeName : ''
       } else {
@@ -136,11 +156,11 @@ export default {
 <style lang="less">
   .productCategoryEdit-modal{
     .ant-modal-body {
-    	padding: 40px 40px 24px;
+      padding: 40px 40px 24px;
     }
     .btn-cont {
-    	text-align: center;
-    	margin: 35px 0 10px;
+      text-align: center;
+      margin: 35px 0 10px;
     }
   }
 </style>

+ 24 - 19
src/views/productManagement/productCategory/list.vue

@@ -1,8 +1,8 @@
 <template>
   <a-card size="small" :bordered="false" class="productCategoryList-wrap">
     <!-- 操作按钮 -->
-    <div class="table-operator">
-      <a-button id="productCategoryList-add" type="primary" class="button-error" @click="handleAdd()" style="margin-top: 18px;">新增一级分类</a-button>
+    <div class="table-operator-nobor">
+      <a-button id="productCategoryList-add" type="primary" class="button-error" @click="handleAdd()">新增一级分类</a-button>
     </div>
     <!-- 列表 -->
     <s-table
@@ -14,61 +14,66 @@
       :data="loadData"
       :showPagination="false"
       :defaultExpandedRowKeys="defaultExpandedRowKeys"
+      :scroll="{ y: tableHeight }"
       bordered>
       <!-- 操作 -->
       <template slot="action" slot-scope="text, record">
         <a-button
           v-if="record.productTypeLevel<3"
           type="link"
+          class="button-success"
           size="small"
           icon="plus"
-          class="button-error"
           id="productCategory-addSubItem"
           @click="handleAdd(record)">新增子级</a-button>
         <a-button
           v-if="record.pid != 0"
           type="link"
+          class="button-info"
           size="small"
           icon="edit"
-          class="btn-edit-s"
           id="productCategory-edit"
           @click="handleEdit(record)">编辑</a-button>
         <a-button
           v-if="record.pid != 0"
           type="link"
+          class="button-error"
           size="small"
           icon="delete"
-          class="btn-del-s"
           id="productCategory-del"
           @click="handleDel(record)">删除</a-button>
       </template>
     </s-table>
     <!-- 新增/编辑产品分类 -->
-    <product-category-edit-modal :openModal="openModal" :nowData="nowData" :itemId="itemId" @ok="handleOk" @close="closeModal" />
+    <product-category-edit-modal :openModal="openModal" :nowData="nowData" :itemSn="itemSn" @ok="handleOk" @close="closeModal" />
   </a-card>
 </template>
 
 <script>
-// import { dealerProductTypeQuery, dealerProductTypeDel } from '@/api/dealerProductType'
+import { productTypeQuery, productTypeDel } from '@/api/productType'
 import { STable } from '@/components'
 import productCategoryEditModal from './editModal.vue'
 export default {
   components: { STable, productCategoryEditModal },
   data () {
     return {
+      tableHeight: 0,
       formItemLayout: {
         labelCol: { span: 6 },
         wrapperCol: { span: 16 }
       },
       columns: [
         { title: '分类名称', dataIndex: 'productTypeName', align: 'left' },
-        { title: '创建时间', dataIndex: 'createDate', align: 'center' },
-        { title: '操作', scopedSlots: { customRender: 'action' }, align: 'center' }
+        { title: '创建时间', dataIndex: 'createDate', width: 320, align: 'center' },
+        { title: '操作', scopedSlots: { customRender: 'action' }, width: 300, align: 'center' }
       ],
       // 加载数据方法 必须为 Promise 对象
       loadData: parameter => {
         this.disabled = true
-        return dealerProductTypeQuery({}).then(res => {
+        if (this.tableHeight == 0) {
+          this.tableHeight = window.innerHeight - 250
+        }
+        return productTypeQuery({}).then(res => {
           //  递归去除空children
           this.recursionFun(res.data)
           if (res.data.length > 0) {
@@ -81,17 +86,17 @@ export default {
       },
       defaultExpandedRowKeys: [], //  树形数据默认展开项
       openModal: false, //  新增编辑  弹框
-      itemId: '', //  当前id
+      itemSn: '', //  当前sn
       nowData: null //  当前记录数据
     }
   },
   methods: {
     //  新增子级
     handleAdd (row) {
-      this.itemId = null
+      this.itemSn = null
       if (row) { //  新增子级
         const nowData = row
-        nowData.psn = nowData && nowData.productTypeSn ? nowData.productTypeSn : null
+        nowData.productTypeSn = nowData && nowData.productTypeSn ? nowData.productTypeSn : null
         this.nowData = nowData
       } else { //  最高级
         this.nowData = null
@@ -100,15 +105,15 @@ export default {
     },
     //  编辑
     handleEdit (row) {
-      this.itemId = row && row.id ? row.id : null
+      this.itemSn = row && row.productTypeSn ? row.productTypeSn : null
       const nowData = row
-      nowData.psn = nowData && nowData.productTypeSn ? nowData.productTypeSn : null
+      nowData.productTypeSn = nowData && nowData.productTypeSn ? nowData.productTypeSn : null
       this.nowData = nowData
       this.openModal = true
     },
     //  关闭弹框
     closeModal () {
-      this.itemId = ''
+      this.itemSn = ''
       this.openModal = false
     },
     //  新增/编辑  成功
@@ -116,15 +121,15 @@ export default {
       this.$refs.table.refresh(true)
     },
     //  删除
-    handleDel (item) {
+    handleDel (row) {
+      console.log(row)
       const _this = this
-      _this.nowId = item.id
       _this.$confirm({
         title: '提示',
         content: '删除后原数据不可恢复,是否删除?',
         centered: true,
         onOk () {
-          dealerProductTypeDel({ id: _this.nowId }).then(res => {
+          productTypeDel({ sn: row.productTypeSn }).then(res => {
             if (res.status == 200) {
               _this.$message.success(res.message)
               _this.$refs.table.refresh()