<template>
  <div>
    <!-- 永济项目没有订单状态  制单人-->
    <!-- <div class="common-card">
              <h3>订单状态</h3>
              <yl-step></yl-step>
          </div> -->
    <div class="common-card">
      <h3>基本信息</h3>
      <el-form
        :model="listForm"
        ref="listform"
        label-width="150px"
        class="grid-form-class"
      >
        <div class="form-body">
          <div class="flex-css">
            <el-form-item label="采购单号" prop="id">
              <div class="content">
                {{ listForm.id }}
              </div>
            </el-form-item>
            <el-form-item label="采购品种" prop="detlCnt">
              <div class="content">
                {{ listForm.detlCnt }}
              </div>
            </el-form-item>
            <el-form-item label="总数量" prop="qtySum">
              <div class="content">
                {{ listForm.qtySum }}
              </div>
            </el-form-item>
            <el-form-item label="总金额" prop="purcAmt">
              <div class="content">
                {{ listForm.purcAmt }}
              </div>
            </el-form-item>
          </div>
          <div class="flex-css">
            <el-form-item label="客户名称" prop="purcAmt">
              <div class="content">
                {{ listForm.purcAmt }}
              </div>
            </el-form-item>
            <el-form-item label="采购员" prop="docmker">
              <div class="content">
                {{ listForm.docmker }}
              </div>
            </el-form-item>
            <el-form-item label="采购时间" prop="docmkDate">
              <div class="content">
                {{ listForm.docmkDate }}
              </div>
            </el-form-item>
            <el-form-item label="当前状态" prop="stas">
              <div class="content">
                {{ listForm.stas }}
              </div>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
    <div class="common-card">
      <h3>耗材明细</h3>
      <el-form :model="list">
        <el-table
          v-loading="listLoading"
          element-loading-text="加载中"
          :data="list"
          fit
          stripe
          border
        >
          <template slot="empty">
            <img src="@/assets/nopage.png" alt />
            <p>暂无数据</p>
          </template>
          <el-table-column fixed type="index" label="序号" width="60" />
          <el-table-column label="耗材编码" prop="materialId" />
          <el-table-column label="医保编码" prop="ybbm" />
          <el-table-column label="耗材名称" prop="materialName" width="300">
          </el-table-column>
          <el-table-column label="耗材类别" prop="prodType" />
          <el-table-column label="规格" prop="spec" />
          <el-table-column label="型号" prop="model" />
          <el-table-column label="材质" prop="matl" />
          <el-table-column label="注册证号" prop="approveNo" width="150" />
          <el-table-column label="生产企业" prop="factory" width="200" />
          <el-table-column label="采购数量" prop="purcCnt" />
          <el-table-column label="采购价" prop="purcPric" />
          <el-table-column label="总金额" prop="purcAmt" />
          <el-table-column label="采购来源" prop="deptName" />
          <el-table-column label="订单发起人" prop="docmker" width="100" />
          <el-table-column label="备注" prop="memo" />
          <!-- <el-table-column label="驳回原因" prop="rejtRea" width="200">
                      <template slot-scope="scope">
                          <el-form-item
                              label-width="0"
                              class="item"
                              :prop="scope.$index + '.rejtRea'"
                          >
                              <el-input placeholder="请输入" v-model="scope.row.rejtRea" :readonly="!returnInfo"></el-input>
                          </el-form-item>
                      </template>
                  </el-table-column> -->
          <!-- <el-table-column label="是否驳回" width="100">
                      <template slot-scope="scope">
                          <el-switch v-model="scope.row.flag" @change="handleSwitch(scope.$index,scope.row)" :disabled="!isShow"></el-switch>
                      </template>
                  </el-table-column> -->
          <!-- <el-table-column label="操作" width="100">
                      <template slot-scope="scope">
                          <el-popconfirm
                              title="是否驳回？"
                              @confirm="handleReject(scope.row)"
                              confirm-button-text="确定"
                              cancel-button-text="取消"
                              icon="el-icon-info"
                              icon-color="red"
                              v-if="scope.row.stas == '0'"
                          >
                              <el-button
                                  class="red"
                                  type="text"
                                  slot="reference"
                                  >驳回</el-button
                              >
                          </el-popconfirm>
                          <el-popconfirm
                              title="是否取消驳回？"
                              @confirm="handleNoReject(scope.row)"
                              confirm-button-text="确定"
                              cancel-button-text="取消"
                              icon="el-icon-info"
                              icon-color="red"
                              v-else
                          >
                              <el-button
                                  class="red"
                                  type="text"
                                  slot="reference"
                                  >取消驳回</el-button
                              >
                          </el-popconfirm>
                      </template>
                  </el-table-column> -->
        </el-table>
      </el-form>

      <div class="foot-button">
        <el-button type="info" @click="handleBack">返 回</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import ylStep from "@/components/yl-step";
