index.js 9.7 KB

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