chenrui 9 ماه پیش
والد
کامیت
d5f8d36bd7

+ 10 - 1
src/api/shopProduct.js

@@ -76,7 +76,7 @@ export const shopProductDetail = params => {
 // 商城产品 批量保存
 export const saveBatchProduct = params => {
   return axios({
-    url: '/shopProduct/saveBatchProduct',
+    url: '/shopProduct/saveBatchProductExcel',
     data: params,
     method: 'post',
     headers: {
@@ -108,3 +108,12 @@ export const shopProductUpdateStatus = params => {
     }
   })
 }
+
+// 获取类目添加的产品
+export const queryProductSnList = (params) => {
+  return axios({
+    url: 'shopProduct/queryProductSnList',
+    data: params,
+    method: 'post'
+  })
+}

+ 2 - 1
src/views/easyPassManagement/shoppingManagement/addCategoryModal.vue

@@ -121,7 +121,7 @@ export default {
       this.$refs.ruleForm.validate(valid => {
         if (valid) {
           _this.spinning = true
-          if (_this.parentData && _this.parentData.categorySn) {
+          if (_this.parentData && _this.parentData.categorySn && _this.pageType === 'addChild') {
             _this.form.parentSn = _this.parentData.categorySn
           }
           saveShopCategory(_this.form).then(res => {
@@ -144,6 +144,7 @@ export default {
     },
     // 重置
     resetAddForm () {
+      this.form.parentSn = undefined
       this.form.categoryName = ''
       this.form.sort = undefined
       this.form.iconUrl = undefined

+ 6 - 18
src/views/easyPassManagement/shoppingManagement/chooseProductsModal.vue

@@ -68,7 +68,7 @@
           size="small"
           :rowKey="(record) => record.productSn"
           rowKeyName="productSn"
-          :row-selection="{ columnWidth: 40, getCheckboxProps: record => ({ props: { disabled: !record.terminalPrice } })}"
+          :row-selection="{ columnWidth: 40, getCheckboxProps: record => ({ props: { disabled: !record.terminalPrice || record.disabledFlag } })}"
           @rowSelection="rowSelectionFun"
           :columns="columns"
           :pagination="{pageSizeOptions: ['20','50','100','200','500']}"
@@ -112,28 +112,12 @@ export default {
       type: Boolean,
       default: false
     },
-    chooseData: {// 隐藏选择的产品
+    chooseData: {// 选中的产品
       type: Array,
       default: () => {
         return []
       }
     },
-    chooseType: {// 选中的分类
-      type: Array,
-      default: () => {
-        return []
-      }
-    },
-    chooseProduct: {// 当前行选中的数据
-      type: Array,
-      default: () => {
-        return []
-      }
-    },
-    itemSn: {// 活动sn
-      type: String,
-      default: ''
-    },
     zIndex: { // 层级
       type: [String, Number],
       default: 1000
@@ -187,6 +171,10 @@ export default {
             const no = (data.pageNo - 1) * data.pageSize
             for (var i = 0; i < data.list.length; i++) {
               data.list[i].no = no + i + 1
+              // 回显禁用
+              if (this.chooseData && this.chooseData.length > 0) {
+                data.list[i].disabledFlag = this.chooseData.includes(data.list[i].productSn)
+              }
             }
             this.disabled = false
           }

+ 35 - 29
src/views/easyPassManagement/shoppingManagement/list.vue

@@ -11,12 +11,14 @@
         ref="table"
         :style="{ height: tableHeight+70+'px'}"
         size="small"
-        :rowKey="(record) => record.id"
+        :rowKey="(record) => record.categorySn"
+        rowKeyName="categorySn"
         :columns="columns"
         :pagination="false"
         :dataSource="loadDataList"
         :scroll="{ y: tableHeight+70 }"
         @expand="expandChild"
+        :expanded-row-keys.sync="expandedRowKeys"
         bordered>
         <!-- 图片 -->
         <template slot="imgs" slot-scope="text, record">
@@ -32,7 +34,7 @@
             checkedChildren="启用"
             unCheckedChildren="禁用"
             v-model="record.enableFlag"
-            @click="e=>changeFlagHandle(e,record)"/>
+            @change="e=>changeFlagHandle(e,record)"/>
           <span v-else :style="{color:(record.enableFlag?'#00aa00':'#999')}"> {{ record.enableFlag? '已启用': '已禁用' }} </span>
         </template>
         <!-- 操作 -->
@@ -48,11 +50,12 @@
             type="link"
             class="button-info"
             @click="handleEdit(record,'addChild')"
-            v-if="record.type && record.type == 'root'"
+            v-if="(record.type && record.type=='root')&&(record.shopCategoryCount==0)"
             :id="'shoppingManagementList-addChild-btn'+record.id">添加子类目</a-button>
           <a-button
             size="small"
             type="link"
+            v-if="(record.shopProductCount==0)||record.type!='root'"
             class="button-success"
             @click="handleAddProduct(record)"
             :id="'shoppingManagementList-addProduct-btn'+record.id">添加产品</a-button>
@@ -73,7 +76,7 @@
       :openModal="openCategoryModal"
       :parentData="parentData"
       @ok="handleCategoryOk"
-      @close="openCategoryModal=false"></addCategoryModal>
+      @close="closeCategory"></addCategoryModal>
   </a-card>
 </template>
 
@@ -104,7 +107,8 @@ export default {
       ],
       parentData: null, // 父级类目一行数据
       loadDataList: [], // 表格数据
-      pageType: null// 按钮类型
+      pageType: null, // 按钮类型
+      expandedRowKeys: []// 展开的类目sn合集
     }
   },
   methods: {
@@ -127,9 +131,16 @@ export default {
       this.pageType = typeVal
       this.openCategoryModal = true
     },
+    // 新增类目成功
     handleCategoryOk () {
       this.getTabData()
     },
+    // 关闭新增类目弹窗
+    closeCategory () {
+      this.pageType = null
+      this.parentData = null
+      this.openCategoryModal = false
+    },
     // 编辑  添加子类目
     handleEdit (row, typeVal) {
       this.pageType = typeVal
@@ -142,26 +153,16 @@ export default {
     // 更新状态
     changeFlagHandle (e, row) {
       const _this = this
-      const tipWord = row.status == 1 ? '禁用后,关联的产品会同步下架,确认禁用吗?' : '启用后,关联的产品不会同步上架,确认启用吗?'
-      this.$confirm({
-        title: '提示',
-        content: tipWord,
-        centered: true,
-        onOk () {
-          _this.spinning = true
-          const params = { sn: row.categorySn }
-          params.status = row.status == 1 ? '0' : '1'
-          shopCategoryUpdateStatus(params).then(res => {
-            if (res.status == 200) {
-              _this.$message.success(res.message)
-              _this.spinning = false
-            } else {
-              _this.spinning = false
-            }
-          })
-        },
-        onCancel () {
-
+      _this.spinning = true
+      const params = { categorySn: row.categorySn }
+      params.status = row.status == 1 ? '0' : '1'
+      shopCategoryUpdateStatus(params).then(res => {
+        if (res.status == 200) {
+          _this.$message.success(res.message)
+          row.enableFlag = true
+          _this.spinning = false
+        } else {
+          _this.spinning = false
         }
       })
     },
@@ -185,9 +186,9 @@ export default {
                 const pos = _this.loadDataList.findIndex(item => item.categorySn === row.categorySn)
                 _this.loadDataList.splice(pos, 1)
               } else {
-                const pos = _this.loadDataList.findIndex(item => item.categorySn === row.parentSn)
-                const indexNum = _this.loadDataList[pos].children.findIndex(con => { con.categorySn === row.categorySn })
-                _this.loadDataList[pos].children.splice(indexNum, 1)
+                const posNum = _this.loadDataList.findIndex(item => item.categorySn === row.parentSn)
+                const indexNum = _this.loadDataList[posNum].children.findIndex(con => con.categorySn === row.categorySn)
+                _this.loadDataList[posNum].children.splice(indexNum, 1)
               }
               _this.spinning = false
             } else {
@@ -205,12 +206,17 @@ export default {
         if (res.status == 200) {
           data = res.data
           for (var i = 0; i < data.length; i++) {
-            data[i].enableFlag = data[i].status === 1
+            data[i].enableFlag = data[i].status == 1
             data[i].children = []
             data[i].type = 'root'
           }
         }
         this.loadDataList = res.data
+        if (this.expandedRowKeys && this.expandedRowKeys.length > 0) {
+          this.expandedRowKeys.forEach(item => {
+            this.expandChild(true, { categorySn: item })
+          })
+        }
         this.spinning = false
       })
     },

+ 8 - 1
src/views/easyPassManagement/shoppingProducts/editProductModal.vue

@@ -47,9 +47,10 @@
             id="edit-product-hotFlag"
             placeholder="请选择是否是热销产品"
             allowClear
+            @change="handleHotProduct"
           ></v-select>
         </a-form-model-item>
-        <a-form-model-item label="热销产品优先级" prop="hotSort">
+        <a-form-model-item label="热销产品优先级" prop="hotSort" v-if="form.hotFlag==='1'">
           <a-input-number
             style="width:100%;"
             id="edit-product-money"
@@ -123,6 +124,12 @@ export default {
         }
       })
     },
+    //热销产品切换时清空数据
+    handleHotProduct(e){
+      if(e==0){
+        this.form.hotSort = ''
+      }
+    },
     //  保存
     handleSave () {
       const _this = this

+ 50 - 22
src/views/easyPassManagement/shoppingProducts/list.vue

@@ -12,7 +12,7 @@
             </a-col>
             <a-col :md="6" :sm="24">
               <a-form-item label="产品编码/原厂编码">
-                <a-input id="shoppingProductsList-queryWord" v-model.trim="queryParam.queryWord" allowClear placeholder="请输入产品编码/原厂编码"/>
+                <a-input id="shoppingProductsList-productCode" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码/原厂编码"/>
               </a-form-item>
             </a-col>
             <a-col :md="6" :sm="24">
@@ -27,7 +27,7 @@
             </a-col>
             <a-col :md="6" :sm="24">
               <a-form-item label="产品商城状态">
-                <v-select code="ENABLE_FLAG" id="shoppingProductsList-status" v-model="queryParam.status" allowClear placeholder="请选择产品商城状态"></v-select>
+                <v-select code="SHOP_PRODUCT_STATUS" id="shoppingProductsList-status" v-model="queryParam.status" allowClear placeholder="请选择产品商城状态"></v-select>
               </a-form-item>
             </a-col>
             <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
@@ -86,6 +86,20 @@
               @click="handleEdit(record)"
               class="button-info"
               :id="'chooseProductEdit-edit-btn'+record.id">编辑</a-button>
+            <a-button
+              size="small"
+              type="link"
+              @click="changeStatus('1',record)"
+              class="button-info"
+              v-if="record.status=='0'"
+              :id="'chooseProductEdit-top-btn'+record.id">上架</a-button>
+            <a-button
+              size="small"
+              type="link"
+              @click="changeStatus('0',record)"
+              class="button-info"
+              v-else
+              :id="'chooseProductEdit-bottom-btn'+record.id">下架</a-button>
             <a-button
               size="small"
               type="link"
@@ -99,6 +113,7 @@
     <!-- 添加产品 -->
     <chooseProduct
       ref="chooseProduct"
+      :chooseData="chooseDataList"
       :openModal="showProModal"
       @ok="addProductSuccess"
       @close="closeProductModal"></chooseProduct>
@@ -119,7 +134,7 @@ import productType from '@/views/common/productType.js'
 import productBrand from '@/views/common/productBrand.js'
 import chooseProduct from '@/views/easyPassManagement/shoppingManagement/chooseProductsModal'
 // 接口
-import { shopProductList, saveBatchProduct, shopProductDel, shopProductUpdateStatus } from '@/api/shopProduct'
+import { shopProductList, saveBatchProduct, shopProductDel, shopProductUpdateStatus, queryProductSnList } from '@/api/shopProduct'
 export default {
   name: 'ShoppingProductsList',
   mixins: [commonMixin],
@@ -134,24 +149,27 @@ export default {
     const _this = this
     return {
       spinning: false,
+      disabled: false, //  查询、重置按钮是否可操作
       tableHeight: 0, // 表格高度
+      // form表单label布局
       formItemLayout: {
         labelCol: { span: 6 },
         wrapperCol: { span: 16 }
       },
-      chooseTypeList: [],
-      showProModal: false,
-      productType: [],
+      showProModal: false, // 打开添加产品弹窗
+      productType: [], // 产品分类
+      chooseDataList: [], // 已选产品sn集合
+      // 查询条件
       queryParam: {
         productName: '', // 产品名称
-        queryWord: '', // 产品编码/原厂编码
+        productCode: '', // 产品编码/原厂编码
         productBrandSn: undefined, //  产品品牌
         productTypeSn1: '', //  产品一级分类
         productTypeSn2: '', //  产品二级分类
         productTypeSn3: '', //  产品三级分类
         status: undefined
       },
-      disabled: false, //  查询、重置按钮是否可操作
+      // 表头
       columns: [
         { title: '序号', dataIndex: 'no', align: 'center', width: '60px' },
         { title: '产品编码', dataIndex: 'productCode', width: '12%', align: 'center', scopedSlots: { customRender: 'productCode' } },
@@ -190,12 +208,9 @@ export default {
           return data
         })
       },
-      defaultExpandedRowKeys: [], //  树形数据默认展开项
-      openModal: false, //  新增编辑  弹框
-      nowData: null, //  当前记录数据
       openGuideModal: false, // 打开导入弹窗
       openEditModal: false, // 打开编辑弹窗
-      itemProductSn: null
+      itemProductSn: null// 当前行商城产品sn
     }
   },
   methods: {
@@ -204,7 +219,12 @@ export default {
       this.rowSelectionInfo = obj || null
     },
     // 选择产品
-    handleChooseProduct () {
+    async handleChooseProduct () {
+      // 回显已选择产品并禁用
+      const res = await queryProductSnList({})
+      if (res.status == 200) {
+        this.chooseDataList = res.data
+      }
       this.showProModal = true
     },
     // 选择产品 成功
@@ -247,12 +267,13 @@ export default {
     //  重置
     resetSearchForm () {
       this.queryParam.productName = ''
-      this.queryParam.queryWord = ''
+      this.queryParam.productCode = ''
       this.queryParam.productBrandSn = undefined
       this.queryParam.productTypeSn1 = ''
       this.queryParam.productTypeSn2 = ''
       this.queryParam.productTypeSn3 = ''
       this.queryParam.status = ''
+      this.productType = []
       this.$refs.table.refresh(true)
     },
     // 编辑
@@ -307,16 +328,21 @@ export default {
       })
     },
     // 批量上、下架
-    changeStatus (type) {
-      const row = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys
-      if (!this.rowSelectionInfo || (row.length < 1)) {
-        this.$message.warning('请在列表中进行勾选!')
-        return false
+    changeStatus (type, row) {
+      let newRow = []
+      if (!row) {
+        newRow = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys
+        if (!this.rowSelectionInfo || (newRow.length < 1)) {
+          this.$message.warning('请在列表中进行勾选!')
+          return false
+        }
+      } else {
+        newRow.push(row.shopProductSn)
       }
-      this.handleChangeStatus(type)
+      this.handleChangeStatus(type, newRow)
     },
     // 确定上、下架
-    handleChangeStatus (typeVal) {
+    handleChangeStatus (typeVal, ajaxData) {
       const _this = this
       this.$confirm({
         title: '提示',
@@ -324,7 +350,7 @@ export default {
         centered: true,
         onOk () {
           _this.spinning = true
-          shopProductUpdateStatus({ shopProductSnList: _this.rowSelectionInfo.selectedRowKeys, status: typeVal }).then(res => {
+          shopProductUpdateStatus({ shopProductSnList: ajaxData, status: typeVal }).then(res => {
             if (res.status == 200) {
               _this.$message.success(res.message)
               _this.$refs.table.clearSelected()
@@ -335,12 +361,14 @@ export default {
         }
       })
     },
+    // 初始化
     pageInit () {
       const _this = this
       this.$nextTick(() => { // 页面渲染完成后的回调
         _this.setTableH()
       })
     },
+    // 计算表格高度
     setTableH () {
       const tableSearchH = this.$refs.tableSearch.offsetHeight
       this.tableHeight = window.innerHeight - tableSearchH - 240