periods.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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" />
  48. </template>
  49. <template #periodName="{ row }">
  50. <hc-table-input v-model="row.periodName" is-new :index-style="{ width: 60 }" :disabled="row.isLock === 1" />
  51. </template>
  52. <template #periodYear="{ row }">
  53. <el-select v-model="row.periodYear" placeholder="选择年份" filterable block :disabled="row.isLock === 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">
  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" @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 { 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. //渲染完成
  91. onMounted(() => {
  92. getTableData()
  93. })
  94. //搜索表单
  95. const searchForm = ref({
  96. current: 1, size: 10, total: 0,
  97. })
  98. //分页
  99. const pageChange = ({ current, size }) => {
  100. searchForm.value.current = current
  101. searchForm.value.size = size
  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:1,
  122. })
  123. tableLoading.value = false
  124. if (!error && code === 200) {
  125. tableData.value = getArrValue(data['records'])
  126. } else {
  127. tableData.value = []
  128. }
  129. }
  130. //计量期编辑
  131. const editVisible = ref(false)
  132. const editModalShow = ref(false)
  133. const editModalClick = () => {
  134. editModalShow.value = true
  135. getTableEditData()
  136. }
  137. //锁定
  138. const lockLoading = ref(false)
  139. const lockRow = async (row)=>{
  140. lockLoading.value = true
  141. const { error, code, msg } = await mainApi.locking({
  142. isLock:row?.isLock,
  143. id:row?.id,
  144. })
  145. //判断状态
  146. lockLoading.value = false
  147. if (!error && code === 200) {
  148. window?.$message?.success(msg)
  149. }
  150. getTableData()
  151. }
  152. //编辑的表格
  153. const tableEditColumn = [
  154. { key: 'periodNumber', name: '期号' },
  155. { key: 'periodName', name: '期名称' },
  156. { key: 'periodYear', name: '年份' },
  157. { key: 'periodMonth', name: '月份' },
  158. { key: 'formPrintDate', name: '报表打印日期' },
  159. { key: 'action', name: '操作', width: 80, align: 'center' },
  160. ]
  161. const tableEditData = ref([])
  162. const tableEditLoading = ref(false)
  163. const getTableEditData = async () => {
  164. tableEditLoading.value = true
  165. const { error, code, data } = await mainApi.allPeriod({
  166. ...searchForm.value,
  167. contractId:contractId.value,
  168. type:1,
  169. })
  170. tableEditLoading.value = false
  171. if (!error && code === 200) {
  172. tableEditData.value = getArrValue(data)
  173. if (tableEditData.value.length === 0) {
  174. tableEditData.value.push({ isNew:true })
  175. }
  176. } else {
  177. tableEditData.value = []
  178. }
  179. }
  180. const delRow = (row, index)=>{
  181. tableEditData.value.splice(index, 1)
  182. // if ( tableEditData.value.length === 0) {
  183. // tableEditData.value.push({})
  184. // }
  185. }
  186. const curIndex = ref(0)
  187. const hangeRow = ({ row })=>{
  188. tableEditData.value.forEach((ele, index)=>{
  189. if (row.id === ele.id) {
  190. curIndex.value = index
  191. }
  192. })
  193. }
  194. const addPreRow = ()=>{
  195. tableEditData.value.splice( curIndex.value, 0, { isNew:true })
  196. }
  197. const addNextRow = ()=>{
  198. tableEditData.value.splice( curIndex.value + 1, 0, { isNew:true })
  199. }
  200. const saveLoading = ref(false)
  201. const editModalSave = async () => {
  202. saveLoading.value = true
  203. const { error, code, msg } = await mainApi.edit({
  204. list: tableEditData.value,
  205. contractId:contractId.value,
  206. projectId:projectId.value,
  207. type:1,
  208. })
  209. //判断状态
  210. saveLoading.value = false
  211. if (!error && code === 200) {
  212. window?.$message?.success(msg)
  213. getTableData()
  214. editModalClose()
  215. }
  216. }
  217. const editModalClose = () => {
  218. editModalShow.value = false
  219. }
  220. </script>
  221. <style scoped lang="scss">
  222. </style>