actionplanDetails.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. setTimeout(() => {
  121. this.setData({
  122. bootBool: false
  123. })
  124. }, 1000);
  125. })
  126. },
  127. closeWt() {
  128. localStorage.setItem('isWt', true);
  129. this.isWt = false;
  130. },
  131. addThePlan(item) {
  132. if (!this.isShowAdd || this.has_finish) {
  133. return false
  134. }
  135. let data = {
  136. know: this.knowFrom,
  137. keys: JSON.stringify(item) || null,
  138. apList: JSON.stringify(this.apDetails),
  139. packId: this.packId,
  140. assessID: this.assessID,
  141. planIndex: this.planIndex[0] //维度下标
  142. };
  143. this.$setCache('addthePlan', data);
  144. // 添加
  145. this.$router.push({ name: 'addthePlan' });
  146. },
  147. bindTextAreaBlur: function (e) {
  148. this.setData({
  149. titValue: e.detail.value,
  150. });
  151. },
  152. bindTextAreaBlur2: function (e) {
  153. this.setData({
  154. messageVal: e.detail.value,
  155. });
  156. },
  157. employeeDet() {
  158. let params = {
  159. id: this.data.packId
  160. };
  161. app.$get('api/per/package/employee/info', params).then(res => {
  162. if (res.data.code == 1) {
  163. let data = res.data.data;
  164. this.setData({
  165. has_finish: data.has_finish
  166. })
  167. let dimension = data.dimension[this.data.planIndex[0]].index[this.data.planIndex[1]];
  168. this.setData({
  169. apList: JSON.stringify(data.dimension)
  170. })
  171. if (this.data.knowFrom == 'action') {
  172. // 执行计划
  173. if (dimension.schedule) {
  174. dimension.schedule.map(item => {
  175. if (app.globalData.usersList[item.employee_id]) {
  176. item.userName = app.globalData.usersList[item.employee_id] ? app.globalData.usersList[item.employee_id].name : ''
  177. }
  178. })
  179. this.setData({
  180. apdList: dimension.schedule
  181. })
  182. }
  183. } else if (this.data.knowFrom == 'admnin') {
  184. // 管理记录
  185. if (dimension.mamage_record) {
  186. dimension.mamage_record.map(item => {
  187. if (app.globalData.usersList[item.employee_id]) {
  188. item.userName = app.globalData.usersList[item.employee_id] ? app.globalData.usersList[item.employee_id].name : ''
  189. }
  190. })
  191. this.setData({
  192. apdList: dimension.mamage_record
  193. })
  194. }
  195. }
  196. }
  197. this.routeBack();
  198. })
  199. },
  200. init() {
  201. let query = this.data.query;
  202. let apList = JSON.parse(query.apList);
  203. this.setData({
  204. knowFrom: query.know,
  205. packId: query.packId,
  206. assessID: query.assessID,
  207. planIndex: apList.planIndex,
  208. apDetails: apList,
  209. })
  210. if (this.data.knowFrom == 'action') {
  211. if (this.data.assessID == app.globalData.userData.id) {
  212. this.setData({
  213. isShowAdd: true
  214. })
  215. }
  216. // 执行计划
  217. this.setData({
  218. detailsTIt: '执行计划'
  219. })
  220. } else if (this.data.knowFrom == 'admnin') {
  221. this.setData({//管理记录人判断
  222. isShowAdd: apList.isOperation
  223. })
  224. // this.$getEmployeeAll()[this.assessID].employee_detail.superior_list.some(item => {
  225. // // 判断被考核人的上级是否包含登录者
  226. // if (item.id == this.$getUserData_jx().id) {
  227. // this.isShowAdd = true;
  228. // return true;
  229. // }
  230. // });
  231. if (app.globalData.userData.is_creator == 1) {
  232. // 如果是创始人也可以操作
  233. this.setData({
  234. isShowAdd: true
  235. })
  236. }
  237. if (app.getPermis(3)) {
  238. // 如果是子管理员并且管理范围权限为“全公司”
  239. this.setData({
  240. isShowAdd: true
  241. })
  242. }
  243. this.setData({
  244. detailsTIt: '管理记录'
  245. })
  246. }
  247. this.employeeDet();
  248. },
  249. showImg(e) {
  250. let img = e.target.dataset.img.url
  251. dd.previewImage({
  252. current: 0,
  253. urls: [img],
  254. });
  255. },
  256. openDetail(e) {
  257. let item = e.target.dataset.item
  258. if (!this.data.isShowAdd || this.data.has_finish) {
  259. return false
  260. }
  261. let data = {
  262. know: this.data.knowFrom,
  263. keys: JSON.stringify(item) || null,
  264. apList: JSON.stringify(this.data.apDetails),
  265. packId: this.data.packId,
  266. assessID: this.data.assessID,
  267. planIndex: this.data.planIndex[0] //维度下标
  268. };
  269. setCache('addthePlan', data);
  270. dd.navigateTo({
  271. url: `../addthePlan/addthePlan`
  272. })
  273. },
  274. //图片选择
  275. openImg(e) {
  276. var files = that.data.img_fileList;
  277. if (files.length >= 3) {
  278. app.globalData.showToast("只能上传三张");
  279. return false;
  280. }
  281. dd.chooseImage({
  282. count: 1,
  283. success: (res) => {
  284. that.postImg(res.filePaths[0]);
  285. },
  286. });
  287. },
  288. postImg(img_url) {
  289. var files = that.data.img_fileList;
  290. dd.httpRequest({
  291. url: app.globalData.imgHttpUrl,
  292. method: 'POST',
  293. data: {
  294. md5: that.random_string(32),
  295. 'name': app.globalData.day
  296. },
  297. success: function (res) {
  298. if (app.globalData.userData.site_id) {
  299. var key = 'intesys/ddJx/' + app.globalData.userData.site_id + "/" + app.globalData.day + '/' + that.random_string(32) + '.png';
  300. } else {
  301. var key = 'intesys/ddJx/' + app.globalData.day + '/' + that.random_string(32) + '.png';
  302. }
  303. var obj = res.data.data;
  304. dd.uploadFile({
  305. url: app.globalData.ALIOSS_URL,
  306. fileType: 'image',
  307. fileName: 'file',
  308. filePath: img_url,
  309. formData: {
  310. key: key,
  311. policy: obj.policy,
  312. OSSAccessKeyId: obj.accessid,
  313. success_action_status: 200,
  314. signature: obj.signature
  315. },
  316. success: (res) => {
  317. if (res.statusCode == 200) {
  318. if (files.length > 0) {
  319. files.push(app.globalData.ALIOSS_URL +'/'+key)
  320. } else {
  321. files = [app.globalData.ALIOSS_URL +'/'+ key];
  322. }
  323. that.setData({
  324. img_fileList: files
  325. });
  326. app.globalData.showToast("已上传");
  327. }
  328. },
  329. fail: (err) => {
  330. console.log(err);
  331. }
  332. });
  333. },
  334. fail: function (res) {
  335. app.globalData.showToast("上传失败");
  336. }
  337. })
  338. },
  339. random_string(len) {
  340. len = len || 32
  341. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  342. var maxPos = chars.length
  343. var pwd = ''
  344. for (let i = 0; i < len; i++) {
  345. pwd += chars.charAt(Math.floor(Math.random() * maxPos))
  346. }
  347. return pwd
  348. },
  349. });