<template>
  <div>
    <div class="gutter-example">
      <a-row :gutter="20">
        <a-col class="gutter-row" :span="8">
          <div class="gutter-box">
            <a-row type="flex" justify="space-between" style="flex:1; font-size:22px;font-weight: 500;color: #373737;">
              <a-col>设备数量汇总</a-col>
              <a-col style="color:#E4007F;">{{ record.totalDNumber }}</a-col>
            </a-row>
            <a-row type="flex" justify="space-between" :gutter="[0,16]" style="flex:1;font-size:18px;font-weight: 500;">
              <a-col style="width:130px;">
                <a-badge color="#E4007F"/>
                <span style="color:#E4007F;">在用 &nbsp; {{ record.dbNumber }}</span>
              </a-col>
              <a-col style="width:130px;">
                <a-badge color="#E4007F"/>
                <span style="color:#E4007F;">报废中 &nbsp; {{ record.bfNumber }}</span>

              </a-col>
            </a-row>
            <a-row type="flex" justify="space-between" :gutter="[0,16]" style="flex:1;font-size:18px;font-weight: 500;">
              <a-col style="width:130px;">
                <a-badge color="#E4007F"/>
                <span style="color:#E4007F;">已停机 &nbsp; {{ record.stopNumber }}</span>
              </a-col>
              <a-col style="width:130px;">
                <a-badge color="#E4007F"/>
                <span style="color:#E4007F;">已报废 &nbsp; {{ record.pdNumber }}</span>
              </a-col>
            </a-row>
          </div>
        </a-col>
        <a-col class="gutter-row" :span="8">
          <div class="gutter-box">
            <a-row type="flex" justify="space-between" style="flex:1; font-size:22px;font-weight: 500;color: #373737;">
              <a-col>设备维修</a-col>
              <a-col style="color:#E4007F;">{{ record.totalRepairNumber }}</a-col>
            </a-row>
            <a-row type="flex" justify="space-between" :gutter="[0,16]" style="flex:1;font-size:18px;font-weight: 500;">
              <a-col style="width:130px;">
                <a-badge color="#E4007F"/>
                <span style="color:#E4007F;">计划性 &nbsp; {{ record.planNumber }}</span>
              </a-col>
              <a-col style="width:130px;">
                <a-badge color="#E4007F"/>
                <span style="color:#E4007F;">非计划性 &nbsp; {{ record.notPlanNumber }}</span>

              </a-col>
            </a-row>
            <a-row type="flex" justify="space-between" :gutter="[0,16]" style="flex:1;font-size:18px;font-weight: 500;">
              <a-col style="width:130px;">
                <a-badge color="#E4007F"/>
                <span style="color:#E4007F;">其他 &nbsp; {{ record.otherNumber }}</span>
              </a-col>
              <a-col style="width:130px;">
                <a-badge color="#E4007F"/>
                <span style="color:#E4007F;">未设置 &nbsp; {{ record.noIdeaNumber }}</span>
              </a-col>
            </a-row>
          </div>
        </a-col>
        <a-col class="gutter-row" :span="8">
          <div style="display:flex;text-align:center;background:#fff;height: 170px;">
            <div style="width:48%;margin:auto;font-size:26px; line-height: 60px;">
              <div>设备总数</div>
              <div style="font-size:24px;color:#E4007F;">{{ record.totalNumber }}</div>
            </div>
            <div style="width: 1px;height: 70px;background: #999999;margin:auto;"></div>
            <div style="width:48%;margin:auto; font-size:26px;line-height: 60px;">
              <div>在用总数</div>
              <div style="font-size:24px;color:#E4007F;">{{ record.useNumber }}</div>
            </div>
          </div>
        </a-col>
      </a-row>
    </div>
    <div class="gutter-example">
      <a-row :gutter="[20,40]">
        <a-col class="gutter-row" :span="8">
          <div style="height: 471px;background: #FFFFFF;padding:24px">
            <div style="display:flex;justify-content: space-between;height: 18px; font-size:16px;color: #555555; ">
              <div>设备状态一览图</div>
              <!-- <div>设备总数100</div> -->
            </div>
            <div id="container-pie"></div>
          </div>
        </a-col>
        <a-col class="gutter-row" :span="12">
          <div style="height: 471px;background: #FFFFFF; padding:24px;">
            <div style="justify-content: space-between;height: 18px; font-size:16px;color: #555555; margin-bottom:25px;">
              <div style="width: 7px;background: #4D86ED;"></div>
              <div>近一周设备故障统计（截止到今天的一周）</div>
            </div>
            <div id="container-line"></div>
          </div>
        </a-col>
        <a-col class="gutter-row" :span="4">
          <div style="height: 471px;display:flex;flex-direction:column;justify-content: space-between">
            <div class="btn" style="background:linear-gradient(to right,#36B5FA,#26ECF5);">
              <my-icon type="icon-wuliaotiaobo" style="font-size:58px;"/>
              <span>调拨</span>
            </div>
            <div class="btn" style="background:linear-gradient(to right,#FF416D,#FF847F);">
              <my-icon type="icon-jijubaofeishenqing" style="font-size:58px;"/>
              <span>报废</span>
            </div>
            <div class="btn" style="background:linear-gradient(to right,#FB47D1,#F96EFE);">
              <my-icon type="icon-tingjiyuanyinweihu" style="font-size:58px;"/>
              <span>停机</span>
            </div>
            <div class="btn" style="background:linear-gradient(to right,#941FFF,#BC72FB);">
              <my-icon type="icon-PC" style="font-size:58px;"/>
              <span>盘点</span>
            </div>
          </div>
        </a-col>
      </a-row>
    </div>
    <div class="gutter-example">
      <a-row :gutter="20">
        <a-col class="gutter-row" :span="6">
          <div class="information">
            <div style="display:flex;justify-content: space-between;align-items: center; padding-bottom:20px;">
              <div style="display:flex; width:65px;height:17px;justify-content: space-between;align-items: center;">
                <div style=" width: 17px;height: 17px;background: #3462FD;border-radius: 50%;"></div>
                <div style="font-size: 18px;font-weight: 800;color: #333333;">资料</div>
              </div>
              <div >
                <a href="/operate/article/Article" target="_block"> 查看全部
                  <my-icon type="icon-xiangyou-copy" style="font-size:13px;"/></a>
              </div>
            </div>
            <div
              class="demo-infinite-container"
            >
              <a-list size="small" bordered :data-source="information">
                <a-list-item slot="renderItem" slot-scope="item,index" :class="{discolor: index%2}">
                  <a-list-item-meta @click="handleView(item)" >
                    <div slot="title" style="cursor:pointer">{{ item.title }}</div>
                  </a-list-item-meta>
                  <div>{{ item.updateTime }}</div>
                </a-list-item>
              </a-list>
            </div>
          </div>
        </a-col>
        <a-col class="gutter-row" :span="18">
          <div class="information">
            <s-table
              ref="table"
              size="small"
              bordered
              rowKey="id"
              :columns="columns"
              :data="loadData"
              :pageSize="10"
              :scroll="{ y: 190 }"
            >
              <span slot="action" slot-scope="record">
                <template>
                  <a @click="handle(record)">详情</a>
                  <a-divider v-if="record.status === 1" type="vertical" />
                  <a v-if="record.status === 1" @click="dealJumpDetail(record)">跳转</a>
                </template>
              </span>
              <span slot="content" slot-scope="text" v-html="text">
              </span>
            </s-table>
          </div>
        </a-col>
      </a-row>
    </div>
    <detail ref="detailModal"></detail>
  </div>
