uploadModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="reply" ref = "replyModal">
  3. <a-modal
  4. title="生成工资单"
  5. width="30%"
  6. :visible="visible"
  7. :confirmLoading="loading"
  8. :getContainer ='()=>$refs.replyModal'
  9. @cancel="handleCancel"
  10. destroyOnClose
  11. :closable="!loading"
  12. :maskClosable="!loading"
  13. >
  14. <template #footer>
  15. <a-button @click="handleCancel" :loading = "loading">取消</a-button>
  16. <a-button @click="handleOk" type="primary" style="margin-left: 8px;" :loading = "loading">确认</a-button>
  17. </template>
  18. <div class="table-page-search-wrapper">
  19. <a-form-model layout="inline" ref="form" :model="formState" :rules="validatorRules">
  20. <a-row :gutter="24">
  21. <a-col :md="24">
  22. <a-form-model-item label="类型" prop="type" :labelCol="{offset: 2}">
  23. <a-select v-model="formState.type" @change="changeType">
  24. <a-select-option value="加班工资单">加班工资单</a-select-option>
  25. <a-select-option value="年休工资单">年休工资单</a-select-option>
  26. <a-select-option value="月度工资单">月度工资单</a-select-option>
  27. </a-select>
  28. </a-form-model-item>
  29. </a-col>
  30. <a-col :md="24" >
  31. <a-form-model-item label="计算月份" prop="yearWithMonth" :labelCol="{offset:1}" v-if="formState.type=='加班工资单'||formState.type=='月度工资单'">
  32. <a-month-picker placeholder="请选择" v-model="formState.yearWithMonth" style="width:100% !important"/>
  33. </a-form-model-item>
  34. </a-col>
  35. <a-col :md="24" >
  36. <a-form-model-item label="计算年份" prop="yearWith" :labelCol="{offset: 1}" v-if="formState.type=='年休工资单'">
  37. <a-date-picker placeholder="请选择" :open="isopen" mode="year" v-model="formState.yearWith" format="YYYY" style="width:100% !important" @openChange="changeopen" @panelChange="handlePanelChange1"/>
  38. </a-form-model-item>
  39. </a-col>
  40. <a-col :md="24" >
  41. <a-form-model-item label="加班月份区间" prop="DateTime" v-if="formState.type=='加班工资单'">
  42. <a-range-picker
  43. style="width: 100% !important"
  44. v-model="formState.DateTime"
  45. format="YYYY-MM"
  46. valueFormat="YYYY-MM"
  47. :mode="mode2"
  48. :open="open"
  49. :placeholder="['开始时间', '结束时间']"
  50. @panelChange="handlePanelChange2"
  51. @openChange="onDateChange"
  52. @change="changeData"
  53. />
  54. </a-form-model-item>
  55. </a-col>
  56. </a-row>
  57. </a-form-model>
  58. </div>
  59. </a-modal>
  60. <a-modal
  61. width="30%"
  62. title="请确认"
  63. :visible="visibleOk"
  64. @ok="handleOkPayroll"
  65. @cancel="handleCancelPayroll"
  66. :getContainer ='()=>$refs.replyModal'
  67. >
  68. <p>{{ ModalText }}</p>
  69. </a-modal>
  70. </div>
  71. </template>
  72. <script>
  73. import moment from 'moment'
  74. import pick from 'lodash.pick'
  75. import { FormTypes } from '@/utils/JEditableTableUtil'
  76. import { putAction,getAction,postAction,downFile } from '@/api/manage'
  77. export default {
  78. name: 'uploadModal',
  79. components: {
  80. moment,
  81. },
  82. data() {
  83. return {
  84. formState:{
  85. type:'月度工资单',
  86. yearWithMonth:moment().subtract(1, 'months'),
  87. DateTime:[],
  88. yearWith:''
  89. },
  90. open: false,
  91. isopen:false,
  92. dataSource: [{}],
  93. mode2: ['month', 'month'],
  94. visible:false,
  95. visibleOk:false,
  96. ModalText:'',
  97. loading:false,
  98. validatorRules: {
  99. type: [{required: true, message: '请选择!' }],
  100. yearWithMonth: [{required: true, message: '请选择!' }],
  101. DateTime: [{required: true, message: '请选择!',trigger: 'change' }],
  102. yearWith: [{required: true, message: '请选择!',trigger: 'change' }],
  103. },
  104. }
  105. },
  106. created(){
  107. },
  108. watch: {
  109. },
  110. methods: {
  111. handleCancel(){
  112. this.visible = false
  113. this.formState={
  114. type:'月度工资单',
  115. yearWithMonth:moment().subtract(1, 'months'),
  116. DateTime:[],
  117. yearWith:''
  118. }
  119. // this.DateTime = []
  120. },
  121. changeType(data){
  122. if(data=='月度工资单'){
  123. this.formState={
  124. type:'月度工资单',
  125. yearWithMonth:moment().subtract(1, 'months')
  126. }
  127. }else if(data=='加班工资单'){
  128. this.formState={
  129. type:'加班工资单',
  130. yearWithMonth:moment().subtract(1, 'months'),
  131. DateTime:[]
  132. }
  133. }else if(data=='年休工资单'){
  134. this.formState={
  135. type:'年休工资单',
  136. yearWith:moment().subtract(1, 'year')
  137. }
  138. }
  139. },
  140. handleOk(){
  141. this.$refs.form.validate((valid,err) => {
  142. if (valid) {
  143. if(this.formState.type=='加班工资单'){
  144. this.formState.beginMonth = moment(this.formState.DateTime[0]).format('YYYY-MM')
  145. this.formState.endMonth = moment(this.formState.DateTime[1]).format('YYYY-MM')
  146. delete this.formState.DateTime
  147. }
  148. if(this.formState.type=='加班工资单'||this.formState.type=='月度工资单'){
  149. this.formState.yearWithMonth = moment(this.formState.yearWithMonth).format('YYYY-MM')
  150. }
  151. if(this.formState.type=='年休工资单'){
  152. this.formState.yearWith = moment(this.formState.yearWith).format('YYYY')
  153. }
  154. this.loading = true
  155. let that = this;
  156. postAction('/salary/salaryManagement/generatePayrollBefore',this.formState).then((res) => {
  157. if (res.success) {
  158. this.generatePayroll(this.formState)
  159. } else {
  160. this.ModalText = res.message
  161. this.visibleOk = true
  162. }
  163. }).finally(() => {
  164. this.loading = false
  165. })
  166. }
  167. })
  168. },
  169. handleOkPayroll(){
  170. this.ModalText = ''
  171. this.visibleOk = false
  172. this.generatePayroll(this.formState)
  173. },
  174. handleCancelPayroll(){
  175. this.ModalText = ''
  176. this.visibleOk = false
  177. },
  178. generatePayroll(data){
  179. this.loading = true
  180. let that = this;
  181. postAction('/salary/salaryManagement/generatePayroll',data).then((res) => {
  182. if (res.success) {
  183. if(res.data&&res.data.ZZ){
  184. that.handleDownload(res.data.ZZ,that.formState.type,"正织",data);
  185. }
  186. if(res.data&&res.data.MFY){
  187. that.handleDownload(res.data.MFY,that.formState.type,"马菲羊",data);
  188. }
  189. if(res.data&&res.data.NBSY){
  190. that.handleDownload(res.data.NBSY,that.formState.type,"宁波森语",data);
  191. }
  192. this.$message.success(res.message);
  193. this.handleCancel()
  194. this.$emit('ok')
  195. } else {
  196. this.$message.error(res.message);
  197. }
  198. }).finally(() => {
  199. this.loading = false
  200. })
  201. },
  202. handleDownload(id,type,name,datas){
  203. downFile('/salary/salaryManagement/exportXls2',{id:id,type:type}).then(data => {
  204. this.$message.success(name+type+"数据导出中,请稍等");
  205. if (!data) {
  206. this.$message.warning('文件下载失败')
  207. return
  208. }
  209. let datePar = "";
  210. if(type == '年休工资单'){
  211. datePar = datas.yearWith;
  212. // datePar = moment(data.yearWith).format('YYYY');
  213. }else{
  214. datePar = datas.yearWithMonth;
  215. // datePar = moment(data.yearWithMonth).format('YYYY-MM');
  216. }
  217. if (typeof window.navigator.msSaveBlob !== 'undefined') {
  218. window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), name+datePar+type + '.xls')
  219. } else {
  220. let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
  221. let link = document.createElement('a')
  222. link.style.display = 'none'
  223. link.href = url
  224. link.setAttribute('download', name+datePar+type+'.xls')
  225. document.body.appendChild(link)
  226. link.click()
  227. document.body.removeChild(link) // 下载完成移除元素
  228. window.URL.revokeObjectURL(url) // 释放掉blob对象
  229. }
  230. })
  231. },
  232. changeData(value){
  233. this.formState.DateTime = value
  234. },
  235. onDateChange(status) {
  236. if(status){
  237. this.open = true;
  238. }else{
  239. this.open = false
  240. }
  241. },
  242. handlePanelChange2(value,mode){
  243. if (this.formState.DateTime[1] && this.formState.DateTime[1]._d != value[1]._d) {
  244. this.open = false;
  245. this.$refs.form.clearValidate();
  246. }
  247. this.formState.DateTime = value
  248. this.mode2 = [mode[0] === 'date' ? 'month' : mode[0], mode[1] === 'date' ? 'month' : mode[1]];
  249. },
  250. handlePanelChange1(value){
  251. this.isopen = false
  252. this.formState.yearWith =value
  253. },
  254. changeopen(status){
  255. if(status){
  256. this.isopen = true
  257. }
  258. }
  259. }
  260. }
  261. </script>
  262. <style scoped lang="less">
  263. /deep/ .nresume .ant-input{
  264. height: 100px !important;
  265. }
  266. /deep/ .ant-select{
  267. width: 100%;
  268. }
  269. .form-table-heard:before {
  270. content: '*';
  271. color: red;
  272. }
  273. /deep/ .ant-calendar-picker{
  274. width: 113px !important;
  275. }
  276. /deep/.ant-modal-root>.ant-modal-wrap>.ant-modal {
  277. min-width: 0 !important;
  278. }
  279. </style>