lilei vor 1 Jahr
Ursprung
Commit
19d00a7144

+ 39 - 0
src/api/dealer.js

@@ -218,3 +218,42 @@ export const getDealerListInfo = (params) => {
     }
   })
 }
+
+// 经销商差价分配列表
+export const dealerUpsList = (params) => {
+  const url = `/dealerUps/queryPage/${params.pageNo}/${params.pageSize}`
+  delete params.pageNo
+  delete params.pageSize
+  return axios({
+    url: url,
+    data: params,
+    method: 'post',
+    headers:{
+      'module': encodeURIComponent('经销商差价设置列表')
+    }
+  })
+}
+
+// 差价品类列表 
+export const dealerUpsPlQuery = (params) => {
+  return axios({
+    url: `/dealerUps/queryWaitingData`,
+    data: params,
+    method: 'post',
+    headers:{
+      'module': encodeURIComponent('经销商差价设置品类列表')
+    }
+  })
+}
+
+// 差价设置保存
+export const dealerUpsCreate = (params) => {
+  return axios({
+    url: `/dealerUps/create`,
+    data: params,
+    method: 'post',
+    headers:{
+      'module': encodeURIComponent('经销商差价设置保存')
+    }
+  })
+}

+ 1 - 1
src/views/allocationManagement/transferReturn/list.vue

@@ -161,7 +161,7 @@ import { STable, VSelect } from '@/components'
 import basicInfoModal from './basicInfoModal.vue'
 import rangeDate from '@/views/common/rangeDate.vue'
 import auditModal from '@/views/common/auditModal.vue'
-import { allocateReturnQueryPage, allocateReturnAudit, allocateReturnDelete, allocateReturnExport } from '@/api/allocateReturn'
+import { allocateReturnQueryPage, allocateReturnAudit, allocateReturnDelete } from '@/api/allocateReturn'
 import AllocateType from '@/views/common/allocateType.js'
 import warehouse from '@/views/common/chooseWarehouse.js'
 import customerService from '@/views/common/customerService'

+ 15 - 0
src/views/common/custList.vue

@@ -47,6 +47,16 @@ export default {
     dealerLevel: { // 商户级别
       type: String,
       default: undefined
+    },
+    // 过滤该类别1
+    notDealerType: {
+      type: Array,
+      default: function () { return [] }
+    },
+    // 过滤该sn
+    notDealerSn: {
+      type: Array,
+      default: function () { return [] }
     }
   },
   data () {
@@ -83,6 +93,11 @@ export default {
           return
         }
         this.data = res.data && res.data.list ? res.data.list : []
+        const notSn = []
+        this.notDealerSn.map(item => { notSn.push(item.parentDealerSn) })
+        this.data = this.data.filter(item => item.dealerType1 && !this.notDealerType.includes(item.dealerType1))
+        console.log(notSn)
+        this.data = this.data.filter(item => !notSn.includes(item.dealerSn))
         this.fetching = false
       })
     },

+ 1 - 1
src/views/dealerManagement/merchantInfoManagement/list.vue

@@ -85,7 +85,7 @@
           <template slot="action" slot-scope="text, record">
             <a-button size="small" type="link" class="button-warning" v-if="record.auditState == 'WAIT' && $hasPermissions('B_merchantInfo_audit')" @click="handleAudit(record)" >审核</a-button>
             <a-button size="small" type="link" class="button-info" v-if="$hasPermissions('B_merchantInfo_cooperation')" @click="handleCooperation(record)" >合作设置</a-button>
-            <!-- <a-button size="small" type="link" class="button-primary" v-if="$hasPermissions('B_merchantInfo_level')" @click="handleLevel(record)">级别设置</a-button> -->
+            <a-button size="small" type="link" class="button-primary" v-if="$hasPermissions('B_merchantInfo_level')" @click="handleLevel(record)">级别设置</a-button>
             <a-button size="small" type="link" class="button-info" v-if="$hasPermissions('B_merchantInfo_edit')" @click="handleEdit(record)">编辑</a-button>
             <br>
             <a-button size="small" type="link" class="button-error" v-if="record.auditState != 'WAIT'" @click="handlePriceSpread(record)">差价</a-button>

