<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">id</label>
        <el-input v-model="query.id" clearable placeholder="id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">店铺id</label>
        <el-input v-model="query.shopId" clearable placeholder="店铺id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">商品名称</label>
        <el-input v-model="query.name" clearable placeholder="商品名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">包装费</label>
        <el-input v-model="query.packFee" clearable placeholder="包装费" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">商品最低价</label>
        <el-input v-model="query.lowPrice" clearable placeholder="商品最低价" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">单位Id</label>
        <el-input v-model="query.unitId" clearable placeholder="单位Id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">商品封面图</label>
        <el-input v-model="query.coverImg" clearable placeholder="商品封面图" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">商品规格</label>
        <el-input v-model="query.specId" clearable placeholder="商品规格" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">品牌Id</label>
        <el-input v-model="query.brandId" clearable placeholder="品牌Id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">商品图片（第一张为缩略图，其他为详情）</label>
        <el-input v-model="query.images" clearable placeholder="商品图片（第一张为缩略图，其他为详情）" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">视频封面图</label>
        <el-input v-model="query.videoCoverImg" clearable placeholder="视频封面图" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">商品状态</label>
        <el-input v-model="query.status" clearable placeholder="商品状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">是否回收站 </label>
        <el-input v-model="query.isDel" clearable placeholder="是否回收站 " style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">是否免邮</label>
        <el-input v-model="query.isFreeFreight" clearable placeholder="是否免邮" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">是否删除</label>
        <el-input v-model="query.isDelete" clearable placeholder="是否删除" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">基础出售数量</label>
        <el-input v-model="query.baseSalesNumber" clearable placeholder="基础出售数量" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">实际销量</label>
        <el-input v-model="query.realSalesNumber" clearable placeholder="实际销量" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">合计销量</label>
        <el-input v-model="query.salesNumber" clearable placeholder="合计销量" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">点赞次数</label>
        <el-input v-model="query.thumbCount" clearable placeholder="点赞次数" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">收藏次数</label>
        <el-input v-model="query.storeCount" clearable placeholder="收藏次数" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">支持堂食</label>
        <el-input v-model="query.furnishMeal" clearable placeholder="支持堂食" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">支持配送</label>
        <el-input v-model="query.furnishExpress" clearable placeholder="支持配送" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="id" prop="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="店铺id">
            <el-input v-model="form.shopId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品名称">
            <el-input v-model="form.name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="包装费">
            <el-input v-model="form.packFee" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品最低价" prop="lowPrice">
            <el-input v-model="form.lowPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单位Id">
            <el-input v-model="form.unitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品封面图">
            <el-input v-model="form.coverImg" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品规格">
            <el-input v-model="form.specId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="品牌Id">
            <el-input v-model="form.brandId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品图片（第一张为缩略图，其他为详情）">
            <el-input v-model="form.images" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="视频封面图">
            <el-input v-model="form.videoCoverImg" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品状态" prop="status">
            <el-input v-model="form.status" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否回收站" prop="isDel">
            <el-input v-model="form.isDel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否免邮" prop="isFreeFreight">
            <el-input v-model="form.isFreeFreight" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否删除" prop="isDelete">
            <el-input v-model="form.isDelete" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="基础出售数量">
            <el-input v-model="form.baseSalesNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="实际销量">
            <el-input v-model="form.realSalesNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="合计销量">
            <el-input v-model="form.salesNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="点赞次数">
            <el-input v-model="form.thumbCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="收藏次数">
            <el-input v-model="form.storeCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支持堂食">
            <el-input v-model="form.furnishMeal" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支持配送">
            <el-input v-model="form.furnishExpress" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="shopId" label="店铺id" />
        <el-table-column prop="name" label="商品名称" />
        <el-table-column prop="packFee" label="包装费" />
        <el-table-column prop="lowPrice" label="商品最低价" />
        <el-table-column prop="unitId" label="单位Id" />
        <el-table-column prop="coverImg" label="商品封面图" />
        <el-table-column prop="specId" label="商品规格" />
        <el-table-column prop="brandId" label="品牌Id" />
        <el-table-column prop="images" label="商品图片（第一张为缩略图，其他为详情）" />
        <el-table-column prop="videoCoverImg" label="视频封面图" />
        <el-table-column prop="status" label="商品状态">
          <template slot-scope="scope">
            {{ dict.label.product_status[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column prop="isDel" label="是否回收站">
          <template slot-scope="scope">
            {{ dict.label.product_is_del[scope.row.isDel] }}
          </template>
        </el-table-column>
        <el-table-column prop="isFreeFreight" label="是否免邮">
          <template slot-scope="scope">
            {{ dict.label.product_is_free_freight[scope.row.isFreeFreight] }}
          </template>
        </el-table-column>
        <el-table-column prop="isDelete" label="是否删除">
          <template slot-scope="scope">
            {{ dict.label.product_is_delete[scope.row.isDelete] }}
          </template>
        </el-table-column>
        <el-table-column prop="baseSalesNumber" label="基础出售数量" />
        <el-table-column prop="realSalesNumber" label="实际销量" />
        <el-table-column prop="salesNumber" label="合计销量" />
        <el-table-column prop="thumbCount" label="点赞次数" />
        <el-table-column prop="storeCount" label="收藏次数" />
        <el-table-column prop="furnishMeal" label="支持堂食" />
        <el-table-column prop="furnishExpress" label="支持配送" />
        <el-table-column v-if="checkPer(['admin','tbProduct:edit','tbProduct:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTbProduct from '@/api/tbProduct'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, sourcePath: null, merchantId: null, shopId: null, name: null, type: null, packFee: null, lowPrice: null, unitId: null, coverImg: null, categoryId: null, specId: null, brandId: null, shortTitle: null, lowMemberPrice: null, unitSnap: null, shareImg: null, images: null, video: null, videoCoverImg: null, sort: null, limitNumber: null, productScore: null, status: null, failMsg: null, isRecommend: null, isHot: null, isNew: null, isOnSale: null, isShow: null, typeEnum: null, isDistribute: null, isDel: null, isStock: null, isPauseSale: null, isFreeFreight: null, freightId: null, strategyType: null, strategyId: null, isVip: null, isDelete: null, notice: null, createdAt: null, updatedAt: null, baseSalesNumber: null, realSalesNumber: null, salesNumber: null, thumbCount: null, storeCount: null, furnishMeal: null, furnishExpress: null, furnishDraw: null, furnishVir: null, isCombo: null, groupSnap: null, isShowCash: null, isShowMall: null, isNeedExamine: null, showOnMallStatus: null, showOnMallTime: null, showOnMallErrorMsg: null, enableLabel: null, taxConfigId: null }
export default {
  name: 'TbProduct',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['product_status', 'product_is_del', 'product_is_free_freight', 'product_is_delete'],
  cruds() {
    return CRUD({ title: '/product', url: 'api/tbProduct', idField: 'id', sort: 'id,desc', crudMethod: { ...crudTbProduct }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'tbProduct:add'],
        edit: ['admin', 'tbProduct:edit'],
        del: ['admin', 'tbProduct:del']
      },
      rules: {
        id: [
          { required: true, message: 'id不能为空', trigger: 'blur' }
        ],
        lowPrice: [
          { required: true, message: '商品最低价不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '商品状态', trigger: 'blur' }
        ],
        isDel: [
          { required: true, message: '是否回收站 0-否，1回收站不能为空', trigger: 'blur' }
        ],
        isFreeFreight: [
          { required: true, message: '是否免邮1-是 0-否不能为空', trigger: 'blur' }
        ],
        isDelete: [
          { required: true, message: '是否删除不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'id', display_name: 'id' },
        { key: 'shopId', display_name: '店铺id' },
        { key: 'name', display_name: '商品名称' },
        { key: 'packFee', display_name: '包装费' },
        { key: 'lowPrice', display_name: '商品最低价' },
        { key: 'unitId', display_name: '单位Id' },
        { key: 'coverImg', display_name: '商品封面图' },
        { key: 'specId', display_name: '商品规格' },
        { key: 'brandId', display_name: '品牌Id' },
        { key: 'images', display_name: '商品图片（第一张为缩略图，其他为详情）' },
        { key: 'videoCoverImg', display_name: '视频封面图' },
        { key: 'status', display_name: '0--待审核 1审核通过 -1审核失败  -2违规下架' },
        { key: 'isDel', display_name: '是否回收站 0-否，1回收站' },
        { key: 'isFreeFreight', display_name: '是否免邮1-是 0-否' },
        { key: 'isDelete', display_name: '是否删除' },
        { key: 'baseSalesNumber', display_name: '基础出售数量' },
        { key: 'realSalesNumber', display_name: '实际销量' },
        { key: 'salesNumber', display_name: '合计销量' },
        { key: 'thumbCount', display_name: '点赞次数' },
        { key: 'storeCount', display_name: '收藏次数' },
        { key: 'furnishMeal', display_name: '支持堂食' },
        { key: 'furnishExpress', display_name: '支持配送' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
