index.js 9.4 KB

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