HwOrderUploadContractModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <a-modal
  3. :title="title"
  4. :width="modelStyle.width"
  5. :bodyStyle="bodyStyle"
  6. :visible="visible"
  7. :confirmLoading="confirmLoading"
  8. @ok="handleOk"
  9. @cancel="handleCancel"
  10. :footer="null"
  11. cancelText="关闭">
  12. <a-spin :spinning="confirmLoading">
  13. <a-form :form="form">
  14. <a-form-item label="用户合同" :labelCol="labelCol" :wrapperCol="wrapperCol" :required="true">
  15. <a-upload
  16. name="file"
  17. :multiple="true"
  18. :remove="handleDelete"
  19. :action="uploadAction"
  20. :headers="headers"
  21. :data="{'isup':1,'bizPath':bizPath}"
  22. :fileList="fileList"
  23. :beforeUpload="beforeUpload"
  24. @change="handleChange">
  25. <a-button> <a-icon type="upload" /> 选择上传 </a-button>
  26. </a-upload>
  27. </a-form-item>
  28. <template v-if="!disableSubmit">
  29. <a-form-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
  30. <j-date placeholder="请选择开始时间" v-decorator="[ 'startDate', validatorRules.startDate]" @change="handleDateChange1" :trigger-change="true" style="width: 100%"/>
  31. </a-form-item>
  32. <a-form-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
  33. <template v-if="model.isAutoRenew==1">
  34. <div>—</div>
  35. </template>
  36. <template v-else>
  37. <j-date placeholder="请选择结束时间" v-decorator="[ 'endDate', validatorRules.endDate]" :trigger-change="true" style="width: 100%"/>
  38. </template>
  39. </a-form-item>
  40. <a-form-item label="自动续约" :labelCol="labelCol" :wrapperCol="wrapperCol">
  41. <a-radio-group buttonStyle="outline" @change="changeAutoRenew" v-decorator="[ 'isAutoRenew', {'initialValue':1}]">
  42. <a-radio :value="1">是</a-radio>
  43. <a-radio :value="0">否</a-radio>
  44. </a-radio-group>
  45. </a-form-item>
  46. <div style="color:#E70000;font-size: 12px;padding-left: 11%">
  47. 温馨提示:<br/>
  48. <div style="margin-top: 12px;padding-left: 20px;color:#E70000">1、请确认此处选择的“开始/结束时间”与真实合同保持一致</div><br/>
  49. <div style="padding-left: 20px;color:#E70000">2、新上传合同与已上传老合同时间不能重叠</div><br/>
  50. <div style="padding-left: 20px;color:#E70000">3、请在时间上尽量保持新上传合同与上一份合同相互连续</div>
  51. </div>
  52. </template>
  53. </a-form>
  54. </a-spin>
  55. <div class="drawer-bootom-button" v-show="!disableSubmit">
  56. <a-button class="ant-btn ant-btn-primary" style="margin-left: 8px" @click="handleOk">保存</a-button>
  57. </div>
  58. </a-modal>
  59. </template>
  60. <script>
  61. import Vue from 'vue'
  62. import { ACCESS_TOKEN } from '@/store/mutation-types'
  63. import { httpAction,getAction, deleteAction, putAction, postAction,downFile } from '@/api/manage'
  64. import JUpload from '@/components/jeecg/JUpload'
  65. import pick from 'lodash.pick'
  66. import JDate from '@/components/jeecg/JDate'
  67. import moment from "moment"
  68. const FILE_TYPE_ALL = "all"
  69. const FILE_TYPE_PDF = 'pdf'
  70. const uidGenerator = () => {
  71. return '-' + parseInt(Math.random() * 10000 + 1, 10)
  72. }
  73. const getFileName = (path) => {
  74. if (path.lastIndexOf('\\') >= 0) {
  75. let reg = new RegExp('\\\\', 'g')
  76. path = path.replace(reg, '/')
  77. }
  78. return path.substring(path.lastIndexOf('/') + 1)
  79. }
  80. export default {
  81. name: "HwOrderUploadContractModal ",
  82. components: {
  83. JDate
  84. },
  85. data () {
  86. return {
  87. plainOptions:[],
  88. valueInfo:[],
  89. headers: {},
  90. fileList: [],
  91. form: this.$form.createForm(this),
  92. title:"操作",
  93. modelStyle: {
  94. width: '52%',
  95. style: { top: '20px' },
  96. fullScreen: false
  97. },
  98. bodyStyle: {
  99. paddingTop: '20px',
  100. paddingBottom:'50px',
  101. height: (window.innerHeight * 0.6) + 'px',
  102. 'overflow-y': 'auto'
  103. },
  104. disableSubmit:false,
  105. visible: false,
  106. model: {},
  107. labelCol: {
  108. xs: { span: 24 },
  109. sm: { span: 5 },
  110. },
  111. wrapperCol: {
  112. xs: { span: 24 },
  113. sm: { span: 16 },
  114. },
  115. selectedDepartKeys:[], //保存用户选择服务商id
  116. checkedDepartKeys:[],
  117. confirmLoading: false,
  118. validatorRules:{
  119. workContract:{},
  120. startDate: { rules: [{ required: true, message: '请选择合同开始时间' }] },
  121. endDate: { rules: [{ required: true, message: '请选择合同结束时间' }] }
  122. },
  123. url: {
  124. add: '/ordermanager/hwOrder/editContract',
  125. fileUpload: window._CONFIG['domianURL'] + '/hpSys/common/ossUpload',
  126. imgerver: window._CONFIG['imgDomainOssURL'],
  127. getOneYearLaterTime:"/ordermanager/hwOrder/getOneYearLaterTime",
  128. }
  129. }
  130. },
  131. props: {
  132. fileType: {
  133. type: String,
  134. required: false,
  135. default: FILE_TYPE_ALL
  136. },
  137. /*这个属性用于控制文件上传的业务路径*/
  138. bizPath: {
  139. type: String,
  140. required: false,
  141. default: '/hpwork/hworder'
  142. },
  143. },
  144. created () {
  145. const token = Vue.ls.get(ACCESS_TOKEN)
  146. this.headers = { 'X-Access-Token': token }
  147. },
  148. computed: {
  149. uploadAction: function() {
  150. return this.url.fileUpload
  151. }
  152. },
  153. methods: {
  154. add (record) {
  155. this.edit(record);
  156. },
  157. edit (record) {
  158. this.form = this.$form.createForm(this)
  159. this.form.resetFields();
  160. this.model={}
  161. this.model = Object.assign({}, record);
  162. if(this.model.isAutoRenew==undefined){
  163. this.model.isAutoRenew = 1
  164. }
  165. console.log(this.model)
  166. this.visible = true;
  167. this.$nextTick(() => {
  168. this.form.setFieldsValue(pick(this.model,'startDate','endDate','isAutoRenew'))
  169. if(!this.model.contractId){
  170. this.form.setFieldsValue({ startDate: moment(new Date()).format('YYYY-MM-DD') })
  171. this.getOneYearLaterTime(moment(new Date()).format('YYYY-MM-DD'))
  172. }
  173. })
  174. this.editFileList(this.model.workContract)
  175. },
  176. getOneYearLaterTime(time){
  177. getAction(this.url.getOneYearLaterTime,{startDate:time}).then((res)=>{
  178. if (res.success) {
  179. this.$nextTick(() => {
  180. this.form.setFieldsValue({ endDate: res.result })
  181. })
  182. }
  183. })
  184. },
  185. close () {
  186. this.$emit('ok');
  187. this.visible = false;
  188. },
  189. modalFormOk(){
  190. },
  191. handleCancel(){
  192. this.$emit('ok');
  193. this.close()
  194. },
  195. handleOk () {
  196. const that = this;
  197. const { fileList } = that
  198. // 触发表单验证
  199. this.form.validateFields((err, values) => {
  200. if (!err) {
  201. that.confirmLoading = true;
  202. let httpurl = '';
  203. httpurl+=this.url.add;
  204. let method = 'post';
  205. var workContract = "";
  206. let formData = Object.assign(this.model, values);
  207. let isDone = true;
  208. fileList.forEach((file,index) => {
  209. if(!file.thUrl){
  210. isDone = false;
  211. }
  212. if(index === 0){
  213. workContract = file.thUrl;
  214. }else{
  215. workContract += "," + file.thUrl;
  216. }
  217. });
  218. //上传文件出错
  219. if(!isDone){
  220. that.$message.error("正在上传,请稍后提交!");
  221. that.confirmLoading = false
  222. return;
  223. }
  224. if(!workContract || workContract==""){
  225. that.$message.error("请先上传合同!");
  226. that.confirmLoading = false
  227. return;
  228. }
  229. if(this.form.getFieldValue('endDate')<this.form.getFieldValue('startDate')){
  230. that.$message.error("合同结束时间需大于开始时间!");
  231. that.confirmLoading = false
  232. return;
  233. }
  234. formData.workContract = workContract;
  235. console.log("表单提交数据",formData)
  236. httpAction(httpurl,formData,method).then((res)=>{
  237. if(res.success){
  238. that.$message.success(res.message);
  239. that.$emit('ok');
  240. that.close();
  241. }else{
  242. that.$message.warning(res.message);
  243. }
  244. }).finally(() => {
  245. that.confirmLoading = false;
  246. })
  247. }
  248. })
  249. },
  250. handlePathChange() {
  251. let uploadFiles = this.fileList
  252. let path = ''
  253. if (!uploadFiles || uploadFiles.length == 0) {
  254. path = ''
  255. }
  256. let arr = []
  257. for (var a = 0; a < uploadFiles.length; a++) {
  258. arr.push(uploadFiles[a].response.message)
  259. }
  260. if (arr.length > 0) {
  261. path = arr.join(',')
  262. }
  263. this.$emit('change', path)
  264. console.log(1111,this.fileList)
  265. },
  266. beforeUpload: function(file) {
  267. //TODO 验证文件大小
  268. },
  269. handleChange(info) {
  270. let fileList = info.fileList
  271. if (info.file.status === 'done') {
  272. if (info.file.response.success) {
  273. fileList = fileList.map((file) => {
  274. if (file.response) {
  275. file.url = this.url.imgerver + file.response.message
  276. file.thUrl = file.response.message
  277. }
  278. return file
  279. })
  280. }
  281. this.$message.success(`${info.file.name} 上传成功!`)
  282. }else if (info.file.status === 'error') {
  283. this.$message.error(`${info.file.name} 上传失败.`)
  284. } else if (info.file.status === 'removed') {
  285. this.handleDelete(info.file)
  286. }
  287. this.fileList = fileList
  288. },
  289. //移除文件
  290. handleDelete(file){
  291. const index = this.fileList.indexOf(file);
  292. const newFileList = this.fileList.slice();
  293. newFileList.splice(index, 1);
  294. this.fileList = newFileList;
  295. },
  296. //回显文件所用
  297. editFileList(paths) {
  298. if (!paths || paths.length == 0) {
  299. //return [];
  300. // update-begin- --- author:os_chengtgen ------ date:20190729 ---- for:issues:326,Jupload组件初始化bug
  301. this.fileList = []
  302. return
  303. // update-end- --- author:os_chengtgen ------ date:20190729 ---- for:issues:326,Jupload组件初始化bug
  304. }
  305. let fileList = []
  306. let arr = paths.split(',')
  307. for (var a = 0; a < arr.length; a++) {
  308. fileList.push({
  309. uid: uidGenerator(),
  310. name: getFileName(arr[a]),
  311. status: 'done',
  312. url: this.getAvatarView(arr[a]),
  313. thUrl: arr[a]
  314. })
  315. }
  316. this.fileList = fileList
  317. },
  318. getAvatarView(idcardPicture) {
  319. if( idcardPicture.indexOf("http")!=-1){
  320. return idcardPicture
  321. }else{
  322. return this.url.imgerver+idcardPicture
  323. }
  324. },
  325. handleDateChange1(time){
  326. this.getOneYearLaterTime(time)
  327. },
  328. changeAutoRenew(e){
  329. if(e.target.value==0){
  330. if(this.form.getFieldValue("startDate")){
  331. this.getOneYearLaterTime(moment(this.form.getFieldValue("startDate")).format('YYYY-MM-DD'))
  332. }
  333. }
  334. this.model.isAutoRenew=e.target.value
  335. }
  336. }
  337. }
  338. </script>
  339. <style>
  340. .drawer-bootom-button {
  341. position: absolute;
  342. bottom: -8px;
  343. width: 100%;
  344. border-top: 1px solid #e8e8e8;
  345. padding: 10px 16px;
  346. text-align: right;
  347. left: 0;
  348. background: #fff;
  349. border-radius: 0 0 2px 2px;
  350. }
  351. .avatar-uploader > .ant-upload {
  352. width: 104px;
  353. height: 104px;
  354. }
  355. .ant-upload-select-picture-card i {
  356. font-size: 49px;
  357. color: #999;
  358. }
  359. .ant-upload-select-picture-card .ant-upload-text {
  360. margin-top: 8px;
  361. color: #666;
  362. }
  363. </style>