index.js 8.3 KB

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