<template>
  <div>
    <el-card>
      <el-form :model="codeQuery" class="query-form" size="mini" label-width="100px">
        <el-row>
          <el-col :span="18">
            <el-form-item prop="code" label="扫码查询:">
              <el-input
                id="inputer"
                @focus="getInputFocus($event)"
                @keypress.enter.native="enterKey($event)"
                ref="inputRef"
                style="ime-mode: disabled"
                type="tel"
                placeholder="请点击输入框进行扫码设置或者扫码录入"
                v-model="codeQuery.scanCode"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style=" display:flex;  flex-wrap: wrap; ">
          <template v-for="(item, index) in queryList">
            <div v-if="showSearch || item.isImport">
              <el-form-item v-if="item.columnType == 'input' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`" :key="item.id"
              >
                <el-input
                  v-model="codeQuery[item.columnName]"
                  :placeholder="item.columnDesc"
                  :disabled="executeEval(null,item.disabledFuc,false)"
                  @keyup.enter.native="executeFuc($event,'5',item.clickFuc)"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item v-if="item.columnType == 'select' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`"
              >
                <el-select v-model="codeQuery[item.columnName]"
                           :placeholder="item.columnDesc"
                           :disabled="executeEval(null,item.disabledFuc,false)"
                           clearable
                >
                  <el-option
                    v-for="dict in item.lableRuleObj"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
              <!--<el-form-item v-if="item.columnType == 'selectServer' && executeEval(row,item.expression,true)"-->
              <!--              class="query-form-item"-->
              <!--              :label="item.columnDesc+`:`">-->
              <!--  <el-select-->
              <!--    v-model="codeQuery[item.columnName]"-->
              <!--    :placeholder="item.columnDesc"-->
              <!--    @change="executeFuc($event,'5',item.checkRules)"-->
              <!--    :disabled="executeEval(null,item.disabledFuc,false)"-->
              <!--    filterable-->
              <!--    remote-->
              <!--    :remote-method="(query) => executeFuc(query,'5',item.clickFuc)"-->
              <!--    clearable>-->
              <!--    <el-option-->
              <!--      v-for="item in options[item.clickFuc]"-->
              <!--      :key="item.code"-->
              <!--      :label="item.label"-->
              <!--      :value="item.code"-->
              <!--    />-->
              <!--  </el-select>-->
              <!--</el-form-item>-->
              <el-form-item v-if="item.columnType == 'datePicker' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`"
              >
                <el-date-picker
                  :picker-options="pickerOptions"
                  v-model="actDateRange"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                ></el-date-picker>
              </el-form-item>
              <el-form-item v-if="item.columnType == 'date' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`"
              >
                <el-date-picker
                  v-model="codeQuery[item.columnName]"
                  :style="`width:${item.width+'px'}`"
                  value-format="yyyy-MM-dd"
                  :disabled="executeEval(null,item.disabledFuc,false)"
                  type="date"
                  :placeholder="item.columnDesc"
                ></el-date-picker>
              </el-form-item>
            </div>
          </template>
        </el-row>
      </el-form>


      <div class="top-right-btn">
        <el-button-group>
          <el-button icon="el-icon-view" type="primary" @click="hideSearch">高级搜索</el-button>
          <el-button type="primary" icon="el-icon-plus" @click="addBind()"
          >维护绑定关系
          </el-button>
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="onCodeReset"
          >重置
          </el-button>
          <el-button type="primary" icon="el-icon-search" @click="onCodeSubmit"
          >查询
          </el-button>
        </el-button-group>
      </div>
      <el-divider style="margin: 15px"></el-divider>

      <el-table v-loading="codeDetailLoading" :data="codeDetailList" style="width: 100%" border
                row-key="id"
      >
        <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column label="出货槽编号" prop="code" show-overflow-tooltip width="160"></el-table-column>
        <!--<el-table-column label="货架名称" prop="name" show-overflow-tooltip width="160"></el-table-column>-->
        <!--<el-table-column label="产品ID" prop="relId" show-overflow-tooltip width="160"></el-table-column>-->
        <el-table-column label="产品通用名" prop="cpmctymc" show-overflow-tooltip width="160"></el-table-column>
        <el-table-column label="制剂规格" prop="prepnSpec" show-overflow-tooltip width="120"></el-table-column>
        <el-table-column label="包装规格" prop="ggxh" show-overflow-tooltip width="120"></el-table-column>


        <el-table-column label="灯组标签" prop="mac" show-overflow-tooltip width="160"></el-table-column>
        <el-table-column label="所属取货架编号" prop="freightCode" show-overflow-tooltip width="160"></el-table-column>
        <el-table-column label="所属摆货层编号" prop="layerCode" show-overflow-tooltip width="160"></el-table-column>
        <!--<el-table-column label="格数" prop="grid" show-overflow-tooltip width="160"></el-table-column>-->
        <!--<el-table-column label="层级标记" prop="layer" show-overflow-tooltip width="160"></el-table-column>-->
        <el-table-column label="是否特殊槽" prop="specialQueue" show-overflow-tooltip width="160"></el-table-column>
        <el-table-column label="产品标识" prop="nameCode" show-overflow-tooltip width="100"></el-table-column>
        <el-table-column label="分配条件1" prop="assignmentTerms1" show-overflow-tooltip width="160"></el-table-column>
        <el-table-column label="分配条件2" prop="assignmentTerms2" show-overflow-tooltip width="160"></el-table-column>
        <el-table-column label="备注" prop="remark" show-overflow-tooltip width="160"></el-table-column>
        <el-table-column label="操作" fixed="right" width="220">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click.native.stop="bingLed(scope.row)"
              v-if="!scope.row.mac"
            >绑定灯组
            </el-button>
            <el-button
              type="text"
              size="small"
              @click.native.stop="removeMac(scope.row)"
              v-if="scope.row.mac"
            >解绑灯组
            </el-button>
            <el-button
              type="text"
              size="small"
              @click.native.stop="selectBind(scope.row)"
              v-if="!scope.row.nameCode"
            >绑定产品
            </el-button>
            <el-button
              type="text"
              size="small"
              @click.native.stop="removeRelId(scope.row)"
              v-if="scope.row.nameCode"
            >解除产品
            </el-button>
            <el-button
              type="text"
              size="small"
              @click.native.stop="editQueue(scope.row)"
            >编辑
            </el-button>
            <el-button
              type="text"
              size="small"
              @click.native.stop="detailQueue(scope.row)"
            >详情
            </el-button>
          </template>
        </el-table-column>

      </el-table>
      <pagination
        v-show="codeTotal>0"
        :total="codeTotal"
        :page.sync="codeQuery.page"
        :limit.sync="codeQuery.limit"
        @pagination="getCodeDetailList"
      />
    </el-card>


    <el-dialog
      title="维护绑定关系"
      :visible.sync="addBindVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-if="addBindVisible"
      width="65%"
      append-to-body
      @close="getCodeDetailList()"
    >
      <el-form :model="addBindData" ref="stockCompare" class="query-form"
               size="mini" label-width="auto"
      >
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item prop="code" label="出货槽位编号:" class="query-form-item">
              <el-input
                id="inputer1"
                @focus="getInputFocus($event)"
                @keypress.enter.native="enterKey1($event)"
                ref="inputRef1"
                type="tel"
                placeholder="请点击输入框进行出货槽位编号设置或者出货槽位编号录入"
                v-model="addBindData.code"
                style="width: 80%"
                :disabled="addBindData.codeFlag"
              ></el-input>
            </el-form-item>
          </el-col>


          <el-col :span="24">
            <el-form-item prop="udiCode" label="" class="query-form-item">
              <el-descriptions class="margin-top" title="" :column="3" border style="width: 80%">
                <el-descriptions-item label="出货槽编号">{{ sysWorkplaceQueue.code }}</el-descriptions-item>
                <el-descriptions-item label="货架名称">{{ sysWorkplaceQueue.name }}</el-descriptions-item>
                <el-descriptions-item label="备注">{{ sysWorkplaceQueue.remark }}</el-descriptions-item>
              </el-descriptions>
            </el-form-item>
          </el-col>


          <el-col :span="24">
            <el-form-item prop="code" label="灯组标签:" class="query-form-item">
              <el-input
                id="inputer3"
                @focus="getInputFocus($event)"
                @keypress.enter.native="enterKey3($event)"
                ref="inputRef3"
                type="tel"
                placeholder="请点击输入框进行扫描灯组标签"
                v-model="addBindData.macCode"
                style="width: 80%"
                :disabled="!addBindData.macCodeFlag"
              ></el-input>
            </el-form-item>
          </el-col>




          <el-col :span="24">
            <el-form-item prop="udiCode" label="" class="query-form-item">
              <el-descriptions class="margin-top" title="" :column="2" border style="width: 80%">
                <el-descriptions-item label="灯组标签">{{ ledData.mac }}</el-descriptions-item>
                <!--<el-descriptions-item label="货架名称">{{ sysWorkplaceQueue.name }}</el-descriptions-item>-->
                <el-descriptions-item label="备注">{{ ledData.remark }}</el-descriptions-item>
                <el-descriptions-item label="红灯"><el-tag v-if="ledData.red !=null"  :type="ledData.red == 0   ? 'info' : 'success'">{{ ledData.red == 0 ? "关闭" : "开启" }}</el-tag></el-descriptions-item>
                <el-descriptions-item label="黄灯"><el-tag v-if="ledData.red !=null" :type="ledData.orange == 0 ? 'info' : 'success'">{{ ledData.orange == 0 ? "关闭" : "开启" }}</el-tag></el-descriptions-item>
                <el-descriptions-item label="蓝灯"><el-tag v-if="ledData.red !=null" :type="ledData.blue == 0 ? 'info' : 'success'">{{ ledData.blue == 0 ? "关闭" : "开启" }}</el-tag></el-descriptions-item>
                <el-descriptions-item label="绿灯"><el-tag v-if="ledData.red !=null" :type="ledData.green == 0 ? 'info' : 'success'">{{ ledData.green == 0 ? "关闭" : "开启" }}</el-tag></el-descriptions-item>
              </el-descriptions>
            </el-form-item>
          </el-col>

          <el-col :span="24" style="margin-top: 30px">
            <el-form-item prop="udiCode" label="产品编码:" class="query-form-item">
              <el-input
                id="inputer2"
                @focus="getInputFocus($event)"
                @keypress.enter.native="enterKey2($event)"
                ref='inputRef2'
                style="ime-mode:disabled;width: 80%"
                type="tel"
                placeholder="请扫追溯码/产品编码/医保编码绑定"
                v-model="addBindData.udiCode"
                :disabled="!addBindData.udiCodeFlag"
              ></el-input>
            </el-form-item>

          </el-col>
          <!--<el-col :span="2">-->
          <!--  <el-button-group-->
          <!--    style="display: flex; ">-->
          <!--    <el-button-->
          <!--      type="primary"-->
          <!--      size="mini"-->
          <!--      @click.native="selectOrder()"-->
          <!--    >绑定灯组-->
          <!--      &lt;!&ndash;   v-if="(curAction.checkWebNew !== 2 || viewType !== 1) && orderFormData.billNo"&ndash;&gt;-->
          <!--    </el-button-->
          <!--    >-->
          <!--  </el-button-group>-->

          <!--</el-col>-->

          <el-col :span="24">
            <el-form-item prop="udiCode" label="" class="query-form-item">
              <el-descriptions class="margin-top" title="" :column="3" border style="width: 80%">
                <el-descriptions-item label="产品标识">{{ product.nameCode }}</el-descriptions-item>
                <el-descriptions-item label="产品通用名">{{ product.cpmctymc }}</el-descriptions-item>
                <el-descriptions-item v-if="product.productsType === 2" label="包装规格">{{
                    product.bzgg
                  }}
                </el-descriptions-item>
                <el-descriptions-item v-else label="规格型号">{{ product.ggxh }}</el-descriptions-item>
              </el-descriptions>
            </el-form-item>
          </el-col>
        </el-row>

        <div class="center-button">
          <!--<div style="text-align: right; margin-bottom: 10px;margin-top: 18px ;margin-right: 18px ;">-->
          <el-button @click="closeAddBindData">取消</el-button>
          <el-button type="primary" @click="submitAddBindData">提交</el-button>
          <!--</div>-->
        </div>


      </el-form>
    </el-dialog>


    <el-dialog
      title="绑定产品"
      :visible.sync="selectBindVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-if="selectBindVisible"
      width="65%"
      append-to-body
    >
      <selectDrugDialog
        :nameCodes="nameCodes"
        @selectDrug="selectDrug"
      >

      </selectDrugDialog>
    </el-dialog>

    <el-dialog
      title="绑定灯组"
      :visible.sync="addBindLedVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-if="addBindLedVisible"
      width="65%"
      append-to-body
      @close=""
    >
      <bingdLedGroupDialog
        :queueData="queueData"
        :closeBindLed="closeBindLed"
      >
      </bingdLedGroupDialog>

    </el-dialog>

    <el-dialog
      :title="titleMap[type]"
      :visible.sync="editWorkPlaceQueueVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-if="editWorkPlaceQueueVisible"
      width="70%"
      append-to-body
      @close="closeDialog"
    >
      <editWorkPlaceQueueDialog
        :rowData="queueData"
        :closeDialog="closeDialog"
        :type="type"
      >
      </editWorkPlaceQueueDialog>

    </el-dialog>



  </div>
