<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-form
          :inline="true"
          class="demo-form-inline"
          label-position="right"
          label-suffix=":"
        >
          <el-form-item :label="$t('Hot.pan1.dialog.point_code')">
            <el-input
              v-model="query.point_code"
              clearable
              :placeholder="$t('Hot.pan1.search.p1')"
              style="width: 185px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.point_status')">
            <el-select
              v-model="query.point_status"
              clearable
              filterable
              size="mini"
              class="filter-item"
              style="width: 185px;"
              @change="hand"
            >
              <el-option
                v-for="item in dict.sch_hot_point_status"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.product_area')">
            <el-select
              v-model="query.product_area"
              clearable
              filterable
              size="mini"
              class="filter-item"
              style="width: 185px;"
              @change="hand"
            >
              <el-option
                v-for="item in dict.product_area"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.is_used')">
            <el-switch
              v-model="query.is_used"
              active-value="0"
              inactive-value="1"
              active-color="#C0CCDA"
              inactive-color="#409EFF"
              @change="hand"
            />
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.point_location')">
            <el-select
              v-model="query.point_location"
              clearable
              filterable
              size="mini"
              class="filter-item"
              style="width: 185px;"
            >
              <el-option
                v-for="item in dict.point_location"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.instorage_time')">
            <el-date-picker
              v-model="query.createTime"
              type="daterange"
              value-format="yyyy-MM-dd HH:mm:ss"
              :start-placeholder="$t('common.startDate')"
              :end-placeholder="$t('common.endDate')"
              :default-time="['00:00:00', '23:59:59']"
              @change="crud.toQuery"
            />
          </el-form-item>
          <rrOperation :crud="crud" />
        </el-form>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <el-button
          slot="right"
          class="filter-item"
          type="success"
          icon="el-icon-position"
          size="mini"
          :disabled="crud.selections.length !== 1"
          @click="uploadMES"
        >
          {{ $t('Hot.pan1.search.button_1') }}
        </el-button>
      </crudOperation>
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        :width="computedLabelWidth"
      >
        <el-form ref="form" :model="form" :rules="rules" size="mini" :label-width="computedFormLabelWidth">
          <el-form-item :label="$t('Hot.pan1.dialog.point_code')" prop="point_code">
            <el-input v-model="form.point_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.product_area')">
            <el-select
              v-model="query.product_area"
              clearable
              filterable
              size="mini"
              class="filter-item"
              style="width: 370px;"
            >
              <el-option
                v-for="item in dict.product_area"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.point_status')" prop="point_status">
            <el-select
              v-model="form.point_status"
              clearable
              filterable
              size="mini"
              class="filter-item"
              style="width: 370px;"
            >
              <el-option
                v-for="item in dict.sch_hot_point_status"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.container_name')">
            <el-input v-model="form.container_name" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.temperature')">
            <el-input v-model="form.temperature" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('Hot.pan1.dialog.is_used')" prop="is_used">
            <el-switch v-model="form.is_used" active-value="1" inactive-value="0" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">{{ $t('common.Cancel') }}</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">{{ $t('common.Confirm') }}</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="mini"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column
          prop="point_code"
          :min-width="flexWidth('point_code',crud.data,$t('Hot.pan1.table.point_code'))"
          show-overflow-tooltip
          :label="$t('Hot.pan1.table.point_code')"
        />
        <el-table-column
          prop="point_status"
          :label="$t('Hot.pan1.table.point_status')"
          :min-width="flexWidth('point_status',crud.data,$t('Hot.pan1.table.point_status'))"
        >
          <template slot-scope="scope">
            {{ dict.label.sch_hot_point_status[scope.row.point_status] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="container_name"
          :label="$t('Hot.pan1.table.container_name')"
          :min-width="flexWidth('container_name',crud.data,$t('Hot.pan1.table.container_name'))"
          show-overflow-tooltip
        />
        <el-table-column
          prop="ivt_qty"
          :label="$t('Hot.pan1.table.ivt_qty')"
          :formatter="crud.formatNum3"
          :min-width="flexWidth('ivt_qty',crud.data,$t('Hot.pan1.table.ivt_qty'))"
        />
        <el-table-column
          prop="instorage_time"
          :label="$t('Hot.pan1.table.instorage_time')"
          :min-width="flexWidth('instorage_time',crud.data,$t('Hot.pan1.table.instorage_time'))"
          show-overflow-tooltip
        />
        <el-table-column
          prop="product_area"
          :label="$t('Hot.pan1.table.product_area')"
          :min-width="flexWidth('product_area',crud.data,$t('Hot.pan1.table.product_area'))"
        >
          <template slot-scope="scope">
            {{ dict.label.product_area[scope.row.product_area] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="temperature"
          :label="$t('Hot.pan1.table.temperature')"
          :min-width="flexWidth('temperature',crud.data,$t('Hot.pan1.table.temperature'), 10)"
        />
        <el-table-column
          prop="last_time"
          :label="$t('Hot.pan1.table.last_time')"
          :min-width="flexWidth('last_time',crud.data,$t('Hot.pan1.table.last_time'))"
        />
        <el-table-column
          prop="group_name"
          :label="$t('Hot.pan1.table.group_name')"
          :min-width="flexWidth('group_name',crud.data,$t('Hot.pan1.table.group_name'))"
        />
        <el-table-column
          prop="ext_code"
          :label="$t('Hot.pan1.table.ext_code')"
          :min-width="flexWidth('ext_code',crud.data,$t('Hot.pan1.table.ext_code'))"
        />
        <el-table-column
          prop="point_location"
          :label="$t('Hot.pan1.table.point_location')"
          :min-width="flexWidth('point_location',crud.data,$t('Hot.pan1.table.point_location'), 10)"
        >
          <template slot-scope="scope">
            {{ dict.label.point_location[scope.row.point_location] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="is_used"
          :label="$t('Hot.pan1.table.is_used')"
          :min-width="flexWidth('is_used',crud.data,$t('Hot.pan1.table.is_used'))"
        >
          <template slot-scope="scope">
            {{ dict.label.is_used[scope.row.is_used] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="remark"
          :label="$t('Hot.pan1.table.remark')"
          :min-width="flexWidth('remark',crud.data,$t('Hot.pan1.table.remark'))"
        />
        <el-table-column
          prop="update_time"
          :label="$t('Hot.pan1.table.update_time')"
          :min-width="flexWidth('update_time',crud.data,$t('Hot.pan1.table.update_time'))"
          show-overflow-tooltip
        />
        <el-table-column v-permission="[]" :label="$t('common.Operate')" width="120px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
              :is-visiable-del="false"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
    <Dialog :dialog-show.sync="dialogShow" :open-param="openParam" />
  </div>
</template>

<script>
import crudHotpointivt from './hotpointivt'
import CRUD, { crud, form, header, presenter } 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 Dialog from '@/views/wms/pdm/ivt/hotpointivt/Dialog.vue'
import i18n from '@/i18n'

const defaultForm = {
  ivt_id: null,
  point_code: null,
  point_status: null,
  container_name: null,
  workorder_id: null,
  full_vehicle_code: null,
  pcsn: null,
  ivt_qty: null,
  qty_unit_id: null,
  instorage_time: null,
  product_area: null,
  temperature: null,
  group_name: null,
  point_location: null,
  sort_seq: null,
  is_used: null,
  remark: null,
  create_id: null,
  create_name: null,
  create_time: null,
  update_optid: null,
  update_optname: null,
  update_time: null
}
export default {
  name: 'HotPointIvt',
  components: { Dialog, pagination, crudOperation, rrOperation, udOperation },
  dicts: ['product_area', 'is_used', 'point_location', 'sch_hot_point_status'],
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: i18n.t('Hot.pan1.title'),
      url: 'api/hotpointivt',
      idField: 'ivt_id',
      sort: 'ivt_id,desc',
      crudMethod: { ...crudHotpointivt },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: false,
        reset: true
      }
    })
  },
  data() {
    return {
      permission: {},
      openParam: null,
      dialogShow: false,
      rules: {
        point_code: [
          { required: true, message: i18n.t('Hot.pan1.msg.m1'), trigger: 'blur' }
        ],
        point_status: [
          { required: true, message: i18n.t('Hot.pan1.msg.m2'), trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    computedLabelWidth() {
      const item = localStorage.getItem('lang')
      if (item === 'zh') {
        return `520px`
      }
      return `540px`
    },
    computedFormLabelWidth() {
      const item = localStorage.getItem('lang')
      if (item === 'zh') {
        return `100px`
      }
      return `120px`
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    hand(value) {
      this.crud.toQuery()
    },
    uploadMES() {
      debugger
      const _selectData = this.$refs.table.selection
      if (_selectData.length !== 1) {
        return this.crud.notify(i18n.t('Hot.pan1.msg.m3'), CRUD.NOTIFICATION_TYPE.INFO)
      }
      this.openParam = _selectData[0]
      this.dialogShow = true
    }
  }
}
</script>

<style scoped>

</style>
