1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<template>
  <FYTable
    :data="data"
    :total-count="total"
    @search="onSearch"
    :extraHeight="tabsHeaderHeight"
    :defaultPageSize="10"
  >
    <template #options>
      <FYOptionLocation
        :disabled="true"
        :checkStrictly="false"
        :initValue="false"
        :allOption="false"
        :level="3"
        v-model:value="formSearch._locations"
      ></FYOptionLocation>
    </template>
    <!-- <template #buttons> </template> -->
    <template #table-column>
      <el-table-column
        fixed="left"
        sortable
        prop="ncNum"
        label="编号"
        width="100"
      >
      </el-table-column>
      <el-table-column
        fixed="left"
        prop="ncItemName"
        label="项目名称"
        :show-overflow-tooltip="true"
        width="400"
      >
      </el-table-column>
      <!-- <el-table-column prop="ncItemUnit" label="业主单位" width="130" /> -->
      <!-- <el-table-column prop="ncProvinceName" label="省" width="90" />
      <el-table-column prop="ncCityName" label="市" width="90" /> -->
      <!-- <el-table-column prop="ncDistrictName" label="区县" width="90" /> -->
      <!-- <el-table-column prop="townname" label="街道" width="110" /> -->
      <el-table-column
        prop="ncConstructionUnit"
        label="施工单位"
        min-width="100"
      />
      <el-table-column prop="ncPerson" label="申请人" width="110" />
      <el-table-column prop="ncApplyContent" label="申请内容" width="110" />
      <el-table-column prop="ncStartDate" label="申请时间" width="110">
        <template #default="{ row }">
          {{ $fm.formatYMD(row.ncCreateTime) }}
        </template>
      </el-table-column>
      <el-table-column prop="ncStartDate" label="工期开始" width="110">
        <template #default="{ row }">
          {{ $fm.formatYMD(row.ncStartDate) }}
        </template>
      </el-table-column>
      <el-table-column prop="ncEndDate" label="工期结束" width="110">
        <template #default="{ row }">
          {{ $fm.formatYMD(row.ncEndDate) }}
        </template>
      </el-table-column>
      <!-- <el-table-column prop="ncCreateTime" label="申请时间" width="110" >
        <template #default="{row}">
          {{ $fm.formatYMD(row.ncCreateTime) }}
        </template>
      </el-table-column> -->
      <el-table-column prop="ncUserId" label="匹配用户">
        <template #default="{ row }">
          <el-text
            :loading="row._loading"
            :type="row._user ? 'primary' : 'danger'"
            >{{ row._user ? row._user.realname : '未匹配' }}</el-text
          >
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="80">
        <template #default="{ row }">
          <el-button
            :disabled="row._loading"
            type="default"
            size="small"
            @click="itemEdit(row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </template>
  </FYTable>
  <el-dialog v-model="dialog" destroy-on-close>
    <CompInfoSearchFysp
      v-model="selectedSVUser"
      :area="area"
      :defaultText="defaultText"
      searchTextWidth="400px"
    />
    <template #footer>
      <el-button @click="dialog = false">取消</el-button>
      <el-button type="primary" @click="submit" :disabled="!selectedSVUser?.svUserId"
        >确定</el-button
      >
    </template>
  </el-dialog>
</template>
<script setup>
import { ref, inject, computed } from 'vue';
import nightConstructionApi from '@/api/fysp/nightConstructionApi';
import userApi from '@/api/fysp/userApi';
import CompInfoSearchFysp from '@/views/fysp/config/components/CompInfoSearchFysp.vue';
import { ElMessage } from 'element-plus';
 
const tabsHeaderHeight = inject('tabsHeaderHeight', 0);
 
const formSearch = ref({
  _locations: {
    pCode: '31',
    pName: '上海市',
    cCode: '3100',
    cName: '上海市',
    dCode: '310106',
    dName: '静安区'
  }
});
// 夜间施工记录及总数
const data = ref([]);
const total = ref(0);
 
// 夜间施工记录匹配弹窗
const dialog = ref(false);
const selectedSVUser = ref(null);
const selectedRow = ref(null);
const area = ref({
  provincecode: '31',
  provincename: '上海市',
  citycode: '3100',
  cityname: '上海市',
  districtcode: '310106',
  districtname: '静安区',
  scensetypeid: '1'
});
const defaultText = computed(() => {
  return selectedRow.value?.ncItemName || undefined;
});
 
function onSearch(page, callback) {
  return nightConstructionApi
    .fetchRecord({
      cityCode: '3100',
      districtCode: '310106',
      page: page.currentPage,
      perPage: page.pageSize
    })
    .then((res) => {
      if (res.success) {
        data.value = res.data;
        data.value.forEach((d) => {
          d._loading = true;
          if (d.ncUserId) {
            userApi
              .getUserById(d.ncUserId)
              .then((res1) => {
                d._user = res1;
              })
              .finally(() => {
                d._loading = false;
              });
          } else {
            d._loading = false;
          }
        });
        total.value = res.head.totalCount;
        callback();
      }
    });
}
 
function itemEdit(row) {
  selectedRow.value = row;
  selectedSVUser.value = {
    svUserId: row._user?.guid,
    svUserName: row._user?.realname,
    ...row._user
  };
  dialog.value = true;
}
 
function submit() {
  if (!selectedSVUser.value) {
    return ElMessage.error('请选择用户');
  }
  nightConstructionApi
    .updateRecord({
      recordId: selectedRow.value.ncId,
      userId: selectedSVUser.value.guid,
      sceneId: selectedSVUser.value.dguid
    })
    .then((res) => {
      if (res.success) {
        selectedRow.value.ncUserId = res.data.ncUserId;
        selectedRow.value.ncSceneId = res.data.ncSceneId;
        userApi
          .getUserById(selectedRow.value.ncUserId)
          .then((res1) => {
            selectedRow.value._user = res1;
          })
          .finally(() => {
            selectedRow.value._loading = false;
          });
      }
    })
    .finally(() => {
      dialog.value = false;
      selectedRow.value._user = selectedSVUser.value;
    });
}
</script>