</template>

<script>
import Detail from '@/views/operate/article/modules/Detail.vue'
import { STable } from '@/components'
import { getArticlePage, fetchArticle } from '@/api/operate/article'
import { getWorkplaceBacklogUserPage } from '@/api/workplace/backlog'
import { Chart } from '@antv/g2'
import { fetchSbWorkplaceData } from '@/api/sb/info'
export default {
  name: 'SbInfoWorkplaceBacklog',
  components: {
    STable,
    Detail,
    Chart
  },
  data () {
    return {
      record: {},
      equipmentData: [
        { item: '事例一', count: 40, percent: 0.4 },
        { item: '事例二', count: 21, percent: 0.21 },
        { item: '事例三', count: 17, percent: 0.17 },
        { item: '事例四', count: 13, percent: 0.13 },
        { item: '事例五', count: 9, percent: 0.09 }
      ],
      lineData: [
        { week: '周一', value: 3 },
        { week: '周二', value: 4 },
        { week: '周三', value: 7.5 },
        { week: '周四', value: 5 },
        { week: '周五', value: 4.9 },
        { week: '周六', value: 6 },
        { week: '周日', value: 7 }
      ],
      allCount: 100,
      chartPie: null,
      chartLine: null,
      queryParam: {
        status: 1
      },
      information: [
        {
          name: '项目管理通知',
          time: '2022-4-7'
        },
        {
          name: '项目管理通知',
          time: '2022-4-7'
        },
        {
          name: '项目管理通知',
          time: '2022-4-7'
        },
        {
          name: '项目管理通知',
          time: '2022-4-7'
        }, {
          name: '项目管理通知',
          time: '2022-4-7'
        },
        {
          name: '项目管理通知',
          time: '2022-4-7'
        },
        {
          name: '项目管理通知',
          time: '2022-4-7'
        }
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          width: 50,
          customRender: (text, record, index) => {
            return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
          }
        },
        {
          title: '类型',
          dataIndex: 'type',
          align: 'center',
          width: 100,
          customRender: (text, record, index) => {
            return this.typeDict[text]
          }
        },
        {
          title: '详细类型',
          dataIndex: 'detailType',
          align: 'center',
          width: 140,
          customRender: (text, record, index) => {
            return this.typeDetailDict[text]
          }
        },
        {
          title: '内容',
          dataIndex: 'content',
          align: 'center',
          width: 460,
          ellipsis: true,
          scopedSlots: { customRender: 'content' }
        },
        {
          title: '时间',
          align: 'center',
          width: 160,
          dataIndex: 'createdTime'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
          width: 100,
          customRender: (text, record, index) => {
            return (text === 1 ? '未读' : '已读')
          }
        },
        {
          title: '操作',
          key: 'action',
          width: 150,
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        parameter = {
          ...parameter,
          ...this.queryParam
        }
        return getWorkplaceBacklogUserPage(parameter)
          .then(res => {
            return res.data
          })
      }
    }
  },
  created () {
    this.getDict()
    // this.getData()
  },
  mounted () {
    this.$nextTick(function () {
      this.getData()
    })
  },
  methods: {
    getDict () {
      this.typeDict = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.WORKPLACE_BACKLOG_TYPE)
      this.typeDetailDict = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.WORKPLACE_BACKLOG_DETAIL_TYPE)
    },
    getData () {
      console.log('测试开始1')
      fetchSbWorkplaceData().then(res => {
        this.getInfo(res.data)
      })
      getArticlePage({
        pageNum: 1,
        pageSize: 10,
        dataScope: {
          sortBy: 'desc',
          sortName: 'update_time'
        }
      }).then(res => {
        this.information = res.data.rows
      })
    },
    getInfo (data) {
      console.log('测试开始3')
      this.equipmentData = data.pieDataList
      this.lineData = data.lineDataList
      this.getPieCharts('container-pie', this.equipmentData)
      this.getLineCharts('container-line', this.lineData)
      this.record = data
    },
    handleView (record) {
      fetchArticle({ id: record.id }).then(res => {
        const modal = this.$refs.detailModal
        modal.base(res.data)
      })
    },
    getPieCharts (id, data) {
      this.chartPie && this.chartPie.destroy()// 防止点击搜索按钮新增一个
      this.chartPie = new Chart({
        container: id,
        autoFit: true,
        height: 400
      })
      this.chartPie.data(data)
      this.chartPie.scale('count', {
        nice: true
      })
      this.chartPie.coordinate('theta', {
        radius: 0.6,
        innerRadius: 0.5
      })
      this.chartPie.tooltip({
        showTitle: false,
        showMarkers: false,
        itemTpl: `<li class="g2-tooltip-list-item">
                     <span style="background-color:{color};" class="g2-tooltip-marker"></span>
                     {name}: {value}
                  </li>`
      })
      // 辅助文本
      this.chartPie
        .annotation()
      this.chartPie
        .interval()
        .adjust('stack')
        .position('percent')
        .color('item')
        .label('percent', (percent) => {
          return {
            content: (data) => {
              return `${data.item}: ${percent}`
            }
          }
        })
        .tooltip('item*count', (item, count) => {
          return {
            name: item,
            value: count
          }
        })
      // this.chartPie.interaction('element-active')
      this.chartPie.interaction('active-region')

      this.chartPie.render()
    },
    getLineCharts (id, data) {
      this.chartLine && this.chartLine.destroy()// 防止点击搜索按钮新增一个
      this.chartLine = new Chart({
        container: id,
        autoFit: true,
        height: 400
      })
      this.chartLine.data(data)
      this.chartLine.scale('维修次数', {
        nice: true
      })
      this.chartLine.tooltip({
        showMarkers: true,
        shared: true
      })
      this.chartLine.interval().position('week*value')
      this.chartLine.interaction('active-region')
      this.chartLine.legend({
        position: 'bottom'
      })
      this.chartLine.option('scrollbar', {
        type: 'horizontal'
      })
      this.chartLine.render()
    }
    /* getLineCharts (id, data) {
      this.chartLine = new Chart({
        container: id,
        autoFit: true,
        height: 300
      })

      this.chartLine.data(data)
      this.chartLine.scale({
        week: {
          range: [0, 1]
        },
        value: {
          min: 0,
          nice: true
        }
      })

      this.chartLine.tooltip({
        showCrosshairs: true, // 展示 Tooltip 辅助线
        shared: true
      })

      this.chartLine.axis('value', {
        label: {
          formatter: (val) => {
            return val
          }
        }
      })

      this.chartLine.area().position('week*value')
      this.chartLine.line().position('week*value')

      this.chartLine.render()
    } */
  }
}
</script>

<style scoped>
.gutter-example >>> .ant-row > div {
  background: transparent;
  border: 0;
  font-family: PingFang SC;
}
.gutter-box {
  display:flex;
  flex-direction:column;
  justify-content: space-between;
  background: #fff;
  padding: 18px 41px;
  height: 170px;
}
.btn{
height: 113px;
width: 100%;
color: #fff!important;
font-size:28px;
border-radius: 20px;
display:flex;
align-items: center;
justify-content: space-around;
}
.information{
  background: #fff;
  padding: 30px 12px;
  height: 500px;
  color:#666;
}
.discolor{
  background: #EFEFFB;
}
.demo-infinite-container {
  overflow: auto;
  height: 400px;
}
::-webkit-scrollbar { width: 0; height: 0; color: transparent; }
</style>
