actionplanDetails.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. var app = getApp();
  2. var that;
  3. import { returnStr, setCache, getCache, _debounce, getRole } from '../../../utils/util'
  4. Page({
  5. data: {
  6. detailsshow: false,
  7. apdList: [],
  8. detailsTIt: '',
  9. apDetails: {},
  10. apList: [],
  11. knowFrom: '',
  12. packId: 0, // 记录id
  13. assessID: 0, // 记录人
  14. planIndex: [], // 维度下标,指标下标
  15. isShowAdd: false, // 是否显示添加按钮
  16. isWt: false,
  17. titValue: '', // 执行计划名
  18. messageVal: '', // 备注
  19. bootBool: false,// 防止多次请求
  20. has_finish: 0,
  21. // 上传图标与附件
  22. img_fileList: [], // 图片附件
  23. isShowText: false,
  24. isShowDetil:false,//显示详情
  25. },
  26. onLoad() {
  27. that=this;
  28. },
  29. onShow() {
  30. this.setData({
  31. query: getCache('actionplanDetails')
  32. })
  33. this.init()
  34. },
  35. showDetil() {
  36. this.setData({
  37. isShowDetil: !this.data.isShowDetil
  38. })
  39. },
  40. showText() {
  41. this.setData({
  42. isShowText: !this.data.isShowText
  43. })
  44. },
  45. deleteImg(e) {
  46. if (this.data.img_fileList.length==0) {
  47. this.setData({
  48. img_fileList:[]
  49. })
  50. return false
  51. }
  52. this.setData({
  53. img_fileList: this.data.img_fileList.splice(e.target.dataset.index, 1)
  54. })
  55. },
  56. // 返回时刷新列表数据
  57. routeBack() {
  58. let query = getCache('actionplanList');
  59. if (query) {
  60. let data = {
  61. know: this.data.knowFrom,
  62. apList: this.data.apList,
  63. packId: this.data.packId,
  64. assessID: this.data.assessID,
  65. recordMemberIds: query.recordMemberIds ? query.recordMemberIds : []
  66. };
  67. setCache('actionplanList', data);
  68. }
  69. },
  70. save() {
  71. // 保存
  72. if (this.data.knowFrom == 'action') {
  73. // 执行计划
  74. this.saveAction('api/per/package/action');
  75. } else if (this.data.knowFrom == 'admnin') {
  76. // 管理记录
  77. this.saveAction('api/per/package/track');
  78. }
  79. },
  80. saveAction(urls) {
  81. if (this.data.bootBool) {
  82. return;
  83. }
  84. // 执行计划
  85. if (!this.data.titValue && this.data.titValue == '') {
  86. app.globalData.showToast('请输入标题');
  87. return;
  88. }
  89. let images = [];
  90. this.data.img_fileList.forEach(item => {
  91. let str = item.split("/")
  92. images.push(
  93. { name: str[str.length - 1], url: item }
  94. )
  95. })
  96. let data = {
  97. package_employee_id: this.data.packId,
  98. index_id: this.data.apDetails.id,
  99. title: this.data.titValue,
  100. remark: this.data.messageVal,
  101. dimension_xb: this.data.planIndex[0],
  102. images: JSON.stringify(images),
  103. append: '', //附件
  104. appendName: '' //附件名称
  105. };
  106. this.setData({
  107. bootBool: true
  108. })
  109. app.$post(urls, data)
  110. .then(res => {
  111. if (res.data.code == 1) {
  112. app.globalData.showToast('提交成功');
  113. this.setData({
  114. titValue: '',
  115. messageVal: '',
  116. img_fileList: [],
  117. })
  118. this.employeeDet();
  119. }
  120. })
  121. .finally(() => {
  122. setTimeout(() => {
  123. this.setData({
  124. bootBool: false
  125. })
  126. }, 1000);
  127. });
  128. },
  129. closeWt() {
  130. localStorage.setItem('isWt', true);
  131. this.isWt = false;
  132. },
  133. addThePlan(item) {
  134. if (!this.isShowAdd || this.has_finish) {
  135. return false
  136. }
  137. let data = {
  138. know: this.knowFrom,
  139. keys: JSON.stringify(item) || null,
  140. apList: JSON.stringify(this.apDetails),
  141. packId: this.packId,
  142. assessID: this.assessID,
  143. planIndex: this.planIndex[0] //维度下标
  144. };
  145. this.$setCache('addthePlan', data);
  146. // 添加
  147. this.$router.push({ name: 'addthePlan' });
  148. },
  149. bindTextAreaBlur: function (e) {
  150. this.setData({
  151. titValue: e.detail.value,
  152. });
  153. },
  154. bindTextAreaBlur2: function (e) {
  155. this.setData({
  156. messageVal: e.detail.value,
  157. });
  158. },
  159. employeeDet() {
  160. let params = {
  161. id: this.data.packId
  162. };
  163. app.$get('api/per/package/employee/info', params).then(res => {
  164. if (res.data.code == 1) {
  165. let data = res.data.data;
  166. this.setData({
  167. has_finish: data.has_finish
  168. })
  169. let dimension = data.dimension[this.data.planIndex[0]].index[this.data.planIndex[1]];
  170. this.setData({
  171. apList: JSON.stringify(data.dimension)
  172. })
  173. if (this.data.knowFrom == 'action') {
  174. // 执行计划
  175. if (dimension.schedule) {
  176. dimension.schedule.map(item => {
  177. if (app.globalData.usersList[item.employee_id]) {
  178. item.userName = app.globalData.usersList[item.employee_id] ? app.globalData.usersList[item.employee_id].name : ''
  179. }
  180. })
  181. this.setData({
  182. apdList: dimension.schedule
  183. })
  184. }
  185. } else if (this.data.knowFrom == 'admnin') {
  186. // 管理记录
  187. if (dimension.mamage_record) {
  188. dimension.mamage_record.map(item => {
  189. if (app.globalData.usersList[item.employee_id]) {
  190. item.userName = app.globalData.usersList[item.employee_id] ? app.globalData.usersList[item.employee_id].name : ''
  191. }
  192. })
  193. this.setData({
  194. apdList: dimension.mamage_record
  195. })
  196. }
  197. }
  198. }
  199. })
  200. .finally(() => {
  201. this.routeBack();
  202. });
  203. },
  204. init() {
  205. let query = this.data.query;
  206. let apList = JSON.parse(query.apList);
  207. this.setData({
  208. knowFrom: query.know,
  209. packId: query.packId,
  210. assessID: query.assessID,
  211. planIndex: apList.planIndex,
  212. apDetails: apList,
  213. })
  214. if (this.data.knowFrom == 'action') {
  215. if (this.data.assessID == app.globalData.userData.id) {
  216. this.setData({
  217. isShowAdd: true
  218. })
  219. }
  220. // 执行计划
  221. this.setData({
  222. detailsTIt: '执行计划'
  223. })
  224. } else if (this.data.knowFrom == 'admnin') {
  225. this.setData({//管理记录人判断
  226. isShowAdd: apList.isOperation
  227. })
  228. // this.$getEmployeeAll()[this.assessID].employee_detail.superior_list.some(item => {
  229. // // 判断被考核人的上级是否包含登录者
  230. // if (item.id == this.$getUserData_jx().id) {
  231. // this.isShowAdd = true;
  232. // return true;
  233. // }
  234. // });
  235. if (app.globalData.userData.is_creator == 1) {
  236. // 如果是创始人也可以操作
  237. this.setData({
  238. isShowAdd: true
  239. })
  240. }
  241. if (app.getPermis(3)) {
  242. // 如果是子管理员并且管理范围权限为“全公司”
  243. this.setData({
  244. isShowAdd: true
  245. })
  246. }
  247. this.setData({
  248. detailsTIt: '管理记录'
  249. })
  250. }
  251. this.employeeDet();
  252. },
  253. showImg(e) {
  254. let img = e.target.dataset.img.url
  255. dd.previewImage({
  256. current: 0,
  257. urls: [img],
  258. });
  259. },
  260. openDetail(e) {
  261. let item = e.target.dataset.item
  262. if (!this.data.isShowAdd || this.data.has_finish) {
  263. return false
  264. }
  265. let data = {
  266. know: this.data.knowFrom,
  267. keys: JSON.stringify(item) || null,
  268. apList: JSON.stringify(this.data.apDetails),
  269. packId: this.data.packId,
  270. assessID: this.data.assessID,
  271. planIndex: this.data.planIndex[0] //维度下标
  272. };
  273. setCache('addthePlan', data);
  274. dd.navigateTo({
  275. url: `../addthePlan/addthePlan`
  276. })
  277. },
  278. //图片选择
  279. openImg(e) {
  280. var files = that.data.img_fileList;
  281. if (files.length >= 3) {
  282. app.globalData.showToast("只能上传三张");
  283. return false;
  284. }
  285. dd.chooseImage({
  286. count: 1,
  287. success: (res) => {
  288. that.postImg(res.filePaths[0]);
  289. },
  290. });
  291. },
  292. postImg(img_url) {
  293. var files = that.data.img_fileList;
  294. dd.httpRequest({
  295. url: app.globalData.imgHttpUrl,
  296. method: 'POST',
  297. data: {
  298. md5: that.random_string(32),
  299. 'name': app.globalData.day
  300. },
  301. success: function (res) {
  302. if (app.globalData.userData.site_id) {
  303. var key = 'intesys/ddJx/' + app.globalData.userData.site_id + "/" + app.globalData.day + '/' + that.random_string(32) + '.png';
  304. } else {
  305. var key = 'intesys/ddJx/' + app.globalData.day + '/' + that.random_string(32) + '.png';
  306. }
  307. var obj = res.data.data;
  308. dd.uploadFile({
  309. url: app.globalData.ALIOSS_URL,
  310. fileType: 'image',
  311. fileName: 'file',
  312. filePath: img_url,
  313. formData: {
  314. key: key,
  315. policy: obj.policy,
  316. OSSAccessKeyId: obj.accessid,
  317. success_action_status: 200,
  318. signature: obj.signature
  319. },
  320. success: (res) => {
  321. if (res.statusCode == 200) {
  322. if (files.length > 0) {
  323. files.push(app.globalData.ALIOSS_URL +'/'+key)
  324. } else {
  325. files = [app.globalData.ALIOSS_URL +'/'+ key];
  326. }
  327. that.setData({
  328. img_fileList: files
  329. });
  330. app.globalData.showToast("已上传");
  331. }
  332. },
  333. fail: (err) => {
  334. console.log(err);
  335. }
  336. });
  337. },
  338. fail: function (res) {
  339. app.globalData.showToast("上传失败");
  340. }
  341. })
  342. },
  343. random_string(len) {
  344. len = len || 32
  345. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  346. var maxPos = chars.length
  347. var pwd = ''
  348. for (let i = 0; i < len; i++) {
  349. pwd += chars.charAt(Math.floor(Math.random() * maxPos))
  350. }
  351. return pwd
  352. },
  353. });