changeRenwu.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <template>
  2. <view class="content">
  3. <view class="param">
  4. <view class="proMiao">任务名称</view>
  5. <input class="proINname" v-model="data.taskName" placeholder="请输入任务名称"/>
  6. <view class="proMiao">评分标准</view>
  7. <textarea class="proINname proIMi" v-model="data.scoreStandard" placeholder="请输入评分标准"/>
  8. <view class="proMiao">附件</view>
  9. <view class="upload-img">
  10. <uni-file-picker limit="3" :maxMb="2"
  11. @select='selectUpload'
  12. @delete="deleteHandle"
  13. :auto-upload='false'
  14. file-extname='pdf,docx,jpg,png,jpeg,doc,docm,dot,dotm,dotx,xlsx,xls,csv,xlsm,slxb,xlt,xltx'
  15. file-mediatype="all"
  16. @success='uploadSuccess'
  17. @fail='uploadFail'
  18. :list-styles='listStyles'
  19. v-model='fileList'
  20. ></uni-file-picker>
  21. </view>
  22. <span style="margin: 20rpx 0 0 20rpx;">支持pdf,docx,jpg,png,jpeg,doc,docm,dot,dotm,dotx,xlsx,xls,csv,xlsm,slxb,xlt,xltx格式,单个文件大小不超过2MB</span>
  23. <view class="proMiao">评分上限</view>
  24. <input class="proINname" placeholder="请输入评分上限" type="number" v-model="data.scoreLimit"/>
  25. <view class="proMiao">权重</view>
  26. <input class="proINname" placeholder="请输入权重" type="digit" v-model="data.weight"/>
  27. <view class="proMiao">任务负责人</view>
  28. <view @click="toggle()">
  29. <view class="proINname" v-if="peopleValue==''">请选择任务负责人</view>
  30. <view class="proINname" v-else>{{peopleValue}}</view>
  31. <!-- <uni-data-select class="proINname" :disabled="true"
  32. v-model="peopleValue" placeholder="请选择主办人"
  33. :localdata="rangePeople"
  34. ></uni-data-select> -->
  35. </view>
  36. <view class="proMiao">提醒时间</view>
  37. <uni-datetime-picker class="proINname" type="datetime" v-model="data.remindTime" @change="changeLog" />
  38. <view class="proMiao">预警时间</view>
  39. <uni-datetime-picker class="proINname" type="datetime" v-model="data.warnTime" @change="changeLog" />
  40. <view class="proMiao">任务周期</view>
  41. <uni-datetime-picker class="proINname" v-model="datetimerange" type="datetimerange" rangeSeparator="至" />
  42. <!-- 操作键 -->
  43. <view class="project">
  44. <view class="butt queren" @click="updateRen">保存</view>
  45. </view>
  46. <view style="width: 100%;height: 60rpx;"></view>
  47. <!-- 任务负责人弹出框-->
  48. <uni-popup ref="popup" background-color="#fff">
  49. <view class="popup-content">
  50. <view class="popup-title">
  51. <view @click="quPopup">取消</view>
  52. <view>选择任务负责人</view>
  53. <view style="color: rgba(0, 97, 255, 1);" @click="selectPeo">确定</view>
  54. </view>
  55. <scroll-view scroll-y="true" class="scroll_view_style">
  56. <view class="popup-list">
  57. <radio-group @change="radioChange" v-for="(item,index) in people" :key="index">
  58. <view class="l-line"></view>
  59. <view class="l-kuang">
  60. <view class="l-circle"></view>
  61. <view style="margin-left: 20rpx;width: 320px;">
  62. <view style="font-size: 28rpx;">{{item.userName}}</view>
  63. <view style="font-size: 24rpx;">{{item.department}}</view>
  64. </view>
  65. <label class="l-label">
  66. <view>
  67. <radio :id="item.userName" :value="item.userName" :checked="index==peopleCruuent"></radio>
  68. </view>
  69. </label>
  70. </view>
  71. </radio-group>
  72. </view>
  73. </scroll-view>
  74. </view>
  75. </uni-popup>
  76. </view>
  77. <!-- 图片压缩 -->
  78. <Compress ref="Compress" />
  79. </view>
  80. </template>
  81. <script>
  82. import configdata from '@/common/config.js'
  83. // 引入压缩组件
  84. import Compress from '@/components/compress/compress.vue'
  85. export default {
  86. components:{
  87. Compress
  88. },
  89. data() {
  90. return {
  91. data:{},
  92. renwuName:'',//任务名称
  93. projectId:'',//项目id
  94. scoreStandard:'',//评价标准
  95. scoreLimit:'',//评分上限
  96. weight:'',//权重
  97. remindTime: '',//提醒时间
  98. warnTime:'',//预警时间
  99. datetimerange: [],
  100. people:[],
  101. peopleCruuent:'',
  102. peopleValue:'',
  103. peopleId:'',
  104. // 附件
  105. fileList: [],
  106. fileList2: [],
  107. fileList22:'',
  108. listStyles: {
  109. "borderStyle": {
  110. "width": "0", // 边框宽度
  111. },
  112. "border": false, // 是否显示边框
  113. "dividline": false
  114. },
  115. page:1,
  116. size:10,
  117. totalCount:0,
  118. }
  119. },
  120. onLoad(option) {
  121. console.log(JSON.parse(decodeURIComponent(option.data)))
  122. console.log(JSON.parse(decodeURIComponent(option.people)))
  123. this.data=JSON.parse(decodeURIComponent(option.data))
  124. this.people=JSON.parse(decodeURIComponent(option.people))
  125. // this.getPeople()
  126. this.peopleValue=this.data.headerName
  127. this.peopleId=this.data.header
  128. this.datetimerange[0]=this.data.startTime
  129. this.datetimerange[1]=this.data.endTime
  130. var image=[]
  131. image=this.data.fileUrl.split(',')
  132. this.fileList =image.map(item =>{
  133. return {
  134. name: item
  135. }
  136. })
  137. this.fileList2=image
  138. this.fileList22=image.join(",")
  139. console.log(this.fileList)
  140. },
  141. methods: {
  142. // 任务负责人弹框
  143. toggle() {
  144. console.log('dd')
  145. // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
  146. this.$refs.popup.open('bottom')
  147. // this.getPeople()
  148. },
  149. //取消弹框
  150. quPopup(){
  151. this.$refs.popup.close()
  152. },
  153. //确定负责人
  154. selectPeo(){
  155. this.$refs.popup.close()
  156. this.peopleValue=this.people[this.peopleCruuent].userName
  157. this.peopleId=this.people[this.peopleCruuent].id
  158. },
  159. // 选择负责人
  160. radioChange: function(evt) {
  161. console.log(evt)
  162. for (let i = 0; i < this.people.length; i++) {
  163. if (this.people[i].userName === evt.detail.value) {
  164. this.peopleCruuent = i;
  165. break;
  166. }
  167. }
  168. },
  169. //选择负责人
  170. getPeople(){
  171. // this.people=[]
  172. uni.showLoading({
  173. title: '加载中',
  174. mask: true, // 是否显示透明蒙层,防止触摸穿透
  175. });
  176. this.$Request.postJson('/api/sysUser/queryPage?page='+this.page+'&rows='+this.size,{
  177. "userName": null, // 姓名
  178. "roleName": null, // 角色名称
  179. "department": null, // 部门
  180. "createBy": "", // 创建时间-开始日期
  181. "updateBy": "" // 创建时间-结束日期
  182. }).then(res => {
  183. if (res.code==200) {
  184. this.totalCount = res.data.total
  185. if (this.page == 1) {
  186. console.log('哈')
  187. this.people = res.data.rows
  188. } else {
  189. this.people = this.people.concat(res.data.rows)
  190. }
  191. console.log(this.people,'人')
  192. }
  193. uni.hideLoading();
  194. });
  195. },
  196. //修改任务
  197. updateRen(){
  198. let that = this
  199. if (!that.data.taskName) {
  200. that.$queue.showToast("请输入任务名称");
  201. }else if (!that.data.scoreStandard) {
  202. that.$queue.showToast("请输入评分标准");
  203. }else if (!that.data.scoreLimit) {
  204. that.$queue.showToast("请输入评分上限");
  205. }else if (!that.data.weight) {
  206. that.$queue.showToast("请输入权重");
  207. }else if (!that.data.remindTime) {
  208. that.$queue.showToast("请选择提醒时间");
  209. }else if (!that.data.warnTime) {
  210. that.$queue.showToast("请选择预警时间");
  211. }else if (!that.datetimerange) {
  212. that.$queue.showToast("请选择周期");
  213. } else if (!that.peopleId) {
  214. that.$queue.showToast("请选择任务负责人");
  215. }else {
  216. uni.showLoading({
  217. title: '加载中',
  218. mask: true, // 是否显示透明蒙层,防止触摸穿透
  219. });
  220. var data={
  221. "id": that.data.id,
  222. "taskName": that.data.taskName, // 任务名称
  223. "projectId": that.data.projectId, // 项目ID
  224. "scoreStandard": that.data.scoreStandard, // 评价标准
  225. "fileUrl": that.fileList22, // 附件
  226. "scoreLimit": that.data.scoreLimit, // 评分上限
  227. "weight": that.data.weight, // 权重
  228. "remindTime": that.data.remindTime, // 提醒时间
  229. "warnTime": that.data.warnTime, // 预警时间
  230. "header": that.peopleId, // 负责人
  231. "startTime": that.datetimerange[0], // 周期-起始时间
  232. "endTime": that.datetimerange[1] // 周期-结束时间
  233. }
  234. that.$Request.postJson('/api/sysTask/update',data).then(res => {
  235. if (res.code==200) {
  236. uni.showToast({
  237. title: '修改成功',
  238. icon: 'none',
  239. duration:800
  240. });
  241. uni.hideLoading()
  242. setTimeout(function() {
  243. uni.switchTab({
  244. url:'/pages/project/index'
  245. })
  246. }, 1000)
  247. } else {
  248. uni.hideLoading();
  249. uni.showToast({
  250. title: res.message,
  251. icon: 'none',
  252. duration:800
  253. });
  254. }
  255. });
  256. }
  257. },
  258. // 上传附件
  259. uploadSuccess(e) {
  260. console.log('上传成功', e)
  261. },
  262. uploadFail(e) {
  263. console.log('上传失败:', e)
  264. },
  265. //删除文件
  266. deleteHandle(index){
  267. console.log(index)
  268. this.fileList2.splice(index.index,1)
  269. // console.log(this.fileList2)
  270. this.fileList22=this.fileList2.join(",")
  271. },
  272. async selectUpload(e) {
  273. console.log('上传:', e)
  274. // console.log((e.tempFiles[0].size / 1024 > 1024 * 2),'大小')
  275. if(e.tempFiles.length>0){
  276. for (let i = 0; i < e.tempFilePaths.length; i++) {
  277. if ((e.tempFiles[i].size / 1024 > 1024 * 2)) {
  278. console.log('过大',e.tempFiles[i].extname)
  279. if(e.tempFiles[i].extname=='jpg' || e.tempFiles[i].extname=='png'||e.tempFiles[i].extname=='jpeg'){
  280. this.yaimg(e.tempFilePaths[i])
  281. }else{
  282. uni.showModal({
  283. title: '提示',
  284. content: '文件大于2M,无法上传',
  285. showCancel: false, // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true
  286. success: function(res) {
  287. if (res.confirm) {
  288. }
  289. }
  290. });
  291. }
  292. }else{
  293. this.imgUpload(e.tempFiles[i].file);
  294. }
  295. }
  296. }
  297. },
  298. //上传图片
  299. async imgUpload(result){
  300. uni.showLoading({
  301. title: '上传中',
  302. mask: true, // 是否显示透明蒙层,防止触摸穿透
  303. });
  304. let data = new FormData();
  305.   data.set("file", result);
  306.   let res = await this.$axios({
  307.     method: "post",
  308.     url: this.config('APIHOST1') + "/api/sysFile/upload",
  309.     headers: {
  310. tokenW: sessionStorage.getItem("token"),
  311. "Content-Type": "multipart/form-data"
  312.     },
  313.     data: data,
  314.   });
  315. // return res
  316.   console.log(res, "图片上传成功");
  317.   if (res.data.code == 200) {
  318.     this.fileList2.push(res.data.data);
  319. this.fileList22=this.fileList2.join(",")
  320. // console.log(this.fileList2.join(","))
  321. uni.hideLoading();
  322.   } else if(res.message=="登录凭证已过去,请重新登录"){
  323. sessionStorage.removeItem("token")
  324. sessionStorage.removeItem("roleId")
  325. uni.showModal({
  326. title: '提示',
  327. content: '用户信息失效,请重新登录!',
  328. showCancel: false, // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true
  329. success: function(res) {
  330. if (res.confirm) {
  331. }
  332. }
  333. });
  334. uni.hideLoading();
  335. }else {
  336.     uni.showToast({
  337. title: res.message,
  338. icon: 'none',
  339. duration:800
  340. });
  341. uni.hideLoading();
  342.   }
  343. },
  344. /**
  345. * 压缩图片
  346. * @description 由组件处理,只需传入临时路径
  347. * @param {Object} url - 临时路径
  348. * @return void
  349. */
  350. yaimg(url) {
  351. uni.showLoading({
  352. title: '压缩中',
  353. mask: true, // 是否显示透明蒙层,防止触摸穿透
  354. });
  355. // 组件参数也有文档,详见文章的最底部!
  356. // const config = {
  357. // src: url,//要压缩的临时路径
  358. // maxSize: 800,//压缩后的最大尺寸
  359. // fileType: 'png',//压缩后的文件类型,可选值 jpg、png
  360. // quality: 0.6,//压缩后的质量(仅jpg类型有效,原因可自行阅读官方canvas文档),可选值 0 ~ 1,值越大越清晰(图片也越大)
  361. // }
  362. // console.log(config)
  363. // 调用压缩方法
  364. this.$refs.Compress.compress({
  365. src: url,//要压缩的临时路径
  366. maxSize: 800,//压缩后的最大尺寸
  367. fileType: '',//压缩后的文件类型,可选值 jpg、png
  368. quality: 0.6,//压缩后的质量(仅jpg类型有效,原因可自行阅读官方canvas文档),可选值 0 ~ 1,值越大越清晰(图片也越大)
  369. }).then((res) => {
  370. // console.log('返回的base64编码', res)
  371. this.base = res
  372. // 时间戳 + 随机数, 防止文件名重复
  373. let timestamp = new Date().getTime();
  374. let sunumber = Math.floor(Math.random()*999);
  375. // H5需要将base64转为file对象进行上传
  376. // 第一个参数是base64编码, 第二个是文件名
  377. var file = this.base64ToFile(res, timestamp + sunumber)
  378. // 最终压缩完毕的file对象
  379. console.log('压缩后的图片(File对象)', file)
  380. this.upload(file)
  381. this.file = file
  382. uni.hideLoading();
  383. //上传到服务器
  384. // this.upload(file)
  385. }).catch((err) => {
  386. console.log('压缩失败',err)
  387. uni.hideLoading();
  388. })
  389. },
  390. /**
  391. * 压缩后上传到服务器
  392. * @description 这块需要您自行处理
  393. * @param {Object} file - 要上传的file对象
  394. * @return void
  395. */
  396. async upload(file){
  397. uni.showLoading({
  398. title: '上传中',
  399. mask: true, // 是否显示透明蒙层,防止触摸穿透
  400. });
  401. let data = new FormData();
  402.   data.set("file", file);
  403. console.log(data)
  404.   let res = await this.$axios({
  405.     method: "post",
  406.     url: this.config('APIHOST1') + "/api/sysFile/upload",
  407.     headers: {
  408. tokenW: sessionStorage.getItem("token"),
  409. "Content-Type": "multipart/form-data"
  410.     },
  411.     data: data,
  412.   });
  413. // return res
  414.   console.log(res, "图片上传成功",res.data.code == 200);
  415.   if (res.data.code == 200) {
  416.     this.fileList2.push(res.data.data);
  417. this.fileList22=this.fileList2.join(",")
  418. console.log(this.fileList22)
  419. uni.hideLoading();
  420.   }else {
  421.     uni.showToast({
  422. title: res.message,
  423. icon: 'none',
  424. duration:800
  425. });
  426. uni.hideLoading();
  427.   }
  428. },
  429. /**
  430. * base64 → File
  431. * @description 转换函数
  432. * @param {String} base64- base64完整字符串
  433. * @param {String} name - 文件名
  434. * @return Object
  435. */
  436. base64ToFile(base64, name) {
  437. if (typeof base64 != 'string') { return; }
  438. var arr = base64.split(',')
  439. var type = arr[0].match(/:(.*?);/)[1]
  440. var fileExt = type.split('/')[1]
  441. var bstr = atob(arr[1])
  442. var n = bstr.length
  443. var u8arr = new Uint8Array(n)
  444. while (n--) {
  445. u8arr[n] = bstr.charCodeAt(n)
  446. }
  447. return new File([u8arr], `${name}.` + fileExt, {
  448. type: type
  449. })
  450. },
  451. config: function (name) {
  452. var info = null
  453. if (name) {
  454. var name2 = name.split('.') //字符分割
  455. if (name2.length > 1) {
  456. info = configdata[name2[0]][name2[1]] || null
  457. } else {
  458. info = configdata[name] || null
  459. }
  460. if (info == null) {
  461. let web_config = cache.get('web_config')
  462. if (web_config) {
  463. if (name2.length > 1) {
  464. info = web_config[name2[0]][name2[1]] || null
  465. } else {
  466. info = web_config[name] || null
  467. }
  468. }
  469. }
  470. }
  471. return info
  472. },
  473. }
  474. }
  475. </script>
  476. <style>
  477. .content {
  478. display: flex;
  479. flex-direction: column;
  480. align-items: center;
  481. justify-content: center;
  482. }
  483. .param{
  484. margin: 20rpx 0 0 0;
  485. width: 100%;
  486. background-color: rgba(255, 255, 255, 1);
  487. font-size: 28rpx;
  488. font-weight: 400;
  489. line-height: 41rpx;
  490. color: rgba(0, 0, 0, 1);
  491. }
  492. .proMiao{
  493. margin: 31rpx 0 0 20rpx;
  494. }
  495. /* 上传附件 */
  496. .upload-img{
  497. /* margin: 25rpx 0 0 21rpx;
  498. width: 200rpx;
  499. height: 80rpx;
  500. opacity: 1;
  501. border-radius: 13rpx;
  502. background: rgba(0, 97, 255, 0.1);
  503. border: 1rpx solid rgba(0, 97, 255, 1); */
  504. }
  505. .proINname{
  506. margin: 25rpx 0 0 21rpx;
  507. width: 709rpx;
  508. height: 90rpx;
  509. border-radius: 13rpx;
  510. background: rgba(245, 248, 252, 1);
  511. border: 1rpx solid rgba(229, 229, 229, 1);
  512. font-size: 28rpx;
  513. line-height: 90rpx;
  514. /* color: rgba(179, 179, 179, 1); */
  515. }
  516. .proIMi{
  517. height: 315rpx;
  518. }
  519. /* 操作键 */
  520. .project{
  521. display: flex;
  522. margin: 61rpx 0 0 0;
  523. justify-content: space-evenly;
  524. }
  525. .butt{
  526. width: 330rpx;
  527. height: 90rpx;
  528. border-radius: 117rpx;
  529. font-size: 32rpx;
  530. line-height: 90rpx;
  531. text-align: center;
  532. }
  533. .quxiao{
  534. border: 1rpx solid rgba(0, 97, 255, 1);
  535. color: rgba(0, 97, 255, 1);
  536. }
  537. .queren{
  538. background: rgba(0, 97, 255, 1);
  539. color: rgba(255, 255, 255, 1);
  540. }
  541. /* 任务负责人弹出框 */
  542. .popup-content{
  543. height: 452px;
  544. overflow-x: hidden;
  545. .scroll_view_style{
  546. height: 100%;
  547. }
  548. }
  549. .popup-title{
  550. display: flex;
  551. width: 100%;
  552. height: 104rpx;
  553. font-size: 32rpx;
  554. line-height: 104rpx;
  555. justify-content: space-around;
  556. color: rgba(0, 0, 0, 1);
  557. }
  558. .l-line{
  559. width: 100%;
  560. border: 1rpx solid rgba(230, 230, 230, 1);
  561. }
  562. .l-kuang{
  563. margin: 40rpx 0 0 20rpx;
  564. display: flex;
  565. }
  566. .l-circle{
  567. width: 80rpx;
  568. height: 80rpx;
  569. border-radius: 50%;
  570. background-color:rgba(204, 204, 204, 1);
  571. }
  572. .l-label1{
  573. width: 50rpx;
  574. height: 50rpx;
  575. opacity: 1;
  576. border-radius: 50%;
  577. background-color: rgba(0, 97, 255, 1);
  578. }
  579. .l-label{
  580. /* margin-left: 404rpx; */
  581. /* width: 50rpx;
  582. height: 50rpx;
  583. opacity: 1;
  584. border-radius: 50%;
  585. border: 1rpx solid rgba(166, 166, 166, 1); */
  586. }
  587. </style>