riskAssessment.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. fileList:[],
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. },
  24. /**
  25. * 生命周期函数--监听页面初次渲染完成
  26. */
  27. onReady() {
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow() {
  33. },
  34. /**
  35. * 页面方法集合
  36. */
  37. //表单栏位值发生变化时
  38. onValuesChange(e) {
  39. console.log(e)
  40. const { changedValues, allValues } = e.detail
  41. // this.setValues(changedValues)
  42. Object.keys(changedValues).forEach((field) => {
  43. this.setData({
  44. ['form.'+field]: changedValues[field],
  45. })
  46. })
  47. console.log('onValuesChange \n', changedValues, allValues)
  48. },
  49. //手机号校验
  50. checkPhone(rule, value){
  51. if(!value){
  52. return Promise.reject(new Error('手机号不能为空!'))
  53. }
  54. const isTel = (value) => /^1[34578]\d{9}$/.test(value)
  55. if(!isTel(value)){
  56. return Promise.reject(new Error('手机号输入错误!'))
  57. }
  58. return Promise.resolve()
  59. },
  60. //上传文件
  61. uploadFile(){
  62. const that = this;
  63. wx.chooseMessageFile({
  64. count: 1, // 默认9,表示一次最多可以选择的文件个数
  65. type: 'file', // 可以指定是文件
  66. success(res) {
  67. console.log(res)
  68. var obj = res.tempFiles[0]
  69. var data = that.data.fileList
  70. data.push(obj)
  71. // that.setData(
  72. // {
  73. // fileList:data
  74. // }
  75. // )
  76. // 返回选定文件的本地文件路径列表,tempFilePath可以作为文件上传的标识
  77. const tempFilePaths = obj.path;
  78. upload.upload(tempFilePaths).then(res=>{
  79. if(res.code == 200){
  80. var arr = that.data.form.fileGuids
  81. if(!arr){
  82. arr = []
  83. }
  84. arr.push(res.data[0])
  85. that.setData(
  86. {
  87. ["form.fileGuids"]:arr,
  88. fileList:data
  89. }
  90. )
  91. }
  92. })
  93. }
  94. });
  95. },
  96. //删除文件
  97. delFile(e){
  98. var {index} = e.currentTarget.dataset
  99. console.log(this.data.form)
  100. var data = this.data.fileList
  101. data.splice(index,1)
  102. var fileGuid = this.data.form.fileGuids
  103. fileGuid.splice(index,1)
  104. this.setData(
  105. {
  106. fileList:data,
  107. ["form.fileGuids"]:arr
  108. }
  109. )
  110. },
  111. //输入备注
  112. changRemark(e){
  113. this.setData(
  114. {
  115. ["form.description"]:e.detail.value
  116. }
  117. )
  118. },
  119. //修改专利无法导出?
  120. onChange(e){
  121. this.setData(
  122. {
  123. ["form.patentExport"]:e.detail
  124. }
  125. )
  126. },
  127. //提交工单
  128. submit(){
  129. var key = api.isLogin()
  130. if(!key){
  131. return false
  132. }
  133. const { validateFields } = $wuxForm()
  134. validateFields((err, values) => {
  135. console.log(err)
  136. if (!err) {
  137. var params = {
  138. ticketType:1,
  139. contactPerson:this.data.form.contactPerson,
  140. contactPhone:this.data.form.contactPhone,
  141. contactMail:this.data.form.contactMail,
  142. fileGuids:this.data.form.fileGuids,
  143. ticketFillInAddDTO:this.data.form
  144. }
  145. wx.showLoading({
  146. title: '加载中',
  147. })
  148. api.addTicket(params).then(res=>{
  149. if(res.code == 200){
  150. wx.navigateTo({
  151. url: '/pages/successReminder/successReminder?id=1',
  152. })
  153. }
  154. })
  155. }else{
  156. var error = Object.keys(err)
  157. var key = error[0]
  158. var len = err[key].errors.length
  159. var message = err[key].errors[len-1].message
  160. wx.showModal({
  161. title: '提示',
  162. content: message,
  163. complete: (res) => {
  164. if (res.cancel) {
  165. }
  166. if (res.confirm) {
  167. }
  168. }
  169. })
  170. }
  171. })
  172. },
  173. /**
  174. * 生命周期函数--监听页面隐藏
  175. */
  176. onHide() {
  177. },
  178. /**
  179. * 生命周期函数--监听页面卸载
  180. */
  181. onUnload() {
  182. },
  183. /**
  184. * 页面相关事件处理函数--监听用户下拉动作
  185. */
  186. onPullDownRefresh() {
  187. },
  188. /**
  189. * 页面上拉触底事件的处理函数
  190. */
  191. onReachBottom() {
  192. },
  193. /**
  194. * 用户点击右上角分享
  195. */
  196. onShareAppMessage() {
  197. }
  198. })