<template>
  <div class="page">
    <LayoutTable :data="tableData" :config="tableConfig">
    </LayoutTable>
    <track-drawer-show ref="trackDrawerShow"  />
    <dialog-show ref="dialogform" @ok="getData" />
    <track-dialog-show ref="trackdialogform" @ok="getData" />
  </div>
</template>

<script>
/** 表单弹出框模式需引入 */
import dialogShow from "./dialogshow";
import trackDrawerShow from "./trackDrawerShow";
import trackDialogShow from "./track/dialogshow";
import table from "@/assets/mixins/table";
export default {
  name: "CareConstraintList",
  components: {
    dialogShow,trackDrawerShow,trackDialogShow
  },
  mixins: [table],
  created() {
  },
  methods: {
    renderTable(tableData) {
      return (
          <el-table stripe data={tableData} class="total-table">
            {this.columnSet.map((item) => this.renderTableColumn(item))}
          </el-table>
      );
    },
    renderTableColumn(options) {
      return (
          <el-table-column
              prop={options.prop}
              label={options.label}
              width={options.width}
          >
          </el-table-column>
      );
    },
    /** 重写新增方法 */
    toAdd(row) {
      this.$refs.dialogform.add(row);
    },
    /** 重写编辑方法 */
    toEdit(row) {
      this.$refs.dialogform.edit(row);
    },
    /** 重写查看方法 */
    toView(row) {
      this.$refs.dialogform.view(row);
    },

    handleTrack(row) {
     // this.$refs.trackDrawerShow.view(row);
      // this.$refs.trackdialogform.view(row);
      let _this = this
      this.$get("/care/constraint/track", {
          id: row.id,
        })
            .then((res) => {
              if (res.code == 1) {
                _this.$message.success("追踪成功！");
                _this.getData();
              }
            })
            .catch((error) => {
              _this.$message.error(error.message);
            });
    },

    cancelTrack(row) {
      let _this = this
      this.$confirm('取消跟踪后，系统将从0开始计算服务频次，是否确认？', "系统服务", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        _this.$get("/care/constraint/track", {
          id: row.id,
        })
            .then((res) => {
              if (res.code == 1) {
                _this.$message.success("取消追踪成功！");
                _this.getData();
              }
            })
            .catch((error) => {
              _this.$message.error(error.message);
            });
        //todo
        // _this.$post("/care/constraint/save", {
        //   id: row.id,
        //   serviceFrequency: 0,
        //   track: 0,
        // })
        //     .then((res) => {
        //       if (res.code == 1) {
        //         _this.$message.success("取消追踪成功！");
        //         _this.getData();
        //       }
        //     })
        //     .catch((error) => {
        //       _this.$message.error(error.message);
        //     });

      }).then(response => {

      })

    }

  },
  data() {
    return {
      /** 子表列元素 */
      columnSet:[
        {prop:"careId",label:"主动关怀约束Id",width:100},
        {prop:"feedbackId",label:"反馈人ID",width:100},
        {prop:"feedbackName",label:"反馈人姓名",width:100},
        {prop:"feedback",label:"反馈内容",width:100},
        {prop:"feedbackTime",label:"跟踪时间",width:100},
        {prop:"createMethod",label:"创建方式",width:100},
      ],
      config: {
        search: [
          {
            name: "name",
            type: "text",
            label: "姓名",
            fuzzy: true
          }
        ],
        columns: [
          {type: "selection", width: 60},
          {type: "index",label: "序号",width: 50},

          {label: "姓名", prop: "name"},

          {label: "联系方式", prop: "contact"},

          {label: "身份证号码", prop: "idCard"},

          {label: "服务频次", prop: "serviceFrequency", formatter: this.formatter},

          {label: "跟踪时间", prop: "trackingTime", formatter: this.formatterDate},

          {label: "创建方式", prop: "createWay",formatter: this.formatter},

          {label: "操作人员", prop: "operator"},

          {label: "是否追踪 ", prop: "track",formatter: this.formatter},

          {
            label: "操作",
            width: 320,
            formatter: row => {
              if(row.track){
                              return (
                  <div>
                    <table-buttons noAdd noView row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
                    <span> </span>
                    <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-open"
                        onClick={() => {
                          this.cancelTrack(row);
                        }}
                    >
                      取消跟踪
                    </el-button>
                  </div>);
              }else{
                return (
                    <div>
                      <table-buttons noAdd noView row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
                      <span> </span>

                      <el-button
                          size="mini"
                          type="text"
                          icon="el-icon-open"
                          onClick={() => {
                            this.handleTrack(row);
                          }}
                      >
                        跟踪反馈
                      </el-button>
                    </div>);

              }
            }
          }
        ]
      }
    };
  }
};
</script>
