<template>
  <div>
    <el-table v-loading="codeLoading" :data="codeDetailList" style="width: 100%" border>
      <template v-for="(item, index) in tableHeader2">
        <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>

    <pagination
      v-show="codeTotal>0"
      :total="codeTotal"
      :limit.sync="codeQuery.limit"
      :page.sync="codeQuery.page"
      @pagination="codeHandleCurrentChange"
    ></pagination>

  </div>
</template>

<script>
import {convertDate} from "@/utils/date";
import {executeFuc, getHead} from "@/utils/customConfig";
import {materialPrescribePage} from "@/api/inout/splitCode";

export default {

  /**
   * 处方赋码明细
   */
  name: "prescribeCodePanel",
  props: {
    prescribeData: {
      type: Object,
      default: null,
      required: true
    },
    //上货方式：1:拆零上货；2:整取上货;
    fifoSplit: {
      type: Object,
      default: null,
      required: true
    },
  },
  data() {

    return {
      //界面配置相关
      //赋码明细
      tableHeader2: [],
      queryList2: [],
      tableObj2: [],
      fromList2: [],
      convertDateFun: convertDate,
      //界面配置-------------end

      codeLoading: false,
      codeDetailList: [],
      codeTotal: 0,
      codeQuery: {
        fifoSplit: null,
        page: 1,
        limit: 10,
      },
    }
  },
  methods: {
    //界面配置相关------------
    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

    getCodeDetail(_this) {
      if (this.prescribeData == null)
        return
      if (this.prescribeData != null) {
        _this.codeQuery.page = 1
        _this.codeQuery.prescribeNum = this.prescribeData.code
      }
      _this.codeLoading = true;
      _this.codeQuery.fifoSplit = this.fifoSplit
      materialPrescribePage(_this.codeQuery).then(res => {
        _this.codeLoading = false
        if (res.code != 20000) {
          _this.$message.error(res.message)
          return
        }
        _this.codeDetailList = res.data.list
        _this.codeLoading = false
      }).catch(() => {
        _this.codeLoading = false
        _this.$message.error("数据加载失败")
      })
    },
    codeHandleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getCodeDetail(this, null);
    },

  },

  created() {
    getHead("prescribePanel-2", "1").then((re) => {
      // 处理返回的数据
      this.tableObj2 = re.data;
      this.tableHeader2 = re.data.tableList;
      this.queryList2 = re.data.queryList;
      this.fromList2 = re.data.fromList;
      this.getList();
    });
  }

}
</script>

<style scoped>

</style>