</template>

<script>

import { isBlank } from '@/utils/strUtil'
import {
  getQueueListPage,
  getInfoByCode,
  getProductByCode,
  bind,
  removeProduct, removeLed, getLedDataByCode, binding
} from '@/api/basic/workPlace/SysWorkplaceQueue'
import { executeFuc, getHead } from '@/utils/customConfig'
import selectDrugDialog from "./selectDrugDialog"
import bingdLedGroupDialog from "./bingdLedGroupDialog"
import editWorkPlaceQueueDialog from "./editWorkPlaceQueueDialog"

const formJson = {
  site_id: '',
  site_name: '',
  describe: '',
  ads: []
}

export default {
  name: 'workplaceQueue',
  components:{selectDrugDialog,bingdLedGroupDialog,editWorkPlaceQueueDialog},
  data() {
    return {

      tableObj: [],
      queryList: [],
      tableHeader: [],
      fromList: [],

      showSearch: false,
      invList: [],
      list: [],
      total: 0,
      loading: false,
      index: null,
      enableDept: false,
      fromTypeMap: {
        '1': 'UDIMS平台',
        '2': '网页新增',
        '3': 'pda即时校验',
        '4': 'pda未校验',
        '5': 'pc端扫码精灵',
        '6': '流转自动补单',
        '7': 'UDI供应商平台',
        '8': '平衡补录单据',
        '10': '手动补单',
        '11': '仓库盘点',
        '12': '采购计划',
        '13': '领用单据',
        '14': '第三方系统单据'
      },
      deleteData: {
        orderId: null
      },
      addBindData: {
        id: null,
        code: null,
        relId: null,
        codeFlag: false,
        udiCode: null,
        udiCodeFlag: false,
        macCode:null,
        macCodeFlag: false
      },
      dialogTableVisible: false,
      radio: 1,
      addBindVisible: false,
      selectBindVisible: false,
      formLoading: false,
      dialogVisible: false,
      formData: formJson,
      deleteLoading: false,
      busTypes: [],
      currentRow: {},
      actDateRange: [],
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      codeQuery: {
        productBind: "1",
        scanCode: null,
        code: null,
        orderId: null,
        status: null,
        invCode: null,
        nameCode: null,
        cpmctymc: null,
        ggxh: null,
        batchNo: null,
        ylqxzcrbarmc: null,
        zczbhhzbapzbh: null,
        page: 1,
        limit: 20,
        keyWords: ''
      },
      codeTotal: 0,
      codeDetailLoading: false,
      sysWorkplaceQueue: {},
      product: {},
      codeDetailList: [],
      codeDetailList1: [],
      nameCodes:[],
      fromOptions: [],
      auditDateRange: [],
      showSup: false,
      statusMap: {
        1: '在库',
        2: '已使用',
        3: '已退回'
      },
      addBindLedVisible: false,
      queueData: null,
      ledData:{},
      lesStatusMap: {
        true : "开启",
        false: "关闭"
      },
      type:1,
      titleMap:{
        1 : "槽位编辑",
        2 : "槽位详情"
      },

      //
      editWorkPlaceQueueVisible:false,
    }
  },
  methods: {
    //页面配置
    executeFuc(row, type, clickFuc, value) {
      return executeFuc(this, row, type, clickFuc, value)
    },
    executeEval(row, expression, defaultRet) {
      if (expression) {
        return eval(expression)
      }
      return defaultRet
    },
    onReset() {
      this.$router.push({
        path: ''
      })
      this.getList()
    },
    onSubmit() {
      this.loading = true

      if (this.auditDateRange !== null) {
        this.codeQuery.startAduditTime = this.auditDateRange[0]
        this.codeQuery.endAduditTime = this.auditDateRange[1]
      } else {
        this.codeQuery.startAduditTime = null
        this.codeQuery.endAduditTime = null
      }
      this.codeQuery.page = 1
      this.getList()
    },
    hideSearch() {
      this.showSearch = !this.showSearch
    },
    getInputFocus(event) {
      event.currentTarget.select()
    },
    enterKey1() {
      //1、后端验证货位是否存在 且 是否绑定 产品
      if (isBlank(this.addBindData.code)) {
        return this.$message.error('出货槽位编码不可以为空')
      }
      getInfoByCode({ code: this.addBindData.code }).then(
        (response) => {
          if (response.code === 20000) {
            this.sysWorkplaceQueue = response.data
            if (this.sysWorkplaceQueue.relId != null) {
              //已绑定
              this.$confirm('出货槽位编码已绑定产品, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              })
                .then(() => {
                  this.product.nameCode = this.sysWorkplaceQueue.nameCode
                  this.product.ggxh = this.sysWorkplaceQueue.ggxh
                  this.product.cpmctymc = this.sysWorkplaceQueue.cpmctymc

                  this.addBindData.id = this.sysWorkplaceQueue.id
                  this.addBindData.codeFlag = true
                  this.addBindData.udiCodeFlag = true

                  this.$nextTick(() => {
                    this.$refs.inputRef3.focus() // 设置焦点到第一个输入框
                  })

                })
                .catch(() => {
                })
            } else {
              this.addBindData.id = this.sysWorkplaceQueue.id
              this.addBindData.codeFlag = true
              this.addBindData.macCodeFlag = true
              //绑定产品
              this.addBindData.udiCodeFlag = true

              this.$nextTick(() => {
                this.$refs.inputRef3.focus() // 设置焦点到第一个输入框
              })

            }
          } else {
            this.$message.error(response.message)
          }
        }).catch((error) => {
        this.$message.error(error.message)
      })
    },
    enterKey2() {
      if (isBlank(this.addBindData.udiCode)) {
        return this.$message.error('UDI码不可以为空')
      }
      getProductByCode({ udiCode: this.addBindData.udiCode }).then(
        (response) => {
          if (response.code === 20000) {
            this.product = response.data
            if (this.product.relId != null) {
              //已绑定
              this.$confirm('当前出货槽位编码将绑定绑定产品, 是否提交?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                this.addBindData.relId = this.product.relId
                this.submitAddBindData()
              })
                .catch(() => {
                })
            } else {

            }
          } else {
            this.$message.error(response.message)
          }
        }).catch((error) => {
        this.$message.error(error.message)
      })
    },
    enterKey3(){
      if (isBlank(this.addBindData.macCode)) {
        return this.$message.error('灯组标签不能为空')
      }
      let query = {
        macCode: this.addBindData.macCode,
        queueCode : this.sysWorkplaceQueue.code
      }
      getLedDataByCode(query).then(
        (response) => {
          if (response.code === 20000) {
            this.ledData = response.data
            this.addBindData.macCodeFlag = false
            if (!isBlank(this.sysWorkplaceQueue.mac) && this.sysWorkplaceQueue.mac === this.ledData.mac){
              this.addBindData.macCodeFlag = true
              return this.$message.warning("当前灯组标签已和当前出货槽绑定")
            }
            if (!isBlank(this.sysWorkplaceQueue.mac)){
              this.$confirm('当前出货槽信息已绑定灯组, 是否更换?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                this.bindLED()
              }).catch(() => {})
            }else {
              this.bindLED()
            }
          } else {
            this.addBindData.macCode = null
            this.$message.error(response.message)
          }
        }).catch((error) => {
        this.$message.error()
      })
    },
    bindLED(){
      let query = {
        id :  this.sysWorkplaceQueue.id,
        code : this.sysWorkplaceQueue.code,
        mac : this.ledData.mac
      }
      binding(query).then(res => {
        if (res.code == 20000){
          this.$nextTick(() => {
            this.$refs.inputRef3.focus() // 设置焦点到第一个输入框
          })
          this.$message.success("绑定成功")
        }else {
          this.$message.error(res.meaage)
        }
      })
      // this.$emit('bindLed', row);
    },
    submitAddBindData() {
      if (this.addBindData.id == null || this.addBindData.code == null) {
        return this.$message.error('请添加槽位')
      }
      if (this.addBindData.udiCode == null) {
        return this.$message.error('请添加产品!')
      }
      this.addBindData.relId = this.product.relId
      bind(this.addBindData).then(
        (response) => {
          if (response.code === 20000) {
            this.$message.success('绑定成功')
            this.addBindData = {
              code: null,
              //todo 绑定灯组完成之后需要更改该addBindData值和下面注释的
              codeFlag: false,
              udiCode: null,
              udiCodeFlag: false
            }
            this.sysWorkplaceQueue = {}
            this.product = {}
            this.addBindVisible = false
            this.$nextTick(() => {
              this.$refs.inputRef1.focus() // 设置焦点到第一个输入框
            })
            this.getCodeDetailList()
          } else {
            this.$message.error(response.message)
            this.$nextTick(() => {
              this.$refs.inputRef1.focus() // 设置焦点到第一个输入框
            })
            this.getCodeDetailList()
          }
        }).catch((error) => {
        this.$message.error(error.message)
        // this.$refs.inputRef1.select()
      })

    },
    selectDrug(drugData){
      this.addBindData.udiCode = drugData.nameCode
      this.addBindData.relId = drugData.id
      bind(this.addBindData).then(
        (response) => {
          if (response.code === 20000) {
            this.$message.success('绑定成功')
            this.addBindData = {
              code: null,
              codeFlag: false,
              udiCode: null,
              udiCodeFlag: false
            }
            this.sysWorkplaceQueue = {}
            this.product = {}
            this.selectBindVisible = false
            this.getCodeDetailList()
          } else {
            this.selectBindVisible = false
            this.getCodeDetailList()
            this.$message.error(response.message)
          }
        }).catch((error) => {
        this.$message.error(error.message)
      })
    },
    closeAddBindData() {
      this.addBindVisible = false
      this.getCodeDetailList()
    },
    enterKey() {
      this.getOrderDetails()
    },
    getBusType() {
      let query = {
        code: this.filterQuery.invCode,
        enabled: true
      }
      getLocalJoinByUser(query)
        .then((response) => {
          this.busTypes = response.data.list || []
          this.filterQuery.action = this.busTypes[0].action
        })
        .catch(() => {
        })
    },
    handleSelectionChange(val) {
      this.currentRow = val
      this.getOrderDetails()
    },

    getOrderDetails() {
      this.codeQuery.page = 1
      this.getCodeDetailList()
    },
    clearDetailList() {
      this.codeDetailList = []
      this.codeTotal = 0
    },

    getList() {
      this.loading = true
      getSysWorkplaceLayerList(this.codeQuery)
        .then((response) => {
          this.loading = false
          if (response.code === 20000) {
            this.list = response.data.list || []
            this.total = response.data.total || 0
          } else {
            this.$message.error(response.message)
          }
        })
        .catch((error) => {
          this.$message.error(error.message)
          this.loading = false
          this.list = []
          this.total = 0
        })
    },
    deleteOrders(data) {
      this.loading = true
      let delQuery = {
        billNo: data
      }
      deleterPrein(delQuery)
        .then((response) => {

          if (response.code == 20000) {
            this.getList()
            this.$message({
              type: 'success',
              message: '删除成功！'
            })
          } else if (response.code == 520) {
            this.$message.error('新增扫码单据列表已不存在该扫码单据！')
            this.getList()
          }

        })
        .catch(() => {
        })
    },
    deleteDialog(row) {
      this.$confirm('此操作将永久删除该订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.deleteOrders(row.billNo)
        })
        .catch(() => {
        })
    },
    onCodeReset() {
      this.codeQuery = {
        orderIdFk: null,
        productBind: "1",
        scanCode: null,
        code: null,
        orderId: null,
        status: null,
        invCode: null,
        nameCode: null,
        cpmctymc: null,
        ggxh: null,
        batchNo: null,
        ylqxzcrbarmc: null,
        zczbhhzbapzbh: null,
        page: 1,
        limit: 20,
        keyWords: ''
      }
      this.getCodeDetailList()
    },

    keyup_submit(event) {
      this.filterQuery.page = 1
      this.getList()
      event.target.select()
    },

    onCodeSubmit() {
      this.codeQuery.page = 1
      this.getCodeDetailList()
    },
    addBind() {
      this.addBindData = {
        code: null,
        codeFlag: false,
        udiCode: null,
        udiCodeFlag: false
      }
      this.sysWorkplaceQueue = {}
      this.product = {}
      this.ledData = {
        red : null,
        orange: null,
        blue: null,
        green: null
      }
      this.addBindVisible = true
      this.$nextTick(() => {
        this.$refs.inputRef1.focus() // 设置焦点到第一个输入框
      })

      // else {
      //   this.addBindData  = {
      //     code: null,
      //     codeFlag: true,
      //     udiCode: null,
      //     udiCodeFlag: true
      //   }
      //   this.bindType = 2
      //   this.titleName = "2"
      //   this.sysWorkplaceQueue.code = row.code
      //   this.sysWorkplaceQueue.remark = row.remark
      //   this.addBindData.code = row.code
      //   this.addBindData.id = row.id
      //   this.product = {}
      //   this.addBindVisible = true
      //   this.$nextTick(() => {
      //     this.$refs.inputRef2.focus();
      //   });
      //
      // }
    },
    selectBind(row){
      this.codeQuery.limit =  1000
      getQueueListPage(this.codeQuery).then((res) => {
        if (res.code === 20000) {
          this.codeDetailList1 = res.data.list || []
          this.nameCodes = this.codeDetailList1.map(queue => queue.nameCode).filter(nameCode => nameCode !== null)
          // this.sysWorkplaceQueue.code = row.code
          this.addBindData.id = row.id
          this.selectBindVisible = true
        } else {
          this.$message.error(res.message)
        }
      })

    },
    getCodeDetailList() {
      this.codeDetailLoading = true
      getQueueListPage(this.codeQuery).then((res) => {
        this.codeDetailLoading = false
        if (res.code === 20000) {
          this.codeDetailList = res.data.list || []
          this.codeTotal = res.data.total || 0
        } else {
          this.$message.error(res.message)
          this.codeDetailList = []
          this.codeTotal = 0
        }
      }).catch((error) => {
        this.codeDetailLoading = true
        this.$message.error(error.message)
        this.codeDetailList = []
        this.codeTotal = 0
      })
    },

    findMethod(query) {
      this.fromOptions = []
      let cQuery = {
        key: query,
        corpType: 2,
        page: 1,
        limit: 10
      }
      getBasicUnitMaintains(cQuery)
        .then((response) => {
          this.loading = false
          this.fromOptions = response.data.list || []
        })
        .catch(() => {
          this.loading = false
          this.fromOptions = []
        })
    },
    removeRelId(row) {
      let query = {
        code: row.code,
        relId: row.relId
      }
      this.$confirm('此操作将解绑该槽位与产品, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        removeProduct(query).then(res => {
          if (res.code == 20000) {
            this.$message.success('解绑成功')
            this.getCodeDetailList()
          } else {
            this.$message.error('解绑失败')
            this.getCodeDetailList()
          }
        })
      }).catch(() => {
      })

    },
    editQueue(row){
      this.queueData = row
      this.type = 1
      this.editWorkPlaceQueueVisible = true
    },
    detailQueue(row){
      this.queueData = row
      this.type = 2
      this.editWorkPlaceQueueVisible = true
    },
    closeDialog(){
      this.queueData = null
      this.editWorkPlaceQueueVisible = false

    },
    bingLed(row){
      this.queueData = row
      this.addBindLedVisible = true
    },
    removeMac(row){
      let query = {
        code: row.code,
        mac: row.mac
      }
      this.$confirm('此操作将解绑该槽位与灯组, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        removeLed(query).then(res => {
          if (res.code == 20000) {
            this.$message.success('解绑成功')
            this.getCodeDetailList()
          } else {
            this.$message.error('解绑失败')
            this.getCodeDetailList()
          }
        })
      }).catch(() => {
      })
    },
    closeBindLed(){
      // this.ledData = row
      this.addBindLedVisible = false
      this.getCodeDetailList()
      // console.log("hagaggaga",row)
    }

  },
  filters: {
    statusFilterType(status) {
      const statusMap = {
        false: 'success',
        true: 'warning'
      }
      return statusMap[status]
    }
  },
  mounted() {
    document.body.ondrop = function(event) {
      event.preventDefault()
      event.stopPropagation()
    }
  },
  created() {
    getHead('workplaceQueue-cwgl', '1').then((re) => {
      // 处理返回的数据
      this.tableObj = re.data
      this.tableHeader = re.data.tableList
      this.queryList = re.data.queryList
      this.fromList = re.data.fromList
    })
    this.getCodeDetailList()
  }
}
</script>

<style type="text/scss" lang="scss">
.el-radio__original {
  display: none !important; /* 隐藏原生 radio 输入，但仍然允许交互 */
}

.el-radio:focus:not(.is-focus):not(:active):not(.is-disabled) .el-radio__inner {
  box-shadow: none !important;
}

.center-button {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  margin-bottom: 10px;
  margin-top: 18px;
}
</style>
