demoForm2.vue 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  1. <template>
  2. <div class="form-main" id="form-main">
  3. <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
  4. <!-- <a-form @submit="handleSubmit" :form="form">
  5. <a-form-item
  6. label="标题"
  7. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  8. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  9. <a-input :disabled="disabled"
  10. v-decorator="[
  11. 'name',
  12. {rules: [{ required: true, message: '请输入标题' }]}
  13. ]"
  14. name="name"
  15. placeholder="给目标起个名字" />
  16. </a-form-item>
  17. <a-form-item v-if="!disabled"
  18. :wrapperCol="{ span: 24 }"
  19. style="text-align: center"
  20. >
  21. <a-button htmlType="submit" type="primary" :disabled="disabled||btndisabled" @click="handleSubmit">保存</a-button>
  22. <a-button style="margin-left: 8px" :disabled="disabled" @click="close">取消</a-button>
  23. </a-form-item>
  24. </a-form>-->
  25. <k-form-build
  26. :value="jsonData"
  27. @change="handleChange"
  28. :dynamicData="dynamicData"
  29. ref="KFB"
  30. @submit="handleSubmit"
  31. />
  32. <div style="text-align:center">
  33. <a-button
  34. htmlType="submit"
  35. type="primary"
  36. :disabled="disabled || btndisabled"
  37. @click="handleSubmit"
  38. class="noprint"
  39. >保存</a-button>
  40. <todoManageOperation
  41. v-if="processData.operationType && processData.operationType == '1'"
  42. :processData="processData"
  43. :todoManageOperationObject="todoManageOperationObject"
  44. :disabled="disabled"
  45. :btndisabled="btndisabled"
  46. @refreshToDo="refreshToDo"
  47. @handleSubmit2="handleSubmit2"
  48. ></todoManageOperation>
  49. <a-button style="margin-left: 8px;" :disabled="disabled || disabled2" @click="close" class="noprint">取消</a-button>
  50. <!-- <a-button type="primary" v-if="printDisable" @click="changedd" class="noprint" style="margin-left:10px">打印</a-button> -->
  51. </div>
  52. </a-card>
  53. <personnel-files-modal ref="personnelFilesModal" @close="closeP"></personnel-files-modal>
  54. <fixed-zy-modal ref="FixedZyModal" @close="closeP"></fixed-zy-modal>
  55. <car-sq-modal ref="CarSqModal" @close="closeP"></car-sq-modal>
  56. <material-sl-modal ref="MaterialSlModal" @close="closeP"></material-sl-modal>
  57. </div>
  58. </template>
  59. <script>
  60. import pick from 'lodash.pick'
  61. import todoManageOperation from '../operation/todoManageOperation'
  62. import PersonnelFilesModal from './personnelFilesModal'
  63. import CarSqModal from './carSqModal'
  64. import MaterialSlModal from './materialSlModal'
  65. import FixedZyModal from './fixedZyModal'
  66. import { postAction, postFormDataAction} from '@/api/manage'
  67. import {annualLeave} from '@api/oa/cd-personnel-files'
  68. import moment from 'moment'
  69. export default {
  70. name: 'DemoForm',
  71. props: {
  72. /* 全局禁用,可表示查看 */
  73. disabled: {
  74. type: Boolean,
  75. default: false,
  76. required: false
  77. },
  78. /* 流程数据 */
  79. processData: {
  80. type: Object,
  81. default: () => {
  82. return {}
  83. },
  84. required: false
  85. },
  86. /* 是否新增 */
  87. isNew: { type: Boolean, default: false, required: false }
  88. },
  89. components: {
  90. todoManageOperation,
  91. moment,
  92. PersonnelFilesModal,
  93. FixedZyModal,
  94. CarSqModal,
  95. MaterialSlModal,
  96. },
  97. data () {
  98. return {
  99. isSJ: false,
  100. todoManageOperationObject: {
  101. isSave: false,
  102. formData: {},
  103. jsonData: {}
  104. },
  105. leave:0,//剩余年假
  106. disabled2: false, // 用来取决于表单时不同流程节点填写不同表单信息使用
  107. jsonData: {}, // 前台任意改变的json
  108. jsonDataSave: {}, // 保存到数据库的json
  109. url: {
  110. getForm: '/actBusiness/getForm',
  111. addApply: '/actBusiness/add',
  112. editForm: '/actBusiness/editForm',
  113. leaveType: '/sys/dict/getDictItems'
  114. },
  115. description: '流程表单demo,按例开发表单。需在 activitiMixin.js 中加入写好的表单',
  116. // form
  117. form: this.$form.createForm(this),
  118. /* 表单回显数据 */
  119. data: {},
  120. btndisabled: false,
  121. ceshi_file: null,
  122. fArr:[],//保存含有help的单个表单信息
  123. cvarr:[],//保存表单所有的label和key(用来寻找改变字段对应的key)
  124. bv:[],//保存所有含有help的表单信息
  125. dynamicData: {
  126. jsonData: {},
  127. typeData: [], // 请假类型下拉数据
  128. reimbursementTypeList: [], // 报销类型下拉数据
  129. invoiceTypeList: [], // 发票类型下拉数据
  130. add: this.add,
  131. gv:this.funName,
  132. department:[],//技能博物管下拉框信息
  133. personListJn:[],//技能博物馆人员信息下拉框
  134. },
  135. postInfo: {},//职位信息
  136. deptInfo: {},//部门信息
  137. itemModelNameList: [], // 子表字段名
  138. buttonArr:[],
  139. printDisable:false//打印按钮
  140. }
  141. },
  142. watch: {
  143. // 'dynamicData.jsonData'(){
  144. // console.log("发生改变了")
  145. // },
  146. dynamicData: {
  147. handler (newName, oldName) {
  148. console.log('obj.a changed')
  149. console.log(newName)
  150. console.log(oldName)
  151. newName.handle = this.funName1
  152. newName.fixed_zy = this.fixedZy
  153. newName.fixed_gh =this.fixedGh
  154. newName.fixed_db=this.fixedDb
  155. newName.fixed_bf=this.fixedBf
  156. newName.car_sq = this.carSq
  157. newName.material_sl = this.materialSl
  158. },
  159. immediate: true,
  160. deep: true
  161. }
  162. },
  163. created () {
  164. window.deleteRow = this.deleteRow
  165. // console.log('流程数据', this.processData)
  166. // 加载一些下拉选择数据等
  167. // this.getDataList()
  168. let businessTable = ''
  169. // 如果没有值则在另一个属性上有值
  170. if (!this.processData.businessTable) {
  171. this.processData.businessTable = this.processData.tableName
  172. }
  173. // debugger
  174. this.getAction('/tbTableInfo/query', {
  175. businessTable: this.processData.businessTable,
  176. taskNodeId: this.processData.key,
  177. tableId: this.processData.tableId,
  178. type: '1'
  179. }).then(res => {
  180. var jsonString = JSON.stringify(res.result.jsonContent)
  181. var index = 1
  182. var dynamicKeyValueList = []
  183. for (var index = 1; index !== -1;) {
  184. // 动态字符位置
  185. index = jsonString.indexOf('"dynamicKey"', index)
  186. if (index !== -1) {
  187. // 从指定字符的周后一个字符后开始找(")
  188. var ihStart = jsonString.indexOf('"', index + 12)
  189. // 再从 (") 后面位置还是找下一个 (")
  190. var ihEnd = jsonString.indexOf('"', ihStart + 1)
  191. // 获取引号之间的字符
  192. var dynamicKeyValue = jsonString.substring(ihStart + 1, ihEnd)
  193. // 如果动态表示不为空则获取
  194. if (dynamicKeyValue != '') {
  195. dynamicKeyValueList.push(dynamicKeyValue)
  196. }
  197. index = ihEnd + 1
  198. }
  199. }
  200. let that = this;
  201. if (dynamicKeyValueList.length > 0) {
  202. // 获取数据字典数据源
  203. postAction('/sys/dict/getDictItems/getDictList', dynamicKeyValueList).then(dictData => {
  204. if (dictData.success) {
  205. this.dynamicData = dictData.result.dicList
  206. //技能博物馆部门信息
  207. this.getAction('/sys/sysDepart/queryMyDeptList').then(res => {
  208. if (res.success) {
  209. var aa=[]
  210. res.result.map(item=>{
  211. aa.push({value:item.departName,label:item.departName})
  212. })
  213. this.dynamicData.department = aa
  214. } else {
  215. this.$message.error(res.message)
  216. }
  217. })
  218. //技能博物馆人员信息
  219. this.getAction('/sys/user/list', { pageSize: -1}).then(res => {
  220. if (res.success) {
  221. var aa = []
  222. res.result.records.map(item =>{
  223. aa.push(
  224. {value:item.realname,
  225. label:item.realname,
  226. workNo:item.workNo,
  227. post:item.post,
  228. nInductionTime:item.nInductionTimenInductionTime,
  229. phone:item.phone,
  230. telephone:item.telephone,
  231. departIds_dictText:item.departIds_dictText,
  232. departIds:item.departIds
  233. })
  234. })
  235. this.dynamicData.personListJn = aa
  236. //技能博物馆 --- 全馆值班 此时无法触碰到handleChange方法 手动触发
  237. if(this.processData.businessTable == 'bwg_house_duty'){
  238. this.handleChange()
  239. }
  240. } else {
  241. this.$message.error(res.message)
  242. }
  243. })
  244. // 获取用户下拉数据
  245. this.getAction('/sys/user/list2', { pageSize: 20000 }).then(userData => {
  246. if (res.success) {
  247. if(userData.data != null && userData.data.supplierList != null){
  248. // userData.data.supplierList.forEach(user => {
  249. // console.log("userDatacode",user.code);
  250. // console.log("userDataname",user.name);
  251. // })
  252. this.dynamicData.supplierList = userData.data.supplierList
  253. }
  254. userData.result.records.forEach(user => {
  255. user.label = user.realname
  256. user.value = user.username
  257. that.postInfo[user.username] = user.post
  258. that.deptInfo[user.username] = user.deptName
  259. })
  260. // 存到动态数据源中
  261. this.dynamicData.userList = userData.result.records
  262. this.dynamicData.add = this.add // 新增按钮
  263. // 获取json
  264. this.jsonData = res.result.jsonContent
  265. // this.jsonData.list[2].columns[0].list[0].help = "date_1663752082983,date_1663753163575,min"
  266. this.cvarr = []
  267. this.cvarr = []
  268. this.fArr =[]
  269. //遍历help
  270. this.forHelp(this.jsonData)
  271. this.jsonDataSave = JSON.parse(JSON.stringify(res.result.jsonContent))
  272. // 获取申请人信息
  273. this.getApplicant()
  274. // 如果是手机端子表初始化子表model
  275. this.listUpdateModel()
  276. if (!this.isNew) {
  277. this.init()
  278. }
  279. } else {
  280. this.$message.error(userData.message)
  281. }
  282. })
  283. } else {
  284. this.$message.error(dictData.message)
  285. }
  286. })
  287. } else {
  288. // 获取json
  289. this.jsonData = res.result.jsonContent
  290. // this.jsonData.list[0].trs[5].tds[2].list[0].help = 'input_1662521241170,input_1662521240862,-'
  291. // this.jsonData.list[0].trs[3].tds[2].list[0].help = 'today'
  292. this.cvarr = []
  293. this.fArr =[]
  294. //遍历help(计算)
  295. this.forHelp(this.jsonData)
  296. // 获取申请人信息
  297. this.getApplicant()
  298. // 如果是手机端子表初始化子表model
  299. this.listUpdateModel()
  300. // window.jsonData=this.jsonData;
  301. if (!this.isNew) {
  302. this.init()
  303. }
  304. }
  305. // 后台检测到流程节点有关联表单且前台处于我的待办界面打开表单详情
  306. if (res.result.isSave && this.processData.isSuspended != undefined) {
  307. this.disabled = false
  308. this.btndisabled = false
  309. }
  310. })
  311. },
  312. methods: {
  313. fixedZy(){
  314. this.$refs.FixedZyModal.fixedZyModVis = true
  315. this.$refs.FixedZyModal.personLists('正常')
  316. this.$refs.FixedZyModal.sat = '转移'
  317. },
  318. fixedGh(){
  319. this.$refs.FixedZyModal.fixedZyModVis = true
  320. this.$refs.FixedZyModal.personLists('正常')
  321. this.$refs.FixedZyModal.sat = '归还'
  322. },
  323. fixedDb(){
  324. this.$refs.FixedZyModal.fixedZyModVis = true
  325. this.$refs.FixedZyModal.personLists('正常')
  326. this.$refs.FixedZyModal.sat = '调拨'
  327. },
  328. fixedBf(){
  329. this.$refs.FixedZyModal.fixedZyModVis = true
  330. this.$refs.FixedZyModal.personLists('正常')
  331. this.$refs.FixedZyModal.sat = '报废'
  332. },
  333. carSq(){
  334. this.$refs.CarSqModal.carSqModVis = true
  335. this.$refs.CarSqModal.personLists()
  336. },
  337. materialSl(){
  338. this.$refs.MaterialSlModal.materialSlModVis = true
  339. this.$refs.MaterialSlModal.personLists()
  340. },
  341. //获取部门信息
  342. getDepartment(){
  343. this.$refs.DepartmentModal.departmentModVis = true
  344. this.$refs.DepartmentModal.personLists()
  345. },
  346. closeP(value){
  347. var that = this
  348. this.cvarr.map(item=>{
  349. for(let key in value){
  350. if(item.model == key){
  351. setTimeout(function(){
  352. that.$refs.KFB.setData({[key]:value[key]})
  353. },0)
  354. }
  355. }
  356. })
  357. },
  358. funName1(){
  359. this.$refs.personnelFilesModal.declareElementsModVis = true
  360. this.$refs.personnelFilesModal.personLists()
  361. },
  362. // 根据字典名字获取数据源
  363. getDataListByName (name) {
  364. this.getAction(this.url.leaveType + '/' + name).then(res => {
  365. if (res.success) {
  366. this.dynamicData[name] = res.result
  367. console.log(111)
  368. } else {
  369. this.$message.error(res.message)
  370. }
  371. })
  372. },
  373. // 获取获取下拉数据等
  374. getDataList () {
  375. // 获取请假类型下拉数据
  376. this.getAction(this.url.leaveType + '/leave_type').then(res => {
  377. if (res.success) {
  378. this.dynamicData.typeData = res.result
  379. } else {
  380. this.$message.error(res.message)
  381. }
  382. })
  383. // 获取报销类型下拉数据
  384. this.getAction(this.url.leaveType + '/reimbursement_type').then(res => {
  385. if (res.success) {
  386. this.dynamicData.reimbursementTypeList = res.result
  387. } else {
  388. this.$message.error(res.message)
  389. }
  390. })
  391. // 获取发票类型下拉数据
  392. this.getAction(this.url.leaveType + '/invoice_type').then(res => {
  393. if (res.success) {
  394. this.dynamicData.invoiceTypeList = res.result
  395. } else {
  396. this.$message.error(res.message)
  397. }
  398. })
  399. },
  400. /* 回显数据 */
  401. init () {
  402. this.btndisabled = true
  403. var r = this.processData
  404. this.getAction(this.url.getForm, {
  405. tableId: r.tableId,
  406. tableName: r.tableName
  407. }).then(res => {
  408. // 第一次调接口根据子表数据渲染子表前台效果
  409. // 只有手机端才执行
  410. if (this.isSJ) {
  411. _.keys(res.result).forEach((e, i) => {
  412. if (e.indexOf('child&') != -1) {
  413. if (i > 0) {
  414. this.add()
  415. }
  416. }
  417. })
  418. }
  419. this.getAction(this.url.getForm, {
  420. tableId: r.tableId,
  421. tableName: r.tableName
  422. }).then(res => {
  423. if (res.success) {
  424. let formData = res.result
  425. formData.tableName = r.tableName
  426. // console.log("taboe",formData);
  427. this.data = formData
  428. // 如果表单是手机端的子表则
  429. if (this.isSJ) {
  430. var formModelList = _.keys(this.data)
  431. .join(',')
  432. .split(',')
  433. var itemList = []
  434. formModelList.forEach(element => {
  435. if (element.indexOf('child&') != -1) {
  436. itemList = JSON.parse(JSON.stringify(this.data[element]))
  437. delete this.data[element]
  438. }
  439. })
  440. // 子表字段名
  441. // 子表数据model和值组装
  442. itemList.forEach((item, index) => {
  443. this.itemModelNameList.forEach(itemModelName => {
  444. this.data[itemModelName + '@' + (index + 1)] = item[itemModelName]
  445. })
  446. })
  447. }
  448. // 赋值
  449. this.$refs.KFB.setData(this.data)
  450. this.btndisabled = false
  451. } else {
  452. this.$message.error(res.message)
  453. }
  454. })
  455. })
  456. },
  457. //遍历help
  458. forHelp(obj){
  459. for(var a in obj){
  460. if (typeof(obj[a]) == "object"){
  461. if(obj[a].help !=='' && obj[a].help){
  462. //保存每一项的label和key
  463. this.cvarr.push({model:obj[a].model,key:obj[a].key,type:obj[a].type})
  464. obj[a].help = obj[a].help.split(',')
  465. //保存含有help的item中的label和help里的信息
  466. this.fArr=[
  467. {
  468. label:obj[a].model,
  469. value:'',
  470. },
  471. {
  472. label: obj[a].help[0],
  473. value:'',
  474. },
  475. {
  476. label: obj[a].help[1],
  477. value:'',
  478. },
  479. {
  480. label: obj[a].help[2],
  481. value:'',
  482. },
  483. ]
  484. //保存多各含有help的数据
  485. this.bv.push({bn:this.fArr})
  486. //默认当天时间
  487. this.defualtData(this.fArr)
  488. }else if(obj[a].help ==''){
  489. this.cvarr.push({model:obj[a].model,key:obj[a].key,type:obj[a].type})
  490. }else if(obj[a].type == 'button'){
  491. this.buttonArr.push(obj[a])
  492. this.buttonShow(obj[a])
  493. }
  494. this.forHelp(obj[a])
  495. }
  496. }
  497. },
  498. buttonShow(obj){
  499. if(obj.label == '打印'){
  500. this.printDisable = true
  501. }
  502. },
  503. defualtData(item){
  504. if(item[1].label =='today'){
  505. item[0].value =moment(new Date().toLocaleDateString()).format('YYYY-MM-DD HH:mm')
  506. var that = this
  507. setTimeout(function(){
  508. that.$refs.KFB.setData({[item[0].label]:item[0].value})
  509. },0)
  510. }else if(item[1].label =='user'){
  511. this.$store.getters.userInfo
  512. var that = this
  513. setTimeout(function(){
  514. that.$refs.KFB.setData({[item[0].label]:that.$store.getters.userInfo.username})
  515. if(that.processData.businessTable == 'regular_employee_apply'){//员工转正申请
  516. that.$refs.KFB.setData({apply_department:that.deptInfo[that.$store.getters.userInfo.username]})
  517. // that.$refs.KFB.setData({job_title:that.postInfo[that.$store.getters.userInfo.username]})
  518. }
  519. if(that.processData.businessTable == 'seal_apply'){//用印申请单
  520. that.$refs.KFB.setData({apply_department:that.deptInfo[that.$store.getters.userInfo.username]})
  521. }
  522. if(that.processData.businessTable == 'separation_application'){//离职申请
  523. that.$refs.KFB.setData({job_title:that.postInfo[that.$store.getters.userInfo.username]})
  524. }
  525. },0)
  526. annualLeave({username:that.$store.getters.userInfo.username}).then(res => {
  527. if (res.success) {
  528. this.leave = res.result.nannualNowNum
  529. }else{
  530. this.$message.error(res.message);
  531. }
  532. })
  533. }
  534. },
  535. // 获取申请人信息
  536. getApplicant () {
  537. console.log('aa', this.$refs.KFB.form.getFieldValue('applicant'))
  538. // if (this.$refs.KFB.form.getFieldValue('applicant')) {
  539. // alert(1)
  540. // this.$refs.KFB.setData({
  541. // applicant: this.$store.getters.userInfo.username
  542. // })
  543. // }
  544. },
  545. changedd(){
  546. window.print()
  547. },
  548. //主子表计算
  549. tableCalculation(value){
  550. var number1 = 0,
  551. number2 = 0
  552. //寻找help信息中对应的modol值
  553. this.bv.map(item=>{
  554. this.cvarr.map(vv=>{
  555. if(vv.key == item.bn[1].label){
  556. number1 = vv.model
  557. }else if(vv.key == item.bn[2].label){
  558. number2 = vv.model
  559. }
  560. })
  561. //表中每一行分别计算
  562. var sum = 0
  563. value.map(b=>{
  564. b[item.bn[0].label] = b[number1]*b[number2]
  565. sum += b[item.bn[0].label] //计算出表格内的总价总和
  566. if(this.$store.getters.nickname=='崔崇杰'){
  567. b['procurement_type']='1'
  568. }else{
  569. b['procurement_type']='2'
  570. }
  571. })
  572. this.$refs.KFB.setData({sum:sum})
  573. })
  574. },
  575. specialTerms(value,key){
  576. var that = this
  577. //剩余年假
  578. if(key == 'employe_name'){
  579. setTimeout(function(){
  580. annualLeave({username:value}).then(res => {
  581. if (res.success) {
  582. //选择姓名获取页面的请假类型和时间间隔
  583. that.leave = res.result.nannualNowNum
  584. var category = that.$refs.KFB.form.getFieldValue('leave_category')
  585. var time1 = that.$refs.KFB.form.getFieldValue('start_date')
  586. var time2 = that.$refs.KFB.form.getFieldValue('end_date')
  587. var timeC=that.timeDifference(time1,time2,'min') //获取时间差
  588. //事假,超过180分钟,年假大于0.5
  589. if(category == 1 &&timeC>=180&&that.leave>=0.5){
  590. that.$refs.KFB.setData({unit:'2'})
  591. that.$refs.KFB.setData({leave_category:'2'})
  592. }else if(category == 2 && that.leave<0.5){ //类型为年假,剩余年假小于0.5
  593. that.$refs.KFB.setData({unit:'1'})
  594. that.$refs.KFB.setData({leave_category:''})
  595. that.$message.error('剩余年假不足!');
  596. }
  597. }else{
  598. that.$message.error(res.message);
  599. }
  600. })
  601. },0)
  602. }
  603. //请假类型与单位
  604. //事假
  605. if(key == 'leave_category' && value == '1'){
  606. setTimeout(function(){
  607. var time1 = that.$refs.KFB.form.getFieldValue('start_date')
  608. var time2 = that.$refs.KFB.form.getFieldValue('end_date')
  609. var timeC=that.timeDifference(time1,time2,'min') //获取时间差
  610. if(timeC>=180 && that.leave>=0.5){ //事假,时间差大于180,剩余年假大于0.5
  611. that.$refs.KFB.setData({unit:'2'})
  612. that.$refs.KFB.setData({leave_category:'2'})
  613. }else{
  614. that.$refs.KFB.setData({unit:'1'})
  615. }
  616. },0)
  617. }else if(key == 'leave_category' && value == '3'){ //病假
  618. setTimeout(function(){
  619. that.$refs.KFB.setData({unit:'1'})
  620. },0)
  621. }else if(key == 'leave_category' && value == '2'){//年假
  622. setTimeout(function(){
  623. if(that.leave >=0.5){ //剩余年假大于0.5
  624. that.$refs.KFB.setData({unit:'2'})
  625. }else{ //剩余年假小于0.5
  626. that.$refs.KFB.setData({unit:'1'})
  627. that.$refs.KFB.setData({leave_category:''})
  628. that.$message.error('剩余年假不足!');
  629. }
  630. },0)
  631. }else if(key == 'leave_category'){
  632. setTimeout(function(){
  633. that.$refs.KFB.setData({unit:'2'})
  634. },0)
  635. }
  636. //时间间隔和类型
  637. if(key =='start_date' || key =='end_date'){
  638. setTimeout(function(){
  639. var time2 = that.$refs.KFB.form.getFieldValue('end_date')
  640. var time1 = that.$refs.KFB.form.getFieldValue('start_date')
  641. var timeC=that.timeDifference(time1,time2,'min')
  642. var lx=that.$refs.KFB.form.getFieldValue('leave_category')
  643. if(timeC>=180&&lx=='1'&&that.leave>=0.5){ //事假,时间差大于180,剩余年假大于0.5
  644. that.$refs.KFB.setData({unit:'2'})
  645. that.$refs.KFB.setData({leave_category:'2'})
  646. }
  647. },0)
  648. }
  649. },
  650. // 表单字段数值发生改变事件
  651. handleChange (value, key) {
  652. if(key == 'proposer' && this.processData.businessTable == 'regular_employee_apply'){//员工转正申请:申请人部门
  653. this.$refs.KFB.setData({apply_department:this.deptInfo[value]})
  654. }
  655. if(key == 'regular_employee' && this.processData.businessTable == 'regular_employee_apply'){//员工转正申请:转正人员岗位
  656. this.$refs.KFB.setData({job_title:this.postInfo[value]})
  657. }
  658. if(key == 'proposer' && this.processData.businessTable == 'seal_apply'){//用印申请单
  659. this.$refs.KFB.setData({apply_department:this.deptInfo[value]})
  660. }
  661. if(key == 'employee_name' && this.processData.businessTable == 'separation_application'){//离职申请
  662. this.$refs.KFB.setData({job_title:this.postInfo[value]})
  663. }
  664. //技能博物馆-----退休录入
  665. if(key == 'name' && this.processData.businessTable == 'bwg_retire_input'){//技能博物馆 ---- 退休录入
  666. this.dynamicData.personListJn.map(item =>{
  667. if(item.label == value){
  668. this.$refs.KFB.setData({employee_number:item.workNo})
  669. this.$refs.KFB.setData({post:item.post})
  670. this.$refs.KFB.setData({rz_date:item.nInductionTim})
  671. }
  672. })
  673. // this.$refs.KFB.setData({employee_number:this.postInfo[value]})
  674. }
  675. //技能博物馆 ---- 全馆值班 (根据登录姓名带出其他字段的值)
  676. if(this.processData.businessTable == 'bwg_house_duty'){
  677. var that = this
  678. setTimeout(function(){
  679. that.dynamicData.personListJn.map(item =>{
  680. if(item.label == that.$store.getters.nickname){
  681. that.$refs.KFB.setData({department_id:item.departIds})
  682. that.$refs.KFB.setData({department_name:item.departIds_dictText})
  683. that.$refs.KFB.setData({telephone:item.telephone})
  684. that.$refs.KFB.setData({mobile_telephone:item.phone})
  685. }
  686. })
  687. },200)
  688. }
  689. //技能博物馆 ----- 费用报销
  690. if(key == 'expense_person' && this.processData.businessTable == 'bwg_expense_apply'){
  691. this.dynamicData.personListJn.map(item =>{
  692. if(item.label == value){
  693. this.$refs.KFB.setData({expense_department:item.departIds_dictText})
  694. }
  695. })
  696. }
  697. //技能博物馆 --- 会议纪要
  698. if(this.processData.businessTable == 'bwg_meeting_summary'){
  699. this.dynamicData.personListJn.map(item =>{
  700. if(item.label == this.$store.getters.nickname){
  701. this.$refs.KFB.setData({record_person:item.value})
  702. this.$refs.KFB.setData({record_department:item.departIds_dictText})
  703. }
  704. })
  705. }
  706. //技能博物馆 ----部门专项预算
  707. if(key == 'department' && this.processData.businessTable == 'bwg_department_budget'){
  708. //预算年份未选择
  709. var year = this.$refs.KFB.form.getFieldValue('budget_year')
  710. if(year == '' || !year){
  711. var that =this
  712. that.$message.error('请先选择报销年份');
  713. setTimeout(function(){
  714. that.$refs.KFB.setData({department:' '})
  715. },0)
  716. }else{ //已选择年份 获取预算金额
  717. this.getAction('/oa/budget/getSelectionList',{year:year,budgetType:'部门预算',dept:value}).then(res => {
  718. if (res.success) {
  719. var money = res.result[0].amount
  720. this.$refs.KFB.setData({budget_sum:money})
  721. } else {
  722. this.$message.error(res.message)
  723. }
  724. })
  725. }
  726. }
  727. //改变的表单是主子表类型时
  728. if((value instanceof Array) && (key.indexOf('child&')!==-1)){
  729. this.tableCalculation(value)
  730. }
  731. //特别字段
  732. this.specialTerms(value,key)
  733. //代码赘余,日后维护
  734. //保存发生改变字段名对应的key
  735. var cc ='',
  736. type = ''
  737. this.cvarr.map(k =>{
  738. if(k.model ==key){
  739. cc=k.key
  740. type = k.type
  741. }})
  742. //根据数值改变计算
  743. var that =this
  744. setTimeout(function(){
  745. that.bv.map(event =>{
  746. if(event.bn[1].label == cc || event.bn[2].label == cc){
  747. that.cvarr.map(k=>{
  748. if(k.key == event.bn[1].label){
  749. event.bn[1].value = that.$refs.KFB.form.getFieldValue(k.model)
  750. }else if(k.key == event.bn[2].label){
  751. event.bn[2].value = that.$refs.KFB.form.getFieldValue(k.model)
  752. }
  753. })
  754. if(type == 'date'){
  755. if(event.bn[1].value!=='' && event.bn[2].value!==''){
  756. var state = ''
  757. state = event.bn[3].label
  758. event.bn[0].value = that.timeDifference(event.bn[1].value,event.bn[2].value,state)
  759. }
  760. }else{
  761. if(event.bn[3].label =="+"){
  762. event.bn[0].value = Number(event.bn[1].value)+Number(event.bn[2].value)
  763. }else if(event.bn[3].label =="-"){
  764. event.bn[0].value = Number(event.bn[1].value)-Number(event.bn[2].value)
  765. }else if(event.bn[3].label =="*"){
  766. event.bn[0].value = Number(event.bn[1].value)*Number(event.bn[2].value)
  767. }
  768. }
  769. that.$refs.KFB.setData({[event.bn[0].label]:event.bn[0].value})
  770. }
  771. })
  772. },0)
  773. // // 数据变化时触发
  774. // // 如果开始时间发生变化
  775. // if (key == 'start_time') {
  776. // // 判断结束时间是否存在
  777. // if (this.$refs.KFB.form.getFieldValue('end_time')) {
  778. // // 获取时间差
  779. // let duration = startEndFun(value, this.$refs.KFB.form.getFieldValue('end_time'))
  780. // if (duration) {
  781. // // 使用k-form-design组件的form属性修改表单数据
  782. // this.$refs.KFB.setData({
  783. // duration: duration
  784. // })
  785. // }
  786. // }
  787. // }
  788. // // 如果结束时间发生变化
  789. // if (key == 'end_time') {
  790. // // 判断结束时间是否存在
  791. // if (this.$refs.KFB.form.getFieldValue('start_time')) {
  792. // // 获取时间差
  793. // let duration = startEndFun(this.$refs.KFB.form.getFieldValue('start_time'), value)
  794. // if (duration) {
  795. // // 使用k-form-design组件的form属性修改表单数据
  796. // this.$refs.KFB.setData({
  797. // duration: duration
  798. // })
  799. // }
  800. // }
  801. // }
  802. },
  803. // handler
  804. handleSubmit (e) {
  805. // return new Promise((resolve)=>{
  806. // 通过函数获取数据
  807. this.$refs.KFB.getData()
  808. .then(res => {
  809. let formData1 = JSON.parse(JSON.stringify(res))
  810. console.log("orl",formData1)
  811. // 处理手机端子表数据
  812. if (this.isSJ) {
  813. this.itemData(res)
  814. }
  815. // 清除为空的表单数据
  816. _.keys(res).forEach(r => {
  817. if (!res[r]) {
  818. delete res[r]
  819. }
  820. })
  821. // 获取数据成功
  822. let formData = JSON.parse(JSON.stringify(res))
  823. console.log(formData)
  824. formData.id = this.data.id
  825. formData.procDefId = this.processData.id
  826. formData.procDeTitle = this.processData.name
  827. if (!formData.tableName) formData.tableName = this.processData.businessTable
  828. formData.filedNames = _.keys(res).join(',')
  829. formData.filedNames = getFiledNames(formData) // 获取主表字段,排除子表标识
  830. var url = this.url.addApply
  831. if (!this.isNew) {
  832. url = this.url.editForm
  833. }
  834. // 是否存在子表
  835. let ischild = false
  836. // 循环表单字段属性判断是否属性中包含数组对象
  837. let i = 0 // 子表数量
  838. _.keys(res)
  839. .join(',')
  840. .split(',')
  841. .forEach(element => {
  842. if (formData[element] instanceof Array) {
  843. // 判断是否符合子表命名规则
  844. if (element.indexOf('&') != -1) {
  845. let tableChildNameList = element.split('&')
  846. // 判断是否能拆分两个字符,子表标识和子表数据库名称
  847. if (tableChildNameList.length == 2) {
  848. i++
  849. let childName = tableChildNameList[1] // 子表数据库名称
  850. if (!formData.table_name_children) {
  851. // 第一次拼接
  852. formData.table_name_children = childName // 表名
  853. } else {
  854. // 后面的表明拼接用“,”隔开
  855. formData.table_name_children = formData.table_name_children + ',' + childName // 表名
  856. }
  857. // 定义属性名和值
  858. formData['childFiledNames' + i] = _.keys(formData[element][0]).join(',') // 子表字段名
  859. formData['childList' + i] = JSON.stringify(formData[element]) // 子表数据
  860. ischild = true
  861. }
  862. } else {
  863. // 如果不是子表则是上传文件,则转字符串
  864. formData[element] = JSON.stringify(formData[element])
  865. }
  866. }
  867. // formData[element];
  868. })
  869. // 判断需不需要存子表
  870. if (ischild) {
  871. formData.filedNames = formData.filedNames + ',table_name_children'
  872. }
  873. console.log(formData)
  874. // 子表数据
  875. // 调用保存接口
  876. this.btndisabled = true
  877. this.todoManageOperationObject.formData = formData
  878. this.todoManageOperationObject.url = url
  879. // formData.jsonContent=JSON.stringify(this.jsonData).toString()
  880. // 获取是否部门负责人
  881. formData.filedNames = formData.filedNames + ',is_leaders'
  882. // formData.is_leaders = this.$store.getters.userInfo.identity
  883. formData.is_leaders = this.$store.getters.userInfo.isPossess
  884. // 清除子表规则的属性
  885. _.keys(formData).forEach(r => {
  886. if (r.indexOf('child&') != -1) {
  887. delete formData[r]
  888. }
  889. })
  890. // 如果手机端子表得则需要修改json
  891. // var jsonPamats = JSON.parse(JSON.stringify(this.jsonData))
  892. var jsonPamats = JSON.parse(JSON.stringify(this.jsonDataSave))
  893. if (!this.isSJ && this.isNew) {
  894. jsonPamats = null
  895. }
  896. this.todoManageOperationObject.jsonData = jsonPamats
  897. // 非我的待办节点打卡表单界面
  898. postFormDataAction(url, formData, { jsonContent: jsonPamats })
  899. .then(res => {
  900. if (res.success) {
  901. this.todoManageOperationObject.isSave = true
  902. this.$message.success('保存成功!')
  903. console.log('123')
  904. this.$emit('afterSubmit', formData)
  905. this.$emit('close')
  906. // resolve(true);
  907. } else {
  908. this.$message.error(res.message)
  909. // resolve(false);
  910. }
  911. })
  912. .finally(() => {
  913. this.btndisabled = false
  914. // resolve(false);
  915. })
  916. })
  917. .catch(err => {
  918. console.log(err, '校验失败')
  919. // resolve(false);
  920. })
  921. // })
  922. },
  923. // 我的待办点击通过保存专用
  924. handleSubmit2 (e) {
  925. // return new Promise((resolve)=>{
  926. // 通过函数获取数据
  927. this.$refs.KFB.getData()
  928. .then(res => {
  929. // 处理手机端子表数据
  930. if (this.isSJ) {
  931. this.itemData(res)
  932. }
  933. // 清除为空的表单数据
  934. _.keys(res).forEach(r => {
  935. if (!res[r]) {
  936. delete res[r]
  937. }
  938. })
  939. // 获取数据成功
  940. let formData = JSON.parse(JSON.stringify(res))
  941. console.log(formData)
  942. formData.id = this.data.id
  943. formData.procDefId = this.processData.id
  944. formData.procDeTitle = this.processData.name
  945. // formData.jsonContent=JSON.stringify(this.jsonData)
  946. if (!formData.tableName) formData.tableName = this.processData.businessTable
  947. formData.filedNames = _.keys(res).join(',')
  948. formData.filedNames = getFiledNames(formData) // 获取主表字段,排除子表标识
  949. var url = this.url.addApply
  950. if (!this.isNew) {
  951. url = this.url.editForm
  952. }
  953. // 是否存在子表
  954. let ischild = false
  955. // 循环表单字段属性判断是否属性中包含数组对象
  956. let i = 0 // 子表数量
  957. _.keys(res)
  958. .join(',')
  959. .split(',')
  960. .forEach(element => {
  961. if (formData[element] instanceof Array) {
  962. // 判断是否符合子表命名规则
  963. if (element.indexOf('&') != -1) {
  964. let tableChildNameList = element.split('&')
  965. // 判断是否能拆分两个字符,子表标识和子表数据库名称
  966. if (tableChildNameList.length == 2) {
  967. i++
  968. let childName = tableChildNameList[1] // 子表数据库名称
  969. if (!formData.table_name_children) {
  970. // 第一次拼接
  971. formData.table_name_children = childName // 表名
  972. } else {
  973. // 后面的表明拼接用“,”隔开
  974. formData.table_name_children = formData.table_name_children + ',' + childName // 表名
  975. }
  976. // 定义属性名和值
  977. formData['childFiledNames' + i] = _.keys(formData[element][0]).join(',') // 子表字段名
  978. formData['childList' + i] = JSON.stringify(formData[element]) // 子表数据
  979. ischild = true
  980. }
  981. } else {
  982. // 如果不是子表则是上传文件,则转字符串
  983. formData[element] = JSON.stringify(formData[element])
  984. }
  985. }
  986. // formData[element];
  987. })
  988. // 判断需不需要存子表
  989. if (ischild) {
  990. formData.filedNames = formData.filedNames + ',table_name_children'
  991. }
  992. console.log(formData)
  993. // 子表数据
  994. // 调用保存接口
  995. this.btndisabled = true
  996. this.todoManageOperationObject.formData = formData
  997. this.todoManageOperationObject.url = url
  998. // 获取是否部门负责人
  999. formData.filedNames = formData.filedNames + ',is_leaders'
  1000. // formData.is_leaders = this.$store.getters.userInfo.identity
  1001. formData.is_leaders = this.$store.getters.userInfo.isPossess
  1002. // 清除子表规则的属性
  1003. _.keys(formData).forEach(r => {
  1004. if (r.indexOf('child&') != -1) {
  1005. delete formData[r]
  1006. }
  1007. })
  1008. // 如果手机端子表得则需要修改json
  1009. // var jsonPamats = JSON.parse(JSON.stringify(this.jsonData))
  1010. var jsonPamats = JSON.parse(JSON.stringify(this.jsonDataSave))
  1011. if (!this.isSJ && this.isNew) {
  1012. jsonPamats = null
  1013. }
  1014. this.todoManageOperationObject.jsonData = jsonPamats
  1015. })
  1016. .catch(err => {
  1017. console.log(err, '校验失败')
  1018. // resolve(false);
  1019. })
  1020. // })
  1021. },
  1022. close () {
  1023. this.$emit('close')
  1024. },
  1025. getData () {
  1026. // 通过函数获取数据
  1027. this.$refs.KFB.getData()
  1028. .then(res => {
  1029. // 获取数据成功
  1030. alert(JSON.stringify(res))
  1031. })
  1032. .catch(err => {
  1033. console.log(err, '校验失败')
  1034. })
  1035. },
  1036. // 刷新待办列表
  1037. refreshToDo () {
  1038. this.close()
  1039. this.$emit('getDataList')
  1040. },
  1041. itemData (res) {
  1042. var childName = '' // 子表规则名称
  1043. var itemIndex = 0
  1044. this.jsonData.list.forEach((element, index) => {
  1045. if (element.label.indexOf('child&') != -1) {
  1046. childName = element.label // 获取规则名
  1047. itemIndex = itemIndex + 1
  1048. }
  1049. })
  1050. var itemList = [] // 封装子表数据
  1051. for (var i = 1; i <= itemIndex; i++) {
  1052. var itemObject = {} // 子表对象
  1053. this.itemModelNameList.forEach(name => {
  1054. // 获取子表得值和封装对象
  1055. itemObject[name] = res[name + '@' + i]
  1056. delete res[name + '@' + i]
  1057. })
  1058. itemList.push(itemObject)
  1059. }
  1060. res[childName] = itemList // 完成子表数据封装
  1061. console.log(res)
  1062. },
  1063. deleteRow (idIndex) {
  1064. // 删除
  1065. this.jsonData.list.splice(idIndex, 1)
  1066. // 删除掉得json之后 重新处理model 和value
  1067. let childIndex = 0
  1068. this.jsonData.list.forEach((element, index) => {
  1069. if (element.label.indexOf('child&') != -1) {
  1070. childIndex = childIndex + 1
  1071. // 只有当前删除的对象json的后面对象json才进行修改
  1072. if (index >= idIndex) {
  1073. // 修改删除按钮的index
  1074. element.columns[0].list[1].options.defaultValue =
  1075. '<a href="javascript:void(0);" \n onclick="deleteRow(' + childIndex + ')">删除</a>'
  1076. // 修改model
  1077. updateModel(element, childIndex)
  1078. // 需要调整的子表值
  1079. var updateModelObject = {}
  1080. // 修改value
  1081. this.$refs.KFB.getData().then(res => {
  1082. // 根据原始字段名拼接带规则的
  1083. this.itemModelNameList.forEach(modelName => {
  1084. updateModelObject[modelName + '@' + childIndex] = res[modelName + '@' + (childIndex + 1)]
  1085. })
  1086. this.$refs.KFB.setData(updateModelObject)
  1087. })
  1088. }
  1089. }
  1090. })
  1091. console.log(JSON.stringify(this.jsonData.list))
  1092. },
  1093. add () {
  1094. let childLable = '' // 子表json标题
  1095. let childValue = {} // 新增子表json
  1096. let isReturn = false
  1097. let childIndex = 0
  1098. var itemList = []
  1099. this.jsonData.list.forEach((element, index) => {
  1100. if (element.label.indexOf('child&') != -1) {
  1101. childValue = JSON.parse(JSON.stringify(element))
  1102. childLable = element.label
  1103. // 处理删除按钮
  1104. childIndex = childIndex + 1
  1105. // element.columns[0].list[1].options.dynamicFun = 'delete' + childIndex
  1106. console.log(element.columns[0].list[1].options)
  1107. element.columns[0].list[1].options.defaultValue =
  1108. '<a href="javascript:void(0);" \n onclick="deleteRow(' + childIndex + ')">删除</a>'
  1109. updateModel(childValue, childIndex)
  1110. }
  1111. if (!isReturn && childLable != '' && element.label != childLable) {
  1112. isReturn = true
  1113. // 处理删除按钮
  1114. childIndex = childIndex + 1
  1115. // childValue.columns[0].list[1].options.dynamicFun = 'delete' + childIndex
  1116. childValue.columns[0].list[1].options.defaultValue =
  1117. '<a href="javascript:void(0);" \n onclick="deleteRow(' + childIndex + ')">删除</a>'
  1118. updateModel(childValue, childIndex)
  1119. // this.jsonData.list.splice(index, 0, childValue)
  1120. itemList.push(childValue)
  1121. }
  1122. itemList.push(element)
  1123. })
  1124. this.jsonData.list = itemList
  1125. console.log(JSON.stringify(this.jsonData.list))
  1126. },
  1127. // 把整个子表json的model进行规则修改
  1128. async listUpdateModel () {
  1129. let modelIndex = 0 // 子表model自增
  1130. // 循环整个json的表单
  1131. this.jsonData.list.forEach((element, index) => {
  1132. // 找到为子表的json
  1133. if (element.label.indexOf('child&') != -1) {
  1134. this.isSJ = true
  1135. // 获取子表原始得model字段名
  1136. if (modelIndex == 0) {
  1137. var i = 1
  1138. var itemString = JSON.stringify(element)
  1139. var itemModelNameList = [] // 储存子表字段名
  1140. for (var i = 1; i !== -1;) {
  1141. // 动态字符位置
  1142. i = itemString.indexOf('"model"', i)
  1143. if (i !== -1) {
  1144. // 从指定字符的周后一个字符后开始找(")
  1145. var ihStart = itemString.indexOf('"', i + 7)
  1146. // 再从 (") 后面位置还是找下一个 (")
  1147. var ihEnd = itemString.indexOf('"', ihStart + 1)
  1148. // 获取引号之间的字符
  1149. var model = itemString.substring(ihStart + 1, ihEnd)
  1150. // 如果动态表示不为空则获取
  1151. if (model != '') {
  1152. if (model.indexOf('@') != -1) {
  1153. model = model.substring(0, model.length - 2)
  1154. }
  1155. itemModelNameList.push(model)
  1156. }
  1157. i = ihEnd + 1
  1158. }
  1159. }
  1160. this.itemModelNameList = itemModelNameList
  1161. }
  1162. modelIndex = modelIndex + 1
  1163. // 修改model
  1164. updateModel(element, modelIndex)
  1165. }
  1166. })
  1167. },
  1168. //计算时间差
  1169. timeDifference(start, end,state){
  1170. // if(start>end){
  1171. // this.$message.error('起始时间不可大于结束时间');
  1172. // }else{
  1173. let beginTime = (new Date(start).getTime()) / 1000;
  1174. let endTime = (new Date(end).getTime()) / 1000;
  1175. //计算天数
  1176. var timediff = endTime - beginTime;
  1177. var days = parseInt(timediff / 86400); //60*60*24
  1178. //计算小时数
  1179. var remain = timediff % 86400 ;
  1180. var hours = parseInt(remain / 3600);
  1181. //计算分钟数
  1182. var remain = remain % 3600;
  1183. var mins = parseInt(remain / 60);
  1184. var res = days + '天' + hours + '小时' + mins + '分';
  1185. if(state == 'min'){
  1186. return days*24*60+hours*60+mins
  1187. }else if(state == 'hour'){
  1188. return days*24+hours+mins/60
  1189. }else if(state == 'day'){
  1190. if(start.split(' ').length==1 && end.split(' ').length == 1){
  1191. return days+1+hours/24+mins/60/24
  1192. }else{
  1193. return days+hours/24+mins/60/24
  1194. }
  1195. }else if(state == 'day/hour/min'){
  1196. return days+'天'+hours+'小时'+mins+'分'
  1197. }else if(state == 'hour/min'){
  1198. return (days*24+hours)+'小时'+mins+'分'
  1199. }
  1200. }
  1201. }
  1202. // }
  1203. }
  1204. // 获取主表字段,排除子表标识
  1205. function getFiledNames (formData) {
  1206. let filedNames = ''
  1207. let list = formData.filedNames.split(',') // 获取表单属性名集合
  1208. list.forEach(element => {
  1209. if (element.indexOf('&') == -1) {
  1210. // 查询是否有这个字段
  1211. if (filedNames == '') {
  1212. // 第一次则直接等于
  1213. filedNames = element
  1214. } else {
  1215. // 后面用逗号隔开
  1216. filedNames = filedNames + ',' + element
  1217. }
  1218. }
  1219. })
  1220. return filedNames
  1221. }
  1222. // 根据开始时间 结束时间计算天数
  1223. function startEndFun (start, end) {
  1224. let startTime = new Date(start)
  1225. let endTime = new Date(end)
  1226. if (startTime >= endTime) {
  1227. return 0
  1228. }
  1229. // 1,分钟取整
  1230. startTime = carryTime(startTime)
  1231. endTime = carryTime(endTime)
  1232. // 2,计算总天数
  1233. var totalTime = 0 // 工时,天数
  1234. if (startTime.getDay() == 6 || startTime.getDay() == 0) {
  1235. totalTime = endTime.getDate() - startTime.getDate()
  1236. } else {
  1237. totalTime = Math.floor((endTime - startTime) / (3600 * 1000) / 24)
  1238. }
  1239. // 3,拿初始值赋值给一个临时变量
  1240. var tempStartTime = new Date()
  1241. tempStartTime.setTime(startTime.getTime())
  1242. // 4,计算出总天数
  1243. while (tempStartTime.getDate() < endTime.getDate()) {
  1244. if (tempStartTime.getDay() == 6 || tempStartTime.getDay() == 0) {
  1245. // 周六或者周日减去
  1246. totalTime--
  1247. }
  1248. tempStartTime.setDate(tempStartTime.getDate() + 1)
  1249. }
  1250. // 5,计算出总小时数
  1251. var temp = 0 // 工时,小时
  1252. do {
  1253. if (startTime.getDay() == 6 || startTime.getDay() == 0) {
  1254. // 周六周日
  1255. startTime.setDate(startTime.getDate() + 1)
  1256. //* ********周六周日直接跳过,初始化为早晨9点
  1257. startTime.setHours(9)
  1258. startTime.setMinutes(0)
  1259. continue
  1260. }
  1261. if (endTime.getDay() == 6 || endTime.getDay() == 0) {
  1262. // 周六周日
  1263. endTime.setDate(endTime.getDate() + 1)
  1264. //* ********周六周日直接跳过,初始化为早晨9点
  1265. endTime.setHours(9)
  1266. endTime.setMinutes(0)
  1267. continue
  1268. }
  1269. let tempMinutes = startTime.getHours() * 60 + startTime.getMinutes()
  1270. // 上午9点到12点半,算工时
  1271. if (tempMinutes >= 9 * 60 && tempMinutes < 12 * 60) {
  1272. temp += 0.05
  1273. }
  1274. // 上午14点到18点半,算工时
  1275. if (tempMinutes >= 13 * 60 && tempMinutes < 18 * 60) {
  1276. temp += 0.05
  1277. }
  1278. startTime.setTime(startTime.getTime() + 0.5 * 3600 * 1000) // 每次增加半个小时
  1279. } while (startTime.getHours() * 60 + startTime.getMinutes() != endTime.getHours() * 60 + endTime.getMinutes())
  1280. {
  1281. totalTime += Math.floor(temp / 0.8)
  1282. totalTime += temp % 0.8
  1283. totalTime = Math.round(totalTime * 100) / 100
  1284. }
  1285. var days = Math.floor(totalTime)
  1286. var hours = Math.round((totalTime - days) * 100) / 10
  1287. console.log(days + '天', hours + '小时')
  1288. return days * 8 + hours
  1289. // if (start && end) {
  1290. // let startTime = new Date(start) // 开始时间
  1291. // let endTime = new Date(end) // 结束时间
  1292. // let usedTime = endTime - startTime // 相差的毫秒数
  1293. // let days = (usedTime / 1000 / 60 / 60).toFixed(2) // 计算出天数
  1294. // return days
  1295. // } else {
  1296. // return null
  1297. // }
  1298. }
  1299. // 格式化时间
  1300. function formatDate (date, fmt) {
  1301. if (/(y+)/.test(fmt)) {
  1302. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  1303. }
  1304. let o = {
  1305. 'M+': date.getMonth() + 1,
  1306. 'd+': date.getDate(),
  1307. 'h+': date.getHours(),
  1308. 'm+': date.getMinutes(),
  1309. 's+': date.getSeconds()
  1310. }
  1311. for (let k in o) {
  1312. if (new RegExp(`(${k})`).test(fmt)) {
  1313. let str = o[k] + ''
  1314. fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str))
  1315. }
  1316. }
  1317. return fmt
  1318. }
  1319. function padLeftZero (str) {
  1320. return ('00' + str).substr(str.length)
  1321. }
  1322. /*
  1323. * 0-15分不算工时
  1324. * 15-45算半个小时
  1325. * 45-60算一个小时
  1326. * */
  1327. function carryTime (date) {
  1328. if (date.getMinutes() > 0 && date.getMinutes() < 15) {
  1329. date.setMinutes(0)
  1330. }
  1331. if (date.getMinutes() >= 15 && date.getMinutes() < 30) {
  1332. date.setMinutes(30)
  1333. }
  1334. if (date.getMinutes() > 30 && date.getMinutes() < 45) {
  1335. date.setMinutes(30)
  1336. }
  1337. if (date.getMinutes() >= 45) {
  1338. date.setHours(date.getHours() + 1)
  1339. date.setMinutes(0)
  1340. }
  1341. return date
  1342. }
  1343. // function
  1344. /**
  1345. * 修改model绑定值
  1346. */
  1347. function updateModel (object, childIndex) {
  1348. let keyString = _.keys(object).join(',')
  1349. if (keyString.indexOf('model') != -1) {
  1350. // 如果没有修改过则直接修改
  1351. if (object['model'].indexOf('@') == -1) {
  1352. object['model'] = object['model'] + '@' + childIndex
  1353. } else {
  1354. // 修改过则截取修改前的再进行修改
  1355. var m = object['model'].substring(0, object['model'].length - 2)
  1356. object['model'] = m + '@' + childIndex
  1357. }
  1358. }
  1359. // 递归
  1360. _.keys(object)
  1361. .join(',')
  1362. .split(',')
  1363. .forEach(l => {
  1364. if (object[l] instanceof Array) {
  1365. object[l].forEach(element => {
  1366. updateModel(element, childIndex)
  1367. })
  1368. }
  1369. })
  1370. }
  1371. </script>
  1372. <style lang="less" scoped>
  1373. @media print {
  1374. @page {
  1375. /* 横向 */
  1376. size: landscape;
  1377. /* 去除浏览器默认页眉页脚 */
  1378. margin: 0;
  1379. }
  1380. .noprint {
  1381. display: none;
  1382. }
  1383. /deep/.ant-input{
  1384. border: none !important;
  1385. }
  1386. /deep/ .ant-modal-header{
  1387. display: none !important;
  1388. }
  1389. /deep/ .ant-modal-content{
  1390. box-shadow:none !important
  1391. }
  1392. }
  1393. /deep/ .anticon-question-circle-o {
  1394. display: none !important;
  1395. }
  1396. </style>