<template>
  <div>
    <!--<el-table v-loading="preLoading" :data="preDetailList" style="width: 100%" border :row-style="rowStyle">-->
    <!--  <template v-for="(item, index) in tableHeader1">-->
    <!--    <el-table-column-->
    <!--      v-if="item.columnType == 'id' && executeEval(row,item.expression,true)"-->
    <!--      type="index" :label="item.columnDesc"></el-table-column>-->
    <!--    <el-table-column-->
    <!--      v-if="item.columnType == 'selection'"-->
    <!--      type="selection"-->
    <!--      :width="item.width"-->
    <!--      :selectable="(row,number) => executeFuc(row,'3',item.clickFuc)"-->
    <!--    ></el-table-column>-->

    <!--    <el-table-column-->
    <!--      v-if="item.columnType == 'radio' && executeEval(row,item.expression,true)"-->
    <!--      :prop="item.columnName"-->
    <!--      :label="item.columnDesc"-->
    <!--      :sortable="item.sort"-->
    <!--      :width="item.width"-->
    <!--      :show-overflow-tooltip="item.tooltip"-->
    <!--      :key="item.columnName"-->
    <!--    >-->
    <!--      <template slot-scope="scope">-->
    <!--        <el-radio :label="scope.row.id" v-model="radioCheck"><span></span></el-radio>-->
    <!--      </template>-->
    <!--    </el-table-column>-->
    <!--    <el-table-column-->
    <!--      v-if="item.columnType == 'laber' && executeEval(row,item.expression,true)"-->
    <!--      :prop="item.columnName"-->
    <!--      :label="item.columnDesc"-->
    <!--      :sortable="item.sort"-->
    <!--      :width="item.width"-->
    <!--      :show-overflow-tooltip="item.tooltip"-->
    <!--      :key="item.columnName"-->
    <!--    >-->
    <!--      <template slot-scope="scope">-->
    <!--            <span :style="{color: executeFuc(scope.row,'4',item.lableRuleObj[scope.row[item.columnName]])}">{{-->
    <!--                item.lableRuleObj[scope.row[item.columnName]]-->
    <!--              }}</span>-->
    <!--      </template>-->
    <!--    </el-table-column>-->
    <!--    <el-table-column-->
    <!--      v-if="item.columnType == 'eltag' && executeEval(row,item.expression,true)"-->
    <!--      :prop="item.columnName"-->
    <!--      :label="item.columnDesc"-->
    <!--      :sortable="item.sort"-->
    <!--      :width="item.width"-->
    <!--      :show-overflow-tooltip="item.tooltip"-->
    <!--      :key="item.columnName"-->
    <!--    >-->
    <!--      <template slot-scope="scope">-->
    <!--        <el-tag-->
    <!--          :type="executeFuc(scope.row,'4',item,item.lableRuleObj?item.lableRuleObj[scope.row[item.columnName]]:scope.row[item.columnName])">-->
    <!--              <span>{{-->
    <!--                  item.lableRuleObj ? item.lableRuleObj[scope.row[item.columnName]] : scope.row[item.columnName]-->
    <!--                }}</span>-->
    <!--        </el-tag>-->
    <!--      </template>-->
    <!--    </el-table-column>-->
    <!--    <el-table-column-->
    <!--      v-if="item.columnType == 'button' && executeEval(row,item.expression,true)"-->
    <!--      :prop="item.columnName"-->
    <!--      :label="item.columnDesc"-->
    <!--      :width="item.width"-->
    <!--      :key="item.columnName"-->
    <!--      fixed="right"-->
    <!--    >-->
    <!--      <template slot-scope="scope">-->
    <!--        <el-button v-for="(buttonItem, buttonIndex) in item.buttonRulObj"-->
    <!--                   :type="buttonItem.type"-->
    <!--                   :size="buttonItem.size"-->
    <!--                   :style="buttonItem.style"-->
    <!--                   :key="buttonItem"-->
    <!--                   v-if="executeEval(scope.row,buttonItem.hasPermi,true)"-->
    <!--                   :disabled="executeEval(scope.row,buttonItem.disabledFuc,false)"-->
    <!--                   @click.native.stop="executeFuc(scope.row,'1',buttonItem.clickFuc)"-->
    <!--        >{{ buttonItem.name }}-->
    <!--        </el-button>-->
    <!--      </template>-->
    <!--    </el-table-column>-->
    <!--    <el-table-column-->
    <!--      v-if="item.columnType == 'text'  && !(item.columnName == 'productDate' || item.columnName == 'expireDate') && executeEval(row,item.expression,true)"-->
    <!--      :prop="item.columnName"-->
    <!--      :label="item.columnDesc"-->
    <!--      :sortable="item.sort"-->
    <!--      :width="item.width"-->
    <!--      :show-overflow-tooltip="item.tooltip"-->
    <!--      :key="item.columnName"-->
    <!--    >-->
    <!--      <template slot-scope="scope">-->
    <!--            <span :style="{color: executeFuc(scope.row,'4',item,scope.row[item.columnName])}">{{-->
    <!--                scope.row[item.columnName]-->
    <!--              }}</span>-->
    <!--      </template>-->
    <!--    </el-table-column>-->
    <!--    <el-table-column-->
    <!--      v-if="item.columnType == 'text' && (item.columnName == 'productDate' || item.columnName == 'expireDate') && executeEval(row,item.expression,true)"-->
    <!--      :prop="item.columnName"-->
    <!--      :label="item.columnDesc"-->
    <!--      :sortable="item.sort"-->
    <!--      :width="item.width"-->
    <!--      :show-overflow-tooltip="item.tooltip"-->
    <!--      :key="item.columnName"-->
    <!--    >-->
    <!--      <template slot-scope="scope">-->
    <!--            <span :style="{color: executeFuc(scope.row,'4',item,scope.row[item.columnName])}">{{-->
    <!--                convertDateFun(scope.row[item.columnName])-->
    <!--              }}</span>-->
    <!--      </template>-->
    <!--    </el-table-column>-->
    <!--  </template>-->
    <!--</el-table>-->

    <el-table :data="preDetailList" highlight-current-row="true" border ref="multipleTable" size="100"
              :row-style="{ height: '60px' }"
              :cell-style="{ padding: '0' }"
    >
      <el-table-column label="赋码状态" prop="cpmctymc">
        <template v-slot="scope">
          <div style="text-align: center;">
            <el-tag :type="getTagColor(scope.row)" size="26">
              {{ codingStatus }}
            </el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="产品通用名" prop="cpmctymc">
        <template v-slot="scope">
          <div :style="{ fontSize: '16px' }">{{ scope.row.cpmctymc }}</div>
        </template>
      </el-table-column>
      <el-table-column label="单据数量" prop="count">
        <template v-slot="scope">
          <div :style="{ fontSize: '26px' }">{{ scope.row.count }}</div>
        </template>
      </el-table-column>
      <el-table-column label="应扫码数量" prop="scanActCount">
        <template v-slot="scope">
          <div :style="getCellStyle(scope.row)">{{ scope.row.scanCount }}/{{ scope.row.shouldCount }}</div>
        </template>
      </el-table-column>
      <el-table-column label="制剂规格" prop="prepnSpec">
        <template v-slot="scope">
          <div :style="{ fontSize: '16px' }">{{ scope.row.prepnSpec }}</div>
        </template>
      </el-table-column>
      <el-table-column label="包装规格" prop="spec">
        <template v-slot="scope">
          <div :style="{ fontSize: '16px' }">{{ scope.row.spec }}</div>
        </template>
      </el-table-column>

      <!--<el-table-column label="产品标识" prop="nameCode" width="120"></el-table-column>  fixed="right"-->
      <el-table-column label="医保编码" prop="ybbm" width="240">
        <template v-slot="scope">
          <div :style="{ fontSize: '16px' }">{{ scope.row.ybbm }}</div>
        </template>
      </el-table-column>
      <el-table-column label="批次号" prop="batchNo">
        <template v-slot="scope">
          <div :style="{ fontSize: '16px' }">{{ scope.row.batchNo }}</div>
        </template>
      </el-table-column>

      >
      <el-table-column
        fixed="right"
        label="操作"
        width="120"
      >
        <template slot-scope="scope">
          <el-button type="primary" @click="scanDetail(scope.row)" style="font-size: 14px"
                     :disabled="scope.row.scanCount == null || scope.row.scanCount == 0 "
          >
            扫码明细({{ scope.row.scanCount == null ? 0 : scope.row.scanCount }})
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="preTotal>0"
      :total="preTotal"
      :limit.sync="preQuery.limit"
      :page.sync="preQuery.page"
      @pagination="preHandleCurrentChange"
    ></pagination>


    <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 } 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 {
      //界面配置相关
      //原始处方明细
      tableHeader1: [],
      queryList1: [],
      tableObj1: [],
      fromList1: [],
      convertDateFun: convertDate,

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

      countVisible: false,
      scanDetailVisible: false,
      bizId: null,
      codingStatus: '已赋码'
    }
  },
  methods: {
    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(row) {
      this.bizId = row.id
      this.scanDetailVisible = true
    },

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

    rowStyle({ row, rowIndex }) {
      let rowBackground = {}
      rowBackground.fontSize = '16px'
      rowBackground.height = '50px'
      if (row.scanActCount < row.count) {
        rowBackground.color = '#F56C6C'
      }
      if (row.autoTagStatus == 2) {
        rowBackground.color = '#E6A23C'
      }
      if (row.scanActCount >= row.count) {
        rowBackground.color = '#56a717'
      }
      return rowBackground
    },

    getCellStyle(row) {
      let cellStyle = {
        fontSize: '32px'
      }
      if (row.shouldCount == 0) {
        cellStyle.fontSize = '30px'
        cellStyle.color = '#F56C6C'
        return cellStyle
      }
      if (row.scanCount < row.shouldCount) {
        cellStyle.color = '#F56C6C'
      } else if (row.scanCount === row.shouldCount) {
        cellStyle.color = '#56a717'
      }
      return cellStyle
    },
    // cellStyle({ row, column, rowIndex, columnIndex }) {
    //     return { height: '60px' };
    // },
    getTagColor(row) {
      if (row.scanActCount < row.count) {
        this.codingStatus = '未赋码'
        return 'danger' // 红色
      } else if (row.autoTagStatus == 2) {
        this.codingStatus = '预赋码'
        return 'warning' // 黄色
      } else if (row.scanActCount >= row.count) {
        this.codingStatus = '已赋码'
        return 'success' // 绿色
      }
    }

  },

  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>
