<template>
  <div class="app-container">
    <el-card style="margin-top: 2px">
      <el-tabs v-model="activeName" type="card">
        <el-tab-pane label="总览" name="1">
          <el-table
            :data="productionplan.results"
            border
            fit
            stripe
            highlight-current-row
            height="620"
            v-el-height-adaptive-table="{ bottomOffset: 40 }"
          >
            <el-table-column type="index" width="50" />
            <el-table-column label="任务编号">
              <template slot-scope="scope">{{ scope.row.number }}</template>
            </el-table-column>
            <el-table-column label="产品名称">
              <template slot-scope="scope">{{
                scope.row.product_.name
              }}</template>
            </el-table-column>
            <el-table-column label="规格型号">
              <template slot-scope="scope">{{
                scope.row.product_.specification
              }}</template>
            </el-table-column>
            <el-table-column label="合格率">
              <el-table-column label="冷加工">
                <template slot-scope="scope" v-if="scope.row.process_json['01']"
                  >{{ scope.row.process_json["01"].rate }}%</template
                >
              </el-table-column>
              <el-table-column label="热弯">
                <template slot-scope="scope" v-if="scope.row.process_json['02']"
                  >{{ scope.row.process_json["02"].rate }}%</template
                >
              </el-table-column>
              <el-table-column label="化学钢化">
                <template slot-scope="scope" v-if="scope.row.process_json['03']"
                  >{{ scope.row.process_json["03"].rate }}%</template
                >
              </el-table-column>
              <el-table-column label="镀膜">
                <template slot-scope="scope" v-if="scope.row.process_json['04']"
                  >{{ scope.row.process_json["04"].rate }}%</template
                >
              </el-table-column>
              <el-table-column label="夹层">
                <template slot-scope="scope" v-if="scope.row.process_json['05']"
                  >{{ scope.row.process_json["05"].rate }}%</template
                >
              </el-table-column>
              <el-table-column label="包边">
                <template slot-scope="scope" v-if="scope.row.process_json['06']"
                  >{{ scope.row.process_json["06"].rate }}%</template
                >
              </el-table-column>
              <el-table-column label="装框">
                <template slot-scope="scope" v-if="scope.row.process_json['07']"
                  >{{ scope.row.process_json["07"].rate }}%</template
                >
              </el-table-column>
            </el-table-column>
            <el-table-column label="创建时间">
              <template slot-scope="scope">{{
                scope.row.create_time
              }}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-link
                  v-if="checkPermission(['material_update'])"
                  type="primary"
                  @click="handledetail(scope)"
                  >详情</el-link
                >
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="productionplan.count > 0"
            :total="productionplan.count"
            :page.sync="listQuery.page"
            :limit.sync="listQuery.page_size"
            @pagination="getList"
          />
        </el-tab-pane>
        <el-tab-pane label="不合格玻璃" name="2">
          <el-table
            :data="wproductticket.results"
            border
            fit
            stripe
            highlight-current-row
            height="620"
            v-el-height-adaptive-table="{ bottomOffset: 40 }"
          >
            <el-table-column type="index" width="50" />
            <el-table-column label="玻璃编号">
              <template slot-scope="scope">{{ scope.row.number }}</template>
            </el-table-column>
            <el-table-column label="订单编号">
              <template slot-scope="scope" v-if="scope.row.order_">{{
                scope.row.order_.number
              }}</template>
            </el-table-column>
            <el-table-column label="产品名称">
              <template slot-scope="scope" v-if="scope.row.product_">{{
                scope.row.product_.name
              }}</template>
            </el-table-column>
            <el-table-column label="规格型号">
              <template slot-scope="scope" v-if="scope.row.product_">{{
                scope.row.product_.specification
              }}</template>
            </el-table-column>
            <el-table-column label="责任工序">
              <template slot-scope="scope" v-if="scope.row.resp_process_">{{
                scope.row.resp_process_.name
              }}</template>
            </el-table-column>
            <el-table-column label="处理结果">
              <template slot-scope="scope">{{
                decision_[scope.row.decision]
              }}</template>
            </el-table-column>
            <el-table-column label="创建时间">
              <template slot-scope="scope">{{
                scope.row.create_time
              }}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-link
                  v-if="checkPermission(['material_update'])"
                  type="primary"
                  @click="handledetailbhg(scope)"
                  >查看</el-link
                >
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="wproductticket.count > 0"
            :total="wproductticket.count"
            :page.sync="listQuery2.page"
            :limit.sync="listQuery2.page_size"
            @pagination="getList2"
          />
           <!--不合格半成品重审-->
    <el-dialog title="不合格半成品重审" :close-on-click-modal="false" :visible.sync="limitedRetrial">
      <el-form label-width="130px" label-position="right">
        <el-form-item :label="item.field_name" v-for="item in customfieldList.ticket_data_" :key="item.id" v-show="!item.is_hidden">
          <template v-if="item.field_type=='string'">
            <el-input v-model="item.default_value" :placeholder="item.description" />
          </template>
          <template v-if="item.field_type==='int'">
            <el-input v-model="item.default_value" type="number" :placeholder="item.description" oninput="value=value.replace(/[^\d]/g,'')" />
          </template>
          <template v-if="item.field_type==='float'">
            <el-input v-model="item.default_value" type="number" :placeholder="item.description" />
          </template>
          <template v-if="item.field_type==='date'">
            <el-date-picker
              v-model="item.default_value"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"
              style="width: 100%"
            >
            </el-date-picker>
          </template>
          <template v-if="item.field_type==='datetime'">
            <el-date-picker
              v-model="item.default_value"
              type="datetime"
              placeholder="选择日期"
              value-format="yyyy-MM-dd HH:mm:ss"
              style="width: 100%"
            >
            </el-date-picker>
          </template>
          <template v-if="item.field_type==='select'">
            <el-select style="width: 100%" v-model="item.default_value" placeholder="请选择">
              <el-option
                v-for="item1 in item.field_choice"
                :key="item1.id"
                :label="item1.name"
                :value="item1.id"
              >
              </el-option>
            </el-select>
          </template>
          <template v-if="item.field_type==='selects'">
            <el-select  style="width: 100%" multiple v-model="item.default_value" placeholder="请选择">
              <el-option
                v-for="item1 in item.field_choice"
                :key="item1.id"
                :label="item1.name"
                :value="item1.id"
              >
              </el-option>
            </el-select>
          </template>
          <template v-if="item.field_type==='textarea'">
            <el-input type="textarea"  :rows="3" v-model="item.default_value" placeholder="内容" />
          </template>
          <template v-if="item.field_type==='file'">
            <el-upload
              ref="upload"
              :action="upUrl"
              :on-preview="handlePreview"
              :on-success="handleUpSuccess"
              :on-remove="handleRemove"
              :headers="upHeaders"
              :file-list="fileList"
              :limit="1"
              accept=".doc,.docx,.xls,.xlsx,.ppt,.pptx"
            >
              <el-button size="small" type="primary">上传文件</el-button>
            </el-upload>
          </template>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="limitedRetrial = false">取 消</el-button>
       
      </div>
    </el-dialog>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>
