<template>
  <div class="yqshop-wrapper">
    <bread-crumb :curmbFirst="curmbFirst"></bread-crumb>
    <div class="yqshop-content screenSet" id="screenSet">
      <div class="header-title">云鹊店铺</div>
      <el-form
        ref="searchForm"
        :model="searchForm"
        label-width="100px"
        label-suffix=":"
        :inline="true"
      >
        <el-row :gutter="30" type="flex" style="margin-top: 10px">
          <el-col :span="6">
            <el-form-item label="店铺名称">
              <el-input
                v-model:value="searchForm.storeName"
                size="small"
                placeholder="请输入店铺名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="店铺ID">
              <el-input
                v-model:value="searchForm.id"
                size="small"
                placeholder="请输入店铺ID"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="店铺类型">
              <el-select
                v-model:value="searchForm.type"
                placeholder="请选择店铺类型"
                size="small"
                clearable
              >
                <el-option
                  v-for="(item, index) in typeList"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30" type="flex" style="margin-top: 10px">
          <el-col :span="6">
            <el-form-item label="分佣方式">
              <el-select
                v-model:value="searchForm.commissionType"
                placeholder="请选择分佣方式"
                size="small"
                clearable
              >
                <el-option
                  v-for="item in commissionTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="药代分佣方式">
              <el-select
                v-model:value="searchForm.proxyCommissionType"
                placeholder="请选择分佣方式"
                size="small"
                clearable
              >
                <el-option
                  v-for="item in commissionTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="店铺状态">
              <el-select
                v-model:value="searchForm.certifyStatus"
                placeholder="请选择"
                size="small"
                clearable
              >
                <el-option
                  v-for="item in storeTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" style="text-align: right">
            <el-button type="primary" size="small" @click="searchList"
              >查询</el-button
            >
            <el-button
              type="default"
              size="small"
              @click="resetForm"
              style="margin-left: 0"
              >重置</el-button
            >
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" style="text-align: right">
            <el-button
              type="primary"
              size="small"
              @click="createShop"
              :disabled="!canAdd"
              >新建店铺</el-button
            >
            <!--<el-button type="primary" size="small" @click="createShop">新建店铺</el-button>-->
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :data="tableData"
        class="item-table"
        style="width: 100%; margin-top: 10px"
      >
        <el-table-column
          prop="id"
          label="店铺ID"
          min-width="100"
          align="center"
        >
          <template v-slot="scope">
            <span>{{ scope.row.tradeStore.id }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="storeName"
          label="店铺名称"
          min-width="100"
          align="center"
          show-overflow-tooltip
        >
          <template v-slot="scope">
            <span>{{ scope.row.tradeStore.storeName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="storeType"
          label="店铺类型"
          min-width="100"
          align="center"
        >
          <template v-slot="scope">
            <span>{{
              storeTypeFormat_filter(scope.row.tradeStore.storeType)
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="storeType"
          label="店铺状态"
          min-width="100"
          align="center"
        >
          <template v-slot="scope">
            <span
              v-if="scope.row.tradeStore.storeType != 2"
              :class="scope.row.tradeStore.certifyStatus == 4 ? 'red' : 'green'"
            >
              {{ storeStatusFormat_filter(scope.row.tradeStore.certifyStatus) }}
            </span>
            <span v-else> 上线 </span>
            <el-popover
              v-if="scope.row.tradeStore.storeType != 2"
              placement="top-start"
              width="200"
              trigger="hover"
              :content="
                certificateInfoRespContent(scope.row.certificateInfoResp)
              "
            >
              <template v-slot:reference>
                <i
                  v-if="scope.row.tradeStore.certifyStatus == 4"
                  class="el-icon-warning-outline red"
                ></i>
              </template>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          prop="count"
          label="已上架商品数"
          min-width="120"
          align="center"
        >
          <template v-slot="scope">
            <span>{{ scope.row.tradeStore.count }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="createdTime"
          label="创建时间"
          min-width="100"
          align="center"
        >
          <template v-slot="scope">
            <!--<span>{{ scope.row.createdTime | liveDateFilter }}</span>-->
            <span>{{ scope.row.tradeStore.createdTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="commissionType"
          label="分佣方式"
          width="120"
          align="center"
        >
          <template v-slot="scope">
            <span>{{
              commissionTypeFormat_filter(scope.row.tradeStore.commissionType)
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="commissionPrice"
          label="店铺分佣"
          width="120"
          align="center"
        >
          <template v-slot="scope">
            <span v-if="scope.row.tradeStore.commissionType == 1"
              >{{
                priceNum_filter(scope.row.tradeStore.commissionPrice)
              }}%</span
            >
            <span v-if="scope.row.tradeStore.commissionType == 2"
              >{{
                priceNum_filter(scope.row.tradeStore.commissionPrice)
              }}元</span
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="commissionType"
          label="药代分佣方式"
          width="120"
          align="center"
        >
          <template v-slot="scope">
            <span>{{
              commissionTypeFormat_filter(
                scope.row.tradeStore.proxyCommissionType
              )
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="commissionPrice"
          label="药代分佣"
          width="120"
          align="center"
        >
          <template v-slot="scope">
            <span v-if="scope.row.tradeStore.proxyCommissionType == 1"
              >{{
                priceNum_filter(scope.row.tradeStore.proxyCommissionPrice)
              }}%</span
            >
            <span v-if="scope.row.tradeStore.proxyCommissionType == 2"
              >{{
                priceNum_filter(scope.row.tradeStore.proxyCommissionPrice)
              }}元</span
            >
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          min-width="230"
          align="center"
          fixed="right"
        >
          <!--          <template slot-scope="scope">-->
          <!--            <div>-->
          <!--              <el-button v-if="scope.row.tradeStore.storeType == 1 && scope.row.tradeStore.certifyStatus == 3" @click="setPrice(scope.row, false)" type="text" size="small">设置分佣</el-button>-->

          <!--              <el-button @click="editShop(scope.row, 'true')" type="text" size="small">查看</el-button>-->

          <!--              <el-button v-if="scope.row.tradeStore.storeType == 1 && scope.row.tradeStore.certifyStatus > 2" @click="editShop(scope.row, 'false')" type="text" size="small">编辑</el-button>-->

          <!--              <el-button v-if="checkIsEdit(scope.row)" @click="shopManage(scope.row)" type="text" size="small">商品管理</el-button>-->

          <!--              <el-button v-if="checkIsEdit(scope.row)" @click="orderManage(scope.row)" type="text" size="small">订单管理</el-button>-->

          <!--              <el-button v-if="scope.row.tradeStore.storeType == 1 && scope.row.tradeStore.certifyStatus == 3"@click="setFreight(scope.row)" type="text" size="small">运费配置</el-button>-->

          <!--              <el-button  v-if="scope.row.tradeStore.storeType == 3" @click="closeShopAction(scope.row)" type="text" size="small">关闭店铺</el-button>-->
          <!--            </div>-->
          <!--          </template>-->
          <template v-slot="scope">
            <div>
              <el-button
                @click="editShop(scope.row, 'true')"
                type="text"
                size="small"
                >查看</el-button
              >

              <el-button
                v-if="checkIsEdit(scope.row)"
                checkIsEdit
                @click="editShop(scope.row, 'false')"
                type="text"
                size="small"
                >编辑</el-button
              >

              <el-button
                v-if="checkGoods(scope.row)"
                @click="shopManage(scope.row)"
                type="text"
                size="small"
                >商品管理</el-button
              >

              <el-button
                v-if="checkBills(scope.row)"
                @click="orderManage(scope.row)"
                type="text"
                size="small"
                >订单管理</el-button
              >

              <el-button
                v-if="checkSpe(scope.row)"
                @click="setPrice(scope.row, false)"
                type="text"
                size="small"
                >设置分佣</el-button
              >

              <el-button
                v-if="checkSpe(scope.row)"
                @click="setFreight(scope.row)"
                type="text"
                size="small"
                >运费配置</el-button
              >

              <el-button
                v-if="
                  scope.row.tradeStore.storeType == 3 && isOutsideGetted == 'no'
                "
                @click="closeShopAction(scope.row)"
                type="text"
                size="small"
                >关闭店铺</el-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleNumChange"
          :current-page="searchForm.pageNo"
          :page-sizes="[10, 30, 50, 100]"
          :page-size="searchForm.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalRows"
        ></el-pagination>
      </div>
      <!-- 设置分佣 -->
      <el-dialog
        title="店铺设置分佣"
        v-model:visible="setPriceVisible"
        width="55%"
      >
        <!--            <el-row :gutter="30" class="row search" type="flex" style="margin-bottom:0;">-->
        <el-form
          ref="setPriceForm"
          :rules="setPriceRules"
          :model="setPriceForm"
          label-width="250px"
          label-suffix=":"
          label-position="right"
          size="mini"
          style="width: 100%"
        >
          <!--          <div v-for="(item, index) in setPriceForm.adminCommissionGoodsRespList" :key="index" >-->
          <el-form-item label="分佣方式">
            <el-col :span="18">
              <el-radio-group
                v-model:value="setPriceForm.commission.commissionType"
                size="small"
                style="line-height: 45px"
              >
                <div>
                  <el-radio
                    :label="1"
                    style="float: left; margin-top: 5px; line-height: 20px"
                    >按比例分佣（%）</el-radio
                  >
                  <span style="float: right; width: 100px"
                    ><el-input-number
                      v-model:value="setPriceForm.commission.commissionPrice1"
                      size="small"
                      :precision="2"
                      :min="0"
                    ></el-input-number
                  ></span>
                </div>
                <div>
                  <el-radio
                    :label="2"
                    style="float: left; margin-top: 30px; line-height: 20px"
                    >固定分佣金额（元）</el-radio
                  >
                  <span style="float: right; width: 100px; margin-left: 14px"
                    ><el-input-number
                      v-model:value="setPriceForm.commission.commissionPrice2"
                      size="small"
                      :precision="2"
                      :min="0"
                      :max="9999.99"
                    ></el-input-number
                  ></span>
                </div>
              </el-radio-group>
            </el-col>
          </el-form-item>
          <el-form-item label="药代分佣方式">
            <el-col :span="18">
              <el-radio-group
                v-model:value="setPriceForm.proxyCommission.commissionType"
                size="small"
                style="line-height: 45px"
              >
                <div>
                  <el-radio
                    :label="1"
                    style="float: left; margin-top: 5px; line-height: 20px"
                    >按比例分佣（%）</el-radio
                  >
                  <span style="float: right; width: 100px"
                    ><el-input-number
                      v-model:value="
                        setPriceForm.proxyCommission.commissionPrice1
                      "
                      size="small"
                      :precision="2"
                      :min="0"
                    ></el-input-number
                  ></span>
                </div>
                <div>
                  <el-radio
                    :label="2"
                    style="float: left; margin-top: 30px; line-height: 20px"
                    >固定分佣金额（元）</el-radio
                  >
                  <span style="float: right; width: 100px; margin-left: 14px"
                    ><el-input-number
                      v-model:value="
                        setPriceForm.proxyCommission.commissionPrice2
                      "
                      size="small"
                      :precision="2"
                      :min="0"
                      :max="9999.99"
                    ></el-input-number
                  ></span>
                </div>
              </el-radio-group>
            </el-col>
          </el-form-item>
          <!--          </div>-->
        </el-form>
        <!--            </el-row>-->
        <template v-slot:footer>
          <span class="dialog-footer">
            <el-button @click="setPriceVisible = false">取 消</el-button>
            <el-button type="primary" @click="confirmSetPrice">确 定</el-button>
          </span>
        </template>
      </el-dialog>
    </div>
  </div>
</template>

<script>
let vm = null
import { openLoading, closeLoading } from '../../utils/utils'
import BreadCrumb from '@/components/breadcrumb.vue'
import { queryStore, queryShopAuth, closeShop } from '@/utils/shop'
import { getUserTypeReq } from '@/utils/cme/cmeApi'
export default {
  components: {
    BreadCrumb,
  },
  data() {
    return {
      isOutsideGetted: 'no',
      curmbFirst: '云鹊店铺',
      showAllFlag: false,
      showNewFlag: false,
      searchForm: {
        storeName: '',
        storeId: '',
        storeType: 0,
        pageNo: 1,
        pageSize: 10,
        id: null,
        type: null,
        commissionType: 0,
        proxyCommissionType: 0,
        certifyStatus: null,
      },
      canAdd: false,
      totalRows: 0,
      tableData: [],
      typeList: [
        {
          label: '供货商',
          value: 1,
        },
        {
          label: '小药房',
          value: 2,
        },
        {
          label: '医生小店',
          value: 3,
        },
      ],
      idType: 0,
      storageIdType: 0,
      commissionTypeList: [
        {
          value: 0,
          label: '全部',
        },
        {
          value: 1,
          label: '按比例分佣',
        },
        {
          value: 2,
          label: '固定分佣',
        },
      ],
      storeTypeList: [
        {
          value: 1,
          label: '待完善',
        },
        {
          value: 2,
          label: '待审核',
        },
        {
          value: 3,
          label: '审核通过',
        },
        {
          value: 4,
          label: '审核失败',
        },
      ],
      setPriceVisible: false,
      setPriceForm: {
        adminCommissionGoodsRespList: [],
        commission: {
          commissionKind: '',
          commissionPrice: '',
          commissionPrice1: '',
          commissionPrice2: '',
          commissionType: '',
          goodsId: '',
          maxPrice: 0,
          storeId: '',
        },
        proxyCommission: {
          commissionKind: '',
          commissionPrice: '',
          commissionPrice1: '',
          commissionPrice2: '',
          commissionType: '',
          goodsId: '',
          maxPrice: 0,
          storeId: '',
        },
      },
      setPriceRules: {},
    }
  },
  created() {
    vm = this
    // this.idType = localStorage.getItem("storageIdType");
    this.storageIdType = localStorage.getItem('storageIdType') - 0
    console.log(this.storageIdType)
    this.getUserTypeReq()
    this.getAddAuth()
    this.searchList()
  },
  methods: {
    storeStatusFormat_filter(v) {
      let s = ''
      switch (v) {
        case 1:
          s = '信息待完善'
          break
        case 2:
          s = '待审核'
          break
        case 3:
          s = '审核成功'
          break
        case 4:
          s = '审核失败'
          break
        default:
          s = '审核成功'
          break
      }
      return s
    },
    priceNum_filter(value) {
      if (value != '' && value != null && value != 'null') {
        return (value / 100).toFixed(2)
      } else if (value == 0) {
        return (value / 100).toFixed(2)
      } else {
        return value
      }
    },
    commissionTypeFormat_filter(value) {
      if (!value && value != 0) {
        return '-'
      } else {
        let hash = {
          1: '按比例分佣',
          2: '固定分佣',
        }
        return hash[value]
      }
    },
    statusFormat_filter(value) {
      if (!value && value != 0) {
        return '-'
      } else {
        let hash = {
          0: '下线',
          1: '上线',
        }
        return hash[value]
      }
    },
    storeTypeFormat_filter: function (value) {
      if (!value && value != 0) {
        return '-'
      } else {
        let hash = {
          1: '供货商',
          2: '小药房',
          3: '医生小店',
        }
        return hash[value]
      }
    },
    getAddAuth() {
      queryShopAuth().then((res) => {
        //  0 表示超级管理员,大于0 表示小店或供应商,null 表示非法用户
        if (res.data == 0) {
          this.canAdd = true
        }
      })
    },
    getUserTypeReq() {
      getUserTypeReq().then((res) => {
        console.log('--res', res)
        if (res.code == '000000') {
          this.isOutsideGetted = res.data.code
        }
      })
    },
    searchList() {
      openLoading(this)
      let params = this.searchForm
      if (this.searchForm.id) {
        params.storeId = this.searchForm.id
      } else {
        params.storeId = ''
      }
      if (this.searchForm.type) {
        params.storeType = this.searchForm.type
      } else {
        params.storeType = 0
      }
      queryStore(params)
        .then((res) => {
          closeLoading(this)
          if (res.code == '000000') {
            this.tableData = res.data.tradeStore
            this.totalRows = res.data.totalCount
          } else {
            this.tableData = []
          }
        })
        .catch((error) => {
          this.$message.error('请重试')
        })
    },
    resetForm() {
      this.searchForm = {
        storeName: '',
        storeId: '',
        storeType: 0,
        pageNo: 1,
        pageSize: 10,
        id: null,
        type: null,
        commissionType: 0,
        proxyCommissionType: 0,
      }
      this.searchList()
    },
    //新建店铺
    createShop() {
      let l = `${location.origin}#/create-shop?disabled=false`
      window.open(l)
    },
    //店铺管理
    shopManage(row) {
      let routeData = this.$router.resolve({
        path: '/goods-manage',
        query: {
          storeId: row.tradeStore.id,
          commissionFlag: row.tradeStore.commissionFlag,
          storeType: row.tradeStore.storeType, //  1: "供货商",2: "小药房",3: "医生小店"
        },
      })
      window.open(routeData.href, '_blank')
    },
    orderManage(row) {
      let routeData = this.$router.resolve({
        path: '/order-manage',
        query: {
          storeId: row.tradeStore.id,
        },
      })
      window.open(routeData.href, '_blank')
    },
    //编辑
    editShop(row, disabled) {
      let l = `${location.origin}#/create-shop?storeId=${row.tradeStore.id}&disabled=${disabled}&certifyStatus=${row.tradeStore.certifyStatus}`
      window.open(l)
    },
    handleSizeChange(val) {
      this.searchForm.pageSize = val
      this.searchForm.pageNo = 1
      this.searchList()
    },
    handleNumChange(val) {
      this.searchForm.pageNo = val
      this.searchList()
    },
    // 关闭医生小店
    closeShopAction(row) {
      this.$confirm('确定要关闭店铺吗', '', {
        confirmButtonText: '确 定',
        cancelButtonText: '取 消',
        type: 'warning',
      })
        .then(() => {
          closeShop(row.tradeStore.id).then((res) => {
            if (res.code == '000000') {
              if (res.data.status == 0) {
                this.$message.error(res.data.message)
              } else {
                this.searchList()
              }
            } else {
              this.$message.error(res.message)
            }
          })
        })
        .catch(() => {
          // this.$message.error('操作失败');
        })
    },
    confirmSetPrice() {
      if (
        this.setPriceForm.commission.commissionType == 1 &&
        (this.setPriceForm.commission.commissionPrice1 == undefined ||
          this.setPriceForm.commission.commissionPrice1 > 100)
      ) {
        this.$message({
          message: '请输入按比例分佣0-100',
          type: 'warning',
        })
        return
      }

      if (
        this.setPriceForm.commission.commissionType == 2 &&
        this.setPriceForm.commission.commissionPrice2 == undefined
      ) {
        this.$message({
          message: '请输入固定分佣金额',
          type: 'warning',
        })
        return
      }

      if (
        this.setPriceForm.proxyCommission.commissionType == 1 &&
        (this.setPriceForm.proxyCommission.commissionPrice1 == undefined ||
          this.setPriceForm.proxyCommission.commissionPrice1 > 100)
      ) {
        this.$message({
          message: '请输入按比例分佣0-100',
          type: 'warning',
        })
        return
      }
      if (
        this.setPriceForm.proxyCommission.commissionType == 2 &&
        this.setPriceForm.proxyCommission.commissionPrice2 == undefined
      ) {
        this.$message({
          message: '请输入固定分佣金额',
          type: 'warning',
        })
        return
      }
      let timeoutId = null
      timeoutId && clearTimeout(timeoutId)
      timeoutId = setTimeout(() => {
        this.clickHandle()
      }, 500)
    },
    // 防止按钮多次点击
    clickHandle() {
      this.$refs.setPriceForm.validate((valid) => {
        if (valid) {
          vm.loading = true

          if (vm.setPriceForm.commission.commissionType == 1) {
            vm.setPriceForm.commission.commissionPrice = (
              vm.setPriceForm.commission.commissionPrice1 * 100
            ).toFixed(0)
          } else if (vm.setPriceForm.commission.commissionType == 2) {
            vm.setPriceForm.commission.commissionPrice = (
              vm.setPriceForm.commission.commissionPrice2 * 100
            ).toFixed(0)
          }
          if (vm.setPriceForm.proxyCommission.commissionType == 1) {
            vm.setPriceForm.proxyCommission.commissionPrice = (
              vm.setPriceForm.proxyCommission.commissionPrice1 * 100
            ).toFixed(0)
          } else if (vm.setPriceForm.proxyCommission.commissionType == 2) {
            vm.setPriceForm.proxyCommission.commissionPrice = (
              vm.setPriceForm.proxyCommission.commissionPrice2 * 100
            ).toFixed(0)
          }
          vm.setPriceForm.adminCommissionGoodsRespList[0] =
            vm.setPriceForm.commission
          vm.setPriceForm.adminCommissionGoodsRespList[1] =
            vm.setPriceForm.proxyCommission
          vm.POST(
            '/store/commission/admin/store/save',
            vm.setPriceForm.adminCommissionGoodsRespList
          ).then((res) => {
            vm.loading = false
            // closeLoading(this);
            if (res.code == '000000') {
              vm.$message({
                message: '设置分佣成功',
                type: 'success',
              })
              vm.setPriceVisible = false
              vm.searchList()
            } else {
              vm.$message({
                message: res.message,
                type: 'error',
              })
            }
          })
        }
      })
    },
    setPrice(row, batchUpdatePriceFlag) {
      if (this.$refs.setPriceForm) {
        this.$refs.setPriceForm.resetFields()
      }

      if (row.adminCommissionGoodsRespList) {
        this.setPriceForm.adminCommissionGoodsRespList =
          row.adminCommissionGoodsRespList
        for (
          let i = 0;
          i < this.setPriceForm.adminCommissionGoodsRespList.length;
          i++
        ) {
          if (
            this.setPriceForm.adminCommissionGoodsRespList[i].commissionType ==
            1
          ) {
            this.setPriceForm.adminCommissionGoodsRespList[i].commissionPrice1 =
              this.setPriceForm.adminCommissionGoodsRespList[i]
                .commissionPrice / 100
          } else if (
            this.setPriceForm.adminCommissionGoodsRespList[i].commissionType ==
            2
          ) {
            this.setPriceForm.adminCommissionGoodsRespList[i].commissionPrice2 =
              this.setPriceForm.adminCommissionGoodsRespList[i]
                .commissionPrice / 100
          }
          if (
            this.setPriceForm.adminCommissionGoodsRespList[i].commissionKind ==
            1
          ) {
            // this.setPriceForm.commission = this.setPriceForm.adminCommissionGoodsRespList[i];

            this.setPriceForm.commission.commissionKind =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionKind
            this.setPriceForm.commission.commissionPrice =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionPrice
            this.setPriceForm.commission.commissionPrice1 =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionPrice1
            this.setPriceForm.commission.commissionPrice2 =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionPrice2
            this.setPriceForm.commission.commissionType =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionType
            this.setPriceForm.commission.goodsId =
              this.setPriceForm.adminCommissionGoodsRespList[i].goodsId
            this.setPriceForm.commission.maxPrice =
              this.setPriceForm.adminCommissionGoodsRespList[i].maxPrice
            this.setPriceForm.commission.storeId =
              this.setPriceForm.adminCommissionGoodsRespList[i].storeId
          } else if (
            this.setPriceForm.adminCommissionGoodsRespList[i].commissionKind ==
            2
          ) {
            // this.setPriceForm.proxyCommission = this.setPriceForm.adminCommissionGoodsRespList[i];
            this.setPriceForm.proxyCommission.commissionKind =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionKind
            this.setPriceForm.proxyCommission.commissionPrice =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionPrice
            this.setPriceForm.proxyCommission.commissionPrice1 =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionPrice1
            this.setPriceForm.proxyCommission.commissionPrice2 =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionPrice2
            this.setPriceForm.proxyCommission.commissionType =
              this.setPriceForm.adminCommissionGoodsRespList[i].commissionType
            this.setPriceForm.proxyCommission.goodsId =
              this.setPriceForm.adminCommissionGoodsRespList[i].goodsId
            this.setPriceForm.proxyCommission.maxPrice =
              this.setPriceForm.adminCommissionGoodsRespList[i].maxPrice
            this.setPriceForm.proxyCommission.storeId =
              this.setPriceForm.adminCommissionGoodsRespList[i].storeId
          }
        }
        let newArray = this.setPriceForm.adminCommissionGoodsRespList.filter(
          function (item) {
            return item.commissionKind == 1
          }
        )
        if (newArray == null || newArray.length == 0) {
          this.setPriceForm.commission = {
            commissionKind: 1,
            commissionPrice: '',
            commissionPrice1: undefined,
            commissionPrice2: undefined,
            commissionType: 0,
            goodsId: row.tradeStore.goodsId,
            maxPrice: 0,
            storeId: row.tradeStore.id,
          }
        }
        let array = this.setPriceForm.adminCommissionGoodsRespList.filter(
          function (item) {
            return item.commissionKind == 2
          }
        )
        if (array == null || array.length == 0) {
          this.setPriceForm.proxyCommission = {
            commissionKind: 2,
            commissionPrice: '',
            commissionPrice1: undefined,
            commissionPrice2: undefined,
            commissionType: 0,
            goodsId: row.tradeStore.goodsId,
            maxPrice: 0,
            storeId: row.tradeStore.id,
          }
        }
      } else {
        this.setPriceForm.commission = {
          commissionKind: 1,
          commissionPrice: '',
          commissionPrice1: undefined,
          commissionPrice2: undefined,
          commissionType: 0,
          goodsId: row.tradeStore.goodsId,
          maxPrice: 0,
          storeId: row.tradeStore.id,
        }

        this.setPriceForm.proxyCommission = {
          commissionKind: 2,
          commissionPrice: '',
          commissionPrice1: undefined,
          commissionPrice2: undefined,
          commissionType: 0,
          goodsId: row.tradeStore.goodsId,
          maxPrice: 0,
          storeId: row.tradeStore.id,
        }
      }
      this.setPriceVisible = true
    },
    // 运费配置
    setFreight(row) {
      let routeData = this.$router.resolve({
        path: '/freight-config',
        query: {
          storeId: row.tradeStore.id,
          commissionFlag: row.tradeStore.commissionFlag,
        },
      })
      window.open(routeData.href, '_blank')
    },
    certificateInfoRespContent(c) {
      let v = ''
      const b = c ? c.certifyValidDtoList : []
      if (b.length > 0) {
        b.map((i, j) => {
          if (j <= 3) {
            v = v + i.refuseContent
          }
        })
      }
      return v
    },
    checkIsEdit(row) {
      const { storeType, certifyStatus } = row.tradeStore
      if (storeType == 1 && Number(certifyStatus) > 2) {
        return true
      } else if (storeType == 2) {
        return true
      } else {
        return false
      }
    },
    checkGoods(row) {
      const { storeType, certifyStatus } = row.tradeStore
      if (storeType == 1 && Number(certifyStatus) === 3) {
        return true
      } else if (storeType == 2) {
        return true
      } else if (storeType == 3) {
        if (Number(certifyStatus) == 1 || Number(certifyStatus) == 3) {
          return true
        } else {
          return false
        }
      } else {
        return false
      }
    },
    checkBills(row) {
      const { storeType, certifyStatus } = row.tradeStore
      if (storeType == 1 && Number(certifyStatus) !== 3) {
        return false
      } else {
        return true
      }
    },
    checkSpe(row) {
      const { storeType, certifyStatus } = row.tradeStore
      if (storeType == 1 && Number(certifyStatus) == 3) {
        return true
      } else if (storeType == 2) {
        return true
      } else {
        return false
      }
    },
  },
}
</script>

<style lang="scss">
.yqshop-wrapper {
  .yqshop-content {
    background: #fff;
    padding: 10px;
    .header-title {
      padding: 10px 12px;
      font-size: 13px;
      color: #449284;
      border-bottom: 1px solid #efefef;
    }
  }
  .el-button--text {
    color: #449284;
    font-size: 14px;
    &::after {
      content: '';
      position: relative;
      height: 14px;
      /*border-right: 1px solid #EBEEF5;*/
      border-right: 1px solid #aaaaaa;
      padding-right: 10px;
    }
    &:last-of-type {
      &::after {
        content: '';
        position: relative;
        width: 1px;
        height: 14px;
        border-right: none;
      }
    }
  }
  .red {
    color: #ff4b33;
  }
  .green {
    color: #449284;
  }
}
</style>
