微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
7.9 KiB

  1. // pages/bankDraft/add/add.js
  2. import * as UTIL from '../../../utils/util.js';
  3. import * as API from '../../../utils/API.js';
  4. let EVN_CONFIG = require('../../../env/env');
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. isIPX: app.globalData.isIPX,
  12. form:{
  13. eventTime: UTIL.formatDate(new Date()), //开票日期 必填
  14. remark: "",
  15. },
  16. showBtn:true,
  17. showEventTime:false,
  18. status:0,
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. let that = this
  25. //所属银行
  26. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'major_type', {method:'GET'}, {
  27. success: (res) => {
  28. this.setData({
  29. majorTypeOptions:res.data
  30. });
  31. }
  32. })
  33. let templateQueryParams = {
  34. // 分页
  35. type:'5'
  36. };
  37. UTIL.httpRequest(API.URL_GET_TEMPLATELIST , templateQueryParams, {
  38. success: (res) => {
  39. that.setData({
  40. approvalTemplateList:res.rows,
  41. ["form.approvalTemplateId"]:res.rows[0].id,
  42. ["form.approvalTemplateName"]:res.rows[0].name,
  43. })
  44. }
  45. })
  46. if(options.id!=null&&options.id!=""){
  47. this.setData({id:options.id})
  48. UTIL.httpRequest(API.URL_GET_MAJOREVENTGET + this.data.id, {method:'GET'}, {
  49. success: (res) => {
  50. console.log(res);
  51. if(res.data.auditStatus!='0'&&res.data.auditStatus!='2'){
  52. this.setData({'showBtn':false});
  53. }
  54. res.data.majorTypeText = UTIL.getTransform(res.data.majorType,that.data.majorTypeOptions);
  55. let op = that.data.approvalTemplateList.filter(function (e) { return e.id == res.data.approvalTemplateId; });
  56. res.data.approvalTemplateName = op[0].name;
  57. this.setData({'form':res.data})
  58. this.selectComponent('#hf_editor').setHtml(res.data.eventContent);
  59. }
  60. })
  61. }else{
  62. this.onShow()
  63. }
  64. },
  65. onConfirmPickApproval(event) {
  66. console.log(event);
  67. var that = this;
  68. this.setData({
  69. ["form.showApprovalTemplateName"]: false,
  70. ["form.approvalTemplateName"]: event.detail.value.name,
  71. ["form.approvalTemplateId"]: event.detail.value.id,
  72. });
  73. },
  74. onConfirmEventTime(e){
  75. let data = this.getNewDate(new Date(e.detail.value));
  76. this.setData({'form.eventTime':data});
  77. },
  78. getHtml(e) {//从组件获取值
  79. this.data.form.eventContent = e.detail.content.html
  80. },
  81. insertImage(){ //图片上传插入示例
  82. wx.chooseImage({
  83. count: 1,
  84. success: r => {
  85. // 本地测试图片插入
  86. // this.selectComponent('#hf_editor').insertSrc(res.tempFilePaths[0]);
  87. wx.uploadFile({ //调用图片上传接口
  88. url: wx.getStorageSync('dressCode')+'/common/upload',
  89. filePath: r.tempFilePaths[0],
  90. name: 'imgFile',
  91. success: res => {
  92. console.log();
  93. let imgUrl = JSON.parse(res.data).url
  94. this.selectComponent('#hf_editor').insertSrc(wx.getStorageSync('dressCode')+'/common/upload' + imgUrl);//调用组件insertSrc方法
  95. }
  96. })
  97. }
  98. })
  99. },
  100. getNewDate(date){
  101. //date是传过来的时间戳,注意需为13位,10位需*1000
  102. //也可以不传,获取的就是当前时间
  103. var time
  104. if(date){
  105. time = new Date(date);
  106. }else{
  107. time = new Date();
  108. }
  109. var year= time.getFullYear() //年
  110. var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
  111. var day = ("0" + time.getDate()).slice(-2); //日
  112. var mydate = year + "-" + month + "-" + day;
  113. return mydate
  114. },
  115. /**
  116. * 生命周期函数--监听页面初次渲染完成
  117. */
  118. onReady() {
  119. },
  120. /**
  121. * 生命周期函数--监听页面显示
  122. */
  123. onShow() {
  124. },
  125. openBox(even){
  126. console.log(even.currentTarget.dataset.name);
  127. this.setData({
  128. [even.currentTarget.dataset.name]:true
  129. })
  130. },
  131. onChange(event){
  132. console.log(event);
  133. this.setData({
  134. [event.currentTarget.dataset.value]: event.detail,
  135. })
  136. },
  137. closeBox(even){
  138. console.log(even.currentTarget.dataset.name);
  139. this.setData({
  140. [even.currentTarget.dataset.name]:false
  141. })
  142. },
  143. goSubmit(){
  144. if(this.data.form.eventName===''||this.data.form.eventName==null){ //事项名称
  145. UTIL.showToastNoneIcon('请填写事项名称!');
  146. return false;
  147. }else if(this.data.form.eventTime===''||this.data.form.eventTime==null){ //事项时间
  148. UTIL.showToastNoneIcon('事项时间不能为空!');
  149. return false;
  150. }else if(this.data.form.eventContent===''||this.data.form.eventContent==null){ //事项内容
  151. UTIL.showToastNoneIcon('事项内容不能为空!');
  152. return false;
  153. }else if(this.data.form.dzbty===''||this.data.form.dzbty==null){ //事项内容
  154. UTIL.showToastNoneIcon('村党支部提议不能为空!');
  155. return false;
  156. }else if(this.data.form.lwhsy===''||this.data.form.lwhsy==null){ //事项内容
  157. UTIL.showToastNoneIcon('两委会商议不能为空!');
  158. return false;
  159. }else if(this.data.form.dqyshsyhjy===''||this.data.form.dqyshsyhjy==null){ //事项内容
  160. UTIL.showToastNoneIcon('党群议事会审议和决议不能为空!');
  161. return false;
  162. }else if(this.data.form.jcjggk===''||this.data.form.jcjggk==null){ //事项内容
  163. UTIL.showToastNoneIcon('决策结果公开不能为空!');
  164. return false;
  165. }else if(this.data.form.ssqkgk===''||this.data.form.ssqkgk==null){ //事项内容
  166. UTIL.showToastNoneIcon('实施情况公开不能为空!');
  167. return false;
  168. }else if(this.data.status=='0'){
  169. this.setData({'status':'1'})
  170. var that = this;
  171. that.data.form.method = 'POST';
  172. that.data.form.eventContent = that.data.form.eventContent.replace(/\\/g,"/")
  173. console.log(that.data.form);
  174. if(that.data.form.id==""||that.data.form.id==null){
  175. UTIL.httpRequest(API.URL_POST_MAJOREVENTADD, that.data.form , {
  176. success: (res) => {
  177. this.setData({'status':0})
  178. if(res.code == 200){
  179. UTIL.showToastNoneIcon('新增成功');
  180. setTimeout(function(){
  181. wx.navigateBack({
  182. delta:1
  183. })
  184. },2000)
  185. }else{
  186. UTIL.showToastNoneIcon('新增失败:'+res.msg);
  187. }
  188. }
  189. })
  190. }else{
  191. UTIL.httpRequest(API.URL_POST_MAJOREVENTUPDATE, that.data.form , {
  192. success: (res) => {
  193. this.setData({'status':0})
  194. if(res.code == 200){
  195. UTIL.showToastNoneIcon('修改成功');
  196. setTimeout(function(){
  197. wx.navigateBack({
  198. delta:1
  199. })
  200. },2000)
  201. }else{
  202. UTIL.showToastNoneIcon('修改失败:'+res.msg);
  203. }
  204. }
  205. })
  206. }
  207. }
  208. },
  209. onConfirmTime(event){
  210. this.setData({
  211. [event.currentTarget.dataset.name]: false,
  212. [event.currentTarget.dataset.value]: UTIL.formatDate(event.detail),
  213. });
  214. },
  215. openBox(even){
  216. console.log(even.currentTarget.dataset.name);
  217. this.setData({
  218. [even.currentTarget.dataset.name]:true
  219. })
  220. },
  221. closeBox(even){
  222. console.log(even.currentTarget.dataset.name);
  223. this.setData({
  224. [even.currentTarget.dataset.name]:false
  225. })
  226. },
  227. back:function(){
  228. wx.navigateBack({
  229. delta: 1
  230. })
  231. },
  232. onConfirm(event) {
  233. this.setData({
  234. [event.currentTarget.dataset.name]: false,
  235. [event.currentTarget.dataset.value]: event.detail.value.dictValue,
  236. [event.currentTarget.dataset.value+'Text']: event.detail.value.dictLabel,
  237. });
  238. },
  239. /**
  240. * 生命周期函数--监听页面隐藏
  241. */
  242. onHide() {
  243. },
  244. /**
  245. * 生命周期函数--监听页面卸载
  246. */
  247. onUnload() {
  248. },
  249. /**
  250. * 页面相关事件处理函数--监听用户下拉动作
  251. */
  252. onPullDownRefresh() {
  253. },
  254. /**
  255. * 页面上拉触底事件的处理函数
  256. */
  257. onReachBottom() {
  258. },
  259. /**
  260. * 用户点击右上角分享
  261. */
  262. onShareAppMessage() {
  263. }
  264. })