<script>
import { getProductionplanList } from "@/api/pm";
import { getwproductticketList } from "@/api/wpm";
import { ticketread } from "@/api/workflow";

import checkPermission from "@/utils/permission";
import { createTestrecord } from "@/api/inm";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination

export default {
  components: { Pagination },
  data() {
    return {
      process_json_: {
        "01": "冷加工",
        "02": "热弯",
        "03": "化学钢化",
        "04": "镀膜",
        "05": "夹层",
        "06": "包边",
        "07": "装框",
      },
      decision_: {
        10: "返工",
        20: "返修",
        30: "报废",
        40: "让步接受",
        50: "偏离许可",
        60: "降级使用",
        70: "退回供方",
        80: "召回",
      },
      productionplan: {
        count: 0,
      },
      wproductticket: {
        count: 0,
      },
      activeName: "1",
      listQuery: {
        page: 1,
        page_size: 20,
      },
      listQuery2: {
        page: 1,
        page_size: 20,
      },
      limitedRetrial:false,
       customfieldList: [],
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getList(); //总览列表
    this.getList2(); //不合格玻璃审批工单列表
  },
  methods: {
    checkPermission,
    //总览列表
    getList() {
      getProductionplanList(this.listQuery).then((response) => {
        if (response.data) {
          this.productionplan = response.data;
        }
      });
    },
    handledetail(scope) {
      this.$router.push({ name: "taskdetails", params: { id: scope.row.id } });
    },

    //不合格玻璃审批工单列表
    getList2() {
      getwproductticketList(this.listQuery2).then((response) => {
        if (response.data) {
          this.wproductticket = response.data;
        }
      });
    },
    //不合格玻璃审理单查看
    handledetailbhg(scope)
    {
      this.limitedRetrial=true;
       ticketread(scope.row.ticket).then((response) => {
        if (response.data) {
          this.customfieldList = response.data;
        }
      });
    }
    
  },
};
</script>
