<template>
  <view class="commonBody">
    <view class="prod-body">
      <view class="prod-body-left">
        <!--        <view class="prod-body-left-btns">-->
        <!--          <view class="workstation">-->
        <!--            工作中心名称：-->
        <!--            {{ this.vuex_workstation == null ? '请选择工作中心' : this.vuex_workstation.workstationName }}-->
        <!--            &lt;!&ndash;            <u-icon name="edit-pen-fill" size="46" color="#2979ff"></u-icon>&ndash;&gt;-->
        <!--          </view>-->
        <!--          <u-button type="primary" @click="changeWorkstation">切换工作中心</u-button>-->
        <!--          &lt;!&ndash;                  <u-button type="primary" @click="commonClick('')">生产任务</u-button>&ndash;&gt;-->
        <!--          &lt;!&ndash;                  <u-button type="primary" @click="commonClick('KnifeTemp')">刀模上架</u-button>&ndash;&gt;-->
        <!--          &lt;!&ndash;                  <u-button type="primary" @click="commonClick('')">生产投料</u-button>&ndash;&gt;-->
        <!--        </view>-->
        <view>
          <u-form :model="tableParams" labelAlign="right" class="tableForm">
            <u-form-item label="扫码" label-width="50px" name="arrangeCode">
              <uni-easyinput type="text" suffixIcon="scan" v-model="tableParams.arrangeCode" style="width: 200px"
                @iconClick="iconClickArrangeCode" placeholder="请输入工单编号或编排单号" />
            </u-form-item>
            <u-form-item name="allowProduce" label-width="80px" label="当前可加工">
              <uni-data-checkbox v-model="tableParams.allowProduce" @change="getTaskList()"
                :localdata="allowProduceLocal"></uni-data-checkbox>
            </u-form-item>
            <u-form-item name="allowProduce">
              <u-button @click="getTaskList()" type="primary" size="medium" style="width: 50px">搜索</u-button>
            </u-form-item>
          </u-form>
        </view>
        <view class="prod-body-left-task">
          <zb-table ref="zbtable" :columns="tableColumn" :stripe="true" rowKey="taskWorkunitId" :cellStyle="cellStyle"
            :isTrClassStyle="isTrClassStyle" @rowClick="rowClick" @toggleRowSelection="toggleRowSelection"
            @toggleAllSelection="toggleAllSelection" :border="true" :data="tableData"></zb-table>
        </view>
        <view class="prod-body-left-num">可选订单数：{{ tableData.length }}</view>
        <!-- <view class="prod-body-left-bom"> -->
        <!--          <view class="prod-body-left-bom-type">-->
        <!--            <u-subsection :list="typeList" :current="currentType" type="primary" font-size="28"-->
        <!--                          @change="typeChange"></u-subsection>-->
        <!--          </view>-->
        <!--          <view class="prod-body-left-bom-table">-->
        <!--            <u-form>-->
        <!--              <u-row gutter="16">-->
        <!--                <u-col span="3">-->
        <!--                  <u-form-item label="任务单号" label-width="150">-->
        <!--                    {{ curTaskInfo.taskCode }}-->
        <!--                  </u-form-item>-->
        <!--                </u-col>-->
        <!--                <u-col span="4">-->
        <!--                  <u-form-item label="物料条码" label-width="150">-->
        <!--                    <SearchInput v-model="materialRecordInfo.materialBatchNumber" placeholder="请输入物料条码"-->
        <!--                                 hassearchbtn="true"-->
        <!--                                 @inputchange="(val)=>{materialRecordInfo.materialBatchNumber=val}"/>-->
        <!--                  </u-form-item>-->
        <!--                </u-col>-->
        <!--                <u-col span="2">-->
        <!--                  <u-form-item label="数量">-->
        <!--                    <uni-number-box :min="0" v-model="materialRecordInfo.quantity"></uni-number-box>-->
        <!--                  </u-form-item>-->
        <!--                </u-col>-->
        <!--                <u-col span="1">-->
        <!--                  <u-button type="primary" size="mini" @click="commonClick('MaterialUsageRecord')">添加</u-button>-->
        <!--                </u-col>-->
        <!--                <u-col span="1">-->
        <!--                </u-col>-->
        <!--                <u-col span="5">-->
        <!--                </u-col>-->
        <!--              </u-row>-->
        <!--            </u-form>-->
        <!-- <zb-table :columns="issusLineColumn" :stripe="true" :fit="true" :border="true" :data="issusLineList"></zb-table> -->
        <!--          </view>-->
        <!-- </view> -->
      </view>
      <scroll-view class="prod-body-right" scroll-y >
        <view style="text-align: center; line-height: 80rpx; font-size: 28rpx; font-weight: 600">
          {{ this.vuex_workunit == null ? '请选择工作单元' : this.vuex_workunit.workunitName }}
        </view>
        <u-button type="primary" @click="commonClick('Refresh')">刷新</u-button>
				<u-button type="primary" @click="commonClick('KnifeTemp')" v-if="!buttonShow || buttonShow.processToolView === '1'">刀模版上下机</u-button>
				<u-button type="primary" @click="commonClick('FeedingInspection')" v-if="!buttonShow || buttonShow.materialView === '1'">投料校验</u-button>
				<u-button type="primary" @click="commonClick('RecoilMaterial')" v-if="!buttonShow || buttonShow.recoilMaterialView === '1'">反冲料登记</u-button>
        <u-button type="success" @click="commonClick('StartTask')">开始作业</u-button>
        <u-button type="warning" @click="commonClick('StopTask')">暂停作业</u-button>
        <u-button type="success" @click="commonClick('Prod')">生产报工</u-button>
        <u-button type="success" @click="commonClick('editProd')">修改报工</u-button>
        <u-button type="primary" @click="commonClick('FinshTask')">完成作业</u-button>
        
        <!-- <u-button type="primary" @click="commonClick('KnifeTemp2')">刀模版上下机2</u-button> -->
        <u-button type="primary" @click="commonClick('MaterialRequest')">补料申请</u-button>
        <u-button type="primary" @click="commonClick('MaterialReturn')">退料申请</u-button>
        <u-button type="primary" @click="commonClick('ViewPpicture')">查看图片</u-button>
        <u-button type="warning" @click="commonClick('abnormal')">异常报告</u-button>
        <!-- <u-button type="primary" @click="commonClick('StockIn')">完工入库申请</u-button> -->
      </scroll-view>
    </view>

    <u-modal title="生产报工" @confirm="handleSubmitfeedback" show-cancel-button
      :show-confirm-button="feedbackForms[0] && feedbackForms[0].isPackage === '1' ? false : true"
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="proVisible" width="1800rpx">
      <view>
        <!-- 是否包装工序isPackage为1是 -->

        <scroll-view style="max-height: 600px" scroll-y="true" class="scroll-Y">
          <view class="feedback-card" v-for="(feedback, i) in feedbackForms" :key="i">
            <view v-if="feedback.isPackage === '1'">
              <u-form label-width="80px" :model="feedback" :rules="rules" labelAlign="right">
                <u-row>
                  <u-col span="4">
                    <u-form-item label="任务单号:" prop="quantity">
                      {{ feedback.taskCode }}
                    </u-form-item>
                  </u-col>
                  <u-col span="4">
                    <u-form-item label="编排单号:" prop="quantity">
                      {{ feedback.arrangeCode }}
                    </u-form-item>
                  </u-col>
                  <u-col span="4">
                    <u-form-item label="工序:" prop="nickName">
                      {{ feedback.processName }}
                    </u-form-item>
                  </u-col>
                </u-row>
                <u-row>
                  <u-col span="4">
                    <u-form-item label="报工总数量:" prop="quantity">
                      {{ feedback.quantity }}
                    </u-form-item>
                  </u-col>
                  <u-col span="4">
                    <u-form-item label="已报工数:" prop="quantity">
                      {{ feedback.reportQualify }}
                    </u-form-item>
                  </u-col>
                  <u-col span="4">
                    <u-form-item label="报工人:" prop="nickName">
                      {{ feedback.nickName }}
                    </u-form-item>
                  </u-col>
                </u-row>
                <u-row>
                  <u-col span="4">
                    <u-form-item label="包装类型:" prop="packType">
                      <dict-tag :options="dict.type.pro_pack_type" :value="feedback.packType" />
                    </u-form-item>
                  </u-col>
                  <u-col span="3">
                    <u-form-item label="包装单位:" prop="packUnitOfMeasure">
                      {{ feedback.packUnitOfMeasure }}
                    </u-form-item>
                  </u-col>
                  <u-col span="5">
                    <u-form-item label-width="150px" label="LOSS数是否单独包装:" prop="lossIndividuallyWrap">
                      <dict-tag :options="dict.type.sap_yes_no" :value="feedback.lossIndividuallyWrap" />
                    </u-form-item>
                  </u-col>
                </u-row>
                <u-row>
                  <u-col span="4">
                    <u-form-item label="生产工单:" prop="workorderId">
                      <uni-data-select v-model="feedback.workorderId" :localdata="feedback.workorderOption"
                        @change="workorderSelect($event, i)"></uni-data-select>
                    </u-form-item>
                  </u-col>
                  <u-col span="4">
                    <u-form-item label="不良品数量:" prop="quantityUnqualify">
                      <u-number-box :min="0" v-model="feedback.quantityUnqualify" :long-press="false" :input-width="140"></u-number-box>
                    </u-form-item>
                  </u-col>
                  <u-col span="4">
                    <u-form-item label="报工时间:" prop="feedbackTime">
                      <uni-datetime-picker return-type="string" class="times" type="datetime" :clear-icon="false"
                        v-model="feedback.feedbackTime" />
                    </u-form-item>
                  </u-col>
                </u-row>
                <u-row>
                  <u-col span="3">
                    <u-form-item label="包装数量:" prop="packNum">
                      <u-number-box :min="0" v-model="feedback.packNum" :long-press="false" :input-width="140"></u-number-box>
                    </u-form-item>
                  </u-col>
                  <u-col span="3">
                    <u-form-item label="装箱数量:" prop="encasementNum">
                      <u-number-box :min="0" v-model="feedback.encasementNum" :long-press="false" :input-width="140"></u-number-box>
                    </u-form-item>
                  </u-col>
                  <u-col span="6">
                    <u-form-item label="检测人员:" prop="checkBy">
                      <u-input disabled v-model="feedback.checkBy"></u-input>
                      <u-button @tap="(userVisible = true), (useData = feedback)" type="success"
                        size="mini">选择人员</u-button>
                    </u-form-item>
                  </u-col>
                </u-row>
                <u-row>
                  <u-col span="6">
                    <u-form-item label="打印模板:" prop="printTemplate">
                      <u-input v-model="feedback.printTemplate" placeholder="请选择打印模板"></u-input>
                      <u-button @tap="getPrintTemplate(feedback)" type="success" style="margin-left: 20rpx"
                        size="mini">选择打印模板</u-button>
                    </u-form-item>
                  </u-col>
                  <u-col span="4">
                    <u-form-item label-width="120px" label="是否合并包装:" prop="mergePack">
                      <view class="uni-list-item__extra">
                        <!-- @change="handleChangePackNum(feedback, i)" -->
                        <u-radio-group v-model="feedback.mergePack">
                          <u-radio :name="1">是</u-radio>
                          <u-radio :name="0">否</u-radio>
                        </u-radio-group>
                      </view>
                    </u-form-item>
                  </u-col>
                  <u-col span="2">
                    <u-button @tap="handleChangePackNum(feedback, i)" type="success" size="mini">计算包装标签</u-button>
                  </u-col>
                </u-row>
              </u-form>
              <view>
                <u-tabs :list="feedback.listTabPro" :is-scroll="false" :show-bar="false"
                  :current="feedback.currentTabPro" @change="handleChangeTabPro($event, feedback)"></u-tabs>
                <!-- 报工列表 -->
                <view v-if="feedback.tableOrderData.length">
                  <zb-table :columns="tableOrderColumn" :stripe="true" :border="true" :data="feedback.tableOrderData">
                    <template slot="reportQuantity" slot-scope="scope">
                      <!-- {{ scope.row }} -->
                      <u-input v-model="scope.row.reportQuantity" type="number"></u-input>
                    </template>
                    <template slot="netWeight" slot-scope="scope">
                      <!-- {{ scope.row }} -->
                      <u-input v-model="scope.row.netWeight" type="number"></u-input>
                    </template>
                    <template slot="peration" slot-scope="scope">
                      <!-- {{ scope.row }} -->
                      
                      <u-button v-if="scope.row.feedbackQuantity && Number(scope.row.feedbackQuantity) > 0"
                        @tap="rePackageInfoPrint(feedback, scope.row, i)" class="successBtn"
                        style="margin-left: 20rpx">
                        补打印
                      </u-button>
                      <u-button v-else-if="Number(scope.row.packageNum) > Number(scope.row.feedbackQuantity) || scope.row.printbtn"
                        @tap="handleSubmitPackageFeedback(feedback, scope.row, i)" class="successBtn"
                        style="margin-left: 20rpx">
                        打印/报工
                      </u-button>
                      <!-- <u-input v-model="scope.row.reportQuantity" type="number"></u-input> -->
                    </template>
                  </zb-table>
                </view>
                <!-- 指令列表 -->
                <view v-if="feedback.tableDirectiveData.length">
                  <zb-table :columns="tableDirectiveColumn" :stripe="true" :border="true"
                    :data="feedback.tableDirectiveData">
                    <template slot="reportQuantity" slot-scope="scope">
                      <!-- {{ scope.row }} -->
                      <u-input v-model="scope.row.reportQuantity" type="number"></u-input>
                    </template>
                    <template slot="netWeight" slot-scope="scope">
                      <!-- {{ scope.row }} -->
                      <u-input v-model="scope.row.netWeight" type="number"></u-input>
                    </template>
                    <template slot="peration" slot-scope="scope">
                      <!-- {{ scope.row }} -->
                      <u-button v-if="scope.row.feedbackQuantity && Number(scope.row.feedbackQuantity) > 0"
                        @tap="rePackageInfoPrint(feedback, scope.row, i)"
                        style="margin-left: 20rpx" class="successBtn">
                        补打印
                      </u-button>
                      <u-button v-else @tap="handleSubmitPackageFeedback(feedback, scope.row, i)"
                        style="margin-left: 20rpx"  class="successBtn">打印/报工</u-button>
                      <!-- <u-input v-model="scope.row.reportQuantity" type="number"></u-input> -->
                    </template>
                  </zb-table>
                </view>
                <!-- SIZE列表 -->
                <view v-if="feedback.tableSizeData.length">
                  <zb-table :columns="feedback.tableSizeColumn" :stripe="true" :border="true"
                    :data="feedback.tableSizeData">
                    <template slot="reportQuantity" slot-scope="scope">
                      <!-- {{ scope.row }} -->
                      <u-input v-model="scope.row.reportQuantity" type="number"></u-input>
                    </template>
                    <template slot="netWeight" slot-scope="scope">
                      <!-- {{ scope.row }} -->
                      <u-input v-model="scope.row.netWeight" type="number"></u-input>
                    </template>
                    <template slot="peration" slot-scope="scope">
                      <!-- {{ scope.row }} -->
                      <u-button v-if="scope.row.feedbackQuantity && Number(scope.row.feedbackQuantity) > 0"
                        @tap="rePackageInfoPrint(feedback, scope.row, i)"
                        style="margin-left: 20rpx" class="successBtn">
                        补打印
                      </u-button>
                      <u-button v-else @tap="handleSubmitPackageFeedback(feedback, scope.row, i)"
                        style="margin-left: 20rpx" class="successBtn">打印/报工</u-button>
                    </template>
                  </zb-table>
                </view>
              </view>
            </view>

            <view v-else>
              <u-form label-width="100px" :model="feedback" :rules="rules" labelAlign="right">
                <u-row>
                  <u-col span="6">
                    <u-form-item label="任务单号:" prop="quantity">
                      {{ feedback.taskCode }}
                    </u-form-item>
                  </u-col>
                  <u-col span="6">
                    <u-form-item label="工序:" prop="nickName">
                      {{ feedback.processName }}
                    </u-form-item>
                  </u-col>
                </u-row>
                <u-row>
                  <u-col :span="6">
                    <u-form-item :label="feedback.taskType&&feedback.taskType===3 ? '委外数量:' : '已报工数:'" prop="quantity">
                      <span v-if="feedback.taskType&&feedback.taskType===3">{{ feedback.quantityQualify }}</span>
                      <span :style="{background: feedback.overFeedback ? '#f56c6c' : '#fff', padding: '0 5px'}" v-else>{{ feedback.workorderFeedbackSum }}</span>
                      <!-- {{ computedQuantityV2 }} -->
                    </u-form-item>
                  </u-col>
                  <u-col :span="6" v-if="!feedback.taskType || feedback.taskType!==3">
                    <u-form-item label="未报工数:">
                      {{ feedback.workorderUnfeedbackSum }}

                      <!-- {{ computedQuantityV2 }} -->
                    </u-form-item>
                  </u-col>
                  <u-col :span="6" v-else>
                    <u-form-item label="报工人:" prop="nickName">
                      <u-input v-model="feedback.nickName"></u-input>
                      <u-button @tap="getCode(feedback)" type="success" size="mini">报工人员</u-button>
                    </u-form-item>
                  </u-col>
                </u-row>

                <u-row>
                  <u-col :span="6">
                    <u-form-item label="编排单号:" prop="quantity">
                      {{ feedback.arrangeCode }}
                    </u-form-item>
                  </u-col>
                  
                  <u-col :span="6">
                    <u-form-item label="生产工单:" prop="workorderId">
                      <view v-if="feedback.taskType&&feedback.taskType===3">{{feedback.workorderCode}}</view>
                      <uni-data-select v-model="feedback.workorderId" v-else :localdata="feedback.workorderOption"
                        @change="workorderSelect($event, i)"></uni-data-select>
                    </u-form-item>
                  </u-col>
                </u-row>
                <u-row>
                  <!-- 
                  <view>
                    <block v-for="(feedback, i) in feedbackForms" :key="i">
                      <view class="feedback-card">
                        {{ i }} - {{ feedback.unitOfConvert }}- {{ feedback.quantity }}
                      </view>
                    </block>

                    <u-col span="6">
                      计算器 : {{ computedQuantity }}

                      feedbackQuantityFu: {{ feedbackQuantityFu }},
                      feedbackUnQuantityFu: {{ feedbackUnQuantityFu }},

                      quantityUnqualify: {{ feedback.quantityUnqualify }}
                      quantityqualify: {{ feedback.quantityQualify }}

                      unitOfConvert: {{ feedback.unitOfConvert }}
                    </u-col>
                    <view class="box" v-if="timeTest.isshow">123</view>
                    <button type="default" @tap="changeShow()">隐藏</button>

                  </view> -->

                  <u-col span="6">
                    <u-form-item label="合格数量:" prop="quantityQualify">
                      <u-number-box :min="0" @change="quantityChanged()" :max="9999999999999999999999999999999999999999" :input-width="190"
                        v-model="feedback.quantityQualify" :long-press="false"></u-number-box>
                    </u-form-item>
                  </u-col>
                  <u-col span="6" v-if="!feedback.taskType||feedback.taskType!==3">
                    <u-form-item label="不良品数量:" prop="quantityUnqualify">
                      <u-number-box :min="0" @change="quantityChanged()" :max="99999999999999999999999999999999999999999" :input-width="190"
                        v-model="feedback.quantityUnqualify" :long-press="false"></u-number-box>
                    </u-form-item>
                  </u-col>
                  <u-col span="6" v-if="!feedback.taskType||feedback.taskType!==3">
                    <u-form-item class="column-type" label-width="100px" label="合格数量(副):" prop="feedbackQuantityFu">
                      <view class="button-type2">
                        <u-number-box :min="0" key="numberBox1" :max="99999999999999999999999999999999999999999" :input-width="190"
                          @change="()=>quantityChangedV2(feedback, feedbackQuantityFu, feedbackUnQuantityFu)"
                          v-model="feedbackQuantityFu" :long-press="false"></u-number-box>
                      </view>

                    </u-form-item>
                  </u-col>
                  <u-col span="6" v-if="!feedback.taskType||feedback.taskType!==3">
                    <u-form-item class="column-type" label-width="100px" label="不良品数量(副):" prop="feedbackUnQuantityFu">
                      <u-number-box :min="0" align="right" key="numberBox2" :max="99999999999999999999999999999999999999999" :input-width="190"
                        @change="()=>quantityChangedV3(feedback, feedbackQuantityFu, feedbackUnQuantityFu)"
                        v-model="feedbackUnQuantityFu" :long-press="false"></u-number-box>
                    </u-form-item>
                  </u-col>
                  <u-col span="6">
                    <u-form-item label="报工时间:" prop="feedbackTime">
                      <uni-datetime-picker return-type="string" class="times" type="datetime" :clear-icon="false"
                        v-model="feedback.feedbackTime" />
                    </u-form-item>
                  </u-col>
                  <u-col span="6" v-if="feedback.taskType&&feedback.taskType===3">
                    <u-form-item label="是否关单:" prop="closeType" >
                      <view class="uni-list-item__extra">
                        <u-radio-group v-model="feedback.closeType">
                          <u-radio :name="1">是</u-radio>
                          <u-radio :name="0">否</u-radio>
                        </u-radio-group>
                      </view>
                    </u-form-item>
                  </u-col>
                  <u-col :span="6" v-if="!feedback.taskType || feedback.taskType!==3">
                    <u-form-item label="报工人:" prop="nickName">
                      <u-input v-model="feedback.nickName"></u-input>
                      <u-button @tap="getCode(feedback)" type="success" size="mini">报工人员</u-button>
                    </u-form-item>
                  </u-col>
                  <u-col span="6" v-if="!feedback.taskType || feedback.taskType!==3">
                    <u-form-item label="打印:" prop="whether">
                      <view class="uni-list-item__extra">
                        <u-radio-group v-model="feedback.whether">
                          <u-radio :name="1">是</u-radio>
                          <u-radio :name="0">否</u-radio>
                        </u-radio-group>
                      </view>
                    </u-form-item>
                  </u-col>
                  

                <!-- <u-row> -->
                <!-- <u-col span="3" width: max-content>
                    <u-button class="auto-size-button" type="default" @tap="changeShow()">隐藏</u-button>
                  </u-col>
                  <view class="box" v-if="timeTest.isshow">
                    <u-col span="6">
                      <u-form-item label="合格数量(副):" prop="feedbackQuantityFu">
                        <uni-number-box :min="0" @change="quantityChangedV2(feedback, feedbackQuantityFu)"
                          v-model="feedbackQuantityFu"></uni-number-box>
                      </u-form-item>
                    </u-col>
                    <u-col span="6">
                      <u-form-item label="不良品数量(副):" prop="feedbackUnQuantityFu">
                        <uni-number-box :min="0" @change="quantityChangedV2(feedback, feedbackUnQuantityFu)"
                          v-model="feedbackUnQuantityFu"></uni-number-box>
                      </u-form-item>
                    </u-col>
                  </view> -->


                </u-row>
              </u-form>
            </view>
          </view>
        </scroll-view>
      </view>
    </u-modal>
    <u-modal title="选择人员" @confirm="chooseUser()" show-cancel-button
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="userVisible" width="1300rpx">
      <view class="feedback-card">
        <user ref="userRef" v-if="userVisible" />
      </view>
    </u-modal>
    <u-modal title="选择打印模板" @confirm="handleSubmitPrintTemplate" show-cancel-button
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="printTemplateVisible" width="1300rpx">
      <view class="feedback-card">
        <print-template ref="printTemplateRef" :data="printTemplateData" />
      </view>
    </u-modal>

    <!-- <u-modal title="刀模版上下机2" v-model="timeTest.isshow" :title-style="{ color: 'red' }">
      <view>
        1
      </view>
    </u-modal> -->
    <u-modal title="刀模版上下机" show-cancel-button :show-confirm-button="!!knifeTempType"
      @confirm="handleSubmitConfirmlKnifeTemp" @cancel="handleSubmitCancelKnifeTemp" :confirmText="knifeTempCancelText"
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="knifeTempVisible" width="100%" :content-style="{ height: '87vh' }">
      <view style="display: flex">
        <view style="width: 520px">
          <!-- #ifdef APP-PLUS -->
          <app-scan v-if="knifeTempAppScanVisible" ref="appScan" @getCode="handleUpdateKnifeTemp"></app-scan>
          <!-- #endif -->
        </view>
        <dModelList :data="dModelData" @action="upDownGetList" @scan="handleAppScanKnifeTemp" />
      </view>
    </u-modal>
    <!-- //生产报工报工人员 -->
    <u-modal title="报工人员" @confirm="userDetermine()" show-cancel-button
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="userTempVisible" width="1300rpx">
      <view>
        <userPersonnel ref="userPersonnelRef" v-if="userTempVisible" :data="usePersonData" />
      </view>
    </u-modal>
    <u-modal title="暂停原因" @confirm="stopReasonSubmit()" show-cancel-button
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="stopReasonVisible" width="1300rpx">
      <view class="feedback-card" style="height: 200px">
        <u-form label-width="120px" :model="stopReasonForm" :rules="rules">
          <u-form-item label="暂停原因" prop="reason">
            <!-- <uni-data-select v-model="stopReasonForm.reason" :localdata="exception" @change="stopReas"></uni-data-select> -->
            <uni-data-select v-model="stopReasonForm.reason" :localdata="causeList"
              @change="stopCause"></uni-data-select>
          </u-form-item>
          <u-form-item label="暂停描述" prop="desc">
            <!-- <uni-data-selec v-model="stopReasonForm.desc" :localdata="reasonList"  type=“textarea”></uni-data-select> -->
            <u-input v-model="stopReasonForm.desc" type="textarea"></u-input>
          </u-form-item>
        </u-form>
      </view>
    </u-modal>

    <u-modal title="异常报告" @confirm="newlyAddss()" show-cancel-button
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '60px', 'padding-top': '0px' }"
      v-model="errorVisible" width="1300rpx">
      <view class="feedback-card">
        <u-form label-width="70px" labelAlign="right" :model="ExceptionForms" :rules="rules">
          <!--     <u-form-item label="异常时间" prop="abnormalTime">
             <u-input   :border="true" v-model="ExceptionForms.abnormalTime"></u-input>
              <uni-datetime-picker class="times" type="date" :clear-icon="false" v-model="ExceptionForms.abnormalTime" />
            </u-form-item> -->

          <u-row>
            <u-col span="6">
              <u-form-item label="异常类型" prop="abnormalType">
                <uni-data-select v-model="ExceptionForms.abnormalType" :localdata="exception"
                  @change="stopReas"></uni-data-select>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item label="原因" prop="abnormalReason">
                <uni-data-select v-model="ExceptionForms.abnormalReason" :localdata="reasonList"></uni-data-select>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item label="编排单号" prop="batchNumber">
                <!--  <u-input :border="true" v-model="ExceptionForms.batchNumber"  ></u-input> -->
                {{ ExceptionForms.batchNumber }}
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item label="工序" prop="processName">
                <!-- <u-input :border="true" v-model="ExceptionForms.processName"></u-input> -->
                {{ ExceptionForms.processName }}
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item label="作业单元" prop="workstationName">
                <!-- <u-input :border="true" v-model="ExceptionForms.workstationName"></u-input> -->
                {{ ExceptionForms.workstationName }}
              </u-form-item>
            </u-col>
          </u-row>
        </u-form>
      </view>
    </u-modal>
    <u-modal title="投料校验" @cancel="$refs.appScan.closed(), (feedingInspectionVisible = false)" show-cancel-button
      cancelText="关闭" :show-confirm-button="false"
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="feedingInspectionVisible" width="100%" height="100%" :content-style="{ height: '87vh' }">
      <view style="display: flex; width: 100%;height:100%">
        <view style="width: 510px" v-if="feedingInspectionVisible">
          <!-- #ifdef APP-PLUS -->
          <app-scan ref="appScan" @getCode="feedingInspectionScan"></app-scan>
          <!-- #endif -->
        </view>
        <view class="list-bar" style="width: calc(100% - 510px);height:90%;">
          <scroll-view scroll-y="true" scroll-x="true" class="scroll-list" show-scrollbar
            :style="{ height: '100%'}"  @touchmove.stop>
            <uni-table border stripe :loading="loading" emptyText="未查询到数据" class="mynotable">
              <uni-tr>
								<uni-th width="100px" align="center">操作</uni-th>
								<uni-th width="65px" align="center">状态</uni-th>
								<uni-th width="110px" align="center">产品物料编码</uni-th>
								<uni-th width="110px" align="center">产品物料名称</uni-th>
								<uni-th width="80px" align="center">领料数量</uni-th>
								<uni-th width="110px" align="center">批次号</uni-th>
							</uni-tr>
              <uni-tr v-for="(line, index) in feedingInspectionList" :key="index" :style="{background: line.attr3 == 1 ? '#19be6b' : '#fff'}">
                <uni-td align="center">
                  <view class="uni-group">
                    <button class="uni-button" size="mini" type="primary"
                      @click="validateFeedingInspection(line)">校验</button>
                  </view>
                </uni-td>
                <uni-td align="center">{{ line.attr3 == 1 ? '已校验' : '未校验' }}</uni-td>
                <uni-td align="center">{{ line.itemCode.substring(line.itemCode.length - 8, line.itemCode.length) }}</uni-td>
                <uni-td align="center">{{ line.itemName }}({{ line.specification }})/{{ line.unitOfMeasure }}</uni-td>
                <uni-td align="center">{{ line.quantityIssued }}</uni-td>
                <uni-td align="center">{{ line.batchCode }}</uni-td>
              </uni-tr>
            </uni-table>
          </scroll-view>
					<view class="sum">共{{feedingInspectionList.length}}条</view>
        </view>
      </view>
    </u-modal>

    <u-modal title="反冲料登记" @cancel="$refs.appScan.closed(), (recoilMaterialVisible = false)" show-cancel-button
      cancelText="关闭" :show-confirm-button="false" height="100%"
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="recoilMaterialVisible" width="100%" :content-style="{ height: '87vh' }">
      <view style="display: flex;width: 100%;height:100%">
        <view style="width: 510px" v-if="recoilMaterialVisible">
          <!-- #ifdef APP-PLUS -->
          <app-scan ref="appScan" @getCode="recoilMaterialScan" v-if="!recoilMaterialFlag"></app-scan>
					<!-- #endif -->
					<view class="scan-mask"  v-show="recoilMaterialFlag" :style="{top: '38px',
						left: '0px',
						height: '87%',
						width: '500px',
						position: 'absolute',
						background: 'black'}"></view>
        </view>
        <view class="list-bar" style="width: calc(100% - 510px);height:90%;">
          <scroll-view scroll-y="true" scroll-x="true" class="scroll-list" :style="{ height: '100%'}" @touchmove.stop>
            <uni-table ref="qcTable" border stripe :loading="loading" emptyText="未查询到数据" class="mynotable">
              <uni-tr>
                <!-- <uni-th width="200px" align="center">操作</uni-th> -->
                <uni-th width="110px" align="center">产品物料编码</uni-th>
                <uni-th width="200px" align="center">产品物料名称</uni-th>
                <uni-th width="90px" align="center">批次号</uni-th>
                <uni-th width="80px" align="center">需求数量</uni-th>
                <uni-th width="65px" align="center">数量</uni-th>

              </uni-tr>
              <uni-tr v-for="(line, index) in recoilMaterialDetailList" :key="index" :class="{'tr-green': line.sum >= line.requestSum}">
                <!-- <uni-td align="center">
                  <view class="uni-group">
                    <button class="uni-button" size="mini" type="primary"
                    @click="materialRequestFormShow(line)">补料</button>
                    <button class="uni-button button-type" size="mini" style="background-color:green;color:white;" 
                      @click="recoilMaterialDelete(line)" disabled="true">删除</button>
                     <button class="uni-button button-type" size="mini"  type="primary"
                      @click="recoilMaterialDelete(line)"  disabled="true">检查</button> 
                  </view>

                </uni-td> -->


                <uni-td align="center">{{ line.sapItemCode.substring(line.sapItemCode.length - 8, line.sapItemCode.length) }}</uni-td>
                <uni-td align="center">{{ line.itemName }}({{ line.specification }})/{{ line.unitOfMeasure }}</uni-td>
                <uni-td align="center">
                  <view class="uni-group">
                    <button class="uni-button button-type column-type" size="mini"
                      @click="batchShow(line)">查看倒冲批次</button>
                  </view>

                </uni-td>

                <uni-td align="center">{{ line.requestSum }}</uni-td>
                <uni-td align="center">{{ line.sum }}</uni-td>


              </uni-tr>
            </uni-table>
          </scroll-view>
        </view>
      </view>
    </u-modal>

   
   <u-modal title="补料申请" @confirm="materialRequestSave()" show-cancel-button
         :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
         v-model="materialRequestVisible" width="1300rpx">
         <view class="list-bar">
           <u-form label-width="65px" labelAlign="right" :model="curTaskInfo">
             <u-row>
               <u-col span="3">
                 <u-form-item label="编排单号">
                   {{ curTaskInfo.arrangeCode }}
                 </u-form-item>
               </u-col>
               <u-col span="4.5">
                 <u-form-item label="生产工单" prop="workorderCode">
                   <uni-data-select v-model="curTaskInfo.workorderCode" @change="materialReturnWorkorderProcessItem"
                     :localdata="curTaskInfo.workorderOption"></uni-data-select>
                 </u-form-item>
               </u-col>
               <u-col span="4.5">
                 <u-form-item label="补料原因" prop="pickingReason">
                   <uni-data-select v-model="curTaskInfo.pickingReason" :localdata="reasonList"
                     @change="pickingCause"></uni-data-select>
                 </u-form-item>
               </u-col>
             </u-row>
           </u-form>
   		<uni-tr>
   		<uni-th width="100px" align="center">操作</uni-th>
   		              <uni-th width="150px" align="center">产品物料编码</uni-th>
   		              <uni-th width="250px" align="center">产品物料名称</uni-th>
   		              <uni-th width="170px" align="center">补取数量</uni-th>
   		            </uni-tr>
           <scroll-view scroll-y="true" class="scroll-list" :style="{ height: this.screenHeight/2 - 150 + 'px' }">
             <uni-table ref="materialRequestTable" border stripe :loading="loading" >
               <uni-tr v-for="(line, index) in materialRequestArrays" :key="index">
                 <uni-td align="center" style="width: 100px">
                   <view class="uni-group">
                     <button class="uni-button" size="mini" type="primary"
                       @click="materialRequestFormShow(line)">补料</button>
                   </view>
                 </uni-td>
                 <uni-td align="center" style="width: 140px">{{ line.itemCode.substring(line.itemCode.length - 8, line.itemCode.length) }}</uni-td>
                 <uni-td align="center" style="width: 160px">{{ line.itemName }}({{ line.specification }})/{{ line.unitOfMeasure }}</uni-td>
                 <uni-td align="center" style="width: 150px">{{ line.applyNum }}</uni-td>
               </uni-tr>
             </uni-table>
   		  
           </scroll-view>
   	<uni-tr>
   			   <uni-th width="200px" align="center">申请单号</uni-th>
   			   <uni-th width="200px" align="center">产品物料名称</uni-th>
   			   <uni-th width="160px" align="center">申请数量</uni-th>
   			   <uni-th width="160px" align="center">状态</uni-th>
   			 </uni-tr>
   		    <scroll-view scroll-y="true" class="scroll-list" :style="{ height: this.screenHeight/2 - 200 + 'px' }" >
   			  <uni-table ref="materialRequestTable" border stripe :loading="loading" >
   			    <uni-tr v-for="(line, index) in materialRequestArrayList" :key="index">
   				  <uni-td align="center" style="width: 125px">{{line.applyNo}}</uni-td>
   			      <uni-td align="center" style="width: 150px">{{ line.sapItemCode.substring(line.sapItemCode.length - 8, line.sapItemCode.length) }}</uni-td>
   			      <uni-td align="center" style="width: 100px">{{ line.applyNum }}</uni-td>
   				  <uni-td align="center" style="width: 100px">{{ line.attr1 }}</uni-td>
   			    </uni-tr>
   			  </uni-table>
   			</scroll-view>
         </view>
       </u-modal>
	    <u-modal title="补料申请数量" @confirm="materialRequestSetting()" show-cancel-button
	   	         :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
	   	         v-model="materialRequestFormVisible" width="700rpx">
	   	         <view class="">
	   	           <u-form label-width="100px">
	   	             <u-row>
	   	               <u-col>
	   	                 <u-form-item label="产品物料名称">
	   	                   {{ materialRequestFormData.itemName }}
	   	                 </u-form-item>
	   	               </u-col>
	   	             </u-row>
	   	             <u-row>
	   	               <u-col>
	   	                 <u-form-item label="补料数量">
	   	                   <u-number-box v-model="materialRequestFormData.applyNum" :long-press="false" :positive-integer="false"
	   	                    :input-width="190"></u-number-box>
	   	                 </u-form-item>
	   	               </u-col>
	   	             </u-row>
	   	           </u-form>
	   	         </view>
	   	       </u-modal>


    <u-modal title="退料申请" @confirm="materialReturnSave()" show-cancel-button
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="materialReturnVisible" width="1600rpx">
      <view class="list-bar">
        <u-form :model="materialReturnFormData" label-width="100px">
          <u-row>
            <u-col span="4">
              <u-form-item label="编排单号">
                {{ curTaskInfo.arrangeCode }}
              </u-form-item>
            </u-col>
			<u-col span="4">
			  <u-form-item label="打印二维码">
			   <u-input v-model="materialReturnFormData.number"></u-input>
			  </u-form-item>
			</u-col>
            <u-col span="4">
              <u-form-item label="生产工单" prop="workorderCode">
                <uni-data-select v-model="materialReturnFormData.workorderCode" @change="materialReturnWorkorderChange"
                  :localdata="curTaskInfo.workorderOption"></uni-data-select>
              </u-form-item>
            </u-col>
			    <u-col span="4">
					     <u-form-item label="退料原因" prop="returnReason">
					    <uni-data-select v-model="curTaskInfo.returnReason" :localdata="reasonReturnList"
					      @change="pickingCauses"></uni-data-select>
					  </u-form-item>
					</u-col>
          </u-row>
        </u-form>

        <scroll-view scroll-y="true" class="scroll-list" :style="{ height: this.screenHeight - 280 + 'px' }">
          <uni-table ref="qcTable" border stripe :loading="loading" emptyText="未查询到数据">
            <uni-tr>
              <uni-th width="60px" align="center">操作</uni-th>
              <uni-th width="110px" align="center">产品物料编码</uni-th>
              <uni-th width="110px" align="center">产品物料名称</uni-th>
              <uni-th width="80px" align="center">领料数量</uni-th>
              <uni-th width="80px" align="center">本次退料数</uni-th>
              <uni-th width="80px" align="center">累计退料数</uni-th>
			        <uni-th width="100px" align="center">版号</uni-th>
              <uni-th width="110px" align="center">批次号</uni-th>
              <uni-th width="60" align="center">合格</uni-th>
            </uni-tr>
            <uni-tr v-for="(line, index) in materialReturnList" :key="index">
              <uni-td align="center">
                <view class="uni-group">
                  <button class="uni-button" size="mini" type="primary"
                    @click="materialReturnFormShow(line)">退料</button>
                </view>
              </uni-td>
              <uni-td align="center">{{ line.itemCode.substring(line.itemCode.length - 8, line.itemCode.length) }}</uni-td>
              <uni-td align="center">{{ line.itemName }}({{ line.specification }})/{{ line.unitOfMeasure }}</uni-td>
              <uni-td align="center">{{ line.quantityIssued }}</uni-td>
              <uni-td align="center">{{ line.applyNum }}</uni-td>
              <uni-td align="center">{{ line.totalBackNum }}</uni-td>
			  <uni-td align="center">{{ line.packNo }}</uni-td>
              <uni-td align="center">{{ line.batchCode }}</uni-td>
              <uni-td align="center">{{ line.isQualified == 1 ? '是' : '' }}{{ line.isQualified == 0 ? '否' : ''
                }}</uni-td>
            </uni-tr>
          </uni-table>
        </scroll-view>
      </view>
    </u-modal>

    <u-modal title="退料申请数量" @confirm="materialReturnSetting()" show-cancel-button
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="materialReturnFormVisible" width="700rpx">
      <view class="">
        <u-form label-width="100px">
          <u-row>
            <u-col>
              <u-form-item label="产品物料名称">
                {{ materialReturnFormData.itemName }}
              </u-form-item>
            </u-col>
          </u-row>
          <u-row>
            <u-col>
              <u-form-item label="退料数量">
                <u-number-box v-model="materialReturnFormData.applyNum" :long-press="false" :positive-integer="false"
                  :input-width="190"></u-number-box>
              </u-form-item>
            </u-col>
          </u-row>
          <u-row>
            <u-col>
              <u-form-item label="是否合格" prop="printName">
                <view class="uni-list-item__extra">
                  <u-radio-group v-model="materialReturnFormData.isQualified">
                    <u-radio name="1">是</u-radio>
                    <u-radio name="0">否</u-radio>
                  </u-radio-group>
                </view>
              </u-form-item>
            </u-col>
          </u-row>
        </u-form>
      </view>
    </u-modal>
    <u-modal title="详细数据" :showConfirmButton="true"
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="showRowDeatilFlag" width="1800rpx">
      <view class="">
        <zb-table :columns="tableDetailColumn" :stripe="true" :border="true" :data="tableDataDetail"></zb-table>
      </view>
    </u-modal>

    <u-modal title="查看倒冲批次" :showRecoilMaterialButton="true" @confirm="$refs.appScan.start()"
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px',' z-index': 9999 }"
      v-model="recoilMaterialFlag" width="1300rpx">
      <view>
        <zb-table :columns="recoilMaterialColumn" :stripe="true" :border="true" :data="recoilMaterialList"></zb-table>
      </view>
    </u-modal>
    <!-- //查询图片生产工单 -->
    <u-modal title="生产工单" show-cancel-button :show-confirm-button="false" cancel-text="返回"
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="materialReturn" width="1300rpx">
      <view class="list-bar">
        <scroll-view scroll-y="true" class="scroll-list" :style="{ height: this.screenHeight - 280 + 'px' }">
          <uni-table ref="qcTable" border stripe :loading="loading" emptyText="未查询到数据">
            <uni-tr>
              <uni-th width="110px" align="center">工单编码</uni-th>
              <uni-th width="110px" align="center">工单名称</uni-th>
              <uni-th width="80px" align="center">来源类型</uni-th>
              <uni-th width="80px" align="center">产品名称</uni-th>
              <uni-th width="110px" align="center">编排单号</uni-th>
              <uni-th width="100px" align="center">操作</uni-th>
            </uni-tr>
            <uni-tr v-for="(line, index) in viewSopPicture" :key="index">
              <uni-td align="center">{{ line.workorderCode }}</uni-td>
              <uni-td align="center">{{ line.workorderName }}</uni-td>
              <uni-td align="center">{{ line.orderSource }}</uni-td>
              <uni-td align="center">{{ line.productName }}</uni-td>
              <uni-td align="center">{{ line.arrangeCode }}</uni-td>
              <uni-td align="center">
                <view class="uni-group">
                  <!-- <button class="uni-button" size="mini" type="primary" @click="materialReturnFormShow(line)">退料 -->
                  <!-- <button class="uni-button" size="mini" type="primary" @click="viewSopsShow()">查看 -->
                  <button class="uni-button" size="mini" type="primary" @click="viewSopsShow(line)">查看</button>
                </view>
              </uni-td>
            </uni-tr>
          </uni-table>
        </scroll-view>
      </view>
    </u-modal>
    <u-modal title="详情" show-cancel-button :show-confirm-button="false" cancel-text="返回"
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="material" width="680px">
      <view class="list-bar">
        <scroll-view scroll-y="true" class="scroll-list" :style="{ height: this.screenHeight - 280 + 'px' }">
          <!-- <view style="display: flex; justify-content: space-between; flex-wrap: wrap">
            <image v-for="(line, index) in viewSop" :key="index" @click="onPreviewTap(line)" style="padding: 10px" class="u-avatar-demo" :src="line" mode="aspectFill"></image>
          </view> -->
          <ProogingSpecificationSheet v-if="material" :form="ProogingSpecificationSheetForm">
          </ProogingSpecificationSheet>
        </scroll-view>
      </view>
    </u-modal>

    <u-modal title="选择工作单元" @confirm="handleSubmitWorkunit" show-cancel-button
      :title-style="{ 'background-color': '#1E3770', color: '#FFFFFF', 'line-height': '37px', 'padding-top': '0px' }"
      v-model="workunitVisible" width="1800rpx">
      <view class="feedback-card" v-if="workunitVisible">
        <workunitList ref="workunitRef" />
      </view>
    </u-modal>
    <editFeeding ref="editFeeding" v-model="editFeedingVisible" @close="editFeedingVisible = false"/>
  </view>
