uploadModal.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. <template #footer>
  69. <a-button @click="handleCancelPayroll" :loading = "loading1">取消</a-button>
  70. <a-button @click="handleOkPayroll" type="primary" style="margin-left: 8px;" :loading = "loading1">确认</a-button>
  71. </template>
  72. <p>{{ ModalText }}</p>
  73. </a-modal>
  74. </div>
  75. </template>
  76. <script>
  77. import moment from 'moment'
  78. import pick from 'lodash.pick'
  79. import { FormTypes } from '@/utils/JEditableTableUtil'
  80. import { putAction,getAction,postAction,downFile } from '@/api/manage'
  81. export default {
  82. name: 'uploadModal',
  83. components: {
  84. moment,
  85. },
  86. data() {
  87. return {
  88. formState:{
  89. type:'月度工资单',
  90. yearWithMonth:moment().subtract(1, 'months'),
  91. DateTime:[],
  92. yearWith:''
  93. },
  94. open: false,
  95. isopen:false,
  96. dataSource: [{}],
  97. mode2: ['month', 'month'],
  98. visible:false,
  99. visibleOk:false,
  100. ModalText:'',
  101. loading:false,
  102. loading1:false,
  103. validatorRules: {
  104. type: [{required: true, message: '请选择!' }],
  105. yearWithMonth: [{required: true, message: '请选择!' }],
  106. DateTime: [{required: true, message: '请选择!',trigger: 'change' }],
  107. yearWith: [{required: true, message: '请选择!',trigger: 'change' }],
  108. },
  109. }
  110. },
  111. created(){
  112. },
  113. watch: {
  114. },
  115. methods: {
  116. handleCancel(){
  117. this.visible = false
  118. this.formState={
  119. type:'月度工资单',
  120. yearWithMonth:moment().subtract(1, 'months'),
  121. DateTime:[],
  122. yearWith:''
  123. }
  124. // this.DateTime = []
  125. },
  126. changeType(data){
  127. if(data=='月度工资单'){
  128. this.formState={
  129. type:'月度工资单',
  130. yearWithMonth:moment().subtract(1, 'months')
  131. }
  132. }else if(data=='加班工资单'){
  133. this.formState={
  134. type:'加班工资单',
  135. yearWithMonth:moment().subtract(1, 'months'),
  136. DateTime:[]
  137. }
  138. }else if(data=='年休工资单'){
  139. this.formState={
  140. type:'年休工资单',
  141. yearWith:moment().subtract(1, 'year')
  142. }
  143. }
  144. },
  145. handleOk(){
  146. this.$refs.form.validate((valid,err) => {
  147. if (valid) {
  148. if(this.formState.type=='加班工资单'){
  149. this.formState.beginMonth = moment(this.formState.DateTime[0]).format('YYYY-MM')
  150. this.formState.endMonth = moment(this.formState.DateTime[1]).format('YYYY-MM')
  151. delete this.formState.DateTime
  152. }
  153. if(this.formState.type=='加班工资单'||this.formState.type=='月度工资单'){
  154. this.formState.yearWithMonth = moment(this.formState.yearWithMonth).format('YYYY-MM')
  155. }
  156. if(this.formState.type=='年休工资单'){
  157. this.formState.yearWith = moment(this.formState.yearWith).format('YYYY')
  158. }
  159. this.loading = true
  160. let that = this;
  161. postAction('/salary/salaryManagement/generatePayrollBefore',this.formState).then((res) => {
  162. if (res.success) {
  163. this.generatePayroll(this.formState)
  164. } else {
  165. this.ModalText = res.message
  166. this.visibleOk = true
  167. }
  168. }).finally(() => {
  169. this.loading = false
  170. this.formState.DateTime = [];
  171. this.formState.yearWith = '';
  172. })
  173. }
  174. })
  175. },
  176. handleOkPayroll(){
  177. this.ModalText = ''
  178. this.visibleOk = false
  179. this.loading1 = true;
  180. this.generatePayroll(this.formState)
  181. },
  182. handleCancelPayroll(){
  183. this.ModalText = ''
  184. this.visibleOk = false
  185. },
  186. generatePayroll(data){
  187. this.loading = true
  188. let that = this;
  189. postAction('/salary/salaryManagement/generatePayroll',data).then((res) => {
  190. if (res.success) {
  191. if(res.data&&res.data.ZZ){
  192. that.handleDownload(res.data.ZZ,that.formState.type,"正织",data);
  193. }
  194. if(res.data&&res.data.MFY){
  195. that.handleDownload(res.data.MFY,that.formState.type,"马菲羊",data);
  196. }
  197. if(res.data&&res.data.NBSY){
  198. that.handleDownload(res.data.NBSY,that.formState.type,"宁波森语",data);
  199. }
  200. this.$message.success(res.message);
  201. this.handleCancel()
  202. this.$emit('ok')
  203. } else {
  204. this.$message.error(res.message);
  205. }
  206. }).finally(() => {
  207. this.loading1 = false;
  208. this.loading = false
  209. this.formState.DateTime = [];
  210. this.formState.yearWith = '';
  211. })
  212. },
  213. handleDownload(id,type,name,datas){
  214. downFile('/salary/salaryManagement/exportXls2',{id:id,type:type}).then(data => {
  215. this.$message.success(name+type+"数据导出中,请稍等");
  216. if (!data) {
  217. this.$message.warning('文件下载失败')
  218. return
  219. }
  220. let datePar = "";
  221. if(type == '年休工资单'){
  222. datePar = datas.yearWith;
  223. // datePar = moment(data.yearWith).format('YYYY');
  224. }else{
  225. datePar = datas.yearWithMonth;
  226. // datePar = moment(data.yearWithMonth).format('YYYY-MM');
  227. }
  228. if (typeof window.navigator.msSaveBlob !== 'undefined') {
  229. window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), name+datePar+type + '.xls')
  230. } else {
  231. let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
  232. let link = document.createElement('a')
  233. link.style.display = 'none'
  234. link.href = url
  235. link.setAttribute('download', name+datePar+type+'.xls')
  236. document.body.appendChild(link)
  237. link.click()
  238. document.body.removeChild(link) // 下载完成移除元素
  239. window.URL.revokeObjectURL(url) // 释放掉blob对象
  240. }
  241. }).catch(
  242. error => {
  243. this.alertMsg(error.toString());
  244. }
  245. )
  246. },
  247. alertMsg(st){
  248. this.spinning = false
  249. this.$message.warning('文件自动下载失败,请联系系统管理员'+st)
  250. },
  251. changeData(value){
  252. this.formState.DateTime = value
  253. },
  254. onDateChange(status) {
  255. if(status){
  256. this.open = true;
  257. }else{
  258. this.open = false
  259. }
  260. },
  261. handlePanelChange2(value,mode){
  262. if (this.formState.DateTime[1] && this.formState.DateTime[1]._d != value[1]._d) {
  263. this.open = false;
  264. this.$refs.form.clearValidate();
  265. }
  266. this.formState.DateTime = value
  267. this.mode2 = [mode[0] === 'date' ? 'month' : mode[0], mode[1] === 'date' ? 'month' : mode[1]];
  268. },
  269. handlePanelChange1(value){
  270. this.isopen = false
  271. this.formState.yearWith =value
  272. },
  273. changeopen(status){
  274. if(status){
  275. this.isopen = true
  276. }
  277. }
  278. }
  279. }
  280. </script>
  281. <style scoped lang="less">
  282. /deep/ .nresume .ant-input{
  283. height: 100px !important;
  284. }
  285. /deep/ .ant-select{
  286. width: 100%;
  287. }
  288. .form-table-heard:before {
  289. content: '*';
  290. color: red;
  291. }
  292. /deep/ .ant-calendar-picker{
  293. width: 113px !important;
  294. }
  295. /deep/.ant-modal-root>.ant-modal-wrap>.ant-modal {
  296. min-width: 0 !important;
  297. }
  298. </style>