periods.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <hc-new-card title="合同计量期">
  3. <template #extra>
  4. <el-button hc-btn type="primary" @click="editModalClick">
  5. <HcIcon name="add" />
  6. <span>编辑</span>
  7. </el-button>
  8. </template>
  9. <hc-table is-new :index-style="{ width: 60 }" :column="tableColumn" :datas="tableData" :loading="tableLoading" />
  10. <template #action>
  11. <hc-pages :pages="searchForm" @change="pageChange" />
  12. </template>
  13. <!-- 计量期编辑 -->
  14. <hc-new-dialog is-table widths="1200px" :show="editModalShow" title="计量期编辑" :loading="saveLoading" @save="editModalSave" @close="editModalClose">
  15. <hc-card-item>
  16. <template #header>
  17. <el-tooltip :visible="editVisible" effect="light" placement="bottom-start">
  18. <template #content>
  19. <div class="text-sm text-red">
  20. 1.日期不能为空<br>
  21. 2.同一期的结束日期不能小于开始日期<br>
  22. 3.连续的两期,上一期结束日期和下一期的开始日期必须连续<br>
  23. 如:期号1的结束日期为2018-1-25,则期号2的开始日期必须是2018-1-26 !<br>
  24. 4.已经存在数据的计量周期不能进行删除!<br>
  25. 5.已经存在上报数据的计量周期不能进行数据修改
  26. </div>
  27. </template>
  28. <el-button type="danger" @mouseenter="editVisible = true" @mouseleave="editVisible = false">
  29. <HcIcon name="question" />
  30. <span>编辑说明</span>
  31. </el-button>
  32. </el-tooltip>
  33. </template>
  34. <template #extra>
  35. <el-button type="primary" @click="addPreRow">
  36. <HcIcon name="page-separator" :line="false" />
  37. <span>插入上一行</span>
  38. </el-button>
  39. <el-button type="primary" @click="addNextRow">
  40. <HcIcon name="page-separator" :line="false" />
  41. <span>插入下一行</span>
  42. </el-button>
  43. </template>
  44. <hc-table is-new :index-style="{ width: 60 }" :column="tableEditColumn" :datas="tableEditData" :loading="tableEditLoading" is-current-row @row-click="hangeRow">
  45. <template #periodNumber="{ row }">
  46. <hc-table-input v-model="row.periodNumber" :disabled="row?.dataStatus === 1 || row?.citeStatus === 1" />
  47. </template>
  48. <template #periodYear="{ row }">
  49. <el-select v-model="row.periodYear" placeholder="选择年份" filterable block :disabled="row?.dataStatus === 1 || row?.citeStatus === 1">
  50. <el-option v-for="item in yearData" :key="item" :label="item" :value="item" />
  51. </el-select>
  52. </template>
  53. <template #periodMonth="{ row }">
  54. <el-select v-model="row.periodMonth" placeholder="选择月份" filterable block :disabled="row?.dataStatus === 1 || row?.citeStatus === 1">
  55. <el-option v-for="item in monthData" :key="item" :label="item" :value="item" />
  56. </el-select>
  57. </template>
  58. <template #startDate="{ row }">
  59. <el-date-picker v-model="row.startDate" class="block" format="YYYY-MM-DD" type="date" value-format="YYYY-MM-DD" :disabled="row?.dataStatus === 1 || row?.citeStatus === 1" @change="changeStart($event, row)" />
  60. </template>
  61. <template #endDate="{ row }">
  62. <el-date-picker v-model="row.endDate" class="block" format="YYYY-MM-DD" type="date" value-format="YYYY-MM-DD" :disabled="row?.dataStatus === 1 || row?.citeStatus === 1" @change="changeEnd($event, row)" />
  63. </template>
  64. <template #formPrintDate="{ row }">
  65. <el-date-picker v-model="row.formPrintDate" class="block" format="YYYY-MM-DD" type="date" value-format="YYYY-MM-DD" :disabled="row?.dataStatus === 1 || row?.citeStatus === 1" />
  66. </template>
  67. <template #action="{ row, index }">
  68. <el-link type="danger" :disabled="row?.dataStatus === 1 || row?.citeStatus === 1" @click="delRow(row, index)">删除</el-link>
  69. </template>
  70. </hc-table>
  71. </hc-card-item>
  72. </hc-new-dialog>
  73. </hc-new-card>
  74. </template>
  75. <script setup>
  76. import { onActivated, ref } from 'vue'
  77. import dayjs from 'dayjs'
  78. import { getArrValue, getMonthList, getYearList } from 'js-fast-way'
  79. import mainApi from '~api/debit-pay/admin/periods.js'
  80. import { useAppStore } from '~src/store'
  81. const useAppState = useAppStore()
  82. const contractId = ref(useAppState.getContractId)
  83. const projectId = ref(useAppState.getProjectId)
  84. defineOptions({
  85. name: 'DebitPayAdminPeriods',
  86. })
  87. //获取年月等相关日期数据
  88. const year = Number(dayjs().format('YYYY')) + 8
  89. const yearData = getYearList(year, 2010)
  90. const monthData = getMonthList()
  91. //渲染完成
  92. onActivated(() => {
  93. getTableData()
  94. })
  95. //搜索表单
  96. const searchForm = ref({ current: 1, size: 10, total: 0 })
  97. //分页
  98. const pageChange = ({ current, size }) => {
  99. searchForm.value.current = current
  100. searchForm.value.size = size
  101. getTableData()
  102. }
  103. //表格数据
  104. const tableLoading = ref(false)
  105. const tableColumn = ref([
  106. { key: 'periodNumber', name: '期号' },
  107. { key: 'periodYear', name: '年份' },
  108. { key: 'periodMonth', name: '月份' },
  109. { key: 'startDate', name: '开始日期' },
  110. { key: 'endDate', name: '结束日期' },
  111. { key: 'formPrintDate', name: '报表打印日期' },
  112. ])
  113. const tableData = ref([])
  114. const getTableData = async () => {
  115. tableLoading.value = true
  116. const { error, code, data } = await mainApi.getPage({
  117. ...searchForm.value,
  118. contractId:contractId.value,
  119. type:1,
  120. })
  121. tableLoading.value = false
  122. if (!error && code === 200) {
  123. tableData.value = getArrValue(data['records'])
  124. searchForm.value.total = data['total']
  125. } else {
  126. tableData.value = []
  127. }
  128. }
  129. //计量期编辑
  130. const editVisible = ref(false)
  131. const editModalShow = ref(false)
  132. const editModalClick = () => {
  133. editModalShow.value = true
  134. getTableEditData()
  135. }
  136. const curIndex = ref(0)
  137. const curRow = ref({})
  138. const hangeRow = ({ row })=>{
  139. tableEditData.value.forEach((ele, index)=>{
  140. if (row.id === ele.id) {
  141. curIndex.value = index
  142. curRow.value = ele
  143. }
  144. })
  145. }
  146. const addPreRow = ()=>{
  147. tableEditData.value.splice( curIndex.value, 0, { isNew:true })
  148. }
  149. const addNextRow = ()=>{
  150. if (!curRow.value?.endDate) {
  151. curRow.value.endDate = tableEditData.value[tableEditData.value.length - 1].endDate
  152. }
  153. const netxtDay = getNextDate(curRow.value?.endDate)
  154. tableEditData.value.splice( curIndex.value + 1, 0, { isNew:true, startDate:netxtDay })
  155. }
  156. //获取连续的时间
  157. const getNextDate = (data)=>{
  158. let dateString = data
  159. // 将日期字符串转换为 Date 对象
  160. let dateObject = new Date(dateString)
  161. // 将日期加一天
  162. dateObject.setDate(dateObject.getDate() + 1)
  163. // 获取新日期的年、月、日
  164. let year = dateObject.getFullYear()
  165. let month = dateObject.getMonth() + 1 // 注意:月份从0开始,所以要加1
  166. let day = dateObject.getDate()
  167. // 将年、月、日格式化为字符串
  168. let newDateString = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`
  169. // 输出结果
  170. console.log(newDateString)
  171. return newDateString
  172. }
  173. const delRow = (row, index)=>{
  174. console.log(index, 'index')
  175. tableEditData.value.splice(index, 1)
  176. // if ( tableEditData.value.length === 0) {
  177. // tableEditData.value.push({})
  178. // }
  179. }
  180. //编辑的表格
  181. const tableEditColumn = [
  182. { key: 'periodNumber', name: '期号' },
  183. { key: 'periodYear', name: '年份' },
  184. { key: 'periodMonth', name: '月份' },
  185. { key: 'startDate', name: '开始日期' },
  186. { key: 'endDate', name: '结束日期' },
  187. { key: 'formPrintDate', name: '报表打印日期' },
  188. { key: 'action', name: '操作', width: 80, align: 'center' },
  189. ]
  190. const tableEditData = ref([])
  191. const tableEditLoading = ref(false)
  192. const getTableEditData = async () => {
  193. tableEditLoading.value = true
  194. const { error, code, data } = await mainApi.allPeriod({
  195. ...searchForm.value,
  196. contractId:contractId.value,
  197. type:1,
  198. })
  199. tableEditLoading.value = false
  200. if (!error && code === 200) {
  201. tableEditData.value = getArrValue(data)
  202. curIndex.value = tableEditData.value.length
  203. if (tableEditData.value.length === 0) {
  204. tableEditData.value.push({ isNew:true })
  205. }
  206. } else {
  207. tableEditData.value = []
  208. }
  209. }
  210. const saveLoading = ref(false)
  211. const editModalSave = async () => {
  212. saveLoading.value = true
  213. tableEditData.value.forEach(ele => {
  214. ele.contractId = contractId.value
  215. ele.projectId = projectId.value
  216. })
  217. const { error, code, msg } = await mainApi.edit({
  218. list: tableEditData.value,
  219. contractId:contractId.value,
  220. projectId:projectId.value,
  221. type:1,
  222. })
  223. //判断状态
  224. saveLoading.value = false
  225. if (!error && code === 200) {
  226. window?.$message?.success(msg)
  227. getTableData()
  228. editModalClose()
  229. }
  230. }
  231. const editModalClose = () => {
  232. editModalShow.value = false
  233. }
  234. const changeStart = (val, row)=>{
  235. if (val > row.endDate) {
  236. window.$message.warning('开始时间不能晚于结束时间')
  237. row.startDate = ''
  238. }
  239. }
  240. const changeEnd = (val, row)=>{
  241. if (val < row.startDate) {
  242. window.$message.warning('结束时间不能早于开始时间')
  243. row.endDate = ''
  244. }
  245. }
  246. </script>
  247. <style scoped lang="scss">
  248. </style>