<template>
  <template-page ref="pageRef" :getList="getList" :operation="operation()" :exportList="exportList"
    :columnParsing="columnParsing" :tableAttributes="tableAttributes" :tableEvents="tableEvents">
    <div class="cartographer_big">
      <el-dialog title="详情" width="100%" :modal="false" :visible.sync="formBool" :before-close="handleClose">
        <zj-page-container v-if="formBool">
          <zj-page-fill class="neibuview" v-if="formBool">
            <zj-form-container v-if="formBool" :formAttributes="{ 'label-position': 'top' }">
              <zj-form-module v-if="formBool" title="费用信息" :form-data="formData" :form-items="formItems">
                <div v-if="openType === 1" style="text-align:right">
                  <el-button size="mini" type="danger" plain @click="WAITfun">确定结算</el-button>
                </div>
              </zj-form-module>
            </zj-form-container>
          </zj-page-fill>
        </zj-page-container>
      </el-dialog>
    </div>
  </template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import operation_mixin from '@/components/template/operation_mixin.js'
import { enginMaterialListLine, enginMaterialListLineExport, enginMaterialDetail, enginMaterialLineSettlement } from "@/api/applicationWithoutFee.js"
import feel from "../../mixins/feel.js"
export default {
  components: {
    TemplatePage,
  },
  mixins: [import_mixin, operation_mixin, feel],
  props: {
    websitId: {
      type: [String, Number],
      default: ""
    },
    workerId: {
      type: [String, Number],
      default: ""
    },
    status: {
      type: [String, Number],
      default: ""
    },
  },
  data() {
    return {
      formBool: false,
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: false,
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      formData: {},
      openType: 0
    }
  },
  methods: {
    // 列表请求函数
    getList(p, cb) {
      try {
        var pam = JSON.parse(JSON.stringify(p))
        if (this.websitId) {
          pam.params.push({ "param": "websit_id", "compare": "=", "value": this.websitId })
        }
        if (this.workerId) {
          pam.params.push({ "param": "worker_id", "compare": "=", "value": this.workerId })
        }
        if (this.status) {
          pam.params.push({ "param": "status", "compare": "=", "value": this.status })
        }
        cb && cb(pam)
        return enginMaterialListLine(pam)
      } catch (err) {
        console.log(err)
      }
    },

    // 列表导出函数
    exportList: enginMaterialListLineExport,

    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },

    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },

    operation() {
      return this.operationBtn({
        detail_mx: {
          click: ({ row, index, column }) => {
            enginMaterialDetail({
              id: row.orderId
            }).then(res => {
              this.openType = 0
              this.formData = res.data
              this.$nextTick(() => {
                this.formBool = true
              })
            })
          }
        },
        settle_mx: {
          conditions: ({ row, index, column }) => {
            return row.status == "WAIT"
          },
          click: ({ row, index, column }) => {
            enginMaterialDetail({
              id: row.orderId
            }).then(res => {
              this.openType = 1
              this.formData = res.data
              this.$nextTick(() => {
                this.formBool = true
              })
            })
          }
        },
      })
    },

    handleClose() {
      this.formData = {}
      this.formBool = false
    },

    WAITfun() {
      this.$confirm('是否确定结算?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        enginMaterialLineSettlement({
          id: this.formData.orderId
        }).then(res => {
          this.$refs.pageRef.refreshList()
          this.handleClose()
        })
      }).catch(() => {

      });
    },
  }
}
</script>

<style lang="scss" scoped>
.neibuview {
  box-sizing: border-box;
  padding-left: 16px;

  ::v-deep &>.zj-page-fill-scroll {
    box-sizing: border-box;
    padding-right: 16px;

    &>div:nth-child(1) {
      margin-top: 20px;
    }
  }
}
</style>
