<template>
  <div class="mod-config">
    <!-- 查询条件 -->
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'物料编码'">
        <el-input v-model="searchData.partNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'物料名称'">
        <el-input v-model="searchData.partDesc" clearable style="width: 200px"></el-input>
      </el-form-item>
      <el-form-item :label="'工艺类型'">
        <el-select v-model="searchData.routingType" clearable style="width: 120px">
          <el-option label="Manufacturing" value="Manufacturing"></el-option>
          <el-option label="Repair" value="Repair"></el-option>
          <el-option label="Prototype" value="Prototype"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'Routing版本号'">
        <el-input-number :controls="false" :step="0" v-model="searchData.routingRevision" style="width: 100px"></el-input-number>
      </el-form-item>
      <el-form-item :label="'替代编码'">
        <el-input v-model="searchData.alternativeNo" style="width: 100px"></el-input>
      </el-form-item>
      <el-form-item :label="'替代名称'">
        <el-input v-model="searchData.alternativeDescription" style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button :loading="queryLoading" @click="getDataList()">查询</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>

    <!-- bom列表 -->
    <el-table
      :height="height"
      :data="dataList"
      border
      style="width: 100%">
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed === ''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页插件 -->
    <el-pagination style="margin-top: 0px"
                   @size-change="sizeChangeHandle"
                   @current-change="currentChangeHandle"
                   :current-page="pageIndex"
                   :page-sizes="[20, 50, 100, 200, 500]"
                   :page-size="pageSize"
                   :total="totalPage"
                   layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- chooseList模态框 -->
    <ChooseList ref="baseList" @getBaseData="getBaseData"></ChooseList>
  </div>
</template>

<script>
import {
  workGuidelinesSearch, // workGuidelines 列表查询
} from '@/api/part/routingOperationWorkGuidelines.js'
import ChooseList from '@/views/modules/common/Chooselist'

