index.js 10 KB

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