+ 66 - 37
src/views/dealerManagement/rebateBinding/categoryList.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="categoryList-wrap">
-    <div ref="tableSearch" v-if="!showEmpty" class="table-page-search-wrapper">
+    <div ref="tableSearch" v-if="showTable" class="table-page-search-wrapper">
       <a-form-model
         ref="ruleForm"
         class="form-model-con"
@@ -8,17 +8,26 @@
         :model="queryParam"
         @keyup.enter.native="handleSearch">
         <a-row :gutter="15">
-          <a-col :md="8" :sm="24">
+          <a-col :md="6" :sm="24">
+            <a-form-item label="品牌分类">
+              <v-select
+                code="BRAND_TYPE"
+                v-model="queryParam.productBrandType"
+                allowClear
+                placeholder="请选择品牌分类"></v-select>
+            </a-form-item>
+          </a-col>
+          <a-col :md="6" :sm="24">
             <a-form-model-item label="品牌">
               <ProductBrand v-model="queryParam.productBrandSn"></ProductBrand>
             </a-form-model-item>
           </a-col>
-          <a-col :md="8" :sm="24">
+          <a-col :md="6" :sm="24">
             <a-form-model-item label="产品分类">
               <ProductType placeholder="请选择产品分类" @change="changeProductType" v-model="productType"></ProductType>
             </a-form-model-item>
           </a-col>
-          <a-col :md="8" :sm="24" style="margin-bottom: 10px;">
+          <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
             <a-button type="primary" @click="handleSearch">查询</a-button>
             <a-button style="margin-left: 5px" @click="resetSearchForm">重置</a-button>
           </a-col>
@@ -28,6 +37,7 @@
 
     <a-spin :spinning="spinning" tip="Loading...">
       <ve-table
+        v-show="!showEmpty"
         border-y
         :scroll-width="0"
         :max-height="tableHeight"
@@ -48,14 +58,15 @@
 
 <script>
 import { commonMixin } from '@/utils/mixin'
