<!--
 * @Description: 变更执行结果-编辑行项目信息
 * @Author:hdk
 * @Date: 2020-11-03 16:38:41
-->
<template>
  <div>
    <el-dialog
      v-dialogDrag
      :visible.sync="dialogData.consignContractVisible"
      append-to-body
      :close-on-click-modal="false"
      :lock-scroll="false"
      title="编辑行项目信息"
      width="1000px"
      custom-class="el-dialog__body-p8 el-dialog_table"
      @close="closeOff"
    >
      <div class="p0-16">
        <el-form
          ref="projectInfo"
          :model="projectInfo"
          :rules="rules"
          :inline-message="true"
        >
          <table class="from_table">
            <tr>
              <td> <el-form-item label="物资编码" /></td>
              <td>
                {{ projectInfo.purchaseCode }}
              </td>
              <td> <el-form-item label="物资名称" /></td>
              <td>
                {{ projectInfo.purchaseName }}
              </td>
            </tr>
            <tr>
              <td> <el-form-item label="物资规格说明" /></td>
              <td>
                {{ projectInfo.purchaseSpecification }}
              </td>
              <td><el-form-item label="二级专业分类" /></td>
              <td>
                {{ projectInfo.purchaseClassification }}
              </td>
            </tr>
            <tr>
              <td> <el-form-item label="品牌" /></td>
              <td>
                {{ projectInfo.purchaseBrand }}
              </td>
              <td> <el-form-item label="是否集采" /></td>
              <td>
                {{ filterDictText(collectionTypeList, projectInfo.collectionType) }}
              </td>
            </tr>
            <tr>
              <td> <el-form-item label="执行结果编号" /></td>
              <td>
                {{ dialogData.executeNo }}
              </td>
              <td> <el-form-item label="数量" /></td>
              <td>
                {{ projectInfo.purchaseNum }}
              </td>
            </tr>
            <tr>
              <td> <el-form-item label="计量单位" /></td>
              <td>
                {{ filterDictText(purchaseUnitList, projectInfo.purchaseUnit) }}
              </td>
              <td> <el-form-item label="采购单价（元）" prop="purchaseBudget" /></td>
              <td>
                <!--金额组件-->
                <money :thousands="true" :width="'286px'" :money-value="projectInfo" name="purchaseBudget" />
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="税率（%）" />
              </td>
              <td>
                {{ filterDictText(taxRateList,projectInfo.purchaseTaxRate) }}
              </td>
              <td>
                <el-form-item label="一级专业分类" />
              </td>
              <td>
                {{ projectInfo.purchaseClassificationParent }}
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="采购单位" prop="belongOrgName" />
              </td>
              <td colspan="3">
                <el-input
                  v-model="projectInfo.belongOrgName"
                  placeholder="请选择"
                  style="width: calc(100% - 254px)"
                  disabled
                />
                <el-button type="primary" class="ml10 choose" @click="organSelect">
                  选择采购单位
                </el-button>
                <el-button type="primary" plain class="ml10 choose" @click="organTree('clear')">
                  清空
                </el-button>
              </td>
            </tr>
            <tr>
              <td> <el-form-item label="交货日期" /></td>
              <td colspan="3">
                {{ projectInfo.deliveryTime }}
                <!-- {{ projectInfo.deliveryTime && $Moment(projectInfo.deliveryTime).format(momentDate) }} -->
              </td>
              <!-- <td> <el-form-item label="供货供应商" /></td>
              <td>
                <el-input
                  v-model="projectInfo.suppliersName"
                  placeholder="请选择"
                  class="mr10"
                  style="width: calc(100% - 150px)"
                  disabled
                />
                <el-button type="primary" class="ml10 choose" @click="openSupplier()">
                  选择
                </el-button>
                <el-button type="primary" plain @click="checkSupplier('clear')">
                  清空
                </el-button>
              </td> -->
            </tr>
            <tr>
              <td><el-form-item label="交货地点" /></td>
              <td colspan="3">
                {{ projectInfo.deliveryAddress ? projectInfo.deliveryAddress.replace(/,/g,'') : '' }}
              </td>
            </tr>
          </table>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="okdialog('projectInfo')">确认</el-button>
        <el-button @click="closeOff">取消</el-button>
      </span>
      <!-- 采购单位弹框 -->
      <organTree-dialog ref="organTree" @call-back="organTree" />
      <!-- 供应商弹窗 -->
      <!-- <materielSupplierDialog :dialog-data="supplierDialogData" @consignContractInfo="checkSupplier" /> -->
    </el-dialog>
  </div>
