addthePlan.js 8.9 KB

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