riskAssessment.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // pages/form/riskAssessment/riskAssessment.js
  2. const upload = require("../../../utils/upload")
  3. const api = require('../../../api/index')
  4. import { $wuxForm} from '../../../miniprogram_npm/wux-weapp/index'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. validateMessages: {
  11. required: '%s 字段为必填',
  12. },
  13. form:{
  14. unableExport:true
  15. },
  16. labelWidth:350,
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady() {
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow() {
  32. },
  33. /**
  34. * 页面方法集合
  35. */
  36. //表单栏位值发生变化时
  37. onValuesChange(e) {
  38. console.log(e)
  39. const { changedValues, allValues } = e.detail
  40. // this.setValues(changedValues)
  41. Object.keys(changedValues).forEach((field) => {
  42. this.setData({
  43. ['form.'+field]: changedValues[field],
  44. })
  45. })
  46. console.log('onValuesChange \n', changedValues, allValues)
  47. },
  48. //手机号校验
  49. checkPhone(rule, value){
  50. if(!value){
  51. return Promise.reject(new Error('手机号不能为空!'))
  52. }
  53. const isTel = (value) => /^1[34578]\d{9}$/.test(value)
  54. if(!isTel(value)){
  55. return Promise.reject(new Error('手机号输入错误!'))
  56. }
  57. return Promise.resolve()
  58. },
  59. //上传文件
  60. uploadFile(){
  61. const that = this;
  62. wx.chooseMessageFile({
  63. count: 1, // 默认9,表示一次最多可以选择的文件个数
  64. type: 'file', // 可以指定是文件
  65. success(res) {
  66. // 返回选定文件的本地文件路径列表,tempFilePath可以作为文件上传的标识
  67. const tempFilePaths = res.tempFilePaths[0];
  68. upload(tempFilePaths).then(res=>{
  69. console.log(res)
  70. })
  71. }
  72. });
  73. },
  74. //输入备注
  75. changRemark(e){
  76. this.setData(
  77. {
  78. ["form.description"]:e.detail.value
  79. }
  80. )
  81. },
  82. //修改专利无法导出?
  83. onChange(e){
  84. this.setData(
  85. {
  86. ["form.patentExport"]:e.detail
  87. }
  88. )
  89. },
  90. //提交工单
  91. submit(){
  92. var key = api.isLogin()
  93. if(!key){
  94. return false
  95. }
  96. const { validateFields } = $wuxForm()
  97. validateFields((err, values) => {
  98. console.log(err)
  99. if (!err) {
  100. var params = {
  101. ticketType:1,
  102. contactPerson:this.data.form.contactPerson,
  103. contactPhone:this.data.form.contactPhone,
  104. contactMail:this.data.form.contactMail,
  105. fileGuids:this.data.form.fileGuids,
  106. ticketFillInAddDTO:this.data.form
  107. }
  108. api.addTicket(params).then(res=>{
  109. if(res.code == 200){
  110. wx.navigateTo({
  111. url: '/pages/successReminder/successReminder?id=1',
  112. })
  113. }
  114. })
  115. }else{
  116. var error = Object.keys(err)
  117. var key = error[0]
  118. var len = err[key].errors.length
  119. var message = err[key].errors[len-1].message
  120. wx.showModal({
  121. title: '提示',
  122. content: message,
  123. complete: (res) => {
  124. if (res.cancel) {
  125. }
  126. if (res.confirm) {
  127. }
  128. }
  129. })
  130. }
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面隐藏
  135. */
  136. onHide() {
  137. },
  138. /**
  139. * 生命周期函数--监听页面卸载
  140. */
  141. onUnload() {
  142. },
  143. /**
  144. * 页面相关事件处理函数--监听用户下拉动作
  145. */
  146. onPullDownRefresh() {
  147. },
  148. /**
  149. * 页面上拉触底事件的处理函数
  150. */
  151. onReachBottom() {
  152. },
  153. /**
  154. * 用户点击右上角分享
  155. */
  156. onShareAppMessage() {
  157. }
  158. })