licp
2024-03-29 41cad2434411b2eac1b9814d47d06e34c291f285
src/views/equipment/mould/index.vue
@@ -1,33 +1,219 @@
<template>
  <div class="mod-config">
      <basic-container>
      <ttable
      :table="table"
      :isShowHide="true"
      :ajaxFun="ajaxFun"
      :prelang="prelang"
      :options="options"
      ref="processconfiguration"
      >
      <template #toolbar></template>
      </ttable>
        <ttable
        @handleSelectionChange="handleSelectionChange"
        :table="table"
        :uploadInfo="uploadInfo"
        :ajaxFun="ajaxFun"
        :prelang="prelang"
        :options="options"
        ref="mouldTable"
        class="mouldTable"
        >
        <template #toolbar>
            <el-dropdown
            @command="handleCommand"
          >
            <el-button>
              状态改变<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                :command="item.value"
                v-for="item in optList"
                >{{ item.label }}</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </template>
        </ttable>
      </basic-container>
      <table-form
        v-if="true"
      ></table-form>
      <el-dialog
        :title="editRow.id==null ? '新增':'修改'"
        :visible.sync="dialogVisible"
        width="40%">
            <el-form :model="editRow" label-position="right" label-width="100px" ref="editForm" :rules="editRules">
                <el-row :gutter="16">
                    <el-col :span="12">
                        <el-form-item prop="model" label="模具型号">
                            <el-input v-model="editRow.model" placeholder="请输入模具型号" :disabled="editRow.id"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="name" label="模具名称">
                            <el-input v-model="editRow.name" placeholder="请输入模具名称"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="16">
                    <el-col :span="12">
                        <el-form-item prop="status" label="模具状态">
                            <el-select v-model="editRow.status" placeholder="请选择模具状态" style="width: 100%;">
                                <el-option
                                v-for="item in optList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="drawingNo" label="模具图号">
                            <el-input v-model="editRow.drawingNo" placeholder="请输入模具图号"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="16">
                    <el-col :span="12">
                        <el-form-item prop="workShop" label="车间">
                            <el-select v-model="editRow.workShop" placeholder="请选择车间" style="width: 100%;">
                                <el-option
                                v-for="item in workshopList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="shelfNo" label="货架号">
                            <el-input v-model="editRow.shelfNo" placeholder="请输入货架号"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="16">
                    <el-col :span="12">
                        <el-form-item prop="erpOrder" label="ERP订单号">
                            <el-input v-model="editRow.erpOrder" placeholder="请输入ERP订单号"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="texture" label="材质">
                            <el-input v-model="editRow.texture" placeholder="请输入材质"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="16">
                    <el-col :span="12">
                        <el-form-item prop="supplier" label="供应商">
                            <el-input v-model="editRow.supplier" placeholder="请输入供应商"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="userTime" label="投入使用日期">
                            <el-date-picker
                            v-model="editRow.userTime"
                            type="datetime"
                            placeholder="请投入使用日期"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            format="yyyy-MM-dd HH:mm:ss" style="width: 100%;">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="16">
                    <el-col :span="12">
                        <el-form-item prop="serviceLife" label="使用寿命">
                            <el-input v-model="editRow.serviceLife" placeholder="请输入使用寿命"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="number" label="已使用次数">
                            <el-input v-model="editRow.number" placeholder="请输入已使用次数"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="16">
                    <el-col :span="12">
                        <el-form-item prop="person" label="责任人">
                            <el-input v-model="editRow.person" placeholder="请输入责任人"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="remark" label="备注">
                            <el-input v-model="editRow.remark" placeholder="请输入备注" type="textarea" :rows="3"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="confirmSaveOrUpdateMould">确 定</el-button>
        </span>
        </el-dialog>
        <el-dialog title="标签列表" :visible.sync="diaPrintTab" width="500px" top="5vh">
      <div style="width:100%;height:400px;overflow-y: auto;">
        <div class="dia_body" id="printRaw">
          <el-card class="box-card" v-for="(tem, i) in multipleSelection" :key="i" style="margin-bottom: 10px; font-size: 16px !important;">
            <!-- <el-row>
              <el-col :span="8" :offset="1">序号:</el-col>
              <el-col :span="7" style="font-weight: bold;">{{ tem.id }}</el-col>
            </el-row> -->
            <el-row>
              <el-col :span="6" :offset="1">编号:</el-col>
              <el-col :span="12" style="font-weight: bold;">{{ tem.code }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="6" :offset="1">模具名称:</el-col>
              <el-col :span="12" style="font-weight: bold;">{{ tem.name }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="6" :offset="1">模具位置:</el-col>
              <el-col :span="12" style="font-weight: bold;">{{ tem.workShop }}-{{tem.shelfNo}}</el-col>
            </el-row>
            <el-row>
              <el-col :span="6" :offset="1">模具二维码:</el-col>
              <el-col :span="7">
                <vueQr :text="tem.code" :size="80" :margin="2"></vueQr>
              </el-col>
            </el-row>
          </el-card>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="diaPrintTab = false">取 消</el-button>
        <el-button type="primary" @click="printFun">打 印</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import ttable from '@/views/common/ztt-table.vue'
import { page, } from '@/api/equipment/mould'
import TableForm from './mould-from.vue'
import * as fecha from 'element-ui/lib/utils/date'
import { fetchList,addMould,updateMould,delById } from '@/api/equipment/moulde'
import { mapGetters } from 'vuex'
import { remote } from '@/api/admin/dict'
import vueQr from 'vue-qr'
import PrintJS from 'print-js'
export default {
  data(){
      return {
          ajaxFun: page,
          prelang: 'operation',
          addOrUpdateVisible: false,
          diaPrintTab: false,
          editRules: {
            model: [{required:true,message:'请输入模具型号',trigger:'blur'}],
            name: [{required:true,message:'请输入模具名称',trigger:'blur'}],
            status: [{required:true,message:'请选择模具状态',trigger:'change'}]
          },
          editRow: {
            code: null,
            name: null,
          },
          uploadInfo: {
            // 是否展示上传EXCEL以及对应的url
            isShow: true,
            url: '/mes/mould/upload',
            download: true,
            fileName: '模具统计表'
          },
          dialogVisible: false,
          ajaxFun: fetchList,
          prelang: 'moudle',
          multipleSelection: [],
          dataListLoading: false,
          options: {
              height: 300, // 默认高度-为了表头固定
              stripe: true, // 是否为斑马纹 table
@@ -50,86 +236,346 @@
              // 标题
              column: [
                {
                  minWidth: '140',
                  prop: 'packageNo',
                  label: '设备',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },{
                  minWidth: '140',
                  prop: 'outBatchNo',
                  minWidth: '140px',
                  prop: 'code',
                  label: '模具编号',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                  render: { fun: this.addOrUpdateHandle }
                },
                {
                  minWidth: '140',
                  prop: 'partNo',
                  minWidth: '140px',
                  prop: 'name',
                  label: '模具名称',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },
                {
                  minWidth: '140',
                  prop: 'partName',
                  label: '工序',
                  minWidth: '140px',
                  prop: 'drawingNo',
                  label: '模具图号',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },
                {
                  minWidth: '140',
                  prop: 'specs',
                  label: '工步',
                  minWidth: '140px',
                  prop: 'status',
                  label: '模具状态',
                  isTrue: true,
                  isSearch: true,
                  isTags:true,
                  searchInfoType: 'select',
                  formatter: this.workShopFormatter,
                  optList: () => {
                    return this.optList
                  },
                },
                {
                  minWidth: '140px',
                  prop: 'model',
                  label: '模具型号',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },
                {
                  minWidth: '140',
                  prop: 'unit',
                  label: '寿命转换系数',
                  minWidth: '140px',
                  prop: 'workShop',
                  label: '车间',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'select',
                  formatter: this.workShopFormatter,
                  optList: () => {
                    return this.workshopList
                  }
                },
                {
                  minWidth: '140px',
                  prop: 'shelfNo',
                  label: '货架号',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },
                {
                  minWidth: '140px',
                  prop: 'erpOrder',
                  label: 'ERP订单号',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },
                {
                  minWidth: '140px',
                  prop: 'texture',
                  label: '材质',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },
                {
                  minWidth: '140px',
                  prop: 'supplier',
                  label: '供应商',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },
                {
                  minWidth: '140px',
                  prop: 'userTime',
                  label: '投入使用日期',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'date',
                  formatter: this.formatDateTime
                },
                {
                  minWidth: '140px',
                  prop: 'serviceLife',
                  label: '使用寿命',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text'
                },
                {
                  minWidth: '140px',
                  prop: 'number',
                  label: '已使用次数',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },
                {
                  minWidth: '140px',
                  prop: 'person',
                  label: '责任人',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'text',
                },
                {
                  minWidth: '140px',
                  prop: 'createTime',
                  label: '创建时间',
                  isTrue: true,
                  isSearch: true,
                  searchInfoType: 'date',
                  formatter: this.formatDateTime
                },
              ],
              toolbar: [{
                text: '新增',
                type: 'primary',
                fun: this.addOrUpdateHandle
                }],
              operator: [{
                text: '删除',
                type: 'text',
                size: 'small',
                fun: this.deleteHandle
              }],
              toolbar: [],
              operator: null,
              operatorConfig: {
                fixed: 'right',
                label: '操作',
                width: 100,
                minWidth: 100
                },
              },
          },
          optList:[
            {
                value:'正常',
                label:'正常',
                type:'success'
            },
            {
                value:'异常',
                label:'异常',
                type:'danger'
            },
            {
                value:'返修',
                label:'返修',
                type:'warning'
            },
            {
                value:'报废',
                label:'报废',
                type:'info'
            },
            ],
        workshopList: []
     }
  },
  // computed: {
  //   ...mapGetters(['permissions'])
  // },
  computed: {
    ...mapGetters(['permissions'])
  },
  components: {
    ttable,
    TableForm
    vueQr,
  },
  watch: {
    dialogVisible(newVal){
        if(!newVal){
            this.editRow = {
                code: null,
                name: null,
            }
        }
    }
  },
  created(){
    if(this.permissions.equipment_mould_add){
        this.table.toolbar.push({
            text: '新增',
            type: 'primary',
            fun: this.addOrUpdateHandle
        })
    }
    if(this.permissions.equipment_mould_del){
        this.table.operator = [{
            text: '删除',
            type: 'text',
            fun: this.deleteHandle
        }]
    }
    if(this.permissions.equipment_mould_labelprint){
      this.table.toolbar.push({
              text: '标签打印',
              type: 'primary',
              fun: this.labelPrint
            })
    }
    this.table.operator = arr.length>0 ? arr : null
  },
  mounted(){
    remote('work_shop').then((response) => {
      if (response.data.code === 0) {
        this.workshopList = response.data.data
      } else {
        this.workshopList = []
      }
    })
  },
  methods: {
        addOrUpdateHandle() {
          this.addOrUpdateVisible = true
          console.log(this.addOrUpdateVisible,"--=--");
        },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    deleteHandle(row){
        this.$confirm('是否确认删除模具名称为' + row.name, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          closeOnClickModal: false,
          type: 'warning'
        })
          .then(function() {
            return delById(row.id)
          }).then((data) => {
            this.$message.success('删除成功')
            this.getData()
          })
    },
    confirmSaveOrUpdateMould(){
        this.$refs.editForm.validate(valid=>{
            if(valid){
                if(this.editRow.id){
                    updateMould(this.editRow).then(res=>{
                        if(res.status===200){
                            this.$message.success("修改成功")
                            this.getData()
                        }
                    }).catch(error=>{
                        console.error(error)
                    })
                }else{
                    addMould(this.editRow).then(res=>{
                        if(res.status===200){
                            this.$message.success("新增成功")
                            this.getData()
                        }
                    }).catch(error=>{
                        console.error(error)
                    })
                }
                this.dialogVisible = false
            }
        })
    },
    workShopFormatter(row, column, cellValue) {
      this.workshopList.forEach((obj) => {
        if (obj.value == cellValue) {
          cellValue = obj.label
        }
      })
      return cellValue
    },
    addOrUpdateHandle(row){
        if(row){
            this.editRow = row
        }
        this.dialogVisible = true
        this.$refs["editForm"].clearValidate()
    },
    formatDateTime(row, column, cellValue) {
        return cellValue ? fecha.format(new Date(cellValue), 'yyyy-MM-dd HH:mm:ss') : ''
    },
    getData() {
      this.$refs.mouldTable.getDataList()
    },
    // 标记状态
    handleCommand(event) {
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        this.multipleSelection.forEach((item) => {
            item.status = event;
            updateMould(item).then(res=>{
                if(res.status===200){
                    // this.$message.success("修改成功")
                    this.getData()
                }
            }).catch(error=>{
                console.error(error)
            })
        })
        this.$message.success('改变' + event + '成功')
      } else {
        this.$message.error('请选择模具')
      }
    },
    labelPrint(){
        if(this.multipleSelection.length==0){
          this.$message.warning('请选择一条数据')
          return
        }
        this.diaPrintTab = true
    },
    printFun() {
        // this.printDialogVisible = false;
        this.diaPrintTab = false;
        PrintJS({
            printable: 'printRaw',//页面
            type: "html",//文档类型
                maxWidth:450,
                targetStyles:['*'],
                style: `@page {
                margin:0;
                padding: 0;
                size: 360px 170px landscape;
                }
                html{
                zoom:100%;
                }
                @media print{
                width: 360px;
                height: 170px;
                margin:0;
                padding: 0;
                }`,
                onPrintDialogClose: this.erexcel=false,
                targetStyles: ["*"], // 使用dom的所有样式,很重要
                font_size: '',
        });
    },
  },
}
</script>
</script>
<style scoped>
.mouldTable >>>.el-table__fixed-right .el-table__fixed-body-wrapper {
  top: 74px !important;
}
</style>