<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="237px"
        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>
          </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="docmkDate">
              <div class="content">
                {{ listForm.docmkDate }}
              </div>
            </el-form-item>
            <el-form-item label="采购员" prop="docmker">
              <div class="content">
                {{ listForm.docmker }}
              </div>
            </el-form-item>
          </div>
          <div class="flex-css">
            <el-form-item label="手术名称" prop="stas">
              <div class="content">
                {{ listForm.stas }}
              </div>
            </el-form-item>
            <el-form-item label="手术间" prop="stas">
              <div class="content">
                {{ listForm.stas }}
              </div>
            </el-form-item>
            <el-form-item label="主治医生" prop="stas">
              <div class="content">
                {{ listForm.stas }}
              </div>
            </el-form-item>
          </div>
          <div class="flex-css">
            <el-form-item label="手术日期" prop="stas">
              <div class="content">
                {{ listForm.stas }}
              </div>
            </el-form-item>
            <el-form-item label="当前状态" prop="stas">
              <div class="content">
                {{ listForm.stas }}
              </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="耗材信息" width="230">
            <template slot-scope="scope">
              <mcs-info :info="scope.row"></mcs-info>
            </template>
          </el-table-column>
          <el-table-column label="规格" prop="spec" />
          <el-table-column label="型号" prop="model" />
          <el-table-column label="材质" prop="matl" />
          <el-table-column label="是否集采" prop="isFas">
            <template #default="{ row }">
              <span v-if="row.isFas == '0'">否</span>
              <span v-if="row.isFas == '1'">是</span>
            </template>
          </el-table-column>
          <el-table-column label="包装" prop="convrat" width="120px">
            <template #default="{ row }">
              <span
                >{{ row.purcUnt }} ({{ row.convrat }}{{ row.prcUnt }}/{{
                  row.purcUnt
                }})</span
              >
            </template>
          </el-table-column>
          <el-table-column label="申请数量" prop="purcCnt" />
          <el-table-column label="单价" prop="purcPric">
            <template #default="{ row }">
              <span>{{ row.purcPric }}元/{{ row.prcUnt }}</span>
            </template>
          </el-table-column>
          <el-table-column label="总额" prop="purcAmt" />
        </el-table>
      </el-form>

      <div class="foot-button">
        <el-button type="primary" @click="handleAccept" :loading="aaLoad"
          >确 认</el-button
        >
        <el-button type="danger" @click="handleReturn" :loading="aaLoad"
          >退 回</el-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("purOrderAccept");
          })
          .catch(err => {
            this.aaLoad = false;
          });
      });
    },
    // 返回
    handleBack() {
      this.$router.push({
        name: "purOrderAccept"
      });
    }
  }
};
</script>

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