feedbackinfo.js 6.6 KB

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