<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-width="80px"
          label-suffix=":"
        >
          <el-form-item label="碳化钨">
            <el-input
              v-model="query.material_code"
              clearable
              size="mini"
              placeholder="编码、名称"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="工艺">
            <el-radio v-model="form.tech_type" label="01">负压脱蜡</el-radio>
            <el-radio v-model="form.tech_type" label="02">氢气脱蜡</el-radio>
          </el-form-item>
          <rrOperation />
        </el-form>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表格渲染-->
      <h4>注意：1.修正值必须为-0.5~0.5之间的小数；2.若无此软废，修正填为99；</h4>
      <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 v-if="false" prop="change_id" label="记录标识" />
        <el-table-column v-if="false" prop="material_id" label="物料标识" />
        <el-table-column prop="material_code" label="物料编码" width="120px" show-overflow-tooltip />
        <el-table-column prop="material_name" label="物料名称" width="120px" show-overflow-tooltip />
        <el-table-column prop="" label="型号" />
        <el-table-column prop="tech_type" label="工艺" :formatter="formName" />
        <el-table-column prop="cf_qty" label="CF" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].cf_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="yz_qty" label="YZ" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].yz_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="cx_qty" label="CX" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].cx_qty"
              size="small"
              :controls="false"
              style="width: 95px"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="yc_qty" label="YC" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].yc_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="jy_qty" label="JY" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].jy_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="lt_qty" label="LT" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].lt_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="sj_qty" label="SJ" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].sj_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="ys_qty" label="YS" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].ys_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="ds_qty" label="DS" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].ds_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="cqx_qty" label="CQX" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].cqx_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="xqx_qty" label="XQX" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].xqx_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="qx_qty" label="QX" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].qx_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="jcf_qty" label="JCF" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].jcf_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="tb_qty" label="TB" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].tb_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="ycr_qty" label="YCR" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].ycr_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="gz_qty" label="GZ" width="120">
          <template slot-scope="scope">
            <el-input-number
              v-model="crud.data[scope.$index].gz_qty"
              size="small"
              style="width: 95px"
              :controls="false"
              controls-position="right"
              :precision="2"
              :min="-10000"
            />
          </template>
        </el-table-column>
        <el-table-column prop="create_name" label="维护人" />
        <el-table-column prop="create_time" label="维护时间" width="150px"/>
        <el-table-column v-permission="[]" label="操作" width="120px" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button type="success" size="mini" :loading="confirm_flg" @click="confirm(scope.row)">确认</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudWastecchange from '@/api/wms/basedata/pdm/wastecchange'
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'

const defaultForm = { change_id: null, material_id: null, tech_type: '01', cf_qty: null, yz_qty: null, cx_qty: null, yc_qty: null, jy_qty: null, lt_qty: null, sj_qty: null, ys_qty: null, ds_qty: null, cqx_qty: null, xqx_qty: null, qx_qty: null, jcf_qty: null, tb_qty: null, ycr_qty: null, gz_qty: null, create_id: null, create_name: null, create_time: null }
export default {
  name: 'Wastecchange',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '软废碳平衡修正维护',
      url: 'api/wastecchange',
      idField: 'change_id',
      sort: 'change_id,desc',
      crudMethod: { ...crudWastecchange },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: false,
        reset: true
      }})
  },
  data() {
    return {
      confirm_flg: false,
      permission: {
      },
      rules: {
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    formName(row) {
      if (row.tech_type === '01') {
        return '负压脱蜡'
      } else if (row.tech_type === '02') {
        return '氢气脱蜡'
      }
    },
    confirm(row) {
      row.tech_type = this.form.tech_type
      this.confirm_flg = true
      crudWastecchange.confirm(row).then(res => {
        this.crud.notify('操作成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
        this.crud.toQuery()
        this.confirm_flg = false
      }).catch(() => {
        this.crud.toQuery()
        this.confirm_flg = false
      })
    }
  }
}
</script>

<style scoped>

</style>
