<template>
  <div class="app-container">
    <el-card style="margin-top: 2px">
      <el-descriptions title="任务详情" :column="4" border style="margin-bottom: 20px">
        <el-descriptions-item label="任务编号">{{productionplan.number}}</el-descriptions-item>
        <el-descriptions-item label="产品名称" v-if="productionplan.product_">{{productionplan.product_.name}}
        </el-descriptions-item>
        <el-descriptions-item label="规格型号" v-if="productionplan.product_">{{productionplan.product_.specification}}
        </el-descriptions-item>
        <el-descriptions-item label="生产数量">{{productionplan.count}}</el-descriptions-item>
        <el-descriptions-item label="生产状态">{{state_[productionplan.state]}}</el-descriptions-item>
        <el-descriptions-item label="计划开工时间">{{productionplan.start_date}}</el-descriptions-item>
        <el-descriptions-item label="计划完工时间">{{productionplan.end_date}}</el-descriptions-item>
      </el-descriptions>
      <el-table
        :data="wproduct"
        border
        fit
        stripe
        style="width: 100%"
        height="500"
      >
        <el-table-column type="index" label="序号" 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.step_.name}}
          </template>
        </el-table-column>
        <el-table-column label="产品状态">
          <template slot-scope="scope">{{actstate_[scope.row.act_state]}}</template>
        </el-table-column>
        <el-table-column label="生产状态">
          <template slot-scope="scope">{{scope.row.step_.name}}</template>
        </el-table-column>
        <el-table-column label="最后检验结果">
          <template slot-scope="scope">
            <span v-if="scope.row.last_test_result==false">不合格</span>
            <span v-if="scope.row.last_test_result==true">合格</span>
          </template>
        </el-table-column>
        <el-table-column label="生产记录">
          <template slot-scope="scope">
            <el-button @click="select(scope)">查看</el-button>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          width="220px"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="handleoption(scope)"
            >生成流程卡
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <!--检验记录-->
      <el-dialog title="检验记录" :visible.sync="limitedCheckRecord">
        <el-table
          :data="recordList"
          border
          height="400"
        >
          <el-table-column type="index" width="50"/>
          <el-table-column label="表单名称">
            <template slot-scope="scope">{{ scope.row.form_.name }}</template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <el-link
                @click="handleRecordDetail(scope)"
              >查看
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
        </div>
      </el-dialog>
      <!--非检查表显示-->
      <el-dialog
        :title="formName"
        :visible.sync="recordVisible"
        :close-on-click-modal="false"
      >
        <el-row>
          <el-col v-for="item in fieldList" :key="item.id" :span="12">
            <div class="items" v-if="item.field_type!=='draw'">
              <span class="itemLabel">{{item.field_name}}：</span>
              <span>{{item.field_value}}</span>
            </div>
          </el-col>
          <el-col v-for="item in fieldList" :key="item.id" :span="24">
            <div class="items" v-if="item.field_type==='draw'" style="height: 400px">
              <span class="itemLabel">{{item.field_name}}：</span>
              <img style="width: 45%;vertical-align: text-top;" :src="item.field_value"/>
            </div>
          </el-col>
        </el-row>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
  import {getProductionplan} from "@/api/pm";
  import {getwproductList, getrecordList,recordInit} from "@/api/wpm";
  import checkPermission from "@/utils/permission";
  const defaultrecordform = {enabled: false};
  export default {
    data() {
      return {
        productionplan: {
          number: ""
        },
        activeName: "1",
        wproduct: [],
        recordList: [],
        limitedCheckRecord: false,
        listQuery: {
          page: 1,
          page_size: 20,
        },
        state_: {
         10: "制定中",
        20: "已下达",
        30: "已接受",
        40: "生产中",
        50: "已完成",
        60: "军检完成",
        70: "暂停",
        80: "终止",
        },
        actstate_: {
          6: "待复检",
          10: "操作进行中",
          20: "待检验",
          30: "已合格",
          40: "库存中",
          50: "不合格",
          60: "待成品检验",
          8: "操作准备中",
          26: "待夹层检验",
          70: "报废",
        },
        process_json: null,
        productionplanID: null,
        dialogVisibleForm: false,
        recordform: defaultrecordform,
        dialogType: "new",
        dialogVisible: false,
        dialogType1: "new",
        dialogVisible1: false,
        checkForm: {
          hhh: '',
        },

        recordVisible: false,
        customfieldList: [],
        recordId: null,
        fifo_detail: "",
        formName: "项目检查表",
        hasPicture: false,
        fieldList: [],

      };
    },
    computed: {},
    watch: {},
    created() {
      this.id = this.$route.params.id;
      this.getList();

      this.getwproductList();

    },
    methods: {
      checkPermission,

      getList() {
        getProductionplan(this.id).then((response) => {
          if (response.data) {
            this.productionplan = response.data;
            this.productionplanID = response.data.id;

            let process_json = [];
            for (let item in response.data.process_json) {
              let obj = new Object();
              obj = response.data.process_json[item];
              process_json.push(obj)
            }
            this.process_json = process_json;
          }

        });
      },
      getwproductList() {
        getwproductList({production_plan: this.id, page: 0,}).then((response) => {
          if (response.data) {
            this.wproduct = response.data;
          }
        });
      },
      //查看该玻璃检验记录表
      handleoption(scope) {
        this.$router.push({name: "processcard", params: {id: scope.row.id},})
      },
      //查看生产记录
      select(scope) {
        this.limitedCheckRecord = true;
        getrecordList({wproduct: scope.row.id, page: 0}).then(res => {
          if (res.code == 200) {
            this.recordList = res.data;
          }
        })
      },
      //点击记录里的查看
      handleRecordDetail(scope) {
        let that = this;
        that.fieldList = [];
        recordInit(scope.row.id).then((res) => {
          if (res.code >= 200) {
            that.recordVisible = true;
            that.formName = res.data.form_.name;
            that.fieldList = res.data.record_data;
          }
        })
      },

    },
  };
</script>
<style scoped>
  .items {
    height: 35px;
    line-height: 35px;
    padding-left: 20px;
  }

  .itemLabel {
    font-size: 14px;
    color: #606266;
    font-weight: 600;
  }
</style>