</template>
<style scoped>
@import '/static/css/amebase.css';
</style>

<script>
import SearchInput from '@/components/ScanInput/index.vue';
import dModelList from './components/dModelList.vue';
import User from '@/components/User/User.vue';
import userPersonnel from './components/userPersonnel.vue';
import printTemplate from './components/printTemplate.vue';
import editFeeding from './components/editFeeding.vue';
import workunitList from './components/workunitList.vue';
import ProogingSpecificationSheet from './components/ProogingSpecificationSheet.vue';
import UButton from '../../../uview-ui/components/u-button/u-button.vue';
import cameraAuthMixin from '@/components/AppScan/appScanMixins.js';
import { handleError } from 'vue';
import AppScan from '../../../components/AppScan/AppScan.vue';
import URow from '../../../uview-ui/components/u-row/u-row.vue';
export default {
  name: 'ProdReport',
  dicts: ['pro_pack_type', 'sap_yes_no'],
  mixins: [cameraAuthMixin],
  components: {
    SearchInput,
    editFeeding,
    dModelList,
    userPersonnel,
    printTemplate,
    UButton,
    workunitList,
    AppScan,
    User,
    ProogingSpecificationSheet,
    URow
  },
  data() {
    return {
      getWorkorderDirectiveLoading: false,
      editFeedingVisible: false,
      tableOrderColumn: [
        {
          name: 'quantity',
          label: '派工数',
          width: 170
        },
        {
          name: 'feedbackQuantity',
          label: '已包装数量',
          width: 170
        },
        {
          name: 'reportQuantity',
          label: '本次报工',
          width: 120,
          type: 'slot',
          slot: 'reportQuantity'
        },
        {
          name: 'netWeight',
          label: '净重',
          width: 100,
          type: 'slot',
          slot: 'netWeight'
        },
        {
          name: 'peration',
          label: '操作',
          width: 120,
          type: 'slot',
          slot: 'peration'
        }
      ],
      tableDirectiveColumn: [
        {
          name: 'clientCmd',
          label: '指令号',
          width: 120
        },
        {
          name: 'quantity',
          label: '派工数',
          width: 100
        },
        {
          name: 'packageNum',
          label: '包装数',
          width: 80
        },
        {
          name: 'lossNum',
          label: 'LOSS数',
          width: 100
        },
        {
          name: 'feedbackQuantity',
          label: '已包装数',
          width: 130
        },
        {
          name: 'reportQuantity',
          label: '本次报工',
          width: 120,
          type: 'slot',
          slot: 'reportQuantity'
        },
        {
          name: 'netWeight',
          label: '净重',
          width: 130,
          type: 'slot',
          slot: 'netWeight'
        },
        {
          name: 'peration',
          label: '操作',
          width: 120,
          type: 'slot',
          slot: 'peration'
        }
      ],
      userVisible: false,
      useData: {},
      ProogingSpecificationSheetForm: {},
      knifeTempAppScanVisible: false,
      knifeTempType: null,
      workunitVisible: false,
      jobAssignmentVisible: false,
      jobAssignmentForm: {
        quantity: 1,
        workunitName: null
      },
      listTabPro: [
        {
          name: '报工列表'
        },
        {
          name: '指令列表'
        },
        {
          name: 'SIZE列表'
        }
      ],
      tableParams: {
        allowProduce: 1,
        workorderCode: '',
        arrangeCode: ''
      },
      allowProduceLocal: [
        {
          text: '是',
          value: 1
        },
        {
          text: '否',
          value: 0
        }
      ],
      stopReasonForm: {
        reason: null,
        desc: null
      },
      screenHeight: 768,
      usePersonData: {},
      title: '生产报工',
      proVisible: false,
      errorVisible: false,
      form: {},
      feedbackForm: {},
      tableData: [],
      knifeTempCancelText: '确认',
      knifeTempVisible: false,
      knifeTempSearch: {
        knifeTempCode: '',
        locationCode: ''
      },
      knifeTempInfo: {
        knifeTemplateCode: '',
        knifeTemplateName: '',
        knifeTemplateSpec: '',
        locationCode: '',
        locationName: '',
        locationType: '',
        locationTypeCode: '',
        locationTypeDesc: '',
        locationTypeDescCode: '',
        locationTypeDescName: '',
        locationTypeDescNameCode: '',
        locationTypeDescNameCode2: ''
      },
      stopReasonList: [
        { value: '中午休息吃饭。', text: '休息吃饭' },
        { value: '刀头模具到期更换，更换期间。', text: '刀头模具到期更换' },
        { value: '没料了，正在领料', text: '领料加仓' }
      ],
      exception: [
        {
          value: 'PROD',
          text: '生产异常'
        },
        {
          value: 'QUAL',
          text: '质量异常'
        },
        {
          value: 'DEVI',
          text: '设备异常'
        }
      ],
      stopReason: '',
      stopReasonVisible: false,
      rules: {
        quantity: [
          {
            required: true,
            message: '请输入合格品数量或者不良品数量！',
            trigger: 'blur'
          }
        ]
      },
      typeList: [
        {
          name: '物料扣减'
        },
        {
          name: 'BOM外扣减'
        }
      ],
      materialRecordInfo: {
        taskCode: '',
        materialBatchNumber: '',
        quantity: 0,
        operatorTime: '',
        depletionMethod: 1
      },
      curTaskInfo: {
        pickingReason: null,
		returnReason: null,
      },
      buttonShow: null,
      currentType: 0,
      bomFeeData: [],
      bomFeeColumn: [
        {
          type: 'selection',
          width: 35
        },
        {
          name: 'taskCode',
          label: '物料批次',
          align: 'center',
          width: 150
        },
        {
          name: 'status',
          label: 'ERP物料批次',
          align: 'center',
          width: 150
        },
        {
          name: 'materialBatchNumber',
          label: '物料编码',
          width: 150
        },
        {
          name: 'taskCode',
          label: '序列号',
          width: 150
        },
        {
          name: 'quantity',
          label: '数量',
          width: 150
        },
        {
          name: 'itemCode',
          label: '物料描述'
        }
      ],
      tableColumn: [
        {
          type: 'selection',
          width: 60
        },
        {
          name: 'arrangeCode',
          label: '编排单号',
          align: 'center',
          width: 85,
          cellFun: (row, index) => {
            console.log(row, index);
            this.tableDataDetail = row.proWorkorderList;
            this.showRowDeatilFlag = true;
          }
        },
        {
          name: 'scheduleStartDateStr',
          label: '计划开始时间',
          align: 'center',
          width: 95
        },
        {
          name: 'scheduleEndDateStr',
          label: '计划结束时间',
          align: 'center',
          width: 95
        },
        {
          name: 'quantity',
          label: '任务数量',
          align: 'center',
          width: 70
        },
        {
          name: 'quantityWait',
          label: '可加工数量',
          align: 'center',
          width: 80
        },
        {
          name: 'status',
          label: '状态',
          align: 'center',
          filters: {
            PREPARE: '未开工',
            BEGINNING: '已开工',
            PAUSE: '暂停',
            ERROR_STOP: '异常停工',
            FINISH: '完工'
          },
          width: 65
        },
        // {
        //   name: 'date',
        //   label: '批号',
        //   width: 50,
        // },
        {
          name: 'taskCode',
          label: '任务单号',
          align: 'center',
          width: 100
        },
        // {
        //   name: 'workorderCode',
        //   label: '生产单号',
        //   width: 120
        // },
        // {
        //   name: 'itemCode',
        //   label: '物料编号',
        //   width: 110,
        // },
        // {
        //   name: 'itemName',
        //   label: '物料名称'
        // },
        {
          name: 'processName',
          label: '工序',
          align: 'center',
          width: 80
        },
        {
          name: 'quantityQualify',
          label: '合格数量',
          align: 'center',
          width: 70
        },
        {
          name: 'quantityUnqualify',
          label: '不合格数量',
          align: 'center',
          width: 80
        }
        // {
        //   name: 'clientName',
        //   label: '作业人员',
        //   width: 60,
        //   align: 'center'
        // }
      ],
      dModelData: [],
      tableSelectData: [],
      feedbackForms: [],
      feedbackQuantityFu: 0,
      feedbackUnQuantityFu: 0,

      ExceptionForms: {
        abnormalType: null,
        abnormalReason: null
      },
      viewSopPicture: [],
      viewSop: [],
      causeList: [],
      reasonList: [],
	  reasonReturnList: [],
      workorderList: [],
      materialUsageRecordList: [],
      materialusagerecordLoading: false,
      issusLineList: [],
      issusLineColumn: [
        {
          name: 'itemCode',
          label: '产品物料编码'
        },
        {
          name: 'itemName',
          label: '产品物料名称'
        },
        {
          name: 'specification',
          label: '规格型号'
        },
        {
          name: 'unitOfMeasure',
          label: '单位'
        },
        {
          name: 'quantityIssued',
          label: '领料数量'
        },
        {
          name: 'batchCode',
          label: '批次号'
        },
        {
          name: 'warehouseName',
          label: '仓库名称'
        },
        {
          name: 'locationName',
          label: '库区名称'
        },
        {
          name: 'areaName',
          label: '库位名称'
        }
      ],
      feedingInspectionVisible: false,
      recoilMaterialVisible: false,
      materialRequestVisible: false,
      materialReturnVisible: false,
      materialReturn: false,
      stockInVisible: false,
      material: false,
      feedingInspectionList: [],
      recoilMaterialDetailList: [],
      materialRequestList: [],
      materialRequestArrays: [],
	  materialRequestArrayList: [],
	  materialRequestArrayLists: [],
      materialRequests: [],
      materialReturnList: [],
      materialRequestFormData: {
        itemName: null,
        applyNum: null
      },
      materialRequestFormVisible: false,
      materialRequestSelected: {},
      materialReturnFormData: {
        itemName: null,
        applyNum: 1,
        workorderCode: null,
		number: 0,
      },
      materialReturnProcessItemData: {
        itemName: null,
        itemCode: null,
        applyNum: 1,
        workorderCode: null
      },
	  applyNo: null,
      printTemplateData: null,
      printTemplateVisible: false,
      userTempVisible: false,
      materialReturnFormVisible: false,
      materialReturnSelected: {},
      recoilMaterialColumn: [
        {
          name: 'sapItemCode',
          label: 'sap物料号',
          width: 200
        },
        {
          name: 'batchNo',
          label: '批次号',
          width: 100
        },
        {
          name: 'packNo',
          label: '卷号',
          width: 100
        },
        {
          name: 'quantity',
          label: '数量',
          width: 100
        },
        {
          name: 'createTime',
          label: '创建时间',
          width: 100
        }
      ],

      tableDetailColumn: [
        {
          name: 'workorderCode',
          label: '生产工单',
          width: 140
        },
        {
          name: 'productCode',
          label: '产品编号',
          width: 140
        },
        {
          name: 'productName',
          label: '产品名称',
          width: 140
        },
        {
          name: 'quantity',
          label: '生产订单数量',
          width: 140
        },
				{
				  name: 'startSerial',
				  label: '开始序列码',
				  width: 140
				},
				{
				  name: 'endSerial',
				  label: '结束序列码',
				  width: 140
				},
        {
          name: 'productSpc',
          label: '规格',
          width: 140
        },
        {
          name: 'requestDate',
          label: '需求日期',
          width: 140
        }
      ],
      tableDataDetail: [],
      recoilMaterialList: [],

      showRowDeatilFlag: false,
      recoilMaterialFlag: false,

      loading: false,
      copyFeedBackForms: [],
      timeTest: {
        isshow: true
      },

    };
  },
  // watch() {

  // },
  mounted() {
    //监听工作中心切换事件
    // uni.$on('switchWorkunit', (station) => {
    //   this.getTaskList();
    // });
  },
  created() {
    //获取屏幕高度
    uni.getSystemInfo({
      success(res) {
        this.screenHeight = res.windowHeight;
      }
    });
    //监听工作中心切换事件
    uni.$on('switchWorkunit', (station) => {
      // this.reset();
      this.getTaskList();
    });

    uni.$on('taskStatusChanged', () => {
      this.getTaskList(); //刷新任务状态
    });

    if (this.vuex_workunit != null) {
      this.getTaskList();
    }
    // if (this.vuex_task != null) {
    //   this.shiftTask(this.vuex_task.taskId);
    // }
  },
  destroyed() {
    uni.$off('switchWorkunit');
    uni.$off('taskStatusChanged');
  },
  computed: {
    computedQuantity() {
      return this.feedbackForm.quantityQualify + this.feedbackForm.quantityUnqualify;
    }
  },
  methods: {
		cellStyle ({ row,column,rowIndex,columnIndex }) {
			if(columnIndex === 1) {
				return {color: '#3578ff !important'}
			}
			return ''
		},
    handleChangePackNum(feedback, i) {
      this.getWorkorderDirectiveList(feedback, i, true)
    },
    handleSubmitConfirmlKnifeTemp() {
      this.knifeTempVisible = true;
      this.$refs.appScan.closed();
      this.knifeTempAppScanVisible = false;
      this.knifeTempCancelText = '确认';
      this.knifeTempType = null;
    },
    handleSubmitCancelKnifeTemp() {
      this.knifeTempVisible = true;
			if(this.$refs.appScan) {
				this.$refs.appScan.closed();
			}
      this.knifeTempAppScanVisible = false;
      this.knifeTempCancelText = '取消';
    },
    handleAppScanKnifeTemp(type) {
      this.knifeTempAppScanVisible = true;
      this.knifeTempType = type;
      this.knifeTempCancelText = type === '1' ? '关闭上机扫描' : '关闭下机扫描';
      this.getPemissionScan();
    },
    handleUpdateKnifeTemp(code) {
      console.log('isExistTool', this.knifeTempType, this.tableSelectData[0].isExistTool)

      if (this.knifeTempType === '1') {
        if(this.tableSelectData[0].isExistTool) {
          this.$u.api.dModel.checkIsExsitToolWindow({ type: this.knifeTempType, sn: code, taskWorkunitId: this.tableSelectData[0].taskWorkunitId }).then((res) => {
            if (res.code === 200) {
              if (res.data) {
                uni.showModal({
                  title: '系统提示',
                  content: '是否新增刀模版和产品工序的关联?',
                  success:  (res) => {
                    if (res.confirm) {
                      this.confirmKnifeTemp(code)
                    } else {
                      this.$u.toast("刀模版SN不一致")
                    }
                  }
                })
              } else {
                this.confirmKnifeTemp(code)
              }
            } else {
              this.$u.toast(res.msg)
            }
          })
        } else {
          this.confirmKnifeTemp(code)
        }
      } else {
        this.confirmKnifeTemp(code)
      }
    },
    confirmKnifeTemp(code) {
      const params = { type: this.knifeTempType, sn: code, taskWorkunitId: this.tableSelectData[0].taskWorkunitId }
      if (this.knifeTempType === '1') {
        params['isExistTool'] = this.tableSelectData[0].isExistTool
      }
      this.$u.api.dModel.tmToolMachinesScancode(params).then((res) => {
        console.log(res, 'res333');
        if (res.code === 200) {
          this.$u.toast(this.knifeTempType === '1' ? '上机成功' : '下机成功');
          this.upDownGetList();
        }
      })
    },
    handleChangeTabPro(index, row) {
      row.currentTabPro = index;
    },
    onPreviewTap(url) {
      uni.previewImage({
        current: url,
        urls: this.viewSop
      });
    },
    // cellClick(row, index, column) {
    //   if (column.name === 'arrangeCode') {
    //     this.tableDataDetail = row.proWorkorderList;
    //     this.showRowDeatilFlag = true;
    //     console.log(e)
    //     e.stopPropagation()
    //   }
    // },
    iconClickArrangeCode() {
      uni.scanCode({
        success: (res) => {
          // console.log(res, 'res');
					this.tableParams.arrangeCode = res.result
          this.getTaskList({ arrangeCode: res.result });
        },
        fail: () => {
          this.$u.toast('扫码失败，请重新扫描');
        }
      });
    },
    numclik(...arg) {
      console.log('99999999', arg);
    },
    changeWorkstation() {
      uni.$emit('changeWorkunit');
    },
    // 判断是否显示红色
    isTrClassStyle(row, i) {
      // console.log(row, i, 999)
			const index = this.tableSelectData.findIndex(v=> v.taskWorkunitId === row.taskWorkunitId)
			if (index > -1) {
				return 'selectrow'
			}
      if (row.status === 'PAUSE') {
        return 'yellow'; //暂停
      } else if (row.status === 'BEGINNING') {
        return 'green'; //已开工
      } else if (row.status === 'ERROR_STOP') {
        return 'red'; //异常停工
      } else {
        return ''; //第二个大
      }
    },
    commonClick(oper) {
      if (['Refresh', 'MaterialUsageRecord', 'editProd'].indexOf(oper) === -1 && this.tableSelectData.length === 0) {
        this.$u.toast('请选择工作任务！');
        return;
      }
      switch (oper) {
        case 'Refresh':
          this.getTaskList();
          break;
        case 'StartTask':
          let status = false;
          this.tableSelectData.forEach((item) => {
            if (item.status === 'BEGINNING') {
              status = true;
            } else {
              this.$u.api
                .changeCheckMachineTool({
                  taskWorkunitId: item.taskWorkunitId
                })
                .then((res) => {
                  if (res.code === 200) {
                    this.changeStatus(item.taskId, item.taskWorkunitId, 'BEGINNING', item.workunitId, false);
                  }
                });
            }
          });
          if (status) {
            this.$u.toast('该任务已开工，请勿重复开工');
            return;
          }
          break;
        case 'StopTask':
          this.stopCause();
          this.stopReason = '';
          this.stopReasonVisible = true;
          break;
        case 'FinshTask':
          this.tableSelectData.forEach((item) => {
            this.changeStatus(item.taskId, item.taskWorkunitId, 'FINISHED', item.workunitId);
          });
          break;
        case 'Prod':
          if (this.tableSelectData[0].status === 'PREPARE') {
            this.$u.toast('工序未开工');
            return;
          }
          this.doFeedback();
          break;
        case 'editProd':
          this.doEditProd();
          break;
        case 'MaterialUsageRecord':
          this.addMaterialUsageRecord();
          break;
        case 'KnifeTemp':
          this.knifeTempShow();
          break;
        case 'KnifeTemp2':
          this.changeShow();
          break;
        case 'abnormal':
          this.doException();
          break;
        case 'ViewPpicture':
          this.viewiPctureShow();
          break;
        case 'FeedingInspection':
          this.feedingInspectionShow();
          break;
        case 'RecoilMaterial':
          this.recoilMaterialShow();
          break;
        case 'MaterialRequest':
          this.materialRequestShow();
          this.pickingCause();
          break;
        case 'MaterialReturn':
          this.materialReturnShow();
		  this.pickingCauses();
          break;
        case 'StockIn':
          this.stockInShow();
          break;
        default:
          this.$u.toast('功能正在开发中！');
          break;
      }
    },

    handleJobAssignment() {
      this.jobAssignmentForm = {
        quantity: 1,
        workunitName: null
      };
      this.jobAssignmentVisible = true;
    },
    handleSubmitWorkunit() {
      this.jobAssignmentForm.workunitId = this.$refs.workunitRef.tableSelectData[0].workunitId;
      this.jobAssignmentForm.workunitName = this.$refs.workunitRef.tableSelectData[0].workunitName;
    },
    doEditProd(){
      // console.log('vuex_workstation', this.$store.state.vuex_workunit)
      const datas = Object.assign({}, this.tableSelectData[0]);
      this.$refs['editFeeding'].getList().then(() => {
        this.editFeedingVisible = true
      }).catch(()=>{
        this.$u.toast('修改报工出现问题')
      })
    },
    handleSubmitJobAssignment() {
      let datas = Object.assign({}, this.tableSelectData[0]);
      datas.taskWorkunit = this.jobAssignmentForm;
      delete datas.proWorkorderList;
      this.$u.api.putProtaskSplit(datas).then((res) => {
        // console.log(res, 'res333')
        if (res.code === 200) {
          this.jobAssignmentVisible = false;
          this.getTaskList();
        }
      });
    },
    async knifeTempShow() {
      if (this.tableSelectData.length > 1) {
        return;
      }
      const params = {
        taskWorkunitId: this.tableSelectData[0].taskWorkunitId
        // arrangeCode: this.tableSelectData[0].arrangeCode || '',
        // processId: this.tableSelectData[0].processId,
        // workunitId: this.vuex_workunit.workunitId
      };
      const records = await this.$u.api.dModel.getRecordsByProcessIdAndArrangeCode(params);
      // 如果有数据
      if (records?.data && records.data.length) {
        this.dModelData = records.data;
        this.knifeTempVisible = true;
        return;
      }
      // else {
      //   return this.$u.toast('该刀模版具不属于该工单');
      // }
      this.addDModelRecord(params);
    },
    async upDownGetList() {
      const params = {
        taskWorkunitId: this.tableSelectData[0].taskWorkunitId
        // arrangeCode: this.tableSelectData[0].arrangeCode || '',
        // processId: this.tableSelectData[0].processId
      };
      const records = await this.$u.api.dModel.getRecordsByProcessIdAndArrangeCode(params);
      this.dModelData = records.data;
    },
    // 新增刀模版上下机记录
    async addDModelRecord(params) {
      // const { data } = await this.$u.api.dModel.getToolsByProcessIdAndArrangeCode(params);
      // if (data?.length) {
      const [selectData] = this.tableSelectData;
      const ps = {
        // toolMachinesCode: '',
        // arrangeCode: selectData.arrangeCode,
        // workunitId: this.vuex_workunit.workunitId,
        // workunitCode: this.vuex_workunit.workunitCode,
        // workunitName: this.vuex_workunit.workunitName,
        // processId: selectData.processId,
        // taskId: selectData.taskId,
        taskWorkunitId: selectData.taskWorkunitId
        // workorderId: selectData.workorderId,
        // toolRequestUseId: data[0].toolRequestUseId,
        // toolMachinesRecordList: data.map((v) => {
        //   return {
        //     toolRequestUseItemId: v.toolRequestUseItemId,
        //     type: 3,
        //     upDate: '',
        //     downDate: ''
        //   };
        // })
      };
      // 新增
      const data2 = await this.$u.api.dModel.tmToolMachines(ps);
      if (data2.code == 200) {
        const records = await this.$u.api.dModel.getRecordsByProcessIdAndArrangeCode(params);
        this.dModelData = records.data || [];
        this.knifeTempVisible = true;
      }
      // }
    },
    getIssusLinebyWorkorderCodes() {
      this.issusLineList = [];
      this.$u.api.getIssusLinebyWorkorderCodes({ workorderCodes: this.curTaskInfo.workorderCodes?.split(',') }).then((res) => {
        if (res.code === 200) {
          this.issusLineList = res.rows;
        }
      });
    },
    rowClick(row, index) {
      this.$refs.zbtable.toggleRowSelection(row);
      this.curTaskInfo = row;
      this.getMaterialUsageRecordList();
    },
    getCode(row) {
      this.usePersonData = row;
      this.userTempVisible = true;
    },
    toggleAllSelection(checked, arr) {
      // console.log(arr, 'this.tableSelectData');
      this.tableSelectData = arr;
    },
    toggleRowSelection(checked, arr) {
      // console.log(arr, 'this.tableSelectData');
      this.tableSelectData = arr;
      
      if(this.tableSelectData.length > 0) {
        this.$u.api.buttonList(this.tableSelectData[0]['taskWorkunitId']).then(res => {
          if (res && res.length > 0) {
            this.buttonShow = res[0]
          } else {
            this.buttonShow = null
          }
        }).catch(()=>{
          this.buttonShow = null
        });
      } else {
        this.buttonShow = null
      }
      
    },
    knifeTemp() {
      // this.$u.toast('刀具校验通过！');
    },
    userDetermine() {
		let nick= '';
		let user= '';
		const tableSelectData = JSON.parse(JSON.stringify(this.$refs.userPersonnelRef.tableSelectData))
		const a= tableSelectData.length - 1;
		tableSelectData.forEach((item) =>{
		if(item.nickName ===tableSelectData[a].nickName){
			nick=nick+item.nickName;
			user=user+item.userName;
		}else{
			nick=nick+item.nickName+"，";
			user=user+item.userName+"，";
		}
	   });
	  this.usePersonData.nickName = nick;
	  this.usePersonData.userName = user;
	
    },
    stopReasonSubmit() {
      this.tableSelectData.forEach((item) => {
        this.changeStop(item.taskId, item.taskWorkunitId, 'PAUSE', item.workunitId);
      });
      this.getTaskList();
    },
    stopReasonChange(e) {
      this.stopReason += e;
    },
    workorderSelect(id, index) {
      console.log(id, '9999');
      const row = this.feedbackForms[index];
      const items = row.workorderList.find((item) => item.workorderId === id);
      if (!id) {
        row.packUnitOfMeasure = '';
        row.printContents = row.arrangeCode;
        row.tableDirectiveData = [];
        row.tableSizeData = [];
        row.tableOrderData = [];
        row.packNum = '';
        row.packType = '';
        row.lossIndividuallyWrap = undefined;
        row.currentTabPro = 0;
        row.workorderFeedbackSum = row.workorderFeedback
        row.workorderUnfeedbackSum = row.workorderUnfeedback
        row.quantityQualify = row.quantityWait
        this.$set(this.feedbackForms, index, row)
        return;
      } else {
        if (row.isPackage === '1') {
          row.packNum = items.usagePackNum ? items.usagePackNum : 0;
          row.mergePack = items.mergePack ? items.mergePack : 0;
          row.encasementNum = items.usageEncasementNum ? items.usageEncasementNum : 0;
          this.getWorkorderDirectiveList(id, index);
        } else {
          this.$u.api.quantitywaitsum({
            workorderCode: items.workorderCode,
            taskWorkunitId: row.taskWorkunitId
          }).then((res) => {
            if (res.code === 200) {
              row.quantityQualify = res.data.workorderQualify
              row.workorderFeedbackSum = res.data.workorderFeedbackSum
              row.workorderUnfeedbackSum = res.data.workorderUnfeedbackSum
              row.overFeedback = res.data.overFeedback 
              this.$set(this.feedbackForms, index, row)
            }
          })
        }
      }
      row.workorderId = id;
      row.workorderCode = items.workorderCode;
      row.printName = items.workorderCode;
      //row.printContents =row.arrangeCode+row.workorderCode
      row.printContents = row.workorderCode;
      row.packByDirective = items.packByDirective;
      row.packBySize = items.packBySize;
    },

    stopReas(abnormalType) {
      // 查询原因
      this.$u.api.abnormal
        .detail({
          pageNum: 1,
          pageSize: 10,
          abnormalType
        })
        .then((res) => {
          this.reasonList = res.rows.map((item) => {
            return {
              value: item.abnormalReason,
              text: item.abnormalReason
            };
          });
        });
    },
    stopCause() {
      // 查询原因
      this.$u.api.abnormal
        .detail({
          pageNum: 1,
          pageSize: 10,
          abnormalType: 'WORK'
        })
        .then((res) => {
          this.causeList = res.rows.map((item) => {
            return {
              value: item.abnormalReason,
              text: item.abnormalReason
            };
          });
        });
    },

    pickingCause() {
      // 查询原因
      this.$u.api.abnormal
        .detail({
          pageNum: 1,
          pageSize: 10,
          abnormalType: 'REASON'
        })
        .then((res) => {
          this.reasonList = res.rows.map((item) => {
            return {
              value: item.abnormalReason,
              text: item.abnormalReason
            };
          });
        });
    },
		   pickingCauses() {
	      // 查询原因
	      this.$u.api.abnormal
	        .detail({
	          pageNum: 1,
	          pageSize: 10,
	          abnormalType: 'RETURN_REASON'
	        })
	        .then((res) => {
	          this.reasonReturnList = res.rows.map((item) => {
	            return {
	              value: item.abnormalReason,
	              text: item.abnormalReason
	            };
	          });
	        });
	    },

    async getWorkorderWithSizeAndDirective(item, index) {
      await this.$u.api
        .getWorkorderWithSizeAndDirective({
          pageNum: 1,
          pageSize: 10,
          arrangeCode: item.arrangeCode,
          taskWorkunitId: item.taskWorkunitId,
          processId: item.processId
        })
        .then(async (res) => {
          item.workorderList = res.rows;
          //如果只关联一个订单，默认选中
          if (res.rows.length == 1) {
            item.printContents = res.rows[0].workorderCode;
            item.workorderId = res.rows[0].workorderId;
            item.workorderCode = res.rows[0].workorderCode;
            item.packByDirective = res.rows[0].packByDirective;
            item.packBySize = res.rows[0].packBySize;
            item.unitOfConvert = res.rows[0].unitOfConvert;
            if ((!item.isPackage || item.isPackage !== '1') && (!item.taskType || item.taskType !== 3)) {
              // 请求了证明了中间的报工
              await this.$u.api.quantitywaitsum({
                workorderCode: item.workorderCode,
                taskWorkunitId: item.taskWorkunitId
              }).then((res) => {
                if (res.code === 200) {
                  item.quantityQualify = res.data.workorderQualify
                  item.workorderFeedbackSum = res.data.workorderFeedbackSum
                  item.workorderUnfeedbackSum = res.data.workorderUnfeedbackSum
                  item.overFeedback = res.data.overFeedback 
                }
              })
            }
          }
          this.feedbackForms.push(item);
          item.workorderOption = res.rows.map((temp) => {
            if (temp.saleDirectiveList != null) {
              item.directiveData[temp.workorderId] = temp.saleDirectiveList.map((temp2) => {
                return {
                  value: temp2.workorderSoDirectiveId,
                  text: temp2.clientCmd
                };
              });
            }
            if (temp.sizeList2 != null) {
              item.sizeData[temp.workorderId] = temp.sizeList2.map((temp2) => {
                return {
                  value: temp2.workorderSoSizeItemId,
                  text: temp2.standardSize
                };
              });
            }

            return {
              value: temp.workorderId,
              text: temp.workorderCode
            };
          });
          
          if (item.isPackage === '1' && res.rows.length > 0) {
            item.workorderId = res.rows[0].workorderId;
            item.packNum = res.rows[0].usagePackNum ? res.rows[0].usagePackNum : 0;
            item.mergePack = res.rows[0].mergePack ? res.rows[0].mergePack : 0;
            item.encasementNum = res.rows[0].usageEncasementNum ? res.rows[0].usageEncasementNum : 0;
            this.getWorkorderDirectiveList(res.rows[0].workorderId, index);
          }
        }).catch(() => {
          this.feedbackForms.push(item);
        });
    },

    getTaskList(params) {
      this.form = {};
      const t = this;
      this.tableData = [];
      this.tableSelectData = []
      this.$u.api
        .getTaskList({
          workunitId: t.vuex_workunit.workunitId,
          ...this.tableParams,
          ...params
        })
        .then((res) => {
          if (res.code === 200) {
						let currentIndex = -1
						this.$refs['zbtable'].bodyScrollTop = 0
            // 过滤可加工数量为0的数据
            this.tableData = res.rows.map((item, index) => {
							if (item.location) {
								currentIndex = index
								item['checked'] = true
								this.tableSelectData.push(item)
							}
              return {
                ...item,
                scheduleStartDateStr: item.scheduleStartDate.substring(2, 16),
                scheduleEndDateStr: item.scheduleEndDate.substring(2, 16)
              };
            });
            if (this.tableData.length > 0) {
              this.curTaskInfo = this.tableData[0];
              this.getMaterialUsageRecordList();
							if (currentIndex > -1) {
								this.$nextTick(()=>{
									const query = uni.createSelectorQuery().in(this)
									query
										.select('#tableBody')
										.boundingClientRect()
									query.selectAll('#tableBody .item-tr')
										.boundingClientRect()
									query.exec(res => {
											const data1 = res[0]
											let scrollTop = 0
											// const currentIndexPlus = currentIndex + 1
											let sumheight = 0
											if (res[1] && Array.isArray(res[1]) && res[1].length > 0) {
												res[1].forEach((item, index) => {
													if (index < currentIndex) {
														sumheight += item.height
													}
												})
                        // 当查找项高度不在当前窗口，需要滚动到指定高度
                        // 当查找项目在当前窗口，则不滚动
                        // 当查找项目只有一半部分在当前窗口，则滚动到当前项目之前叠加的高度
												scrollTop = (sumheight > data1.height) ? sumheight : (res[1][currentIndex].height + sumheight) > data1.height ? sumheight : 0
											} else {
												const height = 80.8
												scrollTop = ((height * currentIndex) > data1.height) ? (height * currentIndex) : 0
											}
											
											this.$refs['zbtable'].bodyScrollTop = scrollTop
										})
								})
							}
            }
          }
        }).catch(e=>{
					console.log('eee', e)
				})
    },
    typeChange(index) {
      this.currentType = index;
      this.getMaterialUsageRecordList();
    },
		// px转rpx
		pxToRpx(px) {
		  const screenWidth = uni.getSystemInfoSync().screenWidth
		  return (750 * Number.parseInt(px)) / screenWidth
		},
    getMaterialUsageRecordList() {
      this.materialusagerecordLoading = true;
      this.$u.api
        .materialusagerecordList({
          workstationId: this.vuex_workstation?.workstationId,
          depletionMethod: this.currentType + 1,
          taskId: this.curTaskInfo.taskId
        })
        .then((res) => {
          this.materialusagerecordLoading = false;
          if (res.code === 200) {
            this.materialUsageRecordList = res.rows;
          }
        });
    },
    
    addMaterialUsageRecord() {
      if (this.materialRecordInfo.materialBatchNumber !== this.curTaskInfo.itemCode && this.currentType === 0) {
        this.$u.toast('物料不在生产目录中！');
        return;
      }
      if (this.materialRecordInfo.quantity === 0) {
        this.$u.toast('请输入物料数量！');
        return;
      }
      this.materialRecordInfo.operatorTime = new Date();
      this.materialRecordInfo.operatorId = this.vuex_user.userId;
      this.materialRecordInfo.operatorName = this.vuex_user.userName;
      this.materialRecordInfo.taskId = this.curTaskInfo.taskId;
      this.materialRecordInfo.depletionMethod = this.currentType + 1;
      this.materialRecordInfo.workstationId = this.vuex_workstation.workstationId;
      this.$u.api.addMaterialusagerecord(this.materialRecordInfo).then((res) => {
        if (res.code === 200) {
          this.materialRecordInfo.quantity = 0;
          this.materialRecordInfo.materialBatchNumber = '';
          this.$u.toast('上报成功');
          this.getMaterialUsageRecordList();
        }
      });
    },
    shiftTask(tid) {
      this.$u.api
        .getTaskInfo({
          taskId: tid
        })
        .then((res) => {
          if (res.code === 200) {
            this.form = res.data;
            this.$u.vuex('vuex_task', res.data);
            this.form.progress = Math.round((this.form.quantityProduced / this.form.quantity) * 100, 0);
          }
        });
    },
    changeStatus(taskId, taskWorkunitId, status, workunitId, showToast) {
      // this.form.status = status;
      this.$u.api
        .changeStatus({
          taskId: taskId,
          status: status,
          taskWorkunitId: taskWorkunitId,
          workunitId: workunitId,
          attr1: this.stopReason
        })
        .then((res) => {
          if (res.code === 200) {
            let showToastData = showToast === false ? false : true;
            if (showToastData) {
              this.$u.toast('变更成功');
            }
            this.getTaskList();
          }
        });
    },
    //暂停作业
    changeStop(taskId, taskWorkunitId, status, workunitId) {
      // this.form.status = status;
      this.$u.api
        .changeStatus({
          taskId: taskId,
          status: status,
          taskWorkunitId: taskWorkunitId,
          workunitId: workunitId,
          attr1: this.stopReasonForm.reason,
          attr2: this.stopReasonForm.desc
        })
        .then((res) => {
          if (res.code === 200) {
            this.$u.toast('变更成功');
            this.getTaskList();
          }
        });
    },
    quantityChanged(val) {
      this.feedbackForm.quantity = this.feedbackForm.quantityQualify + this.feedbackForm.quantityUnqualify;
    },

    changeShow() {
      console.log(this.timeTest.isshow);
      this.timeTest.isshow = !this.timeTest.isshow;
    },

    quantityChangedV2(feedback, val1, val2) {
      let qq = (val1 === 0 || val1 === null) ? 0 : val1;
      let quq = (val2 === 0 || val2 === null) ? 0 : val2;

      if (qq > 0) {
        feedback.quantityQualify = qq / (feedback.unitOfConvert || 1);
      }

      if (quq > 0) {
        feedback.quantityUnqualify = quq / (feedback.unitOfConvert || 1);
      }

      feedback.quantityUnqualify = isNaN(feedback.quantityUnqualify) || feedback.quantityUnqualify === null ? 0 : feedback.quantityUnqualify;
      feedback.quantityQualify = isNaN(feedback.quantityQualify) || feedback.quantityQualify === null ? 0 : feedback.quantityQualify;

      feedback.quantity = feedback.quantityUnqualify + feedback.quantityQualify;
    },
    quantityChangedV3(feedback, val1, val2) {
      let qq = (val1 === 0 || val1 === null) ? 0 : val1;
      let quq = (val2 === 0 || val2 === null) ? 0 : val2;

      if (qq > 0) {
        feedback.quantityQualify = qq / (feedback.unitOfConvert || 1);
      }

      if (quq > 0) {
        feedback.quantityUnqualify = quq / (feedback.unitOfConvert || 1);
      }

      feedback.quantityUnqualify = isNaN(feedback.quantityUnqualify) || feedback.quantityUnqualify === null ? 0 : feedback.quantityUnqualify;
      feedback.quantityQualify = isNaN(feedback.quantityQualify) || feedback.quantityQualify === null ? 0 : feedback.quantityQualify;

      feedback.quantity = feedback.quantityUnqualify + feedback.quantityQualify;
    },
    getPrintTemplate(row) {
      this.printTemplateData = row;
      this.printTemplateVisible = true;
    },
    chooseUser() {
      console.log(this.$refs.userRef.tableSelectData, 'this.$refs.userRef.tableSelectData');
      this.useData.checkBy = this.$refs.userRef.tableSelectData[0]?.userName;
    },
    handleSubmitPrintTemplate() {
      this.printTemplateData.printTemplate = this.$refs.printTemplateRef.tableSelectData[0].name;
      this.printTemplateVisible = false;
    },
    async doFeedback() {
      // this.reset();
      this.feedbackUnQuantityFu = 0;
      this.feedbackQuantityFu = 0;

      this.feedbackForms = [];
      let flagPackage = [];
      this.tableSelectData.forEach((item, index) => {
        flagPackage.push(item.isPackage === '1');
        let defQualify = item.quantity - item.quantityQualify - item.quantityUnqualify;
        defQualify = defQualify < 0 ? 0 : defQualify;
        defQualify = defQualify > item.quantityWait ? item.quantityWait : defQualify;
        const feedback = {
          ...item,
          workorderFeedback: 0,
          workorderUnfeedback: 0,
          workstationId: item.workstationId,
          userName: this.vuex_user.userName,
          taskId: item.taskId,
          taskWorkunitId: item.taskWorkunitId,
          processId: item.processId,

          feedbackChannel: 'PAD',
          quantity: item.quantity,
           //默认为排产数量-合格数-不合格数
          quantityUnqualify: 0,
          reportQualify: item.quantityQualify + item.quantityUnqualify,
          printName: '',
          lastProcess: item.isLastProcess == 1, //未工序
          nickName: this.vuex_user.nickName,
          workorderId: 0,
          workorderCode: null,
          netWeight: 0,
          minPackageNum: 0,
          workorderList: [],
          workorderOption: [],
          directiveData: {},
          sizeData: {},
          printContents: item.arrangeCode,
          feedbackTime: this.parseTime(new Date()),
          whether: '',
          closeType: null,
          printTemplate: '',
          tableSizeData: [],
          tableSizeColumn: [
            {
              name: 'standardSizeIdx',
              label: '序号',
              width: 60
            },
            {
              name: 'standardSize',
              label: '标准SIZE',
              width: 100
            },
            {
              name: 'quantity',
              label: '派工数',
              width: 60
            },
            {
              name: 'packageNum',
              label: '包装数',
              width: 60
            },
            {
              name: 'lossNum',
              label: 'LOSS数',
              width: 60
            },
            {
              name: 'feedbackQuantity',
              label: '已包装数',
              width: 80
            },
            {
              name: 'reportQuantity',
              label: '本次报工',
              width: 120,
              type: 'slot',
              slot: 'reportQuantity'
            },
            {
              name: 'netWeight',
              label: '净重',
              width: 100,
              type: 'slot',
              slot: 'netWeight'
            },
            {
              name: 'peration',
              label: '操作',
              width: 120,
              type: 'slot',
              slot: 'peration'
            }
          ],
          taskType: item.taskType,
          listTabPro: [],
          tableOrderData: [],
          tableDirectiveData: [],
          currentTabPro: 0,
          packNum: 0,
          encasementNum: 0,
          mergePack: 0
        };
        feedback.quantityQualify = item.quantityWait
        if(feedback.taskType && feedback.taskType === 3) {
          feedback.quantityQualify = item.quantity - item.quantityQualify - item.quantityUnqualify
          feedback.quantityUnqualify = item.quantityUnqualify
          feedback.workorderCode = item.workorderCode
          feedback.closeType = ''
        } else if(!feedback.isPackage || feedback.isPackage !== '1') {
          this.$u.api.quantitywaitsum({
            taskWorkunitId: item.taskWorkunitId
          }).then((res) => {
            if (res.code === 200) {
              // row.quantityQualify = res.data.workorderQualify
              feedback.workorderFeedbackSum = res.data.workorderFeedbackSum
              feedback.workorderUnfeedbackSum = res.data.workorderUnfeedbackSum
              feedback.workorderFeedback = res.data.workorderFeedbackSum
              feedback.workorderUnfeedback = res.data.workorderUnfeedbackSum
              feedback.overFeedback = res.data.overFeedback 
            }
          })
        }
        this.getWorkorderWithSizeAndDirective(feedback, index);
      });
      if (Array.from(new Set(flagPackage)).length === 2) {
        this.$u.toast('包装工序禁止多选报工');
        return;
      }
      // 如果选择了包装工序、非包装工序提示：“包装工序禁止多选报工”
      this.proVisible = true;
    },
    // 获取指令列表
    getWorkorderDirectiveList(rows, index, flag) {
      this.getWorkorderDirectiveLoading = true;
      let row = this.feedbackForms[index];
      this.$u.api
        .workOrderSoDirectiveApi({
          encasementNum: row.encasementNum,
          mergePack: row.mergePack || 0,
          packNum: row.packNum,
          quantity: row.quantity,
          taskId: row.taskId,
          workorderId: row.workorderId
        })
        .then((res) => {
          this.getWorkorderDirectiveLoading = false;
          if (res.code === 200) {
            this.copyFeedBackForms = JSON.parse(JSON.stringify(this.feedbackForms));
            if (res.data.directiveList) {
              row.tableDirectiveData = res.data.directiveList.map((item) => {
                return {
                  ...item,
                  reportQuantity: (Number(item.packageNum) || 0) - (Number(item.feedbackQuantity) || 0)
                };
              });
              row.listTabPro = [
                {
                  name: '指令列表'
                }
              ];
              row.tableDirectiveData.push({reportQuantity: 0, netWeight: 0, printbtn: true})
            } else {
              row.tableDirectiveData = [];
            }
            if (res.data.orderPackageList) {
              row.tableOrderData = res.data.orderPackageList.map((item) => {
                return {
                  ...item,
                  reportQuantity: (Number(item.packageNum) || 0) - (Number(item.feedbackQuantity) || 0)
                };
              });
              row.listTabPro = [
                {
                  name: '报工列表'
                }
              ];
              row.tableOrderData.push({reportQuantity: 0, netWeight: 0, printbtn: true})
            } else {
              row.tableOrderData = [];
            }
            if (res.data.sizeList) {
              row.tableSizeData = res.data.sizeList.map((item) => {
                return {
                  ...item,
                  reportQuantity: (Number(item.packageNum) || 0) - (Number(item.feedbackQuantity) || 0)
                };
              });
              row.listTabPro = [
                {
                  name: 'SIZE列表'
                }
              ];
              row.tableSizeColumn[1].label = res.data.sizeColumnName;
            } else {
              row.tableSizeData = [];
            }
          } else {
            if (flag) {
              // this.$set(this.feedbackForms, index, this.copyFeedBackForms[index])
              this.$set(this.feedbackForms[index], 'packNum', this.copyFeedBackForms[index].packNum);
              this.$set(this.feedbackForms[index], 'encasementNum', this.copyFeedBackForms[index].encasementNum);
              this.$set(this.feedbackForms[index], 'mergePack', this.copyFeedBackForms[index].mergePack);
            }
            row.tableDirectiveData = [];
            row.tableSizeData = []
            row.tableOrderData = [];
            row.listTabPro = [
            ];
          }
        });
    },
    rePackageInfoPrint(item, row, i){
      uni.showModal({
        title: '系统提示',
        content: '是否确认补打?',
        success:  (res) => {
          if (res.confirm) {
            if (!item.printTemplate) {
            return this.$u.toast('请选择打印模版')
          }
          if (item.printTemplate && !this.vuex_printConnect) {
            this.$u.toast('打印机连接失败');
            return;
          }
          item.feedbackTime = this.parseTime(new Date())
          this.$u.api
            .rePackageInfoPrint({
              workorderId: item.workorderId,
              qrcode: row.qrcode,
            })
            .then((res) => {
              if (res.code === 200) {
                // this.proVisible = false;
                // item.quantityUnqualify = 0;
                // this.$u.toast('上报成功');
                // this.getWorkorderDirectiveList(item, i)
                if (item.printTemplate) {
                  let params = {};
                  res.data.forEach((datas) => {
                    params = {
                      reportName: 'mysql:' + item.printTemplate,
                      values: {
                        packagePrint: datas
                      }
                    };
                    this.printPdfSocket(params);
                  });
                }
                this.getTaskList();
              }
            });
          }
        }
      })
      
    },
    handleSubmitPackageFeedback(item, row, i) {
      if (item.printTemplate && !this.vuex_printConnect) {
        this.$u.toast('打印机连接失败');
        return;
      }
      item.feedbackTime = this.parseTime(new Date())
      this.$u.api
        .feedBackPackage({
          taskWorkunitId: item.taskWorkunitId,
          checkBy: item.checkBy,
          encasementNum: item.encasementNum,
          mergePack: item.mergePack,
          packNum: item.packNum,
          printTemplate: item.printTemplate,
          quantityUnqualify: item.quantityUnqualify,
          taskId: item.taskId,
          feedbackTime: item.feedbackTime,
          workorderId: item.workorderId,
          'reportData.netWeight': row.netWeight,
          'reportData.reportQuantity': row.reportQuantity,
          'reportData.packageNum': row.packageNum,
          'reportData.qrcode': row.qrcode,
          'reportData.workorderSoDirectiveId': row.workorderSoDirectiveId,
          'reportData.workorderSoSizeItemId': row.workorderSoSizeItemId
        })
        .then((res) => {
          if (res.code === 200) {
            // this.proVisible = false;
            item.quantityUnqualify = 0;
            this.$u.toast('上报成功');
            this.getWorkorderDirectiveList(item, i)
            if (item.printTemplate) {
              let params = {};
              res.data.forEach((datas) => {
                params = {
                  reportName: 'mysql:' + item.printTemplate,
                  values: {
                    packagePrint: datas
                  }
                };
                this.printPdfSocket(params);
              });
            }
            this.getTaskList();
          }
        });
    },
    // 获取SIZE列表
    getWorkorderSizeList(id, index) {
      let row = this.feedbackForms[index];
      this.$u.api
        .workOrderSoSizeItemApi({
          workorderId: id
        })
        .then((res) => {
          let columns = [];
          if (res.code === 200) {
            for (const key in res.data.columns) {
              if (res.data.columns.hasOwnProperty.call(res.data.columns, key)) {
                const element = res.data.columns[key];
                let obj = {
                  name: key,
                  label: element
                };
                if (key === 'reportQuantity') {
                  obj.width = 130;
                  obj.type = 'slot';
                  obj.slot = 'reportQuantity';
                }
                columns.push(obj);
              }
            }
            // columns.unshift({
            //   name: 'reportQuantity',
            //   label: '本次包装数量',
            //   width: 130,
            //   type: 'slot',
            //   slot: 'reportQuantity'
            // })
            row.tableSizeColumn = columns;
            row.tableSizeData = res.data.sizeList;
          }
        });
    },

    doException() {
      this.ExceptionForms = {
        abnormalType: null,
        abnormalReason: null
      };
      const item = this.tableSelectData[0];
      Object.assign(this.ExceptionForms, {
        ...item,
        batchNumber: item.arrangeCode,
        processId: item.processId,
        processCode: item.processCode,
        processName: item.processName,
        workstationId: this.vuex_workunit.workunitId,
        workstationCode: this.vuex_workunit.workunitCode,
        workstationName: this.vuex_workunit.workunitName,
        abnormalType: '',
        abnormalReason: '',
        abnormalTime: ''
      });
      this.errorVisible = true;
    },

    async newlyAddss() {
      const res = await this.$u.api.abnormal.newlyAdd(this.ExceptionForms).then((res)=>{
		  if(res.code === 200){
			  this.$u.toast('上报成功');
		  }else{
			  this.$u.toast(res.msg);
		  }
	  });
      
      this.getTaskList();
    },
    cancel() {
      this.proVisible = false;
      this.timeTest.isshow = false;
      // this.feedbackUnQuantityFu = 0;
      // this.feedbackQuantityFu = 0;

    },
    handleSubmitfeedback() {
      this.feedbackUnQuantityFu = 0;
      this.feedbackQuantityFu = 0;
      this.proVisible = false;
      this.timeTest.isshow = false;
      this.feedbackForms.forEach((item) => {
        if (item.quantity === 0 || item.quantity === null) {
          this.$u.toast('请填写合格/不合格产品数量！');
          return;
        }
        // if (item.lastProcess) {
        //   //最后工序
        // }
        if ((item.printTemplate || item.whether == '1') && !this.vuex_printConnect) {
          this.$u.toast('打印机连接失败');
          return;
        }
        const par = {
            //工单
            taskWorkunitId: item.taskWorkunitId,
            taskId: item.taskId,
            taskCode: item.taskCode,
            quantityFeedback: item.quantityQualify + item.quantityUnqualify,
            quantityQualify: item.quantityQualify,
            quantityUnqualify: item.quantityUnqualify,
            userName: item.userName || this.vuex_user.userName,
            feedbackType: item.feedbackType,
            routeId: item.routeId,
            routeCode: item.routeCode,
            processId: item.processId,
            processCode: item.processCode,
            processName: item.processName,
            itemId: item.itemId,
            itemCode: item.itemCode,
            itemName: item.itemName,
            workstationId: item.workstationId,
            workstationCode: item.workstationCode,
            workorderId: item.workorderId,
            workorderCode: item.workorderCode,
            workstationName: item.workstationName,
            startTime: item.scheduleStartDate,
            printTemplate: item.printTemplate,
            netWeight: item.netWeight,
            feedbackTime: item.feedbackTime,
            minPackageNum: item.minPackageNum,
            printContents: item.whether == '1' ? item.printContents : null
          }
          if (item.taskType === 3) {
            par.closeType = item.closeType
          }
        this.$u.api
          .feedback(par)
          .then((res) => {
            if (res.code === 200) {
              this.proVisible = false;
              if (item.printTemplate) {
                let params = {};
                res.data.forEach((datas) => {
                  params = {
                    reportName: 'mysql:' + item.printTemplate,
                    values: {
                      proWorkorder: datas.proWorkorder,
                      size: datas.size,
                      directive: datas.directive
                    }
                  };
                  datas.packagePrintList.forEach((v) => {
                    params.values.packagePrint = v;
                    this.printPdfSocket(params);
                  });
                });
              }
              let workunitName='';
			   if (item.whether == '1') {
              this.$u.api.getNextProcess({taskId:item.taskId}).then(workunit =>{
                workunitName=workunit.data.workunitName;
                console.log(item.arrangeCode,item.workorderCode,item.quantityQualify,workunitName);
                let aa='编排单号:'+item.arrangeCode+'\n工单号:'+item.workorderCode+'\n数量:'+item.quantityQualify+'\n下一道工序:'+workunitName;
                console.log(aa);
               
                  this.printPdfSocket({
                    reportName: 'mysql:qrcode-50*50-2',
                    values: {
                      detail: [
                        {
                          barcode: item.printContents,
                          showText: '编排单号:'+item.arrangeCode+'\n数量:'+item.quantityQualify+'\n工单号:'+item.workorderCode+'\n下道工序机台:'+workunitName,
                          gp: 1
                        },
                        {
                          barcode: item.printContents,
                          showText: '编排单号:'+item.arrangeCode+'\n数量:'+item.quantityQualify+'\n工单号:'+item.workorderCode+'\n下道工序机台:'+workunitName,
                          gp: 1
                        }
                      ]
                    }
                  });
                });
			  }
              if (!res.msg) {
                this.$u.toast('上报成功');
              } else {
                this.$u.toast(res.msg);
              }
              console.log('准备刷新')
              this.getTaskList();
            }
          });
      });
    },
    feedingInspectionShow() {
      this.feedingInspectionVisible = true;
      this.getPemissionScan();
      this.feedingInspectionLoadAndScan();
    },
    feedingInspectionLoadAndScan(bool) {
      const taskInfo = this.tableSelectData[0];
      this.$u.api.listFeedingInspectionlist({ taskId: taskInfo.taskId }).then((res) => {
        if (res.code === 200) {
          this.feedingInspectionList = res.data;
          if (bool) {
            this.$u.toast('保存成功');
          }
        }
      });
    },
    feedingInspectionScan(barNumber) {
      console.log(barNumber, '-----barNumberfeedingInspectionScan');
      const taskInfo = this.tableSelectData[0];
      this.$u.api.validateFeedingInspection({ plnr: barNumber, taskId: taskInfo.taskId }).then((res) => {
        if (res.code === 200) {
          this.feedingInspectionLoadAndScan(true);
        }
      });
    },
    async getPemissionScan() {
      /* #ifdef APP-PLUS */
      if (!uni.getStorageSync('iosCameraAuth') && this.isIos) {
        uni.setStorageSync('iosCameraAuth', true);
      } else {
        let bol = await this.getCameraAuth();
        if (!bol) {
          this.refusedCameraAuth();
          return;
        }
      }
      /* #endif */
    },
    validateFeedingInspection(line) {
      // if(line.attr3 == 1) return
      const t = this;
      const taskInfo = this.tableSelectData[0];
      this.$u.api.validateFeedingInspectionById({ lineId: line.lineId }).then((res2) => {
        if (res2.code === 200) {
          t.$u.api.listFeedingInspectionlist({ taskId: taskInfo.taskId }).then((res) => {
            if (res.code === 200) {
              t.feedingInspectionList = res.data;
            }
          });
        }
      });
    },
    recoilMaterialShow() {
      this.recoilMaterialVisible = true;
      this.getPemissionScan();
      this.recoilMaterialLoadAndScan();
    },
    recoilMaterialLoadAndScan(bool) {
      const t = this;
      const taskInfo = this.tableSelectData[0];
      this.$u.api.recoilMaterialList({ taskId: taskInfo.taskId, processId: taskInfo.processId }).then((res) => {
        if (res.code === 200) {
          t.recoilMaterialDetailList = res.data
          if (bool) {
            t.$u.toast('保存成功');
          }
        }
      });
    },
    recoilMaterialScan(barNumber) {
      console.log(barNumber, '-----barNumberrecoilMaterialScan');
      const taskInfo = this.tableSelectData[0];
      this.$u.api.addRecoilMaterial({ taskId: taskInfo.taskId, plnr: barNumber }).then((res) => {
        if (res.code === 200) {
          this.recoilMaterialLoadAndScan(true);
        }
      });
    },
    recoilMaterialDelete(line) {
      const t = this;
      const taskInfo = this.tableSelectData[0];
      this.$u.api.deleteRecoilMaterial({ id: line.id }).then((res2) => {
        t.$u.api.recoilMaterialList({ taskId: taskInfo.taskId, processId: taskInfo.processId }).then((res) => {
          if (res.code === 200) {
            t.recoilMaterialList = res.data;
          }
        });
      });
    },

    batchShow(row) {
      this.recoilMaterialList = row.proRecoilMaterialList;
			this.$refs.appScan.closed()
      this.recoilMaterialFlag = true;
    },

    materialRequestShow() {
	 if(this.tableSelectData.length>1){
		 this.$u.toast("不允许同时操作多条数据");
		 return;
	 }
      this.materialRequestVisible = true;
      const taskInfo = this.tableSelectData[0];
      this.curTaskInfo = this.tableSelectData[0];
      this.curTaskInfo.workorderOption = this.curTaskInfo.proWorkorderList.map((s) => {
        return { value: s.workorderId, text: s.workorderCode };
      });
      this.$u.api.listMaterialRequest({ taskId: taskInfo.taskId }).then((res) => {
        if (res.code === 200) {
          this.materialRequestList = res.data.map((item) => {
            return {
              ...item,
              workorderCode: this.curTaskInfo.workorderCode
            };
          });
          this.materialRequestArrays = this.materialRequestList.concat([]);
        }
      });
	  	  this.$u.api.getMaterialRequest({taskId: taskInfo.taskId}).then((res) =>{
	  		if(res.code === 200){
	  			this.materialRequestArrayLists = res.rows;
	  			this.materialRequestArrayList = this.materialRequestArrayLists.concat([]);
	  		}  
	  		  
	  	  });
    },
    materialRequestFormShow(line) {
      this.materialRequestFormVisible = true;
      this.materialRequestFormData = { itemName: line.itemName, applyNum: 1 };
      this.materialRequestSelected = line;
    },
    materialRequestSetting() {
      this.materialRequestSelected.applyNum = this.materialRequestFormData.applyNum;
      this.materialRequestFormVisible = false;
    },
    materialRequestSave() {
      if (!this.curTaskInfo.pickingReason) {
        this.materialRequestVisible = true;
        this.$u.toast('原因不能为空！');
        return;
      }
      const rst = [];
      const taskInfo = this.tableSelectData[0];
      const t = this;
      // const items = this.curTaskInfo.workorderOption.find((item) => item.value === this.curTaskInfo.workorderCode);
      // console.log(this.curTaskInfo.workorderOption, this.curTaskInfo.workorderCode);
			let workorderCode = null
			if(this.curTaskInfo.workorderOption) {
				const finditem = this.curTaskInfo.workorderOption.find(v=>v.value === this.curTaskInfo.workorderCode)
				if(finditem) workorderCode = finditem.text
			}
      this.materialRequestArrays.forEach((s) => {
        if (s.applyNum != null) {
          rst.push({
            pickingReason: this.curTaskInfo.pickingReason,
            itemId: s.itemId,
            workunitCode: this.curTaskInfo.workunitCode,
            workunitName: this.curTaskInfo.workunitName,
            taskWorkunitId: this.curTaskInfo.taskWorkunitId,
			workstationId: this.curTaskInfo.workstationId,
			isBackflush: s.isBackflush,
            workorderCode: workorderCode,
            taskId: taskInfo.taskId,
            applyNum: s.applyNum,
            applyType: 1
          });
        }
      });
      this.$u.api.addMaterialRequest(rst).then((res) => {
        t.materialRequestFormVisible = false;
        if (res.code === 200) {
          t.$u.toast('保存成功');
        }
      });
    },
    materialReturnShow() {
      const t = this;
	  if(this.tableSelectData.length>1){
	  		 t.$u.toast("不允许同时操作多条数据");
	  		 return;
	  }
      this.materialReturnVisible = true;
      const taskInfo = this.tableSelectData[0];
      this.curTaskInfo = this.tableSelectData[0];
      this.curTaskInfo.workorderOption = this.curTaskInfo.proWorkorderList.map((s) => {
        return { value: s.workorderCode, text: s.workorderCode };
      });
      this.$u.api.listMaterialReturn({ taskId: taskInfo.taskId, workorderCode: '' }).then((res) => {
        if (res.code === 200) {
          t.materialReturnList = res.data;
        }
      });
    },
    viewiPctureShow() {
      this.materialReturn = true;
      // this.viewSopPicture = this.tableSelectData[0];
      const taskInfo = this.tableSelectData[0];
      this.curTaskInfo = this.tableSelectData[0];
      this.$u.api.viewpicture.viewWorkorder({ taskId: this.curTaskInfo.taskId }).then((res) => {
        if (res.code === 200) {
          this.viewSopPicture = res.data;
        }
      });
    },
    materialReturnWorkorderChange(s) {
      const t = this;
      const taskInfo = this.tableSelectData[0];
      this.$u.api.listMaterialReturn({ taskId: taskInfo.taskId, workorderCode: s }).then((res) => {
        if (res.code === 200) {
          t.materialReturnList = res.data;
        }
      });
    },
    materialReturnWorkorderProcessItem(id) {
      if (!id) {
        this.materialRequestArrays = this.materialRequestList.concat([]);
		this.materialRequestArrayList = this.materialRequestArrayLists.concat([]);
      } else {
        const items = this.curTaskInfo.workorderOption.find((item) => item.value === this.curTaskInfo.workorderCode);
        console.log(items);
        this.$u.api.getWproworkOrderProcessItem({ workorderId: id, processId: this.curTaskInfo.processId }).then((res) => {
          if (res.code === 200) {
            const list = res.rows.map((item) => {
              return {
                ...item,
                workorderCode: items.text
              };
            });
            this.materialRequests = this.materialRequestList.concat(list);
            this.materialRequestArrays = this.materialRequests.filter((item, index, self) => {
              return self.findIndex((t) => t.itemCode === item.itemCode) === index;
            });
            console.log(this.materialRequestArrays, 'materialRequestArrays');
          }
        });
				this.materialRequestArrayList =[]
				this.$u.api.getMaterialRequest({ workorderId: id, taskId: this.curTaskInfo.taskId }).then((res) =>{
					if(res.code === 200){
						console.log(res.rows)
						this.materialRequestArrayList = res.rows;
						
					}
				});
				
      }
    },

    materialReturnFormShow(line) {
      this.materialReturnFormVisible = true;
      this.materialReturnFormData = {
        itemName: line.itemName,
        applyNum: 1,
        workorderCode: this.materialReturnFormData.workorderCode,
        isQualified: 1,
				number: 0,
      };
      this.materialReturnSelected = line;
    },
    viewSopsShow(row) {
      // this.viewSopPicture = this.tableSelectData[0];
      this.$u.api.viewpicture.viewSpecificationSheetInfo({ workorderId: Number(row.workorderId) }).then((res) => {
        if (res.code === 200) {
          console.log(res.data);
          this.ProogingSpecificationSheetForm = res.data;
        }
      });
      this.material = true;
    },
    materialReturnSetting() {
      this.materialReturnSelected.applyNum = this.materialReturnFormData.applyNum;
      this.materialReturnSelected.isQualified = this.materialReturnFormData.isQualified;
      this.materialReturnFormVisible = false;
    },
	async formatDateRandom() {
	await this.$u.api.genCode('MATERIAL_RETURN_CODE').then((item) =>{
		console.log(item);  
		this.applyNo = item;
	});
	},
      async materialReturnSave() {
		  if (!this.curTaskInfo.returnReason) {
		    this.materialReturnVisible = true;
		    this.$u.toast('原因不能为空！');
		    return;
		  }
      await this.formatDateRandom()
      let a=null;
	  const taskInfo = this.tableSelectData[0];
      const rst = this.materialReturnList.map((s) => {
        let data = {
          itemId: s.itemId,
          taskId: taskInfo.taskId,
          backNum: s.applyNum,
          issueLineId: s.lineId,
          taskWorkunitId: this.curTaskInfo.taskWorkunitId,
          workOrderId: s.workorderId,
          batchNo: s.batchCode,
          packNo: s.packNo,
		  applyNo: this.applyNo,
          isQualified: s.isQualified,
		  returnReason: this.curTaskInfo.returnReason,
        };
		a=a+s.applyNum;
        if (this.materialReturnFormData.workorderCode) {
          data.workorderCode = this.materialReturnFormData.workorderCode;
        } else {
          // data.workorderCode = this.curTaskInfo.workorderOption.flatMap((it) => it.value).join(',');
		  data.workorderCode = null;
        }
        return data;
      });
      if (this.materialReturnList.length === 0) {
        return;
      }
      this.$u.api.addMaterialReturn(rst).then((res) => {
        this.materialReturnFormVisible = false;
        if (res.code === 200) {
          t.$u.toast('保存成功');
        }
      });
	if(this.materialReturnFormData.number>=1&a>0){
	for(let i=0; i<this.materialReturnFormData.number ;i++){
		this.printPdfSocket({
					  reportName: 'mysql:qrcode-50*50-2',
					  values:{
						  detail:[
							  {
								barcode: this.applyNo,
								showText: '退料单号:'+this.applyNo,
								gp: i+1
								  
							  },
							  {
							  	barcode: this.applyNo,
							  	showText: '退料单号:'+this.applyNo,
							  	gp: i+1
							  					  
							  }
						  ]
					  }
				  });
	    }	  
	  }
	    
    },


    stockInShow() {
      this.stockInVisible = true;
    }
  }
};
</script>

