<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" :tableKey="this.$options.name">
        <el-upload
          class="upload-demo"
          slot='right'
          style="float: right;padding-left: 5px"
          :headers="headers"
          :action="baseApi +'/api/designList/importDesignList'"
          :file-list="fileList"
          :on-error="handleErr"
          :on-success=" (response, file, fileList) => { return handleSuccess(response, file, fileList,crud);}"
          :show-file-list="true">
          <el-button size="mini" type="success" icon="el-icon-upload2">导入</el-button>
        </el-upload>
      </crudOperation>
      <!--表单组件-->
      <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>
        <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" :height="crud.tableHeight" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="no" label="No" />
        <el-table-column prop="chaseCenter" label="変通No.11桁" width="120px"/>
        <el-table-column prop="contraposition" label="设变号"  width="120px"/>
        <el-table-column prop="designation" label="一括番号"  width="120px"/>
        <el-table-column prop="oldItemCode" label="旧品番"  width="120px"/>
        <el-table-column prop="hypothesis" label="关联设变"  width="120px"/>
        <el-table-column prop="newItemCode" label="新品番"  width="120px"/>
        <el-table-column prop="supplierCode" label="供应商代码"  width="120px"/>
        <el-table-column prop="supplierName" label="供应商名称"  width="120px"/>
        <el-table-column prop="ac" label="A/C" />
        <el-table-column prop="content" label="加工内容" />
        <el-table-column prop="productName" label="品名(中文)"  width="120px"/>
        <el-table-column prop="useSingly" label="单用" />
        <el-table-column label="订货要否">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <span>{{ scope.row.enable==true?'要':'否' }}</span>
            </div>
          </template>
        </el-table-column>>
        <el-table-column prop="naso" label="纳所" />
        <el-table-column prop="monthlyOutput" label="月产量" />
        <el-table-column prop="tTypeCode" label="T型式代码"   width="120px"/>
        <el-table-column prop="tTypeName" label="T型式名"   width="120px"/>
        <el-table-column prop="scrapDisposal" label="旧品处理" />
        <el-table-column prop="implementationDate" label="系统实施日" width="120px"/>
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="updateBy" label="更新人" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateTime" label="更新时间" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDesignList from '@/api/designList'
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'
import { getToken } from '@/utils/auth'
import { mapGetters } from 'vuex'

const defaultForm = { id: null, no:null,oldItemCode:null,newItemCode:null,chaseCenter: null, contraposition: null, designation: null, hypothesis: null, supplierCode: null, supplierName: null, ac: null, content: null, productName: null, useSingly: null, enable: null, naso: null, monthlyOutput: null, tTypeCode: null, tTypeName: null, scrapDisposal: null, implementationDate: null, createby: null, updateby: null, createtime: null, updatetime: null, bigItemId: null, newItemId: null, oldItemId: null }
export default {
  name: 'DesignList',
  // eslint-disable-next-line vue/no-unused-components
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'design', url: 'api/designList', idField: 'id', sort: 'id,desc', crudMethod: { ...crudDesignList },
      optShow: {
        add: false,
        edit: false,
        del: true,
        reset: true,
        download: true
      },
    })
  },
  data() {
    return {
      fileList: [],
      headers: { 'Authorization': getToken() },
      permission: {
        add: ['admin', 'designList:add'],
        edit: ['admin', 'designList:edit'],
        del: ['admin', 'designList:del']
      },
      rules: {
      }
    }
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ])
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    // 导入
    handleSuccess(response, file, fileList, crud) {
      // let myError = response.toString();//转字符串
      this.crud.notify(response['message'], CRUD.NOTIFICATION_TYPE.SUCCESS)
      crud.toQuery()
    },
    handleErr(err, file, fileList) {
      let myError = err.toString()// 转字符串
      myError = myError.replace('Error: ', '') // 去掉前面的" Error: "
      myError = JSON.parse(myError)// 转对象
      this.crud.notify(myError['message'], CRUD.NOTIFICATION_TYPE.ERROR)
    }
  }
}
</script>

<style scoped>

</style>
