config.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. Vue.directive('enterNumber', {
  5. inserted: function (el) {
  6. let changeValue = (el, type) => {
  7. const e = document.createEvent('HTMLEvents')
  8. e.initEvent(type, true, true)
  9. el.dispatchEvent(e)
  10. }
  11. el.addEventListener("keyup", function (e) {
  12. let input = e.target;
  13. let reg = new RegExp('^((?:(?:[1-9]{1}\\d*)|(?:[0]{1}))(?:\\.(?:\\d){0,2})?)(?:\\d*)?$');
  14. let matchRes = input.value.match(reg);
  15. if (matchRes === null) {
  16. input.value = "";
  17. } else {
  18. if (matchRes[1] !== matchRes[0]) {
  19. input.value = matchRes[1];
  20. }
  21. }
  22. changeValue(input, 'input')
  23. });
  24. }
  25. });
  26. var indexPage = new Vue({
  27. el: "#indexPage",
  28. data() {
  29. return {
  30. initData: {},
  31. configData: {
  32. commission_level: '1',
  33. self_buy: '0',
  34. invite_lock: 'share',
  35. agent_check: '0',
  36. upgrade_check: '0',
  37. upgrade_jump: '0',
  38. upgrade_display: '0',
  39. become_agent: {
  40. type: 'apply',
  41. value: ''
  42. },
  43. agent_form: {
  44. background_image: '',
  45. content: [],
  46. },
  47. apply_protocol: '0',
  48. commission_price_type: 'goods_price',
  49. commission_event: 'payed',
  50. refund_commission_reward: '0',
  51. refund_commission_order: '0'
  52. },
  53. needApplyProtocol: "0",
  54. needAgentForm: "0",
  55. become_register_options: [{
  56. value: 'input',
  57. label: '文本内容'
  58. }, {
  59. value: 'number',
  60. label: '纯数字'
  61. }, {
  62. value: 'image',
  63. label: '上传图片'
  64. }],
  65. defaultOption: {
  66. sort: true,
  67. animation: 100,
  68. ghostClass: "sortable-ghost",
  69. handle: '#draggableHandle',
  70. forceFallback: true,
  71. fallbackClass: 'clone-item',
  72. fallbackOnBody: true,
  73. dragClass: 'dragin-item',
  74. },
  75. isAjax: true,
  76. goodsDetail: null,
  77. tipshow: true,
  78. configis_upgrade:false,
  79. }
  80. },
  81. created() {
  82. this.init();
  83. this.configis_upgrade=Config.is_upgrade
  84. },
  85. computed: {},
  86. methods: {
  87. operation(type){
  88. switch(type){
  89. case 'close':
  90. this.configis_upgrade=false
  91. break;
  92. case 'refresh':
  93. window.location.reload();
  94. break;
  95. case 'upgrade':
  96. window.open("https://www.fastadmin.net/store/shopro.html")
  97. break;
  98. }
  99. },
  100. tipClose() {
  101. this.tipshow = false;
  102. },
  103. init() {
  104. this.getConfigData();
  105. },
  106. getConfigData() {
  107. let that = this;
  108. Fast.api.ajax({
  109. url: 'shopro/commission/config/index',
  110. type: 'GET',
  111. loading: false,
  112. }, function (ret, res) {
  113. that.initData = res.data;
  114. //转换数据格式
  115. if(Array.isArray(that.initData)){
  116. }else{
  117. that.configData = that.initConfigData(that.initData);
  118. }
  119. that.isAjax = false;
  120. return false;
  121. })
  122. },
  123. initConfigData(data) {
  124. let that = this
  125. //拷贝一份可更改的configData,保留原始数据
  126. let configData = JSON.parse(JSON.stringify(data));
  127. configData.become_agent = JSON.parse(configData.become_agent);
  128. if (configData.become_agent.type == 'goods') {
  129. shoproGoodsList(configData.become_agent.value).then(data => {
  130. this.goodsDetail = data.data
  131. }).catch(error => {
  132. this.goodsDetail = error
  133. });
  134. }
  135. if (configData.agent_form != '0') {
  136. that.needAgentForm = '1';
  137. configData.agent_form = JSON.parse(configData.agent_form);
  138. if (configData.agent_form.content.length == 0) {
  139. configData.agent_form.content.push({
  140. name: '',
  141. type: '',
  142. })
  143. }
  144. }
  145. if (configData.apply_protocol != '0') {
  146. that.needApplyProtocol = '1';
  147. configData.apply_protocol = JSON.parse(configData.apply_protocol);
  148. }
  149. return configData;
  150. },
  151. changeApplyProtocol(value) {
  152. if (value == '0') {
  153. this.configData.apply_protocol = '0';
  154. } else {
  155. this.configData.apply_protocol = {
  156. name: '',
  157. richtext_id: '',
  158. }
  159. }
  160. },
  161. changeBecomeAgentType(value) {
  162. if (value == 'apply') {
  163. this.needAgentForm = '1';
  164. if (this.configData.agent_form == 0) {
  165. this.configData.agent_form = {
  166. background_image: '',
  167. content: [{
  168. name: '',
  169. type: '',
  170. }],
  171. }
  172. }
  173. }
  174. this.configData.become_agent.value = "";
  175. },
  176. changeAgentForm(value) {
  177. if (value == 0) {
  178. this.configData.agent_form = '0'
  179. } else {
  180. this.configData.agent_form = {
  181. background_image: '',
  182. content: [{
  183. name: '',
  184. type: '',
  185. }],
  186. }
  187. }
  188. },
  189. bgimageAdd() {
  190. let that = this;
  191. Fast.api.open("general/attachment/select?multiple=false", "选择", {
  192. callback: function (data) {
  193. that.configData.agent_form.background_image = data.url;
  194. }
  195. });
  196. return false;
  197. },
  198. addGoods() {
  199. let that = this;
  200. let params = {
  201. multiple: true,
  202. type: '',
  203. ids: that.configData.become_agent.value ? that.configData.become_agent.value : ''
  204. }
  205. shoproSelectGoods(params, "选择商品").then(data => {
  206. if(data.data.length>0){
  207. let idsArr = [];
  208. data.data.forEach(goods => {
  209. idsArr.push(goods.id)
  210. })
  211. that.configData.become_agent.value = idsArr.join(',');
  212. that.goodsDetail = data.data;
  213. }
  214. }).catch(error => {
  215. });
  216. return false;
  217. },
  218. deleteGoods(index) {
  219. this.goodsDetail.splice(index, 1)
  220. let idsArr = this.configData.become_agent.value.split(',')
  221. idsArr.splice(index, 1)
  222. this.configData.become_agent.value = idsArr.join(',')
  223. },
  224. chooseRichText() {
  225. var that = this;
  226. Fast.api.open("shopro/richtext/select?multiple=false", "选择申请协议", {
  227. callback: function (data) {
  228. that.configData.apply_protocol.richtext_id = data.data.id;
  229. that.configData.apply_protocol.name = data.data.title;
  230. that.$forceUpdate();
  231. }
  232. });
  233. return false;
  234. },
  235. becomeRegisterAdd() {
  236. this.configData.agent_form.content.push({
  237. name: '',
  238. type: '',
  239. })
  240. this.$forceUpdate();
  241. },
  242. becomeRegisterDelete(index) {
  243. this.configData.agent_form.content.splice(index, 1)
  244. },
  245. formRestore() {
  246. this.configData = this.initConfigData(this.initData);
  247. },
  248. formSubmit() {
  249. let that = this;
  250. this.$refs['configData'].validate((valid) => {
  251. if (valid) {
  252. let configForm = JSON.parse(JSON.stringify(that.configData))
  253. //完善资料内容验证
  254. if (that.needAgentForm != '0') {
  255. let agentFormValidate = true;
  256. if (configForm.agent_form.content.length > 0) {
  257. configForm.agent_form.content.forEach(i => {
  258. if (i.name == '' || i.type == '') {
  259. agentFormValidate = false;
  260. }
  261. })
  262. if (!agentFormValidate) {
  263. this.$notify({
  264. title: '警告',
  265. message: '表单内容必须填写完整',
  266. type: 'warning'
  267. });
  268. return false;
  269. }
  270. configForm.agent_form = JSON.stringify(configForm.agent_form)
  271. } else {
  272. this.$notify({
  273. title: '警告',
  274. message: '至少添加一条表单',
  275. type: 'warning'
  276. });
  277. return false;
  278. }
  279. // 验证申请协议
  280. if (that.needApplyProtocol == '1') {
  281. if (configForm.apply_protocol.richtext_id && configForm.apply_protocol.name) {
  282. configForm.apply_protocol = JSON.stringify(configForm.apply_protocol)
  283. } else {
  284. this.$notify({
  285. title: '警告',
  286. message: '协议内容必须填写完整',
  287. type: 'warning'
  288. });
  289. return false;
  290. }
  291. } else {
  292. configForm.apply_protocol = "0";
  293. }
  294. } else {
  295. configForm.apply_protocol = "0";
  296. }
  297. //验证分销商条件
  298. if (configForm.become_agent.type != 'apply' && configForm.become_agent.value == '') {
  299. this.$notify({
  300. title: '警告',
  301. message: '成为分销商条件必须填写完整',
  302. type: 'warning'
  303. });
  304. return false;
  305. } else {
  306. configForm.become_agent = JSON.stringify(configForm.become_agent)
  307. }
  308. that.isAjax = true;
  309. // return false;
  310. Fast.api.ajax({
  311. url: 'shopro/commission/config/save',
  312. loading: false,
  313. data: configForm
  314. }, function (ret, res) {
  315. that.isAjax = false;
  316. that.getConfigData();
  317. // return false;
  318. }, function (ret, res) {
  319. that.isAjax = false;
  320. })
  321. } else {
  322. return false;
  323. }
  324. });
  325. },
  326. },
  327. })
  328. },
  329. };
  330. return Controller;
  331. });