<style lang="scss" scoped>
.commonBody {
  width: 100%;
  height: 100%;
  background-color: #fefeff;
  margin: 0 0;
  padding: 0 0;
}

.content {
  margin: 10px;
  display: flex;
}

.content_left {
  width: 40%;
}

.tableForm {
  display: flex;
  margin: 20rpx 0rpx;
  /deep/ .uni-data-checklist .checklist-group .checklist-box {
    margin-right: 15px;
  }
}

.task_card {
  width: 90%;
  margin: 5px;
}

.uRow {
  margin-top: 5px;
  margin-bottom: 5px;
}

.content_right {
  width: 60%;
  padding: 10px;
}

.feedback-card {
  margin: 25rpx;
  padding: 18rpx;
  padding-bottom: 70px;
  box-sizing: border-box;
  position: relative;
  background: #ffffff;
  border-radius: 8px;
  cursor: pointer;
  transition: box-shadow 0.2s, border-color 0.2s;
  box-shadow: 0 1px 2px -2px rgba(0, 0, 0, 0.16), 0 3px 6px 0 rgba(0, 0, 0, 0.12), 0 5px 12px 4px rgba(0, 0, 0, 0.09);
}

::v-deep .u-form-item {
  padding: 0px;
}

.prod-body {
  //display: flex;
  height: 100%;
  //overflow: hidden;

  display: flex;
}