-import { waitDispatchDetailAllList } from '@/api/waitDispatchDetail'
+import { VSelect } from '@/components'
+import { dealerUpsPlQuery } from '@/api/dealer'
 import { Empty } from 'ant-design-vue'
 import ProductBrand from '@/views/common/productBrand.js'
 import ProductType from '@/views/common/productType.js'
 export default {
   name: 'DetailProductList',
   mixins: [commonMixin],
-  components: { ProductType, ProductBrand },
+  components: { VSelect, ProductType, ProductBrand },
   props: {
     newLoading: {
       type: Boolean,
@@ -65,9 +76,9 @@ export default {
       type: [String, Number],
       default: '300'
     },
-    showHeader: {
+    showTable: {
       type: Boolean,
-      default: true
+      default: false
     }
   },
   data () {
@@ -95,11 +106,13 @@ export default {
       selectedRowKeys: [],
       productType: [],
       queryParam: { //  查询条件
+        productBrandType: undefined,
         productBrandSn: undefined,
         productTypeSn1: undefined,
         productTypeSn2: undefined,
         productTypeSn3: undefined
-      }
+      },
+      dealerSn: undefined
     }
   },
   computed: {
@@ -119,12 +132,12 @@ export default {
     },
     columns () {
       const arr = [
-        { title: '', field: '', key: 'acheck', width: 60, type: 'checkbox', align: 'center' },
         // { title: '序号', field: 'no', key: 'a', width: 60, align: 'center', operationColumn: false },
-        { title: '品牌', field: 'productCode', key: 'b', width: 150, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
-        { title: '一级分类', field: 'warehouseName', key: 'e', width: 150, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
-        { title: '二级分类', field: 'productOrigUnit', width: 150, key: 'i', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
-        { title: '三级分类', field: 'productName', width: 150, key: 'm', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } }
+        { title: '', field: '', key: 'acheck', width: 40, type: 'checkbox', align: 'center' },
+        { title: '品牌', field: 'productBrandName', key: 'b', width: 100, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
+        { title: '一级分类', field: 'productTypeName1', key: 'e', width: 180, align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
+        { title: '二级分类', field: 'productTypeName2', width: 180, key: 'i', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } },
+        { title: '三级分类', field: 'productTypeName3', width: 180, key: 'm', align: 'center', operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--' } }
       ]
       return arr
     }
@@ -132,7 +145,11 @@ export default {
   methods: {
     // 查询品类列表
     handleSearch () {
-
+      if (this.detailData && this.detailData.upsPriceLevel && this.detailData.upsDealerSn) {
+        this.searchTable()
+      } else {
+        this.$message.info('请选择上级经销商及其价格级别')
+      }
     },
     //  产品分类  change
     changeProductType (val, opt) {
@@ -142,6 +159,7 @@ export default {
     },
     // 重置查询筛选表单
     resetSearchForm () {
+      this.queryParam.productBrandType = undefined
       this.queryParam.productBrandSn = undefined
       this.queryParam.productTypeSn1 = undefined
       this.queryParam.productTypeSn2 = undefined
@@ -149,7 +167,7 @@ export default {
       this.productType = []
       this.dataSource = []
       this.clearSelectTable()
-      this.searchTable()
+      this.handleSearch()
     },
     // 清空选项
     clearSelectTable () {
@@ -162,44 +180,55 @@ export default {
     },
     // 全选行
     selectedAllChange ({ isSelected, selectedRowKeys }) {
-      // console.log(isSelected, selectedRowKeys);
+      // console.log(isSelected, selectedRowKeys)
       this.selectedRowKeys = selectedRowKeys
     },
+    // 获取已选数据
+    getChooseData () {
+      const result = []
+      if (this.selectedRowKeys.length) {
+        const rows = this.dataSource.filter(item => this.selectedRowKeys.includes(item.id))
+        if (rows) {
+          rows.map(item => {
+            result.push({
+              dealerSn: item.dealerSn,
+              priceLevel: item.priceLevel,
+              parentScopeSn: item.dealerScopeSn,
+              productBrandSn: item.productBrandSn,
+              productTypeSn1: item.productTypeSn1,
+              productTypeSn2: item.productTypeSn2,
+              productTypeSn3: item.productTypeSn3
+            })
+          })
+        }
+      }
+      console.log(result)
+      return result
+    },
     async searchTable () {
       this.selectedRowKeys = []
       this.disableSelectedRowKeys = []
       this.dataSource = []
       this.disabled = true
       this.spinning = true
-      const params = this.queryParam
-
-      // 带下推产品
-      const listData = await waitDispatchDetailAllList(params).then(res => res.data)
+      const params = { ...this.detailData }
+      params.dealerScope = { dealerSn: this.dealerSn, ...this.queryParam }
+      console.log(params)
+      // 品类列表
+      const listData = await dealerUpsPlQuery(params).then(res => res.data)
       this.dataSource = listData
       // 格式化数据
-      let f = 0
       this.dataSource.map((item, i) => {
-        if (item.id.indexOf('promo-') >= 0) { f = f - 1 }
-        item.no = i + 1 + f
-        const productCode = (item.productEntity && item.productEntity.code) || (item.dealerProductEntity && item.dealerProductEntity.code)
-        const productName = (item.productEntity && item.productEntity.name) || (item.dealerProductEntity && item.dealerProductEntity.name)
-        const productOrigCode = (item.productEntity && item.productEntity.origCode) || (item.dealerProductEntity && item.dealerProductEntity.origCode)
-        const productOrigUnit = (item.productEntity && item.productEntity.unit) || (item.dealerProductEntity && item.dealerProductEntity.unit)
-        const warehouseName = item.dispatchBill && item.dispatchBill.warehouseName || ''
-        item.productCode = productCode || '--'
-        item.productName = productName || '--'
-        item.productOrigCode = productOrigCode == ' ' ? '--' : productOrigCode
-        item.productOrigUnit = productOrigUnit || '--'
-        item.warehouseName = warehouseName || '--'
+        item.no = i + 1
       })
       this.showEmpty = this.dataSource.length <= 0
-      this.tableHeight = (this.showEmpty ? 300 : this.maxHeight) + 'px'
+      this.tableHeight = (this.showEmpty ? 0 : this.maxHeight) + 'px'
       this.spinning = false
       this.disabled = false
     },
-    pageInit (productForm, detailData) {
-      this.productForm = Object.assign(this.productForm, productForm)
+    pageInit (detailData, dealerSn) {
       this.detailData = detailData
+      this.dealerSn = dealerSn
       // 获取列表
       this.resetSearchForm()
     }

+ 17 - 10
src/views/dealerManagement/rebateBinding/list.vue

@@ -29,9 +29,9 @@
                   <ProductType placeholder="请选择产品分类" @change="changeProductType" v-model="productType"></ProductType>
                 </a-form-model-item>
               </a-col>
-              <a-col :md="6" :sm="24">
+              <a-col :md="6" :sm="24" v-if="!isTeyue">
                 <a-form-model-item label="价格级别">
-                  <v-select code="DEALER_GOODS_TYPE" v-model="queryParam.goodsType" allowClear placeholder="请选择类型"></v-select>
+                  <v-select code="PRICE_LEVEL" :notIn="['SPECIAL']" v-model="queryParam.priceLevel" allowClear placeholder="请选择价格级别"></v-select>
                 </a-form-model-item>
               </a-col>
               <a-col :md="6" :sm="24">
@@ -41,7 +41,7 @@
               </a-col>
               <a-col :md="6" :sm="24">
                 <a-form-model-item label="差价归属方">
-                  <v-select code="DEALER_GOODS_TYPE" v-model="queryParam.goodsType" allowClear placeholder="请选择差价归属方"></v-select>
+                  <v-select code="REBATE_PARENT_TYPE" ref="rpType" v-model="queryParam.rebateParentType" allowClear placeholder="请选择差价归属方"></v-select>
                 </a-form-model-item>
               </a-col>
               <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
@@ -76,15 +76,14 @@
     </a-spin>
 
     <!-- 差价设置 -->
-    <priceDiffModal :openModal="openModal" @close="openModal=false"></pricediffmodal>
+    <priceDiffModal ref="priceDiffModal" :openModal="openModal" @close="openModal=false"></pricediffmodal>
   </div>
 </template>
 
 <script>
 import { commonMixin } from '@/utils/mixin'
 import { STable, VSelect } from '@/components'
-import { dealerScopeList } from '@/api/dealerScope'
-import { dealerDetailBySn } from '@/api/dealer'
+import { dealerDetailBySn, dealerUpsList } from '@/api/dealer'
 import ProductType from '@/views/common/productType.js'
 import ProductBrand from '@/views/common/productBrand.js'
 import priceDiffModal from './priceDiffModal.vue'
@@ -113,7 +112,7 @@ export default {
       loadData: parameter => {
         this.disabled = true
         this.spinning = true
-        return dealerScopeList(Object.assign(parameter, this.queryParam, { dealerSn: this.$route.params.sn })).then(res => {
+        return dealerUpsList(Object.assign(parameter, this.queryParam, { dealerSn: this.$route.params.sn })).then(res => {
           let data
           if (res.status == 200) {
             data = res.data
@@ -131,7 +130,8 @@ export default {
       detail: null,
       productType: [],
       queryParam: { //  查询条件
-        rebateDealerSn: undefined,
+        rebateParentType: undefined,
+        priceLevel: undefined,
         productBrandSn: undefined,
         productTypeSn1: undefined,
         productTypeSn2: undefined,
@@ -140,6 +140,11 @@ export default {
       }
     }
   },
+  computed: {
+    isTeyue () {
+      return this.detail && this.detail.dealerType1 == 'special'
+    }
+  },
   methods: {
     // 返回
     handleBack () {
@@ -158,24 +163,26 @@ export default {
     // 重置表单
     resetSearchForm () {
       this.queryParam.dealerName = ''
+      this.queryParam.rebateParentType = undefined
+      this.queryParam.priceLevel = undefined
       this.queryParam.productBrandSn = undefined
       this.queryParam.productTypeSn1 = undefined
       this.queryParam.productTypeSn2 = undefined
       this.queryParam.productTypeSn3 = undefined
       this.productType = []
-      this.queryParam.rebateDealerSn = undefined
       this.$refs.table.refresh(true)
     },
     // 打开关联弹框
     openGlModal () {
       this.openModal = true
+      this.$refs.priceDiffModal.setData(this.$refs.rpType.getOptionDatas(), this.$route.params.sn, this.detail)
     },
     // 编辑
     handleEdit (row) {
       this.openModal = true
     },
     handleDisassociate (val) {
-      this.queryParam.rebateDealerSn = val ? val.key : ''
+      this.queryParam.rebateParentType = val ? val.key : ''
     },
     // 详情编辑
     getDetail () {

+ 223 - 75
src/views/dealerManagement/rebateBinding/priceDiffModal.vue

@@ -10,7 +10,7 @@
     @cancel="isShow=false"
     :width="960">
     <a-spin :spinning="spinning" tip="Loading...">
-      <div>
+      <div style="min-height:100px;">
         <a-form-model
           id="dealerAccountEdit-form"
           ref="ruleForm"
@@ -19,79 +19,96 @@
           :label-col="formItemLayout.labelCol"
           :wrapper-col="formItemLayout.wrapperCol"
         >
-          <a-form-model-item label="差价归属方" prop="cjgsf">
+          <!-- <a-form-model-item label="差价归属方" prop="rebateParentType">
             <a-row :gutter="10">
               <a-col :span="17">
                 <a-select
-                  v-model="form.cjgsf"
+                  v-model="form.rebateParentType"
+                  :disabled="detailData&&detailData.dealerType1 == 'special'"
                   placeholder="请选择差价归属方"
                   mode="multiple"
-                  allowClear
                   @change="cjgsgChange"
                   style="width: 100%">
-                  <a-select-option v-for="item in cjgsfList" :key="item.code" :value="item.code">{{ item.name }}</a-select-option>
+                  <a-select-option v-for="item in cjgsfList" :key="item.code" :value="item.code">{{ item.dispName }}</a-select-option>
                 </a-select>
               </a-col>
               <a-col :span="6">
               </a-col>
             </a-row>
-          </a-form-model-item>
-          <a-form-model-item label="上级经销商" v-if="form.cjgsf.indexOf('0')>=0">
+          </a-form-model-item> -->
+          <a-form-model-item label="上级经销商" required>
             <a-row :gutter="10">
-              <a-col :span="13">
-                <custList ref="custList" @change="custChange" placeholder="请输入经销商名称搜索"></custList>
+              <a-col :span="17">
+                <custList ref="custList" :notDealerSn="notZdDealer" :notDealerType="['special']" @change="custSupChange" placeholder="请输入经销商名称搜索"></custList>
               </a-col>
-              <a-col :span="5">
-                <v-select code="DEALER_GOODS_TYPE" allowClear placeholder="请选择价格类型"></v-select>
+              <a-col :span="4">
+                <a-input-number :min="0" :max="100" v-model="parentAllotRate" @change="rateSupChange" placeholder="请输入比例"/> %
               </a-col>
-              <a-col :span="4" v-if="showPercent||showPercent1">
-                <a-input-number :min="0" :max="100" placeholder="请输入比例"/> %
+              <a-col :span="2" v-if="zdDealearList.length==0">
+                <a-button
+                  type="primary"
+                  ghost
+                  @click="addItem()"
+                >添加指定</a-button>
               </a-col>
             </a-row>
           </a-form-model-item>
-          <a-form-model-item label="指定经销商" v-if="form.cjgsf.indexOf('1')>=0">
+          <a-form-model-item label="指定经销商" v-if="zdDealearList.length">
             <a-row :gutter="10" v-for="(item,index) in zdDealearList" :key="item.id">
-              <a-col :span="13">
-                <custList ref="custList" @change="custChange" placeholder="请输入经销商名称搜索"></custList>
-              </a-col>
-              <a-col :span="5">
-                <v-select code="DEALER_GOODS_TYPE" allowClear placeholder="请选择价格类型"></v-select>
+              <a-col :span="17">
+                <custList :ref="'custList'+index" :notDealerSn="notZdDealer" @change="(v)=>custChange(v,index)" placeholder="请输入经销商名称搜索"></custList>
               </a-col>
-              <a-col :span="4" v-if="showPercent||showPercent1">
-                <a-input-number :min="0" :max="100" placeholder="请输入比例"/> %
+              <a-col :span="4">
+                <a-input-number :min="0" :max="100" v-model="item.allotRate" @change="(v)=>rateChange(v,index)" placeholder="请输入比例"/> %
               </a-col>
               <a-col :span="2">
-                <a-button @click="addOrDel(item,index)" size="small" shape="circle" :icon="index==zdDealearList.length-1?'plus':'minus'" style="margin-left: 10px;" />
+                <a-button
+                  style="margin-right:5px;"
+                  v-if="index==zdDealearList.length-1 && zdDealearList.length<3"
+                  @click="addItem(item,index)"
+                  title="添加"
+                  size="small"
+                  shape="circle"
+                  icon="plus" />
+                <a-button
+                  @click="delItem(item,index)"
+                  type="primary"
+                  title="删除"
+                  size="small"
+                  shape="circle"
+                  ghost
+                  icon="minus"/>
               </a-col>
             </a-row>
           </a-form-model-item>
-          <a-form-model-item label="箭冠总公司" v-if="form.cjgsf.indexOf('2')>=0">
+          <a-form-model-item label="箭冠总公司">
             <a-row :gutter="10">
-              <a-col :span="13">
+              <a-col :span="17">
                 <a-input value="箭冠总公司" disabled />
               </a-col>
-              <a-col :span="5">
-                <v-select code="DEALER_GOODS_TYPE" allowClear placeholder="请选择价格类型"></v-select>
-              </a-col>
-              <a-col :span="4" v-if="showPercent">
-                <a-input-number :min="0" :max="100" placeholder="请输入比例"/> %
+              <a-col :span="4">
+                <a-input-number :min="0" :max="100" v-model="hAllotRate" @change="rateHChange" placeholder="请输入比例"/> %
               </a-col>
             </a-row>
           </a-form-model-item>
         </a-form-model>
       </div>
-      <div style="padding:10px 10px 10px 90px;">
-        <div style="padding-bottom:10px;">选择品类:</div>
-        <!-- 品类表格 -->
-        <categoryList ref="categoryList"></categoryList>
+      <div style="padding:10px 10px 10px 40px;">
+        <div style="padding-bottom:10px;">
+          <span style="color:red;">*</span> 添加品类:
+          <a-radio-group name="radioGroup">
+            <a-radio :value="1">全选</a-radio>
+            <a-radio :value="2">自主品牌</a-radio>
+            <a-radio :value="3">代理品牌</a-radio>
+          </a-radio-group>
+        </div>
       </div>
       <div class="btn-cont">
         <a-button size="large" @click="isShow = false" style="font-size: 12px;">取消</a-button>
         <a-button
           size="large"
           type="primary"
-          class="button-primary"
-          style="margin-left: 50px;"
+          style="margin-left: 30px;"
           @click="handleSave"
         >确定</a-button>
       </div>
@@ -102,11 +119,12 @@
 <script>
 import custList from '@/views/common/custList.vue'
 import { VSelect } from '@/components'
-import categoryList from './categoryList.vue'
+import { dealerUpsCreate } from '@/api/dealer'
+import { cloneObj } from '@/libs/tools'
 
 export default {
   name: 'PriceDiffModal',
-  components: { VSelect, custList, categoryList },
+  components: { VSelect, custList },
   props: {
     openModal: { //  弹框显示状态
       type: Boolean,
@@ -119,83 +137,213 @@ export default {
       isShow: this.openModal, //  是否打开弹框
       title: '差价设置',
       formItemLayout: {
-        labelCol: { span: 4 },
-        wrapperCol: { span: 18 }
+        labelCol: { span: 3 },
+        wrapperCol: { span: 20 }
       },
       form: {
         dealerSn: undefined,
-        cjgsf: []
+        rebateParentType: [], // 差价归属
+        rebateDealerList: [], // 经销商列表
+        rebateScopeList: [] // 品类列表
       },
+      parentAllotRate: '', // 上级经销商分配比例
+      hAllotRate: '', // 总部分配比例
       rules: {
-        cjgsf: [{ required: true, message: '请选择差价归属方', trigger: 'change' }]
+        rebateParentType: [{ required: true, message: '请选择差价归属方', trigger: 'change' }]
       },
-      cjgsfList: [
-        { code: '0', name: '上级经销商' },
-        { code: '1', name: '指定经销商' },
-        { code: '2', name: '箭冠总公司' }
-      ],
-      zdDealearList: []
+      cjgsfList: [],
+      zdDealearList: [],
+      detailData: null
     }
   },
   computed: {
     showPercent () {
-      return this.form.cjgsf.length > 1
+      return this.form.rebateParentType.length > 1
     },
     showPercent1 () {
       return this.zdDealearList.length > 1
+    },
+    notZdDealer () {
+      return this.form.rebateDealerList.concat(this.zdDealearList).concat([{ 'parentDealerSn': this.form.dealerSn }])
+    },
+    showTable () {
+      return this.form.rebateParentType.indexOf('SUPERIORS') >= 0
     }
   },
   methods: {
-    // 关联经销商变更
-    custChange (val) {
-      this.form.dealerSn = val.key
+    setData (list, dealerSn, detail) {
+      this.detailData = detail
+      this.form.dealerSn = dealerSn
+      this.cjgsfList = list
+      // 如果当前经销商是特约经销商
+      if (this.detailData.dealerType1 == 'special') {
+        // 默认只有上级经销商
+        this.form.rebateParentType = ['SUPERIORS']
+        this.cjgsgChange(['SUPERIORS'])
+      } else {
+        this.cjgsgChange(['SUPERIORS', 'HEAD'])
+      }
+    },
+    // 上级经销商修改
+    custSupChange (val) {
+      this.form.rebateDealerList[0]['parentDealerSn'] = val.key
+      this.getCategoryList()
+    },
+    rateSupChange (val) {
+      this.form.rebateDealerList[0]['allotRate'] = val
+    },
+    // 刷新品类列表
+    getCategoryList () {
+      const a = this.form.rebateDealerList[0]['parentDealerSn']
+      if (a) {
+        // 查询品类树
+      }
+    },
+    rateHChange (val) {
+      this.form.rebateDealerList[1]['allotRate'] = val
+    },
+    // 指定经销商变更
+    custChange (val, index) {
+      console.log(val, index)
+      this.zdDealearList[index]['parentDealerSn'] = val.key
+    },
+    rateChange (val, index) {
+      console.log(val, index)
+      this.zdDealearList[index]['allotRate'] = val
     },
     // 差价归属变更
     cjgsgChange (val) {
-      if (val.indexOf('1') >= 0) {
+      console.log(val)
+      this.form.rebateParentType = val
+      // 指定经销商
+      if (val.indexOf('ASSIGN') >= 0) {
         if (this.zdDealearList.length == 0) {
-          this.zdDealearList.push({ id: new Date().getTime(), dealerSn: '', percent: '' })
+          this.addItem()
         }
       } else {
         this.zdDealearList = []
       }
-    },
-    // 增加或删除指定经销商
-    addOrDel (row, index) {
-      // 加
-      if ((this.zdDealearList.length - 1) == index) {
-        this.zdDealearList.push({ id: new Date().getTime(), dealerSn: '', percent: '' })
+      // 上级经销商
+      if (val.indexOf('SUPERIORS') >= 0) {
+        if (!this.form.rebateDealerList[0]) {
+          this.form.rebateDealerList[0] = {
+            'id': new Date().getTime(),
+            'dealerSn': this.form.dealerSn,
+            'parentDealerSn': undefined,
+            'rebateParentType': 'SUPERIORS',
+            'allotRate': 100
+          }
+          this.parentAllotRate = 100
+        }
       } else {
-        const i = this.zdDealearList.findIndex(item => item.id == row.id)
-        if (i >= 0) {
-          this.zdDealearList.splice(i, 1)
+        this.form.rebateDealerList[0] = null
+        this.parentAllotRate = ''
+      }
+      // 总部经销商
+      if (val.indexOf('HEAD') >= 0) {
+        if (!this.form.rebateDealerList[1]) {
+          this.form.rebateDealerList[1] = {
+            'id': new Date().getTime() - 100,
+            'dealerSn': this.form.dealerSn,
+            'parentDealerSn': 1,
+            'rebateParentType': 'HEAD',
+            'allotRate': 0
+          }
+          this.hAllotRate = 0
         }
+      } else {
+        this.form.rebateDealerList[1] = null
+        this.hAllotRate = ''
+      }
+    },
+    // 增加指定经销商
+    addItem (row, index) {
+      const sn = new Date().getTime()
+      this.zdDealearList.push({
+        'id': sn,
+        'dealerSn': this.form.dealerSn,
+        'parentDealerSn': undefined,
+        'rebateParentType': 'ASSIGN',
+        'allotRate': ''
+      })
+    },
+    // 删除指定经销商
+    delItem (row, index) {
+      const i = this.zdDealearList.findIndex(item => item.id == row.id)
+      if (i >= 0) {
+        this.zdDealearList.splice(i, 1)
       }
     },
     // 重置表单
     resetForm () {
       this.form.dealerSn = undefined
-      this.form.cjgsf = []
+      this.form.rebateParentType = []
+      this.form.rebateDealerList = []
+      this.form.rebateScopeList = []
       this.zdDealearList = []
-      if (this.showPercent1) {
-        this.$refs.custList.resetForm()
+      this.hAllotRate = ''
+      this.parentAllotRate = 100
+      this.$refs.custList.resetForm()
+    },
+    // 校验数据
+    validateFormData (data) {
+      let row
+      let msg = ''
+      for (let i = 0; i < data.length; i++) {
+        row = data[i]
+        if (row) {
+          const rebateParentType = this.cjgsfList.find(item => item.code == row.rebateParentType)
+          const type = rebateParentType ? rebateParentType.dispName : ''
+          if (!row.parentDealerSn) {
+            msg = '请选择' + type
+            break
+          }
+          if (!row.allotRate && row.rebateParentType != 'HEAD') {
+            msg = '请输入' + type + '的分配比例'
+            break
+          }
+        }
       }
+      return msg
     },
     // 保存
     handleSave () {
       const _this = this
       _this.$refs.ruleForm.validate(valid => {
         if (valid) {
-          const formData = _this.form
-          _this.spinning = true
-          dealerUserSave(formData).then(res => {
-            if (res.status == 200) {
-              _this.$message.success(res.message)
-              _this.$emit('ok')
-              _this.isShow = false
+          const formData = JSON.parse(JSON.stringify(_this.form))
+          formData.rebateDealerList = formData.rebateDealerList.concat(JSON.parse(JSON.stringify(this.zdDealearList)))
+          console.log(formData)
+          // 校验数据
+          const errorMsg = this.validateFormData(formData.rebateDealerList)
+          console.log(errorMsg)
+          if (errorMsg) {
+            _this.$message.error(errorMsg)
+          } else {
+            // 处理数据并校验比例之和是否100
+            let pa = 0
+            formData.rebateDealerList = formData.rebateDealerList.filter(item => item)
+            formData.rebateDealerList.map(item => {
+              item.allotRate = item.allotRate ? (item.allotRate / 100) : 0
+              pa += item.allotRate
+            })
+            console.log(formData)
+            console.log(pa)
+            if (pa != 1) {
+              _this.$message.error('差价比例之和必须是100%')
+              return
             }
-            _this.spinning = false
-          })
+
+            _this.spinning = true
+            dealerUpsCreate(formData).then(res => {
+              if (res.status == 200) {
+                _this.$message.success(res.message)
+                _this.$emit('ok')
+                _this.isShow = false
+              }
+              _this.spinning = false
+            })
+          }
         } else {
           return false
         }
@@ -227,7 +375,7 @@ export default {
       text-align: center;
       margin: 15px 0 10px;
       button{
-        width: 120px;
+        width: 80px;
       }
     }
   }