<template>
  <div class="mod-print-printPicLib">
    <!-- 搜索相关区域 -->
    <div class="search-bar">
      <el-form :inline="true" class="search-form" ref="searchForm" :model="searchForm" label-width="auto" size="small">
        <div class="input-row">
          <el-form-item prop="prodType" label="产品类型" class="search-form-item">
            <el-select v-model="searchForm.prodType" clearable filterable >
              <el-option key="smallcard" label="小卡" value="smallcard"></el-option>
              <el-option key="squarecard" label="方卡" value="squarecard"></el-option>
              <el-option key="badge" label="马口铁徽章" value="badge"></el-option>
              <el-option key="plushbadge" label="毛绒徽章" value="plushbadge"></el-option>
              <el-option key="postcard" label="明信片" value="postcard"></el-option>
              <el-option key="bookmark" label="书签" value="bookmark"></el-option>
              <el-option key="tipscard" label="迷你手幅" value="tipscard"></el-option>
              <el-option key="polaroid" label="花式拍立得" value="polaroid"></el-option>
              <el-option key="covercard" label="直拍封面" value="covercard"></el-option>
              <el-option key="stub" label="票根" value="stub"></el-option>
              <el-option key="transformcard" label="变换卡" value="transformcard"></el-option>
              <el-option key="transpolaroid" label="透明胶片拍立得" value="transpolaroid"></el-option>
              <el-option key="bookmark3" label="三宫格透明胶片书签" value="bookmark3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="prodAngle" label="产品角型" class="search-form-item">
            <el-select v-model="searchForm.prodAngle" clearable filterable >
              <el-option key="1" label="圆角" value="圆角"></el-option>
              <el-option key="2" label="直角" value="直角"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="prodId" label="产品名称" class="search-form-item">
            <el-select v-model="searchForm.prodId" clearable filterable >
              <el-option v-for="(item, index) in prodList"
                         :key="index" :label="item.prodName" :value="item.prodId"></el-option>
            </el-select>
          </el-form-item>
          <div class="default-btn primary-btn" @click="searchChange">{{$t('crud.searchBtn')}}</div>
          <div class="default-btn" @click="resetSearchForm('searchForm')">{{$t('shop.resetMap')}}</div>
        </div>

      </el-form>
    </div>
    <!-- 列表相关区域 -->
    <div class="main-container">
      <div class="operation-bar">
        <div class="default-btn primary-btn" @click="addOrUpdateHandle()">{{$t("crud.addTitle")}}</div>
      </div>
      <div class="table-con spec-table">
        <el-table
          ref="specListTable"
          :data="dataList"
          header-cell-class-name="table-header"
          row-class-name="table-row"
          style="width: 100%">
          <!-- 正面图 -->
          <el-table-column label="三方skuId" prop="thirdSkuId" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.thirdSkuId}}</span>
            </template>
          </el-table-column>
          <el-table-column label="三方SKU名称" prop="thirdSkuName" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.thirdSkuName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="三方SKU编号" prop="skuNo" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.skuNo}}</span>
            </template>
          </el-table-column>
          <!-- 背面图 -->
          <el-table-column label="产品类型" prop="prodType" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.prodType === 'smallcard'">小卡</span>
              <span v-if="scope.row.prodType === 'squarecard'">方卡</span>
              <span v-if="scope.row.prodType === 'badge'">马口铁徽章</span>
              <span v-if="scope.row.prodType === 'plushbadge'">毛绒徽章</span>
              <span v-if="scope.row.prodType === 'postcard'">明信片</span>
              <span v-if="scope.row.prodType === 'bookmark'">书签</span>
              <span v-if="scope.row.prodType === 'tipscard'">迷你手幅</span>
              <span v-if="scope.row.prodType === 'polaroid'">仿拍立得</span>
              <span v-if="scope.row.prodType === 'covercard'">直拍封面</span>
              <span v-if="scope.row.prodType === 'stub'">票根</span>
              <span v-if="scope.row.prodType === 'transformcard'">变换卡</span>
              <span v-if="scope.row.prodType === 'transpolaroid'">透明胶片拍立得</span>
              <span v-if="scope.row.prodType === 'bookmark3'">三宫格透明胶片书签</span>
            </template>
          </el-table-column>
          <el-table-column label="产品类型名称" prop="prodName" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.prodName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="产品角型" prop="prodAngle" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.prodAngle}}</span>
            </template>
          </el-table-column>

          <!--&lt;!&ndash; 关联的产品ID &ndash;&gt;
          <el-table-column label="关联产品" prop="prodId" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.prodId}}</span>
            </template>
          </el-table-column>-->
          <!-- 产品名称 -->
          <el-table-column label="关联产品" prop="prodName" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.prodName}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" fixed="right" :label="$t('publics.operating')" width="auto">
            <template slot-scope="scope">
              <div class="text-btn-con">
                <div class="default-btn text-btn" @click="addOrUpdateHandle(scope.row.id)">{{$t("crud.updateBtn")}}</div>
                <div class="default-btn text-btn" @click.stop="deleteHandle(scope.row.id)">{{$t("text.delBtn")}}</div>
                </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
        <el-pagination
          v-if="dataList.length"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="page.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
        </el-pagination>
      </div>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="refreshChange"></add-or-update>
    <el-dialog :visible.sync="previewPicDialogVisible" :modal="false" title="图片预览" width="30%" top="3vh">
      <el-image :src="previewPicUrl" alt=""  style="width: 100%; height: 100%"/>
    </el-dialog>
  </div>
</template>

<script>
import AddOrUpdate from './third-print-sku-add-or-update'
export default {
  data () {
    return {
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      prodList:[],
      previewPicUrl: null,
      previewPicDialogVisible: false,
      resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
      searchForm: {
        prodType: null,
        prodId: null,
        prodAngle: null
      }, // 搜索
      dataListLoading: false,
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  created () {
    this.getDataList();
    this.getProdList();
  },
  mounted () {
  },
  methods: {
    getProdList(){
      this.$http({
        url: this.$http.adornUrl('/prod/prod/simpleList'),
        method: 'GET',
        params: this.$http.adornParams({customized:0})
      }).then(({data}) => {
        this.prodList = data
      })
    },
    resetSearchForm (formName) {
      this.$refs[formName].resetFields()
    },
    getDataList (page) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/prod/thirdPrintSku/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign({
            current: page == null ? this.page.currentPage : page.currentPage,
            size: page == null ? this.page.pageSize : page.pageSize
          },
            this.searchForm
          )
        )
      }).then(({data}) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    deleteHandle (id) {
      this.$confirm(this.$i18n.t('admin.isDeleOper') + '?', this.$i18n.t('text.tips'), {
        confirmButtonText: this.$i18n.t('crud.filter.submitBtn'),
        cancelButtonText: this.$i18n.t('crud.filter.cancelBtn'),
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/print/printPicLib/' + id),
          method: 'delete',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          this.$message({
            message: this.$i18n.t('publics.operation'),
            type: 'success',
            duration: 200,
            onClose: () => {
              this.refreshChange()
            }
          })
        })
      }).catch(() => { })
    },
    // 刷新回调
    refreshChange () {
      this.page.currentPage = 1
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.getDataList(this.page)
    },
    handleSizeChange (val) {
      this.page.pageSize = val
      this.getDataList()
    },
    handleCurrentChange (val) {
      this.page.currentPage = val
      this.getDataList()
    }
  }
}
</script>
<style lang="scss">
.mod-print-printPicLib {
}
</style>