</template>
<script>
/* api */
import { updatePurchaseDetailAndResultExecute } from '@/api/procurement/purchasplan'// 采购平台录入行项目信息
/* 公共混入*/
import { rstMgmtMixins } from '../mixins/rstMgmtMixins'
/* 公共方法 */
import { checkMoney, characters1_auto } from '@/assets/js/validate'// 校验输入内容
import { filterDictText } from '@/assets/js/utils'
// import materielSupplierDialog from './slelectSupplier-dialog' // 供应商弹窗

/* 公共组件 */
import money from '@comp/common/money/money' // 金币组件
import organTreeDialog from '@/views/common/user/organizationTree/organTree-dialog' // 采购单位

export default {
  name: 'LineItemEditDialog',
  components: {
    money, // 金额组件
    organTreeDialog // 采购单位
    // materielSupplierDialog
  },
  mixins: [rstMgmtMixins],
  props: {
    projectInfo: { // 要编辑的行项目
      type: Object,
      default: function() {
        return {}
      }
    },
    dialogData: {
      type: Object,
      default: function() {
        return {
          consignContractVisible: false, // 编辑行项目信息状态
          executeId: '', // 执行表ID
          executeNo: '' // 执行单编号
        }
      }
    }
  },
  data() {
    return {
      supplierDialogData: { // 供货商弹窗参数
        dialog: false, // 供应商弹窗打开状态
        singleChoice: false // 单选
      },
      // 校验规则
      rules: {
        belongOrgName: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 采购单位
        purchaseBudget: [{ required: true, validator: checkMoney, trigger: 'blur' }] // 采购单价（元）
      }
    }
  },
  methods: {
    // 字典检索
    filterDictText,
    // 关闭 取消
    closeOff() {
      this.$emit('lineItemEditClose')
    },
    /* =================选择供应商暂时隐藏Start============================*/
    // openSupplier() {
    //   this.supplierDialogData.dialog = true
    // },
    // 制造厂商 选择/清空
    // checkSupplier(data) {
    //   // 清空
    //   if (data === 'clear') {
    //     // 供货商数据清空
    //     this.projectInfo.suppliersName = ''
    //     this.projectInfo.suppliersValue = ''
    //   } else {
    //     // 选择
    //     // 供货商数据赋值
    //     this.$set(this.projectInfo, 'suppliersName', data.labels)
    //     this.$set(this.projectInfo, 'suppliersValue', data.keys)
    //   }
    // },
    /* =================选择供应商暂时隐藏End============================*/

    /* =====================采购单位Start=========================*/
    organSelect() {
      this.$refs.organTree.open({
        title: '选择采购单位', // 弹框标题
        dialog: true, // 弹窗状态
        selectCodes: this.projectInfo.belongOrgId ? this.projectInfo.belongOrgId.split(',') : '' // 当前选中的供货范围Code
      })
    },
    // 选择/清空机构
    organTree(data) {
      // 清空
      if (data === 'clear') {
        this.projectInfo.belongOrgName = ''
        this.projectInfo.belongOrgId = ''
      } else {
        // 选择
        this.$set(this.projectInfo, 'belongOrgName', data.labels)
        this.$set(this.projectInfo, 'belongOrgId', data.keys)
      }
    },
    /* =====================采购单位End=========================*/
    // 确认
    okdialog(formName) {
      const data = {
        executeId: this.dialogData.executeId, // 执行表ID
        exePdetailId: this.projectInfo.id, // 结果执行表行项目ID
        // planDetailId: this.projectInfo.id, // 行项目ID
        purchaseBudget: this.projectInfo.purchaseBudget, // 预算净单价(元)
        // suppliersValue: this.projectInfo.suppliersValue // 供应商id
        // suppliersName: this.projectInfo.suppliersName // 供应商name
        belongOrgName: this.projectInfo.belongOrgName, // 采购单位名称
        belongOrgId: this.projectInfo.belongOrgId // 采购单位ID
      }
      this.$refs[formName].validate((valid, field) => {
        // 校验通过
        if (valid) {
          // 更新预算净单价(元)接口调用
          updatePurchaseDetailAndResultExecute(data).then(res => {
            this.$message({
              type: 'success',
              message: res.header.msg
            })
            this.closeOff()
          })
        } else {
          this.$message.warning('请注意页面提示信息')
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
