addRenwu.vue 17 KB

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