import ylPagination from "@/components/yl-pagination";
import { getMcsDetlList, acpMcsOrd } from "@/api/orderManage-sup/index";
export default {
  components: {
    ylStep,
    ylPagination
  },
  data() {
    return {
      listForm: {
        id: "",
        detlCnt: "",
        qtySum: "",
        purcAmt: "",
        docmker: "",
        docmkDate: "",
        stas: ""
      },
      listLoading: false,
      list: [],
      aaLoad: false,
      isShow: false,
      returnInfo: false,
      stasOptions: [
        { value: "A", lable: "未受理" },
        { value: "B", lable: "已受理" },
        { value: "R", lable: "被驳回" },
        { value: "C", lable: "已出库" },
        { value: "D", lable: "部分出库" },
        { value: "Y", lable: "已入库" },
        { value: "P", lable: "部分入库" }
      ],
      essdrugOptions: ["非基药", "基药"]
    };
  },
  created() {
    if (this.$route.query.stas == "A") {
      this.isShow = true;
    } else {
      this.isShow = false;
    }
    this.listForm.id = this.$route.query.id;
    this.listForm.detlCnt = this.$route.query.detlCnt;
    this.listForm.purcAmt = this.$route.query.purcAmt;
    this.listForm.qtySum = this.$route.query.qtySum;
    this.listForm.docmker = this.$route.query.docmker;
    this.listForm.docmkDate = this.$route.query.docmkDate;
    this.stasOptions.forEach(i => {
      if (i.value == this.$route.query.stas) {
        this.listForm.stas = i.lable;
      }
    });
    this.getData();
  },
  methods: {
    getData() {
      this.listLoading = true;
      getMcsDetlList({ id: this.$route.query.id })
        .then(res => {
          this.list = res.data;
          this.list.forEach(i => {
            if (i.rejtRea) {
              i.flag = true;
            }
            i.essdrugType = this.essdrugOptions[i.essdrugType * 1];
          });
          this.listLoading = false;
        })
        .catch(err => {
          this.listLoading = false;
        });
    },
    // 是否驳回开关
    handleSwitch(index, row) {
      console.log(row);
      if (row.flag == false) {
        row.rejtRea = "";
        this.returnInfo = false;
      } else {
        this.returnInfo = true;
      }
    },
    // 驳回
    handleReject(row) {
      this.$refs.listRef.validate(valid => {
        if (valid) {
        }
      });
    },
    // 取消驳回
    handleNoReject(row) {},
    // 受理
    handleAccept() {
      this.list.forEach(e => {
        if (e.flag == true && !e.rejtRea) {
          this.$message({
            message: "选择是否驳回后请填写驳回原因",
            type: "warning"
          });
          throw new Error("选择是否驳回后请填写驳回原因");
        }
      });
      this.$confirm("确认受理", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let data = this.list.filter(i => {
          if (i.flag == true) {
            return i;
          }
        });
        let data2 = data.map(i => {
          return { id: i.id, rejtRea: i.rejtRea };
        });
        let data3 = {
          id: this.$route.query.id,
          rejtList: data2
        };
        this.aaLoad = true;
        acpMcsOrd(data3)
          .then(res => {
            this.aaLoad = false;
            this.$router.push("purOrderConfirmed");
          })
          .catch(err => {
            this.aaLoad = false;
          });
      });
    },
    // 返回
    handleBack() {
      this.$router.push({
        name: "purOrderConfirmed"
      });
    }
  }
};
</script>

<style lang="scss" scoped></style>
