period.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <hc-new-card title="开工预付款计量期">
  3. <template #extra>
  4. <el-button hc-btn type="primary" @click="editModalClick">
  5. <HcIcon name="edit" />
  6. <span>编辑</span>
  7. </el-button>
  8. </template>
  9. <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" is-new :index-style="{ width: 60 }">
  10. <template #action="{ row }">
  11. <el-link v-if="row?.isLock === 0" type="danger" @click="lockRow(row)">锁定</el-link>
  12. <el-link v-if="row?.isLock === 1" type="danger" @click="lockRow(row)">解锁</el-link>
  13. </template>
  14. </hc-table>
  15. <template #action>
  16. <hc-pages :pages="searchForm" @change="pageChange" />
  17. </template>
  18. <!-- 编辑修改 -->
  19. <hc-new-dialog is-table widths="1200px" :show="editModalShow" title="开工预付款计量期编辑" :loading="saveLoading" @save="editModalSave" @close="editModalClose">
  20. <hc-card-item>
  21. <template #header>
  22. <el-tooltip :visible="editVisible" effect="light" placement="bottom-start">
  23. <template #content>
  24. <div class="text-sm text-red">
  25. 1.日期不能为空<br>
  26. 2.已经存在数据或者被锁定的计量期不能删除数据
  27. </div>
  28. </template>
  29. <el-button type="danger" @mouseenter="editVisible = true" @mouseleave="editVisible = false">
  30. <HcIcon name="question" />
  31. <span>编辑说明</span>
  32. </el-button>
  33. </el-tooltip>
  34. </template>
  35. <template #extra>
  36. <el-button type="primary" @click="addPreRow">
  37. <HcIcon name="page-separator" :line="false" />
  38. <span>插入上一行</span>
  39. </el-button>
  40. <el-button type="primary" @click="addNextRow">
  41. <HcIcon name="page-separator" :line="false" />
  42. <span>插入下一行</span>
  43. </el-button>
  44. </template>
  45. <hc-table :column="tableEditColumn" :datas="tableEditData" is-new is-current-row :index-style="{ width: 60 }" :loading="tableEditLoading" @row-click="hangeRow">
  46. <template #periodNumber="{ row }">
  47. <hc-table-input v-model="row.periodNumber" is-new :index-style="{ width: 60 }" :disabled="row.isLock === 1 || row?.citeStatus === 1" />
  48. </template>
  49. <template #periodName="{ row }">
  50. <hc-table-input v-model="row.periodName" is-new :index-style="{ width: 60 }" :disabled="row.isLock === 1 || row?.citeStatus === 1" />
  51. </template>
  52. <template #periodYear="{ row }">
  53. <el-select v-model="row.periodYear" placeholder="选择年份" filterable block :disabled="row.isLock === 1 || row?.citeStatus === 1">
  54. <el-option v-for="item in yearData" :key="item" :label="item" :value="item" />
  55. </el-select>
  56. </template>
  57. <template #periodMonth="{ row }">
  58. <el-select v-model="row.periodMonth" placeholder="选择月份" filterable block :disabled="row.isLock === 1 || row?.citeStatus === 1">
  59. <el-option v-for="item in monthData" :key="item" :label="item" :value="item" />
  60. </el-select>
  61. </template>
  62. <template #formPrintDate="{ row }">
  63. <el-date-picker v-model="row.formPrintDate" class="block" format="YYYY-MM-DD" type="date" value-format="YYYY-MM-DD" :disabled="row.isLock === 1" />
  64. </template>
  65. <template #action="{ row, index }">
  66. <el-button plain size="small" type="danger" :disabled="row?.isLock === 1 || row?.citeStatus === 1 " @click="delRow(row, index)">删除</el-button>
  67. </template>
  68. </hc-table>
  69. </hc-card-item>
  70. </hc-new-dialog>
  71. </hc-new-card>
  72. </template>
  73. <script setup>
  74. import { onActivated, onMounted, ref } from 'vue'
  75. import dayjs from 'dayjs'
  76. import { getArrValue, getMonthList, getYearList } from 'js-fast-way'
  77. import mainApi from '~api/debit-pay/material/periods.js'
  78. import { useAppStore } from '~src/store'
  79. const useAppState = useAppStore()
  80. const contractId = ref(useAppState.getContractId)
  81. const projectId = ref(useAppState.getProjectId)
  82. defineOptions({
  83. name: 'DebitPayMaterialPeriods',
  84. })
  85. //获取年月等相关日期数据
  86. const year = Number(dayjs().format('YYYY')) + 8
  87. const yearData = getYearList(year, 2010)
  88. const monthData = getMonthList()
  89. //渲染完成
  90. onActivated(() => {
  91. getTableData()
  92. })
  93. //搜索表单
  94. const searchForm = ref({
  95. current: 1, size: 10, total: 0,
  96. })
  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: 'periodName', name: '期名称' },
  108. { key: 'periodYear', name: '年份' },
  109. { key: 'periodMonth', name: '月份' },
  110. { key: 'formPrintDate', name: '报表打印日期' },
  111. { key: 'action', name: '操作', width: 80 },
  112. ])
  113. const tableData = ref([
  114. { key1: '1111' },
  115. ])
  116. const getTableData = async () => {
  117. tableLoading.value = true
  118. const { error, code, data } = await mainApi.getPage({
  119. ...searchForm.value,
  120. contractId:contractId.value,
  121. type:2,
  122. })
  123. tableLoading.value = false
  124. if (!error && code === 200) {
  125. tableData.value = getArrValue(data['records'])
  126. searchForm.value.total = data['total']
  127. } else {
  128. tableData.value = []
  129. searchForm.value.total = 0
  130. }
  131. }
  132. //计量期编辑
  133. const editVisible = ref(false)
  134. const editModalShow = ref(false)
  135. const editModalClick = () => {
  136. editModalShow.value = true
  137. getTableEditData()
  138. }
  139. //锁定
  140. const lockLoading = ref(false)
  141. const lockRow = async (row)=>{
  142. lockLoading.value = true
  143. const { error, code, msg } = await mainApi.locking({
  144. isLock:row?.isLock,
  145. id:row?.id,
  146. })
  147. //判断状态
  148. lockLoading.value = false
  149. if (!error && code === 200) {
  150. window?.$message?.success(msg)
  151. }
  152. getTableData()
  153. }
  154. //编辑的表格
  155. const tableEditColumn = [
  156. { key: 'periodNumber', name: '期号' },
  157. { key: 'periodName', name: '期名称' },
  158. { key: 'periodYear', name: '年份' },
  159. { key: 'periodMonth', name: '月份' },
  160. { key: 'formPrintDate', name: '报表打印日期' },
  161. { key: 'action', name: '操作', width: 80, align: 'center' },
  162. ]
  163. const tableEditData = ref([])
  164. const tableEditLoading = ref(false)
  165. const getTableEditData = async () => {
  166. tableEditLoading.value = true
  167. const { error, code, data } = await mainApi.allPeriod({
  168. ...searchForm.value,
  169. contractId:contractId.value,
  170. type:2,
  171. })
  172. tableEditLoading.value = false
  173. if (!error && code === 200) {
  174. tableEditData.value = getArrValue(data)
  175. if (tableEditData.value.length === 0) {
  176. tableEditData.value.push({ isNew:true })
  177. }
  178. } else {
  179. tableEditData.value = []
  180. }
  181. }
  182. const delRow = (row, index)=>{
  183. tableEditData.value.splice(index, 1)
  184. // if ( tableEditData.value.length === 0) {
  185. // tableEditData.value.push({})
  186. // }
  187. }
  188. const curIndex = ref(0)
  189. const hangeRow = ({ row })=>{
  190. tableEditData.value.forEach((ele, index)=>{
  191. if (row.id === ele.id) {
  192. curIndex.value = index
  193. }
  194. })
  195. }
  196. const addPreRow = ()=>{
  197. tableEditData.value.splice( curIndex.value, 0, { isNew:true })
  198. }
  199. const addNextRow = ()=>{
  200. tableEditData.value.splice( curIndex.value + 1, 0, { isNew:true })
  201. }
  202. const saveLoading = ref(false)
  203. const editModalSave = async () => {
  204. saveLoading.value = true
  205. const { error, code, msg } = await mainApi.edit({
  206. list: tableEditData.value,
  207. contractId:contractId.value,
  208. projectId:projectId.value,
  209. type:2,
  210. })
  211. //判断状态
  212. saveLoading.value = false
  213. if (!error && code === 200) {
  214. window?.$message?.success(msg)
  215. getTableData()
  216. editModalClose()
  217. }
  218. }
  219. const editModalClose = () => {
  220. editModalShow.value = false
  221. }
  222. </script>
  223. <style scoped lang="scss">
  224. </style>