<template>
  <van-swipe-cell>
    <div class="status_box">
      <div class="title">{{ item.rwmc }}</div>
      <span
        style="whiteSpace: nowrap"
        :class="{
          bule: item.grrwzt == 0,
          cyan: item.grrwzt == 1,
          green: item.grrwzt == 2,
          yellow: item.grrwzt == 3,
          red: item.grrwzt == 4,
        }"
        >{{ setDict(item.grrwzt, dict.D_BZ_GRRWZT) }}</span
      >&nbsp;
      <div>
        <van-tag color="#fcc31f" v-if="item.rwzt == 1">关闭</van-tag>
        <van-tag type="primary" v-else-if="item.rwzt == 2">暂停 </van-tag>
        <van-tag type="success" v-else-if="item.rwzt == 0">正常</van-tag>
      </div>
    </div>
    <div class="nr">开始时间：{{ item.rwfqsj }}</div>
    <div class="nr">{{ item.rwnr }}</div>
    <div class="nr">
      发起人：<span v-if="item.ssbm">{{ item.ssbm }}-</span>
      <span>{{ item.cjrxm }}</span>
    </div>
    <template #right>
      <div class="rw_but_box">
        <!-- <van-button
          type="primary"
          style="margin: 0.5vw"
          @click.stop="
            onLookRw(
              item.ywid,
              item.id,
              item.rwxl,
              item.rwlx,
              item.rwzt,
              item.grrwzt,
              item.rwid
            )
          "
          >查看</van-button
        > -->
        <van-button
          type="warning"
          style="margin: 0.5vw"
          v-if="
            (item.rwzflx == 1 &&
              item.rwxl == '05' &&
              item.rwzt == 0 &&
              item.grrwzt != '2' &&
              item.grrwzt != '3' &&
              item.grrwzt != '34') ||
            item.rwzt == 1
          "
          @click.stop="onTransmit(item.id, item.rwzt)"
          >转发</van-button
        >
        <van-button
          type="danger"
          style="margin: 0.5vw"
          v-if="
            item.rwzflx == 2 &&
            item.rwxl == '05' &&
            ['0', '1'].includes(item.grrwzt)
          "
          @click.stop="onDown(item.id, item.rwzt)"
          >驳回</van-button
        >
      </div>
    </template>
  </van-swipe-cell>
</template>
<script setup>
import { defineProps, ref, defineEmits } from "vue";
import { getDictList, setDict } from "../utils/dict";
import router from "../router/index.js";
import { upGrzt, isMyTask } from "../api/rwzx.js";
import { hintToast } from "../utils/tools.js";
const props = defineProps({
  //是否只查看本人数据
  isMy: {
    type: Boolean,
    default: false,
  },
  item: Object,
  dict: {
    type: Object,
    default: { D_BZ_GRRWZT: [] },
  },
});
const emits = defineEmits(["click:Transmit", "click:onDown"]);
//点击转发按钮
function onTransmit(id, rezt) {
  emits("click:Transmit", { id, rezt });
}
//驳回按钮
function onDown(id, rezt) {
  emits("click:onDown", { id, rezt });
}
//查看任务详情
function onLookRw(ywid, id, rwxl, rwlx, rwzt, grrwzt, rwid) {
  if (props.isMy) {
    isMyTask(id).then((res) => {
      if (res) {
        //判断任务是暂停和关闭
        if (rwzt == 1) {
          hintToast("任务已关闭！！！");
          return;
        }
        if (rwzt == 2) {
          hintToast("任务已暂停！！！");
          return;
        }
        if (grrwzt === "0") {
          upGrzt({ rwid: rwid, rwzt: "1" });
        }
        //通知任务
        if (rwlx == 1) {
          router.push(`/rw/views/rwDetail?id=${id}`);
          return;
        }
        //值班任务
        if (rwxl == "04") {
          router.push("/yyzx/views/addZbbb");
          return;
        }
        //巡防任务
        if (rwxl == "03") {
          router.push("/yyzx/xfbb/addXfbb");
          return;
        }
        //指令任务
        if (rwxl == "05") {
          router.push(`/yyzx/zlzx/zlDetail?id=${ywid}`);
          return;
        }
        //实有人口任务
        if (rwxl == "01") {
          router.push(`/rw/views/syrkRwDetail?id=${rwid}`);
          return;
        }
      }
    });
  } else {
    //判断任务是暂停和关闭
    if (rwzt == 1) {
      hintToast("任务已关闭！！！");
      return;
    }
    if (rwzt == 2) {
      hintToast("任务已暂停！！！");
      return;
    }
    if (grrwzt === "0") {
      upGrzt({ rwid: rwid, rwzt: "1" });
    }
    //通知任务
    if (rwlx == 1) {
      router.push(`/rw/views/rwDetail?id=${rwid}`);
      return;
    }
    //值班任务
    if (rwxl == "04") {
      router.push("/yyzx/views/addZbbb");
      return;
    }
    //巡防任务
    if (rwxl == "03") {
      router.push("/yyzx/xfbb/addXfbb");
      return;
    }
    //指令任务
    if (rwxl == "05") {
      router.push(`/yyzx/zlzx/zlDetail?id=${ywid}`);
      return;
    }
  }
}
</script>
<style lang="scss" scoped>
@import "../assets/styles/mixin.scss";
.status_box {
  display: flex;
  justify-content: space-between;
  @include font_size($font_medium_s);
  @include font_color($font-color-theme);
}
.nr {
  line-height: 5.5vw;
}
.title {
  @include font_size($font_medium);
  font-weight: bold;
  // padding: 1vw 0;
}
.rw_but_box {
  display: flex;
  align-items: center;
  height: 100%;
  padding-left: 2vw;
}
::v-deep .van-tag {
  white-space: nowrap;
}
</style>