feedbackinfo.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import constant from '../../utils/constant';
  4. const app = getApp();
  5. Page({
  6. data: {
  7. Feedback:constant.arrFeedback,
  8. ImageArr:[],
  9. ImagePath: app.globalData.uploadImageUrl,
  10. },
  11. onLoad: function (options) {
  12. var that = this;
  13. var feedbackType=0;
  14. if (options.type){
  15. that.data.Feedback[0].CSS="";
  16. that.data.Feedback[options.type].CSS="Selected";
  17. }
  18. that.setData({
  19. Containnerheight: main.getWindowHeight(),
  20. IsShow:app.globalData.userInfo.IsShow,
  21. Feedback:that.data.Feedback,
  22. });
  23. main.checkGenerating();
  24. },
  25. bindKeyInput:function(e){
  26. var that=this;
  27. that.setData({
  28. InputValue:e.detail.value,
  29. });
  30. },
  31. bindKeyInput2:function(e){
  32. var that=this;
  33. that.setData({
  34. InputValue2:e.detail.value,
  35. });
  36. },
  37. saveFeedback:function(){
  38. var that=this;
  39. if (!that.data.InputValue){
  40. wx.showToast({
  41. title: '请填写内容',
  42. });
  43. }
  44. else if (that.data.InputValue.length<5){
  45. wx.showToast({
  46. title: '请多写点内容',
  47. });
  48. }
  49. else{
  50. wx.showLoading({
  51. title: '保存中',
  52. mask: true,
  53. });
  54. that.uploadImageAll(that.data.ImageArr,function (success,arrResult) {
  55. if (success) {
  56. wx.hideLoading();
  57. var param={};
  58. param.ProgramID=186;
  59. param.UserID=app.globalData.userInfo.UserID;
  60. param.Content=that.data.InputValue;
  61. param.ContactTa=that.data.InputValue2;
  62. param.FeedbackType=[];
  63. for(var i=0;i<that.data.Feedback.length;i++){
  64. if (that.data.Feedback[i].CSS=="Selected")
  65. param.FeedbackType.push(that.data.Feedback[i].Name);
  66. }
  67. param.FeedbackType=param.FeedbackType.join(",");
  68. if (arrResult.length>0)
  69. param.ImageUrl1=arrResult[0].Target;
  70. if (arrResult.length>1)
  71. param.ImageUrl2=arrResult[1].Target;
  72. if (arrResult.length>2)
  73. param.ImageUrl3=arrResult[2].Target;
  74. if (arrResult.length>3)
  75. param.ImageUrl4=arrResult[3].Target;
  76. param.FeedbackUrl=app.globalData.FeedbackUrl;
  77. main.postData('MPSFeedback', param, function (data) {
  78. wx.showModal({
  79. title: '提醒',
  80. content: '您的反馈已经收到,我们会尽快处理。感谢您的支持!',
  81. showCancel: false,
  82. complete: (res) => {
  83. if (res.confirm) {
  84. wx.navigateBack({
  85. delta: 1
  86. });
  87. }
  88. }
  89. });
  90. });
  91. } else {
  92. wx.showToast({
  93. title: '图片上传失败',
  94. image: "../images/universalpic_exclamation_white_120x120.png",
  95. mask: true,
  96. });
  97. }
  98. });
  99. }
  100. },
  101. //选择图片上传
  102. uploadImageField: function () {
  103. //console.log("uploadImageStart");
  104. var that = this;
  105. //若是安卓机
  106. if (app.globalData.IsAndroid) {
  107. selectImage(that);
  108. } else {
  109. wx.showActionSheet({
  110. itemList: ['拍照', '从手机相册选择'],
  111. success(res) {
  112. if (res.tapIndex == 0) {
  113. wx.chooseImage({
  114. count: 1,
  115. sizeType: ['compressed'],
  116. sourceType: ['camera'],
  117. success(res2) {
  118. wx.showLoading({
  119. title: '请稍候',
  120. mask: true,
  121. });
  122. setTimeout(function () {
  123. wx.hideLoading();
  124. selectImage(that);
  125. }, 2000);
  126. },
  127. });
  128. } else if (res.tapIndex == 1) {
  129. selectImage(that);
  130. }
  131. },
  132. fail(res) {
  133. console.log(res.errMsg)
  134. }
  135. });
  136. }
  137. function selectImage(that) {
  138. var sizeType = ['album'];
  139. //若是安卓机
  140. if (app.globalData.IsAndroid)
  141. sizeType = ['album', 'camera'];
  142. wx.chooseImage({
  143. count: 1,
  144. sizeType: ['compressed'],
  145. sourceType: sizeType,
  146. success(res) {
  147. // tempFilePath可以作为img标签的src属性显示图片
  148. var tempFilePaths = res.tempFilePaths;
  149. //console.log(tempFilePaths[0]);
  150. //that.data.FieldContent = that.data.FieldContent + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
  151. that.data.ImageArr.push(tempFilePaths[0]);
  152. that.setData({
  153. ImageArr:that.data.ImageArr,
  154. });
  155. },
  156. fail: function () {
  157. }
  158. });
  159. }
  160. },
  161. uploadFileToServer: function (file, callback) {
  162. var url = common.Encrypt("MiaoguoUploadFile2");
  163. wx.showLoading({
  164. title: '上传中',
  165. mask: true,
  166. });
  167. url=app.globalData.serverUrl + url;
  168. wx.uploadFile({
  169. url: url,
  170. filePath: file,
  171. name: 'file',
  172. success(res) {
  173. var err = JSON.parse(res.data);
  174. if (err.errcode == 10000) {
  175. wx.hideLoading();
  176. callback(err.result);
  177. } else {
  178. wx.hideLoading();
  179. wx.showModal({
  180. title: '上传文件失败1',
  181. showCancel: false,
  182. content: JSON.stringify(err.errMsg),
  183. });
  184. }
  185. },
  186. fail: function (err) {
  187. wx.hideLoading();
  188. wx.showModal({
  189. title: '上传文件失败2',
  190. showCancel: false,
  191. content: JSON.stringify(err)+" url:"+url,
  192. });
  193. }
  194. });
  195. },
  196. uploadImageAll: function (arr, callback) {
  197. var that = this;
  198. var b = false;
  199. var arrResult = [];
  200. for (var i = 0; i < arr.length; i++) {
  201. var source = arr[i];
  202. that.uploadFileToServer(source, function (data) {
  203. if (data) {
  204. var result = data;
  205. result.Target = app.globalData.uploadImageUrl + result.Target;
  206. arrResult.push(result);
  207. }
  208. });
  209. }
  210. //检查是否上传成功
  211. setTimeout(function () {
  212. if (arrResult.length==arr.length)
  213. callback(true, arrResult);
  214. }, 2000);
  215. },
  216. goto: function (e) {
  217. main.goto(e);
  218. },
  219. onSelect:function(event){
  220. var that=this;
  221. main.onSelect(that,event,function(obj,e,result){
  222. if (e.currentTarget.dataset.object=="Feedback"){
  223. }
  224. });
  225. },
  226. onShareTimeline: function () {
  227. return this.onShareAppMessage();
  228. },
  229. onShareAppMessage: function () {
  230. return {
  231. title: app.globalData.ShareTitle,
  232. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  233. imageUrl: app.globalData.ShareImage,
  234. }
  235. },
  236. })