永康嘉持电器有限公司前端
小小儁爺
2024-12-30 ff2f7d7bad0132c130c305364a863ff446e926b2
src/views/basicSettings/meterPrice.vue
@@ -1,707 +1,712 @@
<template>
  <div>
    <div class="body" :style="{height:mainHeight+'px'}">
      <div class="bodyTopButtonGroup" style="justify-content: space-between">
        <el-button v-waves type="primary" icon="el-icon-circle-plus-outline" @click="add('add')">新增</el-button>
        <!--        <el-button v-waves icon="el-icon-download" @click=" ">导入</el-button>-->
      </div>
      <div class="bodyTopFormGroup">
        <el-form
          ref="form"
          :model="form"
          label-width="100px"
          inline
          style="display: flex;"
        >
          <div class="elForm">
            <el-form-item label="产品名称/编码" style=" display: flex;">
              <el-select
                v-model="form.partcode"
                filterable
                :popper-append-to-body="false"
                style="width: 200px"
                placeholder="请选择"
                @change="partChange"
              >
                <!--                @focus="getPartSelect"-->
                <el-option
                  v-for="item in partArr"
                  :key="item.partcode"
                  :label="item.partname+'/'+item.partcode"
                  :value="item.partcode"
                />
              </el-select>
            </el-form-item>
            <el-form-item
              v-if="mesSetting.route"
              label="工艺路线"
              style="display: flex;"
            >
              <el-select
                v-model="form.routecode"
                filterable
                :disabled="form.partcode===''"
                :popper-append-to-body="false"
                style="width: 200px"
                placeholder="请选择"
                @change="routeChange"
              >
                <el-option
                  v-for="item in routeArr"
                  :key="item.route_code"
                  :label="item.route_name"
                  :value="item.route_code"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="关联工序" style=" display: flex;">
              <el-select
                v-model="form.stepcode"
                :disabled="mesSetting.route?form.routecode==='':form.partcode===''"
                :popper-append-to-body="false"
                style="width: 200px"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in stepArr"
                  :key="item.step_code"
                  :label="item.step_name"
                  :value="item.step_code"
                />
              </el-select>
            </el-form-item>
            <!--按工序-->
            <!--            <el-form-item-->
            <!--              v-if="!mesSetting.route"-->
            <!--              label="工艺路线"-->
            <!--              style="display: flex;"-->
            <!--            >-->
            <!--              <el-select-->
            <!--                v-model="form.routecode"-->
            <!--                filterable-->
            <!--                :disabled="form.partcode===''"-->
            <!--                :popper-append-to-body="false"-->
            <!--                style="width: 200px"-->
            <!--                placeholder="请选择"-->
            <!--                @change="routeChange"-->
            <!--              >-->
            <!--                <el-option-->
            <!--                  v-for="item in routeArr"-->
            <!--                  :key="item.route_code"-->
            <!--                  :label="item.route_name"-->
            <!--                  :value="item.route_code"-->
            <!--                />-->
            <!--              </el-select>-->
            <!--            </el-form-item>-->
          </div>
          <div
            class="bodySearchReset"
            :style="{marginLeft:$store.state.app.sidebar.opened? $store.state.settings.menuIsHorizontal?'15%':'3%':'10%'}"
          >
            <el-button v-waves type="primary" icon="el-icon-search" @click="search">查询</el-button>
            <el-button v-waves type="info" icon="el-icon-refresh" @click="reset">重置</el-button>
          </div>
        </el-form>
        <div
          class="bodyTopFormExpand"
        />
      </div>
      <div class="elTableDiv">
        <!--        <TableColumnSettings-->
        <!--          :list1="tableColumnSettingsArray"-->
        <!--          @tableColumnUpdate="tableColumnUpdate"-->
        <!--        />-->
        <el-table
          ref="tableDataRef"
          :key="tableTimeStampArrayKey"
          class="tableFixed"
          :data="tableData"
          :height="tableHeight"
          border
          :row-class-name="tableRowClassName"
          :style="{width: 100+'%',height:tableHeight+'px',}"
          highlight-current-row
          :header-cell-style="this.$headerCellStyle"
          :cell-style="this.$cellStyle"
          @sort-change="sortChange"
        >
          <el-table-column
            v-for="item in tableColumnSettingsArray"
            v-if="item.show"
            :key="item.id"
            :sortable="item.sortable"
            :prop="item.prop"
            :min-width="item.minWidth"
            :label="item.label"
            :width="item.width"
            show-tooltip-when-overflow
            :fixed="item.fixed?(item.fixed==='left'?'left':'right'):false"
          >
            <template slot-scope="{row}">
              <div v-if="!row[item.prop]">/</div>
              <div v-else-if="item.prop==='eqp_value'||item.prop==='stand_value'">
                {{ row[item.prop] }} 秒
              </div>
              <div v-else>{{ row[item.prop] }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            fixed="right"
            width="120"
          >
            <template slot-scope="{row}">
              <div class="operationClass">
                <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                  <i
                    :style="{color:$store.state.settings.theme}"
                    class="el-icon-edit-outline"
                    @click="edit('edit',row)"
                  />
                </el-tooltip>
                <el-tooltip v-del-tab-index class="item" effect="dark" content="删除" placement="top">
                  <i :style="{color:$store.state.settings.theme}" class="el-icon-delete" @click="del(row)" />
                </el-tooltip>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页-->
      <pagination
        :total="total"
        :page.sync="form.page"
        :limit.sync="form.rows"
        align="right"
        layout="total,prev, pager, next,sizes"
        popper-class="select_bottom"
        @pagination="getBeatRateSearch"
      />
    </div>
    <el-dialog
      v-el-drag-dialog
      :title="operation==='add'?'新增':'编辑'"
      :visible.sync="dialogVisible"
      width="1100px"
      top="15vh"
      :close-on-click-modal="false"
      @closed="handleClose"
      @close="handleClose"
    >
      <el-form ref="dialogForm" inline :model="dialogForm" label-width="100px">
        <div style="display: flex;align-items: center">
          <i class="el-icon-s-comment" :style="{color:$store.state.settings.theme}" style="margin-top: -20px" />
          <el-form-item prop="partcode" label="产品名称/编码">
            <el-select
              v-show="operation==='add'"
              v-model="dialogForm.partcode"
              filterable
              style="width: 220px"
              placeholder="请选择"
              :popper-append-to-body="false"
              @change="partDialogChange"
            >
              <!--              @focus="getPartSelect2"-->
              <el-option
                v-for="item in partArr2"
                :key="item.partcode"
                :label="item.partname+'/'+item.partcode"
                :value="item.partcode"
              />
            </el-select>
            <el-input
              v-show="operation!=='add'"
              v-model="editPartName"
              disabled
              style="width: 220px"
            />
          </el-form-item>
          <el-form-item v-if="mesSetting.route" prop="routecode" label="工艺路线">
            <el-select
              v-show="operation==='add'"
              v-model="dialogForm.routecode"
              style="width: 220px"
              filterable
              :disabled="dialogForm.partcode===''"
              placeholder="请选择"
              :popper-append-to-body="false"
              @change="routeDialogChange"
            >
              <el-option
                v-for="item in routeDialogArr"
                :key="item.route_code"
                :label="item.route_name"
                :value="item.route_code"
              />
            </el-select>
            <el-input
              v-show="operation!=='add'"
              v-model="editRouteName"
              disabled
              style="width: 220px"
            />
          </el-form-item>
        </div>
      </el-form>
      <el-table
        :data="stepDialogArr"
        style="width: 100%"
        height="300"
        border
        :header-cell-style="this.$headerCellStyle"
        :cell-style="this.$cellStyle"
        :row-class-name="tableRowClassName"
      >
        <el-table-column
          prop="step_seq"
          label="工序顺序"
          width="100"
        />
        <el-table-column
          prop="step_code"
          label="工序编码"
          width="200"
        />
        <el-table-column
          prop="step_name"
          label="工序名称"
          width="200"
        />
        <el-table-column
          prop="unprice"
          label="工序工价"
        >
          <template slot-scope="{row}">
            <el-input v-model="row.unprice" oninput="value=value.replace(/[^0-9.]/g,'')" />
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <div class="footerButton">
          <el-button v-waves @click="dialogVisibleCancel">返 回</el-button>
          <el-button v-waves type="primary" @click="dialogVisibleConfirm">确 定</el-button>
        </div>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import {
  BeatRateSearch, DeleteBeatRate,
  PartSelect,
  PartSelectRpute,
  RouteSelectStep, SaveBeatRate
} from '@/api/basicSettings'
import elDragDialog from '@/directive/el-drag-dialog'
import waves from '@/directive/waves'
import TableColumnSettings from '@/components/TableColumnSettings'
export default {
  name: 'MeterPrice',
  components: {
    Pagination, TableColumnSettings
  },
  directives: { elDragDialog, waves },
  data() {
    return {
      mesSetting: JSON.parse(localStorage.getItem('mesSetting')),
      mainHeight: 0,
      tableHeight: 0,
      form: {
        partcode: '', // 产品编码
        routecode: '', // 工艺路线编码
        stepcode: '', // 工序编码
        prop: 'partcode', // 排序字段
        order: 'desc', // 排序字段
        page: 1, // 第几页
        rows: 20 // 每页多少条
      },
      partArr: [], // 产品集合
      partArr2: [], // 产品集合对话框
      routeArr: [], // 工艺路线
      stepArr: [], // 工序
      total: 10,
      tableData: [],
      tableColumnSettingsArray: [
        // { minWidth: 50, width: false, prop: 'id', label: 'id', id: 1, show: false, fixed: false, sortable: false }, // 隐藏列  show: false隐藏,true显示
        { minWidth: 25, width: 50, prop: 'rowNum', label: '序号', id: 2, show: true, fixed: 'left', sortable: false }, // custom
        {
          minWidth: 110,
          width: false,
          prop: 'partcode',
          label: '产品编码',
          id: 3,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: 110,
          width: false,
          prop: 'partname',
          label: '产品名称',
          id: 4,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: 110,
          width: false,
          prop: 'partspec',
          label: '产品规格',
          id: 5,
          show: true,
          fixed: false,
          sortable: true
        },
        // {
        //   minWidth: 110,
        //   width: false,
        //   prop: 'wksp_code',
        //   label: '生产车间编码',
        //   id: 6,
        //   show: false,
        //   fixed: false,
        //   sortable: true
        // },
        // {
        //   minWidth: false,
        //   width: 110,
        //   prop: 'wksp_name',
        //   label: '生产车间',
        //   id: 7,
        //   show: true,
        //   fixed: false,
        //   sortable: true
        // },
        {
          minWidth: 110,
          width: false,
          prop: 'route_code',
          label: '工艺路线编码',
          id: 8,
          show: false,
          fixed: false,
          sortable: true
        }, {
          minWidth: 110,
          width: false,
          prop: 'route_name',
          label: '工艺路线',
          id: 9,
          show: true,
          fixed: false,
          sortable: true
        }, {
          minWidth: 110,
          width: false,
          prop: 'stepcode',
          label: '工序编码',
          id: 10,
          show: false,
          fixed: false,
          sortable: true
        }, {
          minWidth: 110,
          width: false,
          prop: 'stepname',
          label: '工序名称',
          id: 11,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: 110,
          width: false,
          prop: 'unprice',
          label: '计件单价',
          id: 12,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: false,
          width: 110,
          prop: 'lm_user',
          label: '创建人员',
          id: 13,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: false,
          width: 160,
          prop: 'lm_date',
          label: '创建时间',
          id: 14,
          show: true,
          fixed: false,
          sortable: true
        }
      ],
      tableTimeStampArrayKey: new Date().getTime(), // 表格key
      dialogVisible: false,
      dialogForm: {
        partcode: '', //  产品编码
        routecode: '', //  工艺路线编码
        stepcode: '', //  工序编码
        wkshopcode: '', // 生产车间编码
        eqp_value: '', // 设备节拍
        stand_value: '', // 生产节拍
        cavity_qty: '', // 型腔数
        unprice: ''//  计件单价
      },
      routeDialogArr: [], // 工艺路线
      stepDialogArr: [], // 工序集合
      editPartName: '', // 编辑时产品名称
      editRouteName: '', // 编辑时工艺路线名称
      editStepName: '', // 编辑时加工工序名称
      operation: ''
    }
  },
  activated() {   window.addEventListener('resize', this.getHeight)   this.getHeight() }, created() {
    this.handleRequest()
  },
  mounted() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
    if (!this.mesSetting.route) {
      this.tableColumnSettingsArray = this.tableColumnSettingsArray.filter(i => i.prop !== 'route_name')
    }
  },
  methods: {
    tableColumnUpdate(val, isCopyTrue) {
      if (isCopyTrue) {
        this.tableColumnSettingsArray = val
      }
      this.tableTimeStampArrayKey = new Date().getTime()
      this.$refs.tableDataRef.doLayout()
    },
    tableRowClassName({ row, rowIndex }) {
      return 'custom-row'
    },
    handleRequest() {
      this.getBeatRateSearch().then(res => {
        if (res.code === '200') {
          this.getPartSelect()
        }
      })
    },
    async getBeatRateSearch() {
      const res = await BeatRateSearch(this.form)
      this.tableData = res.data
      this.total = res.count
      return { code: res.code }
    },
    // 排序改变时
    sortChange({ column, prop, order }) {
      if (order === 'descending') {
        order = 'desc'
      } else if (order === 'ascending') {
        order = 'asc'
      } else {
        order = 'desc'
      }
      this.form.order = order
      this.form.prop = prop
      this.getBeatRateSearch()
    },
    // 查询
    search() {
      this.getBeatRateSearch()
    },
    async getPartSelect() {
      const { data: res } = await PartSelect()
      this.partArr = res
    },
    async getPartSelect2() {
      const { data: res } = await PartSelect()
      this.partArr2 = res
    },
    async partChange(val) {
      const { data: res } = await PartSelectRpute({ partcode: val })
      if (this.mesSetting.route) {
        this.routeArr = res
        this.form.routecode = ''
      } else {
        this.stepArr = res
      }
      this.form.stepcode = ''
    },
    async routeChange(val) {
      const { data: res } = await RouteSelectStep({ partcode: this.form.partcode, routecode: val })
      this.stepArr = res
      this.form.stepcode = ''
    },
    // 重置
    reset() {
      this.form.partcode = ''
      this.form.routecode = ''
      this.form.stepcode = ''
      this.getBeatRateSearch()
    },
    async partDialogChange(val) {
      const { data: res } = await PartSelectRpute({ partcode: val })
      if (this.mesSetting.route) {
        this.routeDialogArr = res
        this.stepDialogArr = []
        this.dialogForm.routecode = ''
      } else {
        this.stepDialogArr = res
      }
    },
    async routeDialogChange(val) {
      const { data: res } = await RouteSelectStep({ partcode: this.dialogForm.partcode, routecode: val })
      this.stepDialogArr = res
    },
    // 新增按钮
    add(operation) {
      this.operation = operation
      this.dialogVisible = true
      this.getPartSelect2()
    },
    // 修改按钮
    async edit(operation, row) {
      this.operation = operation
      this.dialogVisible = true
      this.editPartName = row.partname
      this.editRouteName = row.route_name
      this.editStepName = row.stepname
      await this.partDialogChange(row.partcode)
      this.dialogForm.partcode = row.partcode
      if (this.mesSetting.route) {
        await this.routeDialogChange(row.route_code)
      }
      this.dialogForm.routecode = row.route_code
      this.dialogForm.stepcode = row.stepcode
    },
    // 删除按钮
    async del(row) {
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        DeleteBeatRate({ id: row.id }).then(res => {
          if (res.code === '200') {
            this.$message.success('删除成功!')
            if (this.form.page > 1 && this.tableData.length === 1) {
              this.form.page--
            }
            this.getBeatRateSearch()
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    },
    // 对话框关闭事件
    handleClose() {
      this.dialogForm.partcode = ''
      this.dialogForm.routecode = ''
      this.dialogForm.stepcode = ''
      this.dialogForm.wkshopcode = ''
      this.dialogForm.eqp_value = ''
      this.dialogForm.stand_value = ''
      this.dialogForm.cavity_qty = ''
      this.dialogForm.unprice = ''
      this.eqpTableLength = 0
      this.routeDialogArr = []
      this.stepDialogArr = []
      this.$refs.dialogForm.clearValidate()
      this.getBeatRateSearch()
    },
    // 对话框取消
    dialogVisibleCancel() {
      this.dialogVisible = false
    },
    // 对话框确认
    dialogVisibleConfirm() {
      this.$refs.dialogForm.validate(valid => {
        if (valid) {
          const children = []
          this.stepDialogArr.forEach(i => {
            children.push({
              'code': i.step_code,
              'name': i.step_name,
              'seq': i.step_seq,
              'isbott': i.isbott,
              'isend': i.isend,
              'unprice': i.unprice
            })
          })
          const data = [
            {
              'partcode': this.dialogForm.partcode,
              'defaultroute_code': this.dialogForm.routecode,
              'children': children
            }
          ]
          SaveBeatRate(data).then(res => {
            if (res.code === '200') {
              this.$message.success(this.operation === 'add' ? '添加成功!' : '修改成功!')
              this.dialogVisible = false
              this.getBeatRateSearch()
            } else {
              this.$message.error(this.operation === 'add' ? '添加失败!' : '修改失败!')
            }
          })
        }
      })
    },
    // 获取页面高度
    getHeight() {
      this.$nextTick(() => {
        this.mainHeight = window.innerHeight - 85
        this.tableHeight = this.mainHeight - 195
        if (window.innerHeight < 769) {
          this.tableHeight = this.tableHeight - 40
        }
        this.$refs.tableDataRef.doLayout()
      })
    }
  }
}
</script>
<style>
.el-table .custom-row {
  background: #f8f8fa;
}
</style>
<template>
  <div>
    <div class="body" :style="{height:mainHeight+'px'}">
      <div class="bodyTopButtonGroup" style="justify-content: space-between">
        <el-button v-waves type="primary" icon="el-icon-circle-plus-outline" @click="add('add')">新增</el-button>
        <!--        <el-button v-waves icon="el-icon-download" @click=" ">导入</el-button>-->
      </div>
      <div class="bodyTopFormGroup">
        <el-form
          ref="form"
          :model="form"
          label-width="100px"
          inline
          style="display: flex;"
        >
          <div class="elForm">
            <el-form-item label="产品名称/编码" style=" display: flex;">
              <el-select
                v-model="form.partcode"
                filterable
                :popper-append-to-body="false"
                style="width: 200px"
                placeholder="请选择"
                @change="partChange"
              >
                <!--                @focus="getPartSelect"-->
                <el-option
                  v-for="item in partArr"
                  :key="item.partcode"
                  :label="item.partname+'/'+item.partcode"
                  :value="item.partcode"
                />
              </el-select>
            </el-form-item>
            <el-form-item
              v-if="mesSetting.route"
              label="工艺路线"
              style="display: flex;"
            >
              <el-select
                v-model="form.routecode"
                filterable
                :disabled="form.partcode===''"
                :popper-append-to-body="false"
                style="width: 200px"
                placeholder="请选择"
                @change="routeChange"
              >
                <el-option
                  v-for="item in routeArr"
                  :key="item.route_code"
                  :label="item.route_name"
                  :value="item.route_code"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="关联工序" style=" display: flex;">
              <el-select
                v-model="form.stepcode"
                :disabled="mesSetting.route?form.routecode==='':form.partcode===''"
                :popper-append-to-body="false"
                style="width: 200px"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in stepArr"
                  :key="item.step_code"
                  :label="item.step_name"
                  :value="item.step_code"
                />
              </el-select>
            </el-form-item>
            <!--按工序-->
            <!--            <el-form-item-->
            <!--              v-if="!mesSetting.route"-->
            <!--              label="工艺路线"-->
            <!--              style="display: flex;"-->
            <!--            >-->
            <!--              <el-select-->
            <!--                v-model="form.routecode"-->
            <!--                filterable-->
            <!--                :disabled="form.partcode===''"-->
            <!--                :popper-append-to-body="false"-->
            <!--                style="width: 200px"-->
            <!--                placeholder="请选择"-->
            <!--                @change="routeChange"-->
            <!--              >-->
            <!--                <el-option-->
            <!--                  v-for="item in routeArr"-->
            <!--                  :key="item.route_code"-->
            <!--                  :label="item.route_name"-->
            <!--                  :value="item.route_code"-->
            <!--                />-->
            <!--              </el-select>-->
            <!--            </el-form-item>-->
          </div>
          <div
            class="bodySearchReset"
            :style="{marginLeft:$store.state.app.sidebar.opened? $store.state.settings.menuIsHorizontal?'15%':'3%':'10%'}"
          >
            <el-button v-waves type="primary" icon="el-icon-search" @click="search">查询</el-button>
            <el-button v-waves type="info" icon="el-icon-refresh" @click="reset">重置</el-button>
          </div>
        </el-form>
        <div
          class="bodyTopFormExpand"
        />
      </div>
      <div class="elTableDiv">
        <!--        <TableColumnSettings-->
        <!--          :list1="tableColumnSettingsArray"-->
        <!--          @tableColumnUpdate="tableColumnUpdate"-->
        <!--        />-->
        <el-table
          ref="tableDataRef"
          :key="tableTimeStampArrayKey"
          class="tableFixed"
          :data="tableData"
          :height="tableHeight"
          border
          :row-class-name="tableRowClassName"
          :style="{width: 100+'%',height:tableHeight+'px',}"
          highlight-current-row
          :header-cell-style="this.$headerCellStyle"
          :cell-style="this.$cellStyle"
          @sort-change="sortChange"
        >
          <el-table-column
            v-for="item in tableColumnSettingsArray"
            v-if="item.show"
            :key="item.id"
            :sortable="item.sortable"
            :prop="item.prop"
            :min-width="item.minWidth"
            :label="item.label"
            :width="item.width"
            show-tooltip-when-overflow
            :fixed="item.fixed?(item.fixed==='left'?'left':'right'):false"
          >
            <template slot-scope="{row}">
              <div v-if="!row[item.prop]">/</div>
              <div v-else-if="item.prop==='eqp_value'||item.prop==='stand_value'">
                {{ row[item.prop] }} 秒
              </div>
              <div v-else>{{ row[item.prop] }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            fixed="right"
            width="120"
          >
            <template slot-scope="{row}">
              <div class="operationClass">
                <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                  <i
                    :style="{color:$store.state.settings.theme}"
                    class="el-icon-edit-outline"
                    @click="edit('edit',row)"
                  />
                </el-tooltip>
                <el-tooltip v-del-tab-index class="item" effect="dark" content="删除" placement="top">
                  <i :style="{color:$store.state.settings.theme}" class="el-icon-delete" @click="del(row)" />
                </el-tooltip>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页-->
      <pagination
        :total="total"
        :page.sync="form.page"
        :limit.sync="form.rows"
        align="right"
        layout="total,prev, pager, next,sizes"
        popper-class="select_bottom"
        @pagination="getBeatRateSearch"
      />
    </div>
    <el-dialog
      v-el-drag-dialog
      :title="operation==='add'?'新增':'编辑'"
      :visible.sync="dialogVisible"
      width="1100px"
      top="15vh"
      :close-on-click-modal="false"
      @closed="handleClose"
      @close="handleClose"
    >
      <el-form ref="dialogForm" inline :model="dialogForm" label-width="100px">
        <div style="display: flex;align-items: center">
          <i class="el-icon-s-comment" :style="{color:$store.state.settings.theme}" style="margin-top: -20px" />
          <el-form-item prop="partcode" label="产品名称/编码">
            <el-select
              v-show="operation==='add'"
              v-model="dialogForm.partcode"
              filterable
              style="width: 220px"
              placeholder="请选择"
              :popper-append-to-body="false"
              @change="partDialogChange"
            >
              <!--              @focus="getPartSelect2"-->
              <el-option
                v-for="item in partArr2"
                :key="item.partcode"
                :label="item.partname+'/'+item.partcode"
                :value="item.partcode"
              />
            </el-select>
            <el-input
              v-show="operation!=='add'"
              v-model="editPartName"
              disabled
              style="width: 220px"
            />
          </el-form-item>
          <el-form-item v-if="mesSetting.route" prop="routecode" label="工艺路线">
            <el-select
              v-show="operation==='add'"
              v-model="dialogForm.routecode"
              style="width: 220px"
              filterable
              :disabled="dialogForm.partcode===''"
              placeholder="请选择"
              :popper-append-to-body="false"
              @change="routeDialogChange"
            >
              <el-option
                v-for="item in routeDialogArr"
                :key="item.route_code"
                :label="item.route_name"
                :value="item.route_code"
              />
            </el-select>
            <el-input
              v-show="operation!=='add'"
              v-model="editRouteName"
              disabled
              style="width: 220px"
            />
          </el-form-item>
        </div>
      </el-form>
      <el-table
        :data="stepDialogArr"
        style="width: 100%"
        height="300"
        border
        :header-cell-style="this.$headerCellStyle"
        :cell-style="this.$cellStyle"
        :row-class-name="tableRowClassName"
      >
        <el-table-column
          prop="step_seq"
          label="工序顺序"
          width="100"
        />
        <el-table-column
          prop="step_code"
          label="工序编码"
          width="200"
        />
        <el-table-column
          prop="step_name"
          label="工序名称"
          width="200"
        />
        <el-table-column
          prop="unprice"
          label="工序工价"
        >
          <template slot-scope="{row}">
            <el-input v-model="row.unprice" oninput="value=value.replace(/[^0-9.]/g,'')" />
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <div class="footerButton">
          <el-button v-waves @click="dialogVisibleCancel">返 回</el-button>
          <el-button v-waves type="primary" @click="dialogVisibleConfirm">确 定</el-button>
        </div>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import {
  BeatRateSearch, DeleteBeatRate,
  PartSelect,
  PartSelectRpute,
  RouteSelectStep, SaveBeatRate
} from '@/api/basicSettings'
import elDragDialog from '@/directive/el-drag-dialog'
import waves from '@/directive/waves'
import TableColumnSettings from '@/components/TableColumnSettings'
export default {
  name: 'MeterPrice',
  components: {
    Pagination, TableColumnSettings
  },
  directives: { elDragDialog, waves },
  data() {
    return {
      mesSetting: JSON.parse(localStorage.getItem('mesSetting')),
      mainHeight: 0,
      tableHeight: 0,
      form: {
        partcode: '', // 产品编码
        routecode: '', // 工艺路线编码
        stepcode: '', // 工序编码
        prop: 'partcode', // 排序字段
        order: 'desc', // 排序字段
        page: 1, // 第几页
        rows: 20 // 每页多少条
      },
      partArr: [], // 产品集合
      partArr2: [], // 产品集合对话框
      routeArr: [], // 工艺路线
      stepArr: [], // 工序
      total: 10,
      tableData: [],
      tableColumnSettingsArray: [
        // { minWidth: 50, width: false, prop: 'id', label: 'id', id: 1, show: false, fixed: false, sortable: false }, // 隐藏列  show: false隐藏,true显示
        { minWidth: 25, width: 50, prop: 'rowNum', label: '序号', id: 2, show: true, fixed: 'left', sortable: false }, // custom
        {
          minWidth: 110,
          width: false,
          prop: 'partcode',
          label: '产品编码',
          id: 3,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: 110,
          width: false,
          prop: 'partname',
          label: '产品名称',
          id: 4,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: 110,
          width: false,
          prop: 'partspec',
          label: '产品规格',
          id: 5,
          show: true,
          fixed: false,
          sortable: true
        },
        // {
        //   minWidth: 110,
        //   width: false,
        //   prop: 'wksp_code',
        //   label: '生产车间编码',
        //   id: 6,
        //   show: false,
        //   fixed: false,
        //   sortable: true
        // },
        // {
        //   minWidth: false,
        //   width: 110,
        //   prop: 'wksp_name',
        //   label: '生产车间',
        //   id: 7,
        //   show: true,
        //   fixed: false,
        //   sortable: true
        // },
        {
          minWidth: 110,
          width: false,
          prop: 'route_code',
          label: '工艺路线编码',
          id: 8,
          show: false,
          fixed: false,
          sortable: true
        }, {
          minWidth: 110,
          width: false,
          prop: 'route_name',
          label: '工艺路线',
          id: 9,
          show: true,
          fixed: false,
          sortable: true
        }, {
          minWidth: 110,
          width: false,
          prop: 'stepcode',
          label: '工序编码',
          id: 10,
          show: false,
          fixed: false,
          sortable: true
        }, {
          minWidth: 110,
          width: false,
          prop: 'stepname',
          label: '工序名称',
          id: 11,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: 110,
          width: false,
          prop: 'unprice',
          label: '计件单价',
          id: 12,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: false,
          width: 110,
          prop: 'lm_user',
          label: '创建人员',
          id: 13,
          show: true,
          fixed: false,
          sortable: true
        },
        {
          minWidth: false,
          width: 160,
          prop: 'lm_date',
          label: '创建时间',
          id: 14,
          show: true,
          fixed: false,
          sortable: true
        }
      ],
      tableTimeStampArrayKey: new Date().getTime(), // 表格key
      dialogVisible: false,
      dialogForm: {
        partcode: '', //  产品编码
        routecode: '', //  工艺路线编码
        stepcode: '', //  工序编码
        wkshopcode: '', // 生产车间编码
        eqp_value: '', // 设备节拍
        stand_value: '', // 生产节拍
        cavity_qty: '', // 型腔数
        unprice: ''//  计件单价
      },
      routeDialogArr: [], // 工艺路线
      stepDialogArr: [], // 工序集合
      editPartName: '', // 编辑时产品名称
      editRouteName: '', // 编辑时工艺路线名称
      editStepName: '', // 编辑时加工工序名称
      operation: ''
    }
  },
  activated() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
    this.handleRequest()
  },
  created() {
    this.handleRequest()
  },
  mounted() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
    if (!this.mesSetting.route) {
      this.tableColumnSettingsArray = this.tableColumnSettingsArray.filter(i => i.prop !== 'route_name')
    }
  },
  methods: {
    tableColumnUpdate(val, isCopyTrue) {
      if (isCopyTrue) {
        this.tableColumnSettingsArray = val
      }
      this.tableTimeStampArrayKey = new Date().getTime()
      this.$refs.tableDataRef.doLayout()
    },
    tableRowClassName({ row, rowIndex }) {
      return 'custom-row'
    },
    handleRequest() {
      this.getBeatRateSearch().then(res => {
        if (res.code === '200') {
          this.getPartSelect()
        }
      })
    },
    async getBeatRateSearch() {
      const res = await BeatRateSearch(this.form)
      this.tableData = res.data
      this.total = res.count
      return { code: res.code }
    },
    // 排序改变时
    sortChange({ column, prop, order }) {
      if (order === 'descending') {
        order = 'desc'
      } else if (order === 'ascending') {
        order = 'asc'
      } else {
        order = 'desc'
      }
      this.form.order = order
      this.form.prop = prop
      this.getBeatRateSearch()
    },
    // 查询
    search() {
      this.getBeatRateSearch()
    },
    async getPartSelect() {
      const { data: res } = await PartSelect()
      this.partArr = res
    },
    async getPartSelect2() {
      const { data: res } = await PartSelect()
      this.partArr2 = res
    },
    async partChange(val) {
      const { data: res } = await PartSelectRpute({ partcode: val })
      if (this.mesSetting.route) {
        this.routeArr = res
        this.form.routecode = ''
      } else {
        this.stepArr = res
      }
      this.form.stepcode = ''
    },
    async routeChange(val) {
      const { data: res } = await RouteSelectStep({ partcode: this.form.partcode, routecode: val })
      this.stepArr = res
      this.form.stepcode = ''
    },
    // 重置
    reset() {
      this.form.partcode = ''
      this.form.routecode = ''
      this.form.stepcode = ''
      this.getBeatRateSearch()
    },
    async partDialogChange(val) {
      const { data: res } = await PartSelectRpute({ partcode: val })
      if (this.mesSetting.route) {
        this.routeDialogArr = res
        this.stepDialogArr = []
        this.dialogForm.routecode = ''
      } else {
        this.stepDialogArr = res
      }
    },
    async routeDialogChange(val) {
      const { data: res } = await RouteSelectStep({ partcode: this.dialogForm.partcode, routecode: val })
      this.stepDialogArr = res
    },
    // 新增按钮
    add(operation) {
      this.operation = operation
      this.dialogVisible = true
      this.getPartSelect2()
    },
    // 修改按钮
    async edit(operation, row) {
      this.operation = operation
      this.dialogVisible = true
      this.editPartName = row.partname
      this.editRouteName = row.route_name
      this.editStepName = row.stepname
      await this.partDialogChange(row.partcode)
      this.dialogForm.partcode = row.partcode
      if (this.mesSetting.route) {
        await this.routeDialogChange(row.route_code)
      }
      this.dialogForm.routecode = row.route_code
      this.dialogForm.stepcode = row.stepcode
    },
    // 删除按钮
    async del(row) {
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        DeleteBeatRate({ id: row.id }).then(res => {
          if (res.code === '200') {
            this.$message.success('删除成功!')
            if (this.form.page > 1 && this.tableData.length === 1) {
              this.form.page--
            }
            this.getBeatRateSearch()
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    },
    // 对话框关闭事件
    handleClose() {
      this.dialogForm.partcode = ''
      this.dialogForm.routecode = ''
      this.dialogForm.stepcode = ''
      this.dialogForm.wkshopcode = ''
      this.dialogForm.eqp_value = ''
      this.dialogForm.stand_value = ''
      this.dialogForm.cavity_qty = ''
      this.dialogForm.unprice = ''
      this.eqpTableLength = 0
      this.routeDialogArr = []
      this.stepDialogArr = []
      this.$refs.dialogForm.clearValidate()
      this.getBeatRateSearch()
    },
    // 对话框取消
    dialogVisibleCancel() {
      this.dialogVisible = false
    },
    // 对话框确认
    dialogVisibleConfirm() {
      this.$refs.dialogForm.validate(valid => {
        if (valid) {
          const children = []
          this.stepDialogArr.forEach(i => {
            children.push({
              'code': i.step_code,
              'name': i.step_name,
              'seq': i.step_seq,
              'isbott': i.isbott,
              'isend': i.isend,
              'unprice': i.unprice
            })
          })
          const data = [
            {
              'partcode': this.dialogForm.partcode,
              'defaultroute_code': this.dialogForm.routecode,
              'children': children
            }
          ]
          SaveBeatRate(data).then(res => {
            if (res.code === '200') {
              this.$message.success(this.operation === 'add' ? '添加成功!' : '修改成功!')
              this.dialogVisible = false
              this.getBeatRateSearch()
            } else {
              this.$message.error(this.operation === 'add' ? '添加失败!' : '修改失败!')
            }
          })
        }
      })
    },
    // 获取页面高度
    getHeight() {
      this.$nextTick(() => {
        this.mainHeight = window.innerHeight - 85
        this.tableHeight = this.mainHeight - 195
        if (window.innerHeight < 769) {
          this.tableHeight = this.tableHeight - 40
        }
        this.$refs.tableDataRef.doLayout()
      })
    }
  }
}
</script>
<style>
.el-table .custom-row {
  background: #f8f8fa;
}
</style>