index.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. //解析富文本
  70. var article = decodeURIComponent(options.fintroduction);
  71. var that = this;
  72. WxParse.wxParse('article', 'html', article, that, 5);
  73. //处理数据
  74. const data = JSON.parse(options.data);
  75. this.returnData(data)
  76. }
  77. },
  78. /* 添加图片 */
  79. imageChange(data) {
  80. this.setData({
  81. attinfos: data.detail.fileList
  82. })
  83. },
  84. coverImageChange(data) {
  85. this.setData({
  86. coverAttinfos: data.detail.fileList
  87. })
  88. },
  89. /* 选择类目回调 */
  90. saleprodChange(arr) {
  91. let detail = arr.detail,
  92. showSaleprodclass = "";
  93. for (let i = 0; i < detail.length; i++) {
  94. showSaleprodclass += (detail[i] + ',');
  95. };
  96. this.setData({
  97. popups: false,
  98. saleprodclass: detail,
  99. showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1)
  100. })
  101. },
  102. /* 返回数据 */
  103. returnData(data) {
  104. var attinfos = [],
  105. coverAttinfos = [];
  106. // 格式化图片
  107. for (let i = 0; i < data.attinfos.length; i++) {
  108. const Data = {
  109. url: data.attinfos[i].fobsurl,
  110. ownerid: data.attinfos[i].ownerid,
  111. tattachmentid: data.attinfos[i].tattachmentid,
  112. ownertable: data.attinfos[i].ownertable,
  113. fdocument: data.attinfos[i].fdocument
  114. };
  115. (data.attinfos[i].ftype == "brandlogo") ? attinfos.unshift(Data): coverAttinfos.unshift(Data);
  116. }
  117. //格式化经营类目
  118. if (data.saleprodclass.length >= 1) {
  119. this.saleprodChange({
  120. detail: data.saleprodclass
  121. })
  122. }
  123. /* fintroduction: data.fintroduction, */
  124. this.setData({
  125. fbrand: data.fbrand,
  126. saleprodclass: data.saleprodclass,
  127. fcontact: data.fcontact,
  128. fphonenumber: data.fphonenumber,
  129. fagentname: data.fagentname,
  130. faddress: data.faddress,
  131. fdutyparagraph: data.fdutyparagraph,
  132. attinfos,
  133. coverAttinfos
  134. })
  135. },
  136. /* 提交数据 */
  137. submit() {
  138. if (!this.formVerify()) return wx.showToast({
  139. title: '请检查表单内容',
  140. icon: "error"
  141. });
  142. if (this.data.attinfos.length < 1) return wx.showToast({
  143. title: '请上传品牌LOGO!',
  144. icon: "none"
  145. });
  146. if (this.data.coverAttinfos.length < 1) return wx.showToast({
  147. title: '请上传品牌展示图!',
  148. icon: "none"
  149. });
  150. const that = this;
  151. if (this.data.requestType == '普通修改') {
  152. wx.showModal({
  153. title: '提示',
  154. content: "是否确认修改商户信息",
  155. success: (res => {
  156. if (res.confirm) {
  157. that.requestToSend();
  158. };
  159. })
  160. })
  161. } else {
  162. that.requestToSend();
  163. }
  164. },
  165. /* 发送请求 */
  166. requestToSend() {
  167. _Http.basic({
  168. "accesstoken": wx.getStorageSync('userData').token,
  169. "classname": "customer.tagents.tagents",
  170. "method": "modify_enterpriseAgent",
  171. "content": {
  172. "ftype": this.data.requestType,
  173. "data": [{
  174. "fbrand": this.data.fbrand,
  175. "saleprodclass": this.data.saleprodclass,
  176. "fcontact": this.data.fcontact,
  177. "fphonenumber": this.data.fphonenumber,
  178. "fagentname": this.data.fagentname,
  179. "fintroduction": this.data.fintroduction,
  180. "faddress": this.data.faddress,
  181. "fdutyparagraph": this.data.fdutyparagraph,
  182. }]
  183. }
  184. }).then(res => {
  185. if (res.msg != '成功') return wx.showToast({
  186. title: res.data,
  187. })
  188. wx.showToast({
  189. title: '提交成功',
  190. });
  191. setTimeout(() => {
  192. wx.navigateBack({
  193. delta: 1,
  194. })
  195. }, 500)
  196. })
  197. },
  198. /* 表单验证 */
  199. formVerify() {
  200. let errTips = this.data.errTips,
  201. verify = true;
  202. /* 验证品牌名 */
  203. if (!_Verify.required(this.data.fbrand)) {
  204. errTips.fbrand = true;
  205. verify = false;
  206. }
  207. /* 验证经营类目 */
  208. if (!_Verify.required(this.data.showSaleprodclass)) {
  209. errTips.saleprodclass = true;
  210. verify = false;
  211. }
  212. /* 验证联系人 */
  213. if (!_Verify.required(this.data.fcontact)) {
  214. errTips.fcontact = true;
  215. verify = false;
  216. }
  217. /* 验证联系方式 */
  218. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  219. errTips.fphonenumber = true;
  220. verify = false;
  221. }
  222. /* 验证商户名称 */
  223. if (!_Verify.required(this.data.fagentname)) {
  224. errTips.fagentname = true;
  225. verify = false;
  226. }
  227. /* 验证商户介绍 */
  228. if (!_Verify.required(this.data.fintroduction)) {
  229. errTips.fintroduction = true;
  230. verify = false;
  231. }
  232. /* 验证地址 */
  233. if (!_Verify.required(this.data.faddress)) {
  234. errTips.faddress = true;
  235. verify = false;
  236. }
  237. this.setData({
  238. errTips
  239. })
  240. return verify;
  241. },
  242. /* 弹出层 */
  243. showPop() {
  244. if (this.data.isDisabled) return;
  245. this.setData({
  246. popups: !this.data.popups
  247. })
  248. },
  249. /* 获取焦点 */
  250. inputFocus(e) {
  251. const {
  252. name
  253. } = e.currentTarget.dataset;
  254. let errTips = this.data.errTips;
  255. errTips[name] = false;
  256. this.setData({
  257. errTips
  258. })
  259. },
  260. /* 失去焦点 */
  261. inputBlur(e) {
  262. const {
  263. name
  264. } = e.currentTarget.dataset;
  265. const {
  266. value
  267. } = e.detail;
  268. let errTips = this.data.errTips;
  269. /* 联系方式验证 */
  270. if (name == 'fphonenumber') {
  271. if (!_Verify.phoneNumber(this.data.fphonenumber, true)) errTips[name] = true;
  272. }
  273. if (value.trim() == "") {
  274. errTips[name] = true;
  275. }
  276. this.setData({
  277. errTips
  278. })
  279. },
  280. /**
  281. * 生命周期函数--监听页面初次渲染完成
  282. */
  283. onReady: function () {
  284. },
  285. /**
  286. * 生命周期函数--监听页面显示
  287. */
  288. onShow: function () {
  289. },
  290. /**
  291. * 生命周期函数--监听页面隐藏
  292. */
  293. onHide: function () {
  294. },
  295. /**
  296. * 生命周期函数--监听页面卸载
  297. */
  298. onUnload: function () {
  299. },
  300. /**
  301. * 页面相关事件处理函数--监听用户下拉动作
  302. */
  303. onPullDownRefresh: function () {
  304. },
  305. /**
  306. * 页面上拉触底事件的处理函数
  307. */
  308. onReachBottom: function () {
  309. },
  310. /**
  311. * 用户点击右上角分享
  312. */
  313. onShareAppMessage: function () {
  314. }
  315. })