<!--
  @description: 收货&发货-订单处理-编辑&详情-行项目列表公共
  @author: 王俊楠
  @date： 2020-9-24 22:41:12
-->
<template>
  <div>
    <div class="clearfix offerInfo">
      <p class="fl page-title">
        2.行项目信息
      </p>
      <p v-if="moneyFlag" class="fr mt10 tip-size">
        订单净总价（元）：<span class="procurement_orange-color">{{ moneyFormat(lineData.orderTotalMoney) }}</span>
        币种： <span class="procurement_orange-color">{{ filterDictText(protproject_currencyList,lineData.currency) }}</span>
      </p>
    </div>
    <el-table
      ref="lineItemInfo"
      :data="lineItemInfoList"
      :row-key="getRowKey"
      border
      class="mb16 tableLimit"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        v-if="pageType === '01'"
        :selectable="isDisabled"
        type="selection"
        width="55"
      />
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column
        prop="lineItemNumber"
        header-align="center"
        align="center"
        min-width="180"
        label="行项目编号"
      />
      <el-table-column
        prop="productNo"
        header-align="center"
        align="center"
        min-width="150"
        label="物资编码"
      />
      <el-table-column
        prop="productDescribe"
        header-align="center"
        align="left"
        min-width="230"
        label="物资描述"
      />
      <!-- 类别 -暂时隐藏 -->
      <!-- <el-table-column align="center" min-width="180" label="类别">
        <template slot-scope="scope">
          <span> {{ filterDictText(plan_purchase_typeList, scope.row.productCategory) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        prop="quantity"
        header-align="center"
        align="right"
        min-width="100"
        label="成交数量"
      />
      <el-table-column
        header-align="center"
        prop="unit"
        align="left"
        min-width="100"
        label="计量单位"
      >
        <template slot-scope="scope">
          {{ filterDictText(purchaseUnitList, scope.row.unit) }}
        </template>
      </el-table-column>
      <!-- 税率 -->
      <el-table-column
        header-align="center"
        align="left"
        min-width="160"
        label="税率(%)"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.taxRate"> {{ filterDictText(taxRateList, scope.row.taxRate.toString()) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        label="成交单价（元）"
        min-width="110"
        align="right"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.transactionBudget?moneyFormat(scope.row.transactionBudget.toFixed(2)):scope.row.transactionBudget }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        label="成交总价（元）"
        min-width="110"
        align="right"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.distributionTotalMoney?moneyFormat(scope.row.distributionTotalMoney.toFixed(2)):scope.row.distributionTotalMoney }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="offerRemarks"
        header-align="center"
        align="left"
        min-width="200"
        label="品牌/生产厂家"
      />
      <el-table-column
        align="center"
        label="交货日期"
        min-width="180"
      >
        <template slot-scope="scope">
          {{ scope.row.deliveryTime && $Moment(scope.row.deliveryTime).format(momentDate) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="deliveryAdress"
        align="left"
        header-align="center"
        min-width="220"
        label="交货地点"
      />
    </el-table>
  </div>
</template>

<script>
/* 公共方法 */
import { filterDictText, moneyFormat } from '@/assets/js/utils' // 字典code翻译中文
/*  混合开发-参数字段 */
// import { procurementGroupMixins } from '@/views/procurement/mixins/procurementGrounpMixins' // 公共字典
import { procurementOrderGroupMixins } from '@/views/procurement/procurementOrder/mixins/procurementOrderGroupMixins.js'
import money from '@comp/common/money/money' // 金币组件
// import { totalHeadCount } from '@/assets/js/utils' // 计算总价 randomData

// 组件
import pagination from '@comp/common/pagination/pagination' // 分页组件
export default {
  name: 'ProcurementOrderLineItemCompDetail',
  components: {
    money, // 金额组件
    pagination // 翻页组件
  },
  mixins: [procurementOrderGroupMixins],
  props: {
    // 行项目信息更新数据
    lineItemInfoData: {
      type: Array,
      default: () => {
        return []
      }
    },
    // 金额
    lineData: {
      type: Object,
      default: function() {
        return {}
      }
    },
    // 金额/币种展示状态
    moneyFlag: {
      type: Boolean,
      default: true
    },
    pageType: {
      type: String,
      default: ''
    },
    // 操作类型 00 提交 01 审批
    operationType: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      roleCode: '',
      // 行项目信息
      lineItemInfoList: [],
      // 选中的行项目信息
      selectLineItemIdArr: [],
      // // 行项目的其他数据
      // lineItemOther: {
      //   currency: '' // 币种
      // },
      confirmLoading: false // 页面加载
    }
  },
  computed: {
    // 计算总价
    // totalPrice: function() {
    //   // 初始化数据
    //   const totalPriceData = []
    //   let totalPrice = 0
    //   this.lineItemInfoList &&
    //     this.lineItemInfoList.map(cur => {
    //       if (this.operationType === '01') {
    //         if (cur.releaseStatus === '03') {
    //           this.$refs.lineItemInfo.toggleRowSelection(cur, true)
    //         }
    //       }
    //       // 判断单向总价是否是数值
    //       if (!isNaN(cur.distributionTotalMoney)) {
    //         // 将总价push到初始数据中
    //         totalPriceData.push(cur.distributionTotalMoney)
    //         // 调用公共求和方法
    //         totalPrice = totalHeadCount(totalPriceData).toFixed(2)
    //         return
    //       }
    //       totalPrice = 0
    //     })
    //   return totalPrice
    // }
  },
  watch: {
    lineItemInfoData: {
      handler(val, old) {
        // 如果新值和旧值相同，则不触发方法。
        if (val !== old) {
          this.lineItemInfoList = val // 赋值props给本页
          this.$nextTick(() => {
            this.isSel() // 退回选中
          })
        }
      },
      deep: true
    }
  },
  created() {
    this.roleCode = this.$store.getters.info.currentRol.roleCode // 获取角色信息
  },
  methods: {
    filterDictText,
    moneyFormat,
    /*
    * 退回选中逻辑
    *    this.operationType 01 工作流进入
    *    this.roleCode 11 采购员角色
    *    cur.releaseStatus 03 选中状态
    */
    isSel() {
      this.lineItemInfoList && this.lineItemInfoList.map(cur => {
        if (this.operationType === '01') {
          // 采购员
          // if (this.roleCode === '11') {
          //   if (cur.releaseStatus === '03') {
          //     this.$refs.lineItemInfo.toggleRowSelection(cur, true)
          //   }
          // } else {
          //   if (cur.releaseStatus === '03') {
          //     this.$refs.lineItemInfo.toggleRowSelection(cur, true)
          //   }
          // }
          if (cur.releaseStatus === '03') {
            this.$refs.lineItemInfo.toggleRowSelection(cur, true)
          }
        }
      })
    },
    // 指定一个key标识这一行的数据
    getRowKey(row) {
      return row.id
    },
    isDisabled(row) {
      // this.$route.query.routePathStatus 判断代办/已办
      if (this.operationType === '01') {
        if (this.roleCode === '11' && this.$route.query.routePathStatus !== '02') {
          return true
        }
        return false
      } else if (this.operationType === '00') {
        if (row.releaseStatus === '02') {
          return false
        }
      }
      return true
    },
    // 选中行项目
    handleSelectionChange(data) {
      this.selectLineItemIdArr = []
      data.forEach(item => {
        this.selectLineItemIdArr.push(item.id)
      })
    },
    // 调用组件内取值
    selectedItem(data) {
      // 抛出数据调用组件取值
      return this.selectLineItemIdArr
    }
  }
}
</script>

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