index.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. import {
  6. TestVerify
  7. } from "../../utils/verify";
  8. const _Verify = new TestVerify();
  9. var WxParse = require('../../wxParse/wxParse.js')
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. isDisabled: false, //是否禁用
  16. butText: "保存", //按钮文字
  17. popups: false, //弹出层控制
  18. /* */
  19. fbrand: "", //品牌名称
  20. attinfos: [], // 图片列表
  21. coverAttinfos: [], //品牌展示图
  22. isLogo: [], //用于判断是否上传logo
  23. saleprodclass: [], //经营类目
  24. showSaleprodclass: "", //显示经营类目
  25. fcontact: "", //联系人
  26. fphonenumber: "", //联系方式
  27. fagentname: "", //商户名称
  28. fintroduction: "", //商户介绍
  29. faddress: "", //地址
  30. fdutyparagraph: "", //统一社会代码
  31. requestType: "普通修改", //请求类型
  32. /* */
  33. errTips: {
  34. fbrand: false,
  35. attinfos: false,
  36. saleprodclass: false,
  37. fcontact: false,
  38. fphonenumber: false,
  39. fagentname: false,
  40. fintroduction: false,
  41. faddress: false,
  42. }
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. // 判断主子账号 是否禁用
  49. this.setData({
  50. isDisabled: (wx.getStorageSync('userData').fisadministrator == 1) ? false : true
  51. });
  52. //判断进入方式
  53. if (options.data == null) {
  54. console.log("注册进入")
  55. this.setData({
  56. requestType: "商户认证"
  57. })
  58. } else if (options.data == 1) {
  59. wx.showToast({
  60. title: '商户信息审核中',
  61. icon: 'none',
  62. duration: 5000
  63. });
  64. this.setData({
  65. requestType: "商户认证",
  66. isDisabled: true
  67. })
  68. } else {
  69. console.log("商户进入", options)
  70. //解析富文本
  71. var article = decodeURIComponent(options.fintroduction);
  72. var that = this;
  73. WxParse.wxParse('article', 'html', article, that, 5);
  74. //处理数据
  75. const data = JSON.parse(options.data);
  76. this.returnData(data)
  77. }
  78. },
  79. /* 添加图片 */
  80. imageChange(data) {
  81. this.setData({
  82. attinfos: data.detail.fileList
  83. })
  84. },
  85. coverImageChange(data) {
  86. this.setData({
  87. coverAttinfos: data.detail.fileList
  88. })
  89. },
  90. /* 选择类目回调 */
  91. saleprodChange(arr) {
  92. let detail = arr.detail,
  93. showSaleprodclass = "";
  94. for (let i = 0; i < detail.length; i++) {
  95. showSaleprodclass += (detail[i] + ',');
  96. };
  97. this.setData({
  98. popups: false,
  99. saleprodclass: detail,
  100. showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1)
  101. })
  102. },
  103. /* 返回数据 */
  104. returnData(data) {
  105. var attinfos = [],
  106. coverAttinfos = [];
  107. // 格式化图片
  108. for (let i = 0; i < data.attinfos.length; i++) {
  109. const Data = {
  110. url: data.attinfos[i].fobsurl,
  111. ownerid: data.attinfos[i].ownerid,
  112. tattachmentid: data.attinfos[i].tattachmentid,
  113. ownertable: data.attinfos[i].ownertable,
  114. fdocument: data.attinfos[i].fdocument
  115. };
  116. (data.attinfos[i].ftype == "brandlogo") ? attinfos.unshift(Data): coverAttinfos.unshift(Data);
  117. }
  118. //格式化经营类目
  119. if (data.saleprodclass.length >= 1) {
  120. this.saleprodChange({
  121. detail: data.saleprodclass
  122. })
  123. }
  124. /* fintroduction: data.fintroduction, */
  125. this.setData({
  126. fbrand: data.fbrand,
  127. saleprodclass: data.saleprodclass,
  128. fcontact: data.fcontact,
  129. fphonenumber: data.fphonenumber,
  130. fagentname: data.fagentname,
  131. faddress: data.faddress,
  132. fdutyparagraph: data.fdutyparagraph,
  133. attinfos,
  134. coverAttinfos
  135. })
  136. },
  137. /* 提交数据 */
  138. submit() {
  139. if (!this.formVerify()) return wx.showToast({
  140. title: '请检查表单内容',
  141. icon: "error"
  142. });
  143. if (this.data.attinfos.length < 1) return wx.showToast({
  144. title: '请上传品牌LOGO!',
  145. icon: "none"
  146. });
  147. if (this.data.coverAttinfos.length < 1) return wx.showToast({
  148. title: '请上传品牌展示图!',
  149. icon: "none"
  150. });
  151. const that = this;
  152. if (this.data.requestType == '普通修改') {
  153. wx.showModal({
  154. title: '提示',
  155. content: "是否确认修改商户信息",
  156. success: (res => {
  157. if (res.confirm) {
  158. that.requestToSend();
  159. };
  160. })
  161. })
  162. } else {
  163. that.requestToSend();
  164. }
  165. },
  166. /* 发送请求 */
  167. requestToSend() {
  168. _Http.basic({
  169. "accesstoken": wx.getStorageSync('userData').token,
  170. "classname": "customer.tagents.tagents",
  171. "method": "modify_enterpriseAgent",
  172. "content": {
  173. "ftype": this.data.requestType,
  174. "data": [{
  175. "fbrand": this.data.fbrand,
  176. "saleprodclass": this.data.saleprodclass,
  177. "fcontact": this.data.fcontact,
  178. "fphonenumber": this.data.fphonenumber,
  179. "fagentname": this.data.fagentname,
  180. "fintroduction": this.data.fintroduction,
  181. "faddress": this.data.faddress,
  182. "fdutyparagraph": this.data.fdutyparagraph,
  183. }]
  184. }
  185. }).then(res => {
  186. if (res.msg != '成功') return wx.showToast({
  187. title: res.data,
  188. })
  189. wx.showToast({
  190. title: '提交成功',
  191. });
  192. setTimeout(() => {
  193. wx.navigateBack({
  194. delta: 1,
  195. })
  196. }, 500)
  197. })
  198. },
  199. /* 表单验证 */
  200. formVerify() {
  201. let errTips = this.data.errTips,
  202. verify = true;
  203. /* 验证品牌名 */
  204. if (!_Verify.required(this.data.fbrand)) {
  205. errTips.fbrand = true;
  206. verify = false;
  207. }
  208. /* 验证经营类目 */
  209. if (!_Verify.required(this.data.showSaleprodclass)) {
  210. errTips.saleprodclass = true;
  211. verify = false;
  212. }
  213. /* 验证联系人 */
  214. if (!_Verify.required(this.data.fcontact)) {
  215. errTips.fcontact = true;
  216. verify = false;
  217. }
  218. /* 验证联系方式 */
  219. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  220. errTips.fphonenumber = true;
  221. verify = false;
  222. }
  223. /* 验证商户名称 */
  224. if (!_Verify.required(this.data.fagentname)) {
  225. errTips.fagentname = true;
  226. verify = false;
  227. }
  228. /* 验证商户介绍 */
  229. if (!_Verify.required(this.data.fintroduction)) {
  230. errTips.fintroduction = true;
  231. verify = false;
  232. }
  233. /* 验证地址 */
  234. if (!_Verify.required(this.data.faddress)) {
  235. errTips.faddress = true;
  236. verify = false;
  237. }
  238. this.setData({
  239. errTips
  240. })
  241. return verify;
  242. },
  243. /* 弹出层 */
  244. showPop() {
  245. if (this.data.isDisabled) return;
  246. this.setData({
  247. popups: !this.data.popups
  248. })
  249. },
  250. /* 获取焦点 */
  251. inputFocus(e) {
  252. const {
  253. name
  254. } = e.currentTarget.dataset;
  255. let errTips = this.data.errTips;
  256. errTips[name] = false;
  257. this.setData({
  258. errTips
  259. })
  260. },
  261. /* 失去焦点 */
  262. inputBlur(e) {
  263. const {
  264. name
  265. } = e.currentTarget.dataset;
  266. const {
  267. value
  268. } = e.detail;
  269. let errTips = this.data.errTips;
  270. /* 联系方式验证 */
  271. if (name == 'fphonenumber') {
  272. if (!_Verify.phoneNumber(this.data.fphonenumber, true)) errTips[name] = true;
  273. }
  274. if (value.trim() == "") {
  275. errTips[name] = true;
  276. }
  277. this.setData({
  278. errTips
  279. })
  280. },
  281. /**
  282. * 生命周期函数--监听页面初次渲染完成
  283. */
  284. onReady: function () {
  285. },
  286. /**
  287. * 生命周期函数--监听页面显示
  288. */
  289. onShow: function () {
  290. },
  291. /**
  292. * 生命周期函数--监听页面隐藏
  293. */
  294. onHide: function () {
  295. },
  296. /**
  297. * 生命周期函数--监听页面卸载
  298. */
  299. onUnload: function () {
  300. },
  301. /**
  302. * 页面相关事件处理函数--监听用户下拉动作
  303. */
  304. onPullDownRefresh: function () {
  305. },
  306. /**
  307. * 页面上拉触底事件的处理函数
  308. */
  309. onReachBottom: function () {
  310. },
  311. /**
  312. * 用户点击右上角分享
  313. */
  314. onShareAppMessage: function () {
  315. }
  316. })