.prod-body-left {
  flex: 1;
  //flex-grow: 1;
  // padding: 10rpx;
  overflow: hidden;

  .prod-body-left-btns {
    height: 80rpx;

    .u-btn {
      width: 250rpx;
      height: 60rpx;
      line-height: 60rpx;
      display: inline-block;
      margin: 10rpx 20rpx;
    }

    .workstation {
      display: inline-block;
    }
  }

  .prod-body-left-task {
    height: calc(100vh - 200rpx);
    min-height: 400rpx;
    border: 1px solid rgb(232, 232, 232);

    /deep/ .item-tr.yellow .item-td {
      background: #ff9900 !important;
      // color:#fff !important;
    }
    /deep/ .item-tr.green .item-td {
      background: #19be6b !important;
      // color:#fff !important;
    }
    /deep/ .item-tr.red .item-td {
      background: #f56c6c !important;
      // color:#fff !important;
    }
		/deep/ .item-tr.selectrow .item-td {
		  background: #00ffff !important;
		  // color:#fff !important;
		}
		
  }

  .prod-body-left-num {
    height: 60rpx;
    line-height: 60rpx;
    padding: 0 16rpx;
    background-color: #add8e6;
  }

  .prod-body-left-bom {
    height: 500rpx;

    .prod-body-left-bom-type {
      width: 500rpx;
      height: 80rpx;
      padding-top: 10rpx;

      .u-subsection {
        border-radius: 5px 5px 0 0 !important;
      }
    }

    .prod-body-left-bom-table {
      height: 400rpx;
      border: 1px solid rgb(232, 232, 232);
    }
  }
}

