<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.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.prepnSpec }}</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.queueCode }}</p>-->
<!--          </div>-->
<!--          <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;margin-top: 80px"><i  class="el-icon-s-opportunity"></i>-->
<!--            <span :style="colorStyle(info)">{{ info.colorName}}</span></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: 130px;" icon="el-icon-document" @click="codeHandleClick(info)"  :disabled="!info.getConfirm">赋码明细</el-button>-->
<!--            <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-table :data="preDetailList"  :row-style="{ height: '50px',fontSize: '16px'}"  highlight-current-row="true" border ref="multipleTable"
px      >
        <el-table-column label="产品通用名" prop="cpmctymc" width="240"></el-table-column>
        <el-table-column label="制剂规格" prop="prepnSpec" width="280"></el-table-column>
        <el-table-column label="包装规格" prop="ggxh" width="100"></el-table-column>
        <el-table-column label="摆放位置" prop="queueCode" ></el-table-column>

        <el-table-column label="操作" width="280" fixed="right">
          <template slot-scope="scope">
              <el-button type="primary"  icon="el-icon-document" @click="codeHandleClick(scope.row)"  :disabled="!scope.row.getConfirm">赋码明细</el-button>
              <el-button type="primary"   icon="el-icon-thumb" @click="handleClick(scope.row)"  :disabled="scope.row.getConfirm">确认取药</el-button>
          </template>
        </el-table-column>
      </el-table>
    </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>

    <el-dialog
      title="赋码明细"
      :visible.sync="codeDetailVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-if="codeDetailVisible"
      width="45%"
      append-to-body
    >
      <PanelOrderTagCodeBiz
        :fifoSplit="3"
        :prescribeData="prescribeData"
        :bizId="bizId"
        :closeScanDialog="closeScanDialog"
      ></PanelOrderTagCodeBiz>
    </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";
import PanelOrderTagCodeBiz from "@/views/collect/PanelOrderTagCodeBiz.vue";

/**
 * 原始处方明细
 */
export default {
  name: "prescribeOriginPanel",
  props: {
    prescribeData: {
      type: Object,
      default: null,
      required: true
    },
    fifoSplitResult: {
      type: Function,
      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,
      codeDetailVisible: false,
      bizId: null,
      collectSet: {}
    }
  },
  methods: {
    handleClick(info){
      bizConfirm(info).then((response) => {
        if (response.code === 20000) {
          if (response.data.needSplitConfirm){
            this.$confirm("是否确定拆零扫码确认?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "忽略",
              type: "warning",
            }).then(() => {
              this.fifoSplitResult(response.data,info)
            }).catch(() => {
              //忽略 改为false 继续提交
              info.skipSplitConfirm  = true
              //触发提交
              bizConfirm(info).then((response) => {
                if (response.code === 20000) {
                  this.getPrescribeDetail(this)
                  this.$message.success("操作成功！");
                  return
                } else {
                  this.$message.error(response.message)
                }
              })
            });
          }
          this.getPrescribeDetail(this)
        } else {
          this.$message.error(response.message);
        }
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      })
    },
    codeHandleClick(info){
      this.bizId = info.id
      this.codeDetailVisible = true
    },
    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.setLed(_this.preDetailList)
        _this.preLoading = false
      }).catch(() => {
        _this.preLoading = false
        _this.$message.error("数据加载失败")
      })
    },

    setLed(preDetailList){
      preDetailList.forEach(item => {
        if (item.ledNum == 1){
          item.colorName = '红灯'
        }
        if (item.ledNum == 2){
          item.colorName = '黄灯'
        }
        if (item.ledNum == 3){
          item.colorName = '蓝灯'
        }
        if (item.ledNum == 4){
          item.colorName = '绿灯'
        }
      })
    },
    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 = '#ec951f';
      }
      if (row.scanActCount >= row.count) {
        rowBackground.color = '#56a717';
      }
      rowBackground.height = "38px"
      return rowBackground;
    },
    colorStyle(info) {
      switch (info.ledNum) {
        case 1:
          return { color: 'red' };
        case 2:
          return { color: '#ec951f' };
        case 3:
          return { color: 'blue' };
        case 4:
          return { color: 'green' };
      }
    }

  },


  components: {
    PanelOrderManuTagCode,PanelOrderTagCodeBiz
  },
  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>
