<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
          <el-select v-model="query.operType" clearable placeholder="操作类型" style="width: 185px;" class="filter-item"
                     @keyup.enter.native="crud.toQuery" clearable>
            <el-option
              v-for="baseStatus in dict.bom_oper_type"
              :key="baseStatus.id"
              :label="baseStatus.label"
              :value="baseStatus.value"
            />
          </el-select>
        <date-range-picker v-model="query.createTime" class="date-item" style="width: 100px"/>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" :tableKey="this.$options.name"/>
      <!--表单组件-->
      <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 id="mytable" ref="table" border :height="crud.tableHeight" 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="序号"  width="60" />
        <el-table-column prop="operType" label="操作类型">
          <template slot-scope="scope">
            {{ dict.label.bom_oper_type[scope.row.operType] }}
          </template>
        </el-table-column>
        <el-table-column prop="bigItem.code" label="机型"  width="120" />
        <el-table-column prop="bigItem.name" label="机型名" width="150" align="center" />
        <el-table-column prop="rArea.code" label="工位" width="80"/>
        <el-table-column prop="rArea.name" label="指示纳所" width="250"/>
        <el-table-column prop="item.code" label="部品品番" width="100"/>
        <el-table-column prop="item.name" label="品名" width="150"/>
        <el-table-column prop="ac" label="A/C" width="50"/>
        <el-table-column prop="process_content#contents" label="加工内容" width="70">
          <template slot-scope="scope">
            {{ dict.label.process_content[scope.row.contents] }}
          </template>
        </el-table-column>
        <el-table-column prop="singles" label="单用" width="50"/>
        <el-table-column prop="zPoint.code" label="制造库位" />
        <el-table-column prop="cArea.code" label="出库库区" width="150" align="center"  />
        <el-table-column prop="out_type#outType" label="出库类型"  width="70">
          <template slot-scope="scope">
            {{ dict.label.out_type[scope.row.outType] }}
          </template>
        </el-table-column>
        <el-table-column prop="bp_type#bp_type" label="部品种类" width="70">
          <template slot-scope="scope">
            {{ dict.label.bp_type[scope.row.bp_type] }}
          </template>
        </el-table-column>
        <el-table-column prop="updateTime" label="操作日期" width="135">
          <template slot-scope="scope">
            {{getFormatDate(scope.row.updateTime)}}
          </template>
        </el-table-column>
        <el-table-column prop="updateBy" label="操作人" />
        <el-table-column prop="createTime" label="创建日期" width="135"/>
        <el-table-column prop="supplier" label="供应商" width="120" :show-overflow-tooltip="true"/>
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="description" label="描述" />
        <el-table-column prop="bomAccountId" label="BOMID" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudBomAccountLog from '@/api/bomAccountLog'
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 {formatDate} from "@/utils/commonUtils";
import bigItem from "@/api/bigItem";
import {queryAreaList} from "@/api/area";
import {getItemsList} from "@/api/item";
import DateRangePicker from "@/components/DateRangePicker/index.vue";

const defaultForm = { id: null, bigItemId: null, itemId: null, ac: null, contents: null, bonded: null, singles: null, rAreaId: null, cAreaId: null, outType: null, stationType: null, bpType: null, zPointId: null, hPointId: null, deptId: null, description: null, enabled: null, createBy: null, updateBy: null, createTime: null, updateTime: null, supplier: null, bomAccountId: null, operType: null }
export default {
  name: 'BomAccountLog',
  components: {DateRangePicker, pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['bom_oper_type','process_content', 'out_type', 'station_type', 'bp_type','bonded_type','ac_type'],
  cruds() {
    return CRUD({ title: 'bomAccountLog', url: 'api/bomAccountLog', idField: 'id', sort: 'id,desc', crudMethod: { ...crudBomAccountLog },
      optShow: {
        add: false,
        edit: false,
        del: false,
        reset: false,
        download: true
      },})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'bomAccountLog:add'],
        edit: ['admin', 'bomAccountLog:edit'],
        del: ['admin', 'bomAccountLog:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'operType', display_name: '操作类型' }
      ],
    }
  },
  mounted() {
    this.getRAreaList()
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, getBigItemList() {
      bigItem.getBigItem(1).then(res => {
        this.bigItemList = res.map(function(obj) {
          if (obj.hasChildren) {
            obj.children = null
          }
          return obj
        })
      })
    },
    getRAreaList() {
      queryAreaList({bexb:true,enabled:true}).then(res=>{
        this.rAreaList = res
      })
      // getAreas().then(res => {
      //   this.rAreaList = res.map(function(obj) {
      //     if (obj.hasChildren) {
      //       obj.children = null
      //     }
      //     return obj
      //   })
      // })
    },
    getCAreaList() {
      queryAreaList({bexb:false,enabled:true}).then(res=>{
        this.cAreaList = res
      })

      // getAreas().then(res => {
      //   this.cAreaList = res.map(function(obj) {
      //     if (obj.hasChildren) {
      //       obj.children = null
      //     }
      //     return obj
      //   })
      // })
    },
    getItemList() {
      getItemsList().then(res => {
        this.itemList = res.map(function(obj) {
          if (obj.hasChildren) {
            obj.children = null
          }
          return obj
        })
      })
    },
    //日期格式化
    getFormatDate(data){
      return  formatDate(data);
    },
  }
}
</script>

<style scoped>

</style>
