periods.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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.approveStatus === 0 || !row.approveStatus)" />
  48. </template>
  49. <template #payNumber="{ row }">
  50. <hc-table-input v-model="row.payNumber" is-new :index-style="{ width: 60 }" disabled />
  51. </template>
  52. <template #periodName="{ row }">
  53. <hc-table-input v-model="row.periodName" is-new :index-style="{ width: 60 }" :disabled="row.isLock === 1 || !(row.approveStatus === 0 || !row.approveStatus)" />
  54. </template>
  55. <template #periodYear="{ row }">
  56. <el-select v-model="row.periodYear" placeholder="选择年份" filterable block :disabled="row.isLock === 1 || !(row.approveStatus === 0 || !row.approveStatus)">
  57. <el-option v-for="item in yearData" :key="item" :label="item" :value="item" />
  58. </el-select>
  59. </template>
  60. <template #periodMonth="{ row }">
  61. <el-select v-model="row.periodMonth" placeholder="选择月份" filterable block :disabled="row.isLock === 1 || !(row.approveStatus === 0 || !row.approveStatus)">
  62. <el-option v-for="item in monthData" :key="item" :label="item" :value="item" />
  63. </el-select>
  64. </template>
  65. <template #formPrintDate="{ row }">
  66. <el-date-picker v-model="row.formPrintDate" class="block" format="YYYY-MM-DD" type="date" value-format="YYYY-MM-DD" :disabled="row.isLock === 1 || !(row.approveStatus === 0 || !row.approveStatus)" />
  67. </template>
  68. <template #action="{ row, index }">
  69. <el-button plain size="small" type="danger" :disabled="row?.isLock === 1 || row?.citeStatus === 1 " @click="delRow(row, index)">删除</el-button>
  70. </template>
  71. </hc-table>
  72. </hc-card-item>
  73. </hc-new-dialog>
  74. </hc-new-card>
  75. </template>
  76. <script setup>
  77. import { onActivated, onMounted, ref } from 'vue'
  78. import dayjs from 'dayjs'
  79. import { getArrValue, getMonthList, getYearList } from 'js-fast-way'
  80. import mainApi from '~api/debit-pay/material/periods.js'
  81. import { useAppStore } from '~src/store'
  82. const useAppState = useAppStore()
  83. const contractId = ref(useAppState.getContractId)
  84. const projectId = ref(useAppState.getProjectId)
  85. defineOptions({
  86. name: 'DebitPayMaterialPeriods',
  87. })
  88. //获取年月等相关日期数据
  89. const year = Number(dayjs().format('YYYY')) + 8
  90. const yearData = getYearList(year, 2018)
  91. const monthData = getMonthList()
  92. //渲染完成
  93. onActivated(() => {
  94. getTableData()
  95. })
  96. //搜索表单
  97. const searchForm = ref({
  98. current: 1, size: 20, total: 0,
  99. })
  100. //分页
  101. const pageChange = ({ current, size }) => {
  102. searchForm.value.current = current
  103. searchForm.value.size = size
  104. getTableData()
  105. }
  106. //表格数据
  107. const tableLoading = ref(false)
  108. const tableColumn = ref([
  109. { key: 'periodNumber', name: '期号' },
  110. { key: 'payNumber', name: '支付期编号' },
  111. { key: 'periodName', name: '期名称' },
  112. { key: 'periodYear', name: '年份' },
  113. { key: 'periodMonth', name: '月份' },
  114. { key: 'formPrintDate', name: '报表打印日期' },
  115. { key: 'action', name: '操作', width: 80 },
  116. ])
  117. const tableData = ref([])
  118. const getTableData = async () => {
  119. tableLoading.value = true
  120. const { error, code, data } = await mainApi.getPage({
  121. ...searchForm.value,
  122. contractId:contractId.value,
  123. type:1,
  124. })
  125. tableLoading.value = false
  126. if (!error && code === 200) {
  127. tableData.value = getArrValue(data['records'])
  128. searchForm.value.total = data['total']
  129. } else {
  130. tableData.value = []
  131. searchForm.value.total = 0
  132. }
  133. }
  134. //计量期编辑
  135. const editVisible = ref(false)
  136. const editModalShow = ref(false)
  137. const editModalClick = () => {
  138. editModalShow.value = true
  139. getTableEditData()
  140. }
  141. //锁定
  142. const lockLoading = ref(false)
  143. const lockRow = async (row)=>{
  144. lockLoading.value = true
  145. const { error, code, msg } = await mainApi.locking({
  146. isLock:row?.isLock,
  147. id:row?.id,
  148. })
  149. //判断状态
  150. lockLoading.value = false
  151. if (!error && code === 200) {
  152. window?.$message?.success(msg)
  153. } else {
  154. window.$message.error(msg ?? '操作失败')
  155. }
  156. getTableData()
  157. }
  158. //编辑的表格
  159. const tableEditColumn = [
  160. { key: 'periodNumber', name: '期号' },
  161. { key: 'payNumber', name: '支付期编号' },
  162. { key: 'periodName', name: '期名称' },
  163. { key: 'periodYear', name: '年份' },
  164. { key: 'periodMonth', name: '月份' },
  165. { key: 'formPrintDate', name: '报表打印日期' },
  166. { key: 'action', name: '操作', width: 80, align: 'center' },
  167. ]
  168. const tableEditData = ref([])
  169. const tableEditLoading = ref(false)
  170. const getTableEditData = async () => {
  171. tableEditLoading.value = true
  172. const { error, code, data } = await mainApi.allPeriod({
  173. ...searchForm.value,
  174. contractId:contractId.value,
  175. type:1,
  176. })
  177. tableEditLoading.value = false
  178. if (!error && code === 200) {
  179. tableEditData.value = getArrValue(data)
  180. curIndex.value = tableEditData.value.length
  181. if (tableEditData.value.length === 0) {
  182. tableEditData.value.push({ isNew:true })
  183. }
  184. } else {
  185. tableEditData.value = []
  186. }
  187. }
  188. const delRow = (row, index)=>{
  189. tableEditData.value.splice(index, 1)
  190. // if ( tableEditData.value.length === 0) {
  191. // tableEditData.value.push({})
  192. // }
  193. }
  194. const curIndex = ref(0)
  195. const hangeRow = ({ row })=>{
  196. tableEditData.value.forEach((ele, index)=>{
  197. if (row.id === ele.id) {
  198. curIndex.value = index
  199. }
  200. })
  201. }
  202. const addPreRow = ()=>{
  203. tableEditData.value.splice( curIndex.value, 0, { isNew:true })
  204. }
  205. const addNextRow = ()=>{
  206. tableEditData.value.splice( curIndex.value + 1, 0, { isNew:true })
  207. }
  208. const saveLoading = ref(false)
  209. const editModalSave = async () => {
  210. saveLoading.value = true
  211. const { error, code, msg } = await mainApi.edit({
  212. list: tableEditData.value,
  213. contractId:contractId.value,
  214. projectId:projectId.value,
  215. type:1,
  216. })
  217. //判断状态
  218. saveLoading.value = false
  219. if (!error && code === 200) {
  220. window?.$message?.success(msg)
  221. getTableData()
  222. editModalClose()
  223. } else {
  224. window.$message.error(msg ?? '操作失败')
  225. }
  226. }
  227. const editModalClose = () => {
  228. editModalShow.value = false
  229. }
  230. </script>
  231. <style scoped lang="scss">
  232. </style>