feedbackinfo.js 6.8 KB

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