.prod-body-right {
  width: 300rpx;
  padding: 10rpx;
  overflow: auto;
  .u-btn {
    height: 100rpx;
    line-height: 100rpx;
    margin: 20rpx 10rpx;
    font-size: 40rpx;
  }
	/deep/ .uni-scroll-view{
		-ms-overflow-style: none;  /* IE 10+ */
		scrollbar-width: none;  /* Firefox */
		&::-webkit-scrollbar {
		  display: none; /* 对于 Chrome, Safari 和 Opera 隐藏滚动条 */
		}
	}
}

.times {
  /deep/ .uni-date-picker__container {
    height: 360rpx;
  }
}
.list-bar {
  position: relative;
  .sum {
    position: absolute;
    bottom: -30px;
    right: 5px;
    
    font-size: 14px;
  }
}
.mynotable {
  .tr-green {
    background: #4ea381 !important;
  }
  .uni-table-td {
    color: black;
  }
}
.successBtn {
	display: inline-flex;
	width: auto;
	font-size: 22rpx;
	padding-top: 1px;
	height: 50rpx;
	line-height: 50rpx;
	padding: 0 20rpx;
	color: #ffffff;
	border-color: #19be6b;
	background-color: #19be6b;
	&:hover {
		border-color: #19be6b !important;
		background-color: #19be6b !important;
		color: #ffffff !important;
	}
}
</style>
<style lang="scss">
	.mynotable {
		width: 100% !important;
		/deep/ .uni-table {
			min-width: 100% !important;
		}
	}
</style>