export default {
  // 组件
  components: {
    ChooseList
  },
  // 监听
  watch: {
    searchData: {
      deep: true,
      handler: function (newV, oldV) {
        this.searchData.partNo = this.searchData.partNo.toUpperCase()
      }
    }
  },
  // 对象
  data () {
    return {
      // 导出
      exportData: [],
      exportName: '工艺指导' + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ['工艺指导'],
      exportFooter: [],
      resultList: [],
      // ======== 行高 ========
      height: 200,
      // ======== 分页 ========
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      // 条件查询
      searchData: {
        site: this.$store.state.user.site,
        partNo: '',
        partDesc: '',
        routingType: '',
        routingRevision: '',
        alternativeNo: '',
        alternativeDescription: '',
        page: 1,
        limit: 10
      },
      // loading
      queryLoading: false,
      // 初始页签

      // ======== 数据对象 ========

      // ======== 选中的当前行数据 ========

      // ======== 数据列表 ========
      dataList: [],
      // ======== 列表表头 ========
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1PartNo',
          tableId: '104011Table1',
          tableName: 'Routing表',
          columnProp: 'partNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1PartDesc',
          tableId: '104011Table1',
          tableName: 'Routing表',
          columnProp: 'partDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1RoutingType',
          tableId: '104011Table1',
          tableName: 'Routing表',
          columnProp: 'routingType',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '工艺类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1RoutingRevision',
          tableId: '104011Table1',
          tableName: 'Routing表',
          columnProp: 'routingRevision',
          headerAlign: 'center',
          align: 'right',
          columnLabel: 'Routing版本号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1AlternativeNo',
          tableId: '104011Table1',
          tableName: 'Routing表',
          columnProp: 'alternativeNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '替代编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1AlternativeDescription',
          tableId: '104011Table1',
          tableName: 'Routing表',
          columnProp: 'alternativeDescription',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '替代名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1OperationNo',
          tableId: '104011Table1',
          tableName: 'Routing表',
          columnProp: 'operationNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '工序编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1OperationName',
          tableId: '104011Table1',
          tableName: 'Routing表',
          columnProp: 'operationName',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '工序名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1GuidelineSeq',
          tableId: '104011Table1',
          tableName: 'workGuideline表',
          columnProp: 'guidelineSeq',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '序号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1GuidelineDesc',
          tableId: '104011Table1',
          tableName: 'workGuideline表',
          columnProp: 'guidelineDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '工艺指导名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1GuidelineText',
          tableId: '104011Table1',
          tableName: 'workGuideline表',
          columnProp: 'guidelineText',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '工艺指导描述',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1GuidelineType',
          tableId: '104011Table1',
          tableName: 'workGuideline表',
          columnProp: 'guidelineType',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '工艺指导类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1SignOffRequired',
          tableId: '104011Table1',
          tableName: 'workGuideline表',
          columnProp: 'signOffRequired',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '签字',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1InspectionSignOffRequired',
          tableId: '104011Table1',
          tableName: 'workGuideline表',
          columnProp: 'inspectionSignOffRequired',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '检验签字',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1CreateDate',
          tableId: '104011Table1',
          tableName: 'BOM信息表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 170
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1CreateBy',
          tableId: '104011Table1',
          tableName: 'BOM信息表',
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1UpdateDate',
          tableId: '104011Table1',
          tableName: 'BOM信息表',
          columnProp: 'updateDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 170
        },
        {
          userId: this.$store.state.user.name,
          functionId: 104011,
          serialNumber: '104011Table1UpdateBy',
          tableId: '104011Table1',
          tableName: 'BOM信息表',
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        }
      ],
      // ======== 必填规则 ========

      // ======== 复选数据集 ========

      // ======== 模态框开关控制 ========

    }
  },

  mounted () {
    this.$nextTick(() => {
      this.height = window.innerHeight - 180
    })
  },

  created () {
    this.getDataList()
  },

  // js
  methods: {
    // ======== 分页相关方法 ========
    /**
     * 每页数
     * @param val
     */
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },

    /**
     * 当前页
     * @param val
     */
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },

    // ======== 列表数据操作方法 ========
    /**
     * 获取数据列表
     */
    getDataList () {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      this.queryLoading = true
      workGuidelinesSearch(this.searchData).then(({data}) => {
        if (data.code === 0) {
          this.dataList = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
        }
        this.queryLoading = false
      })
    },

    // ======== chooseList相关方法 ========
    /**
     * 获取基础数据列表S
     * @param val
     * @param type
     */
    getBaseList (val, type) {
      this.tagNo = val
      this.$nextTick(() => {
        let strVal = ''
        if (val === 117) {
          strVal = this.componentData.issueToLoc
        }
        this.$refs.baseList.init(val, strVal)
      })
    },
    /**
     * 列表方法的回调
     * @param val
     */
    getBaseData (val) {
      if (this.tagNo === 117) {
        this.componentData.issueToLoc = val.location_id
        this.componentData.issueToLocName = val.location_name
      }
    },

    // ======== 导出相关方法 ========
    /**
     * 导出excel
     */
    async createExportData () {
      this.searchData.limit = -1
      this.searchData.page = 1
      await workGuidelinesSearch(this.searchData).then(({data}) => {
        this.resultList = data.page.list
      })
      return this.resultList
    },
    startDownload () {},
    finishDownload () {},
    fields () {
      let json = '{'
      this.columnList.forEach((item, index) => {
        if (index == this.columnList.length - 1) {
          json += '"' + item.columnLabel + '"' + ':' + '"' + item.columnProp + '"'
        } else {
          json += '"' + item.columnLabel + '"' + ':' + '"' + item.columnProp + '"' + ','
        }
      })
      json += '}'
      let s = eval('(' + json + ')')
      return s
    },
    /**
     * 未知
     * @returns {boolean}
     */
    selectFlag () {
      return true
    },
  }
}
</script>

<style scoped lang="scss">
.numInput /deep/ .el-input__inner{
  text-align: right;
}
/deep/  .inlineNumber input::-webkit-outer-spin-button,
/deep/  .inlineNumber input::-webkit-inner-spin-button {
  -webkit-appearance: none;

}
/deep/  .inlineNumber input[type="number"]{
  -moz-appearance: textfield;
  padding-right: 5px !important;
}
</style>










