<template>
  <div>
    <el-row>
      <el-col v-for="(info, index)  in preDetailList"  :key="index" :xs="12" :sm="6" :md="6" :lg="8" >
        <el-card :body-style="{margin:'20px'}"
                 style="margin:20px 20px 20px 20px;;background-color: #e1f3fb;border-radius: 12px; position: relative;">
          <div style="display: flex; justify-content: space-between; align-items: center; height: 26px; /* 约为 200px 的 1/3 */" >
            <p>产品名称：</p> <p style="font-size: 20px;background-color: #e1f3fb;font-weight: bold;">{{ info.cpmctymc }}</p>
          </div>
          <div style="display: flex; justify-content: space-between; align-items: center; height: 26px; /* 约为 200px 的 1/3 */" >
            <p>层级标识：</p><p style="font-size: 16px;background-color: #e1f3fb;font-weight: bold;">{{ info.nameCode }}</p>
          </div>
          <div style="display: flex; justify-content: space-between; align-items: center; height: 26px; /* 约为 200px 的 1/3 */" >
            <p>规格型号：</p><p style="font-size: 16px;background-color: #e1f3fb;font-weight: bold;">{{ info.ggxh }}</p>
          </div>
          <div style="display: flex; justify-content: space-between; align-items: center; height: 26px; /* 约为 200px 的 1/3 */" >
            <p>使用单位：</p><p style="font-size: 16px;background-color: #e1f3fb;font-weight: bold;">{{ info.measureUnit }}</p>
          </div>
          <div style="flex: 1; display: flex; flex-direction: column; justify-content: flex-end; padding-top: 10px;"  >
            <span><h1 :style="{ 'font-size': '45px', 'color': info.getConfirm ? '#67C23A' : '#F56C6C' }">{{ info.count }}</h1></span>
            <el-button type="primary" style="position: absolute; bottom: 20px; right: 20px;" icon="el-icon-thumb" @click="handleClick(info)"  :disabled="info.getConfirm">确认取药</el-button>
          </div>

        </el-card>
      </el-col>
    </el-row>


    <el-dialog
      title="扫码明细"
      :visible.sync="scanDetailVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-if="scanDetailVisible"
      width="65%"
      append-to-body
    >
      <PanelOrderManuTagCode
        :fifoSplit="3"
        :prescribeData="prescribeData"
        :bizId="bizId"
        :closeScanDialog="closeScanDialog"
      ></PanelOrderManuTagCode>
    </el-dialog>

  </div>
</template>

<script>
import {convertDate} from "@/utils/date";
import {detail} from "@/api/basic/sicker/prescribeApi";
import {executeFuc, getHead} from "@/utils/customConfig";
import {orderDetail, codeRemove,bizConfirm} from "@/api/collect/collectOrder";
import PanelOrderManuTagCode from "@/views/collect/PanelOrderManuTagCode";

/**
 * 原始处方明细
 */
export default {
  name: "prescribeOriginPanel",
  props: {
    prescribeData: {
      type: Object,
      default: null,
      required: true
    },
    //上货方式：1:拆零上货；2:整取上货;
    fifoSplit: {
      type: Object,
      default: null,
      required: true
    },
    dealStatus: {
      type: Number,
      default: 1,
      required: true
    },


  },
  data() {
    return {
      currentDate: new Date(),
      //界面配置相关
      //原始处方明细
      tableHeader1: [],
      queryList1: [],
      tableObj1: [],
      fromList1: [],
      convertDateFun: convertDate,


      preLoading: false,
      preDetailList: [],
      preTotal: 0,
      preQuery: {
        orderIdFk: null,
        page: 1,
        limit: 10,
      },

      countVisible: false,
      scanDetailVisible: false,
      bizId: null,
    }
  },
  methods: {
    handleClick(info){
      bizConfirm(info).then((response) => {
        if (response.code === 20000) {
          this.$message.success("操作成功！");
          this.getPrescribeDetail(this);
        } else {
          this.$message.error(response.message);
        }
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      })
    },
    deleteMan(_this, row) {
      _this.$confirm("是否确定删除该条扫码?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        _this.loading = true;
        _this.codeRemoveMan(row.id, 2);
      })
    },
    deleteCode(_this, row) {
      _this.$confirm("是否确定移除一个条码?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        _this.loading = true;
        _this.codeRemoveMan(row.id, 1);
      })
    },
    codeRemoveMan(codeManId, delType) {
      let post = {
        codeManId: codeManId,
        delType: delType
      }
      codeRemove(post).then((response) => {
        if (response.code === 20000) {
          this.$message.success("操作成功！");
          this.getList(this)
        } else {
          this.$message.error(response.message);
        }
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      })
    },
    //界面配置-------------end
    executeFuc(row, type, clickFuc, value) {
      return executeFuc(this, row, type, clickFuc, value);
    },
    executeEval(row, expression, defaultRet) {
      if (expression) {
        return eval(expression);
      }
      return defaultRet;
    },
    handleSortChange(column, prop, order) {
      if (column.order === 'descending') {
        this.query.sort = 'desc'
      } else {
        this.query.sort = 'asc'
      }
      this.query.orderBy = column.prop;
      this.getList();
    },
    ///界面配置相关------------end

    preHandleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getPrescribeDetail(this, null);
    },
    getPrescribeDetail(_this) {

      if (_this.prescribeData == null)
        return
      if (_this.prescribeData != null) {
        _this.preQuery.page = 1
        _this.preQuery.orderIdFk = this.prescribeData.billNo
      }
      _this.preLoading = true;
      orderDetail(_this.preQuery).then(res => {
        _this.preLoading = false
        if (res.code != 20000) {
          _this.$message.error(res.message)
          return
        }
        _this.preDetailList = res.data.list
        _this.preLoading = false
      }).catch(() => {
        _this.preLoading = false
        _this.$message.error("数据加载失败")
      })
    },


    scanDetail(_this, row) {
      _this.bizId = row.id;
      _this.scanDetailVisible = true;
    },

    closeScanDialog() {
      this.getPrescribeDetail(this);
      this.refreshPanel(this)
    },

    rowStyle({row, rowIndex}) {
      let rowBackground = {};

      if (row.scanActCount < row.count) {
        rowBackground.color = '#F56C6C';
      }
      if (row.autoTagStatus == 2) {
        rowBackground.color = '#E6A23C';
      }
      if (row.scanActCount >= row.count) {
        rowBackground.color = '#56a717';
      }
      rowBackground.height = "38px"
      return rowBackground;
    },

  },


  components: {
    PanelOrderManuTagCode
  },
  created() {
    if (this.tableHeader1 == null || this.tableHeader1.length == 0) {
      getHead("prescribeOriginPanel", "1").then((re) => {
        // 处理返回的数据
        this.tableObj1 = re.data;
        this.tableHeader1 = re.data.tableList;
        this.queryList1 = re.data.queryList;
        this.fromList1 = re.data.fromList;
        this.getPrescribeDetail(this);
      });
    }
    this.getPrescribeDetail(this);
    if (this.dealStatus == 1) {
      this.countVisible = false;
    } else {
      this.countVisible = true;
    }
  }


}
</script>

<style scoped>
</style>
