comment.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted } = Vue
  5. const { ElMessageBox } = ElementPlus
  6. const index = {
  7. setup() {
  8. const state = reactive({
  9. order_id: new URLSearchParams(location.search).get('order_id'),
  10. order_item_id: new URLSearchParams(location.search).get('order_item_id'),
  11. data: [],
  12. order: '',
  13. sort: '',
  14. filter: {
  15. drawer: false,
  16. data: {
  17. 'goods.title': '',
  18. user: { field: 'user.nickname', value: '' },
  19. content: '',
  20. status: '',
  21. },
  22. tools: {
  23. 'goods.title': {
  24. type: 'tinput',
  25. label: '商品名称',
  26. value: '',
  27. },
  28. user: {
  29. type: 'tinputprepend',
  30. label: '用户信息',
  31. placeholder: '请输入查询内容',
  32. value: {
  33. field: 'user.nickname',
  34. value: '',
  35. },
  36. options: {
  37. data: [
  38. {
  39. label: '用户昵称',
  40. value: 'user.nickname',
  41. },
  42. {
  43. label: '用户手机号',
  44. value: 'user.mobile',
  45. },
  46. ]
  47. }
  48. },
  49. content: {
  50. type: 'tinput',
  51. label: '评价内容',
  52. value: '',
  53. },
  54. status: {
  55. type: 'tselect',
  56. label: '状态',
  57. value: '',
  58. options: {
  59. data: [
  60. {
  61. label: '显示',
  62. value: 'normal',
  63. },
  64. {
  65. label: '隐藏',
  66. value: 'hidden',
  67. },
  68. ],
  69. },
  70. },
  71. },
  72. condition: {},
  73. }
  74. })
  75. function getData() {
  76. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  77. if (state.order_id) {
  78. tempSearch = { ...tempSearch, order_id: state.order_id }
  79. }
  80. if (state.order_item_id) {
  81. tempSearch = { ...tempSearch, order_item_id: state.order_item_id }
  82. }
  83. let search = composeFilter(tempSearch, {
  84. 'goods.title': 'like',
  85. 'user.nickname': 'like',
  86. 'user.mobile': 'like',
  87. content: 'like',
  88. });
  89. Fast.api.ajax({
  90. url: 'shopro/goods/comment',
  91. type: 'GET',
  92. data: {
  93. page: pagination.page,
  94. list_rows: pagination.list_rows,
  95. order: state.order,
  96. sort: state.sort,
  97. ...search,
  98. },
  99. }, function (ret, res) {
  100. state.data = res.data.data
  101. pagination.total = res.data.total
  102. return false
  103. }, function (ret, res) { })
  104. }
  105. function onOpenFilter() {
  106. state.filter.drawer = true
  107. }
  108. function onChangeFilter() {
  109. pagination.page = 1
  110. getData()
  111. state.filter.drawer && (state.filter.drawer = false)
  112. }
  113. const pagination = reactive({
  114. page: 1,
  115. list_rows: 10,
  116. total: 0,
  117. })
  118. const batchHandle = reactive({
  119. data: [],
  120. })
  121. function onChangeSelection(val) {
  122. batchHandle.data = val
  123. }
  124. function onBatchHandle(type) {
  125. let ids = []
  126. batchHandle.data.forEach((item) => {
  127. ids.push(item.id)
  128. })
  129. switch (type) {
  130. case 'delete':
  131. ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
  132. confirmButtonText: '确定',
  133. cancelButtonText: '取消',
  134. type: 'warning',
  135. }).then(() => {
  136. onDelete(ids.join(','))
  137. });
  138. break;
  139. default:
  140. onCommand({ id: ids.join(','), type: type })
  141. break;
  142. }
  143. }
  144. function onCommand(item) {
  145. Fast.api.ajax({
  146. url: `shopro/goods/comment/edit/id/${item.id}`,
  147. type: 'POST',
  148. data: {
  149. status: item.type
  150. }
  151. }, function (ret, res) {
  152. getData()
  153. }, function (ret, res) { })
  154. }
  155. function onOpenGoodsDetail(id) {
  156. Fast.api.open(`shopro/goods/goods/add?type=edit&id=${id}`, "商品详情", {
  157. callback() {
  158. getData()
  159. }
  160. })
  161. }
  162. function onAdd() {
  163. Fast.api.open("shopro/goods/comment/add?type=add", "添加虚拟评价", {
  164. callback() {
  165. getData()
  166. }
  167. })
  168. }
  169. function onEdit(id) {
  170. Fast.api.open(`shopro/goods/comment/edit?type=edit&id=${id}`, "编辑", {
  171. callback() {
  172. getData()
  173. }
  174. })
  175. }
  176. function onDelete(id) {
  177. Fast.api.ajax({
  178. url: `shopro/goods/comment/delete/id/${id}`,
  179. type: 'DELETE',
  180. }, function (ret, res) {
  181. getData()
  182. }, function (ret, res) { })
  183. }
  184. function onRecyclebin() {
  185. Fast.api.open('shopro/goods/comment/recyclebin', "回收站", {
  186. callback() {
  187. getData()
  188. }
  189. })
  190. }
  191. onMounted(() => {
  192. getData()
  193. })
  194. return {
  195. onClipboard,
  196. state,
  197. getData,
  198. onOpenFilter,
  199. onChangeFilter,
  200. pagination,
  201. batchHandle,
  202. onChangeSelection,
  203. onBatchHandle,
  204. onCommand,
  205. onOpenGoodsDetail,
  206. onAdd,
  207. onEdit,
  208. onDelete,
  209. onRecyclebin
  210. }
  211. }
  212. }
  213. createApp('index', index);
  214. },
  215. add: () => {
  216. Controller.form();
  217. },
  218. edit: () => {
  219. Controller.form();
  220. },
  221. form: () => {
  222. const { reactive, onMounted, getCurrentInstance } = Vue
  223. const addEdit = {
  224. setup() {
  225. const { proxy } = getCurrentInstance();
  226. const state = reactive({
  227. type: new URLSearchParams(location.search).get('type'),
  228. id: new URLSearchParams(location.search).get('id'),
  229. fakeUserData: {},
  230. goodsData: {}
  231. })
  232. const form = reactive({
  233. model: {
  234. content: '',
  235. images: [],
  236. level: 0,
  237. user_id: '',
  238. goods_id: '',
  239. status: 'normal',
  240. },
  241. rules: {
  242. content: [{ required: true, message: '请输入评价内容', trigger: 'blur' }],
  243. level: [{ required: true, message: '请选择评价星级', trigger: 'blur' }],
  244. user_id: [{ required: true, message: '请选择评价用户', trigger: 'blur' }],
  245. goods_id: [{ required: true, message: '请选择商品信息', trigger: 'blur' }],
  246. status: [{ required: true, message: '请选择状态', trigger: 'blur' }],
  247. },
  248. })
  249. function getDetail() {
  250. Fast.api.ajax({
  251. url: `shopro/goods/comment/detail/id/${state.id}`,
  252. type: 'GET',
  253. }, function (ret, res) {
  254. form.model = res.data
  255. return false
  256. }, function (ret, res) { })
  257. }
  258. function onSelectFakeUser() {
  259. Fast.api.open("shopro/data/fake_user/select", "选择虚拟用户", {
  260. callback(data) {
  261. state.fakeUserData = data
  262. form.model.user_id = data.id
  263. }
  264. })
  265. }
  266. function onDeleteFakeUser() {
  267. state.fakeUserData = {}
  268. form.model.user_id = ''
  269. }
  270. function onSelectGoods() {
  271. Fast.api.open(`shopro/goods/goods/select`, "选择商品", {
  272. callback(data) {
  273. state.goodsData = data;
  274. form.model.goods_id = data.id;
  275. }
  276. })
  277. }
  278. function onDeleteGoods() {
  279. state.goodsData = {};
  280. form.model.goods_id = '';
  281. }
  282. function onChangeStatus() {
  283. Fast.api.ajax({
  284. url: `shopro/goods/comment/edit/id/${state.id}`,
  285. type: 'POST',
  286. data: {
  287. status: form.model.status
  288. }
  289. }, function (ret, res) {
  290. getDetail()
  291. }, function (ret, res) { })
  292. }
  293. function onReply() {
  294. Fast.api.open(`shopro/goods/comment/reply/id/${state.id}?id=${state.id}`, "回复", {
  295. callback() {
  296. getDetail()
  297. }
  298. })
  299. }
  300. function onConfirm() {
  301. proxy.$refs['formRef'].validate((valid) => {
  302. if (valid) {
  303. Fast.api.ajax({
  304. url: 'shopro/goods/comment/add',
  305. type: 'POST',
  306. data: form.model,
  307. }, function (ret, res) {
  308. Fast.api.close()
  309. }, function (ret, res) { })
  310. }
  311. });
  312. }
  313. onMounted(() => {
  314. state.type == 'edit' && getDetail()
  315. })
  316. return {
  317. state,
  318. form,
  319. onSelectFakeUser,
  320. onDeleteFakeUser,
  321. onSelectGoods,
  322. onDeleteGoods,
  323. onChangeStatus,
  324. onReply,
  325. onConfirm
  326. }
  327. }
  328. }
  329. createApp('addEdit', addEdit);
  330. },
  331. recyclebin: () => {
  332. const { reactive, onMounted } = Vue
  333. const { ElMessageBox } = ElementPlus
  334. const recyclebin = {
  335. setup() {
  336. const state = reactive({
  337. data: [],
  338. order: '',
  339. sort: '',
  340. })
  341. function getData() {
  342. Fast.api.ajax({
  343. url: 'shopro/goods/comment/recyclebin',
  344. type: 'GET',
  345. data: {
  346. page: pagination.page,
  347. list_rows: pagination.list_rows,
  348. order: state.order,
  349. sort: state.sort,
  350. },
  351. }, function (ret, res) {
  352. state.data = res.data.data
  353. pagination.total = res.data.total
  354. return false
  355. }, function (ret, res) { })
  356. }
  357. function onChangeSort({ prop, order }) {
  358. state.order = order == 'ascending' ? 'asc' : 'desc';
  359. state.sort = prop;
  360. getData();
  361. }
  362. const pagination = reactive({
  363. page: 1,
  364. list_rows: 10,
  365. total: 0,
  366. })
  367. const batchHandle = reactive({
  368. data: [],
  369. tools: [
  370. {
  371. type: 'restore',
  372. label: '还原',
  373. class: 'primary',
  374. },
  375. {
  376. type: 'destroy',
  377. label: '销毁',
  378. class: 'danger',
  379. },
  380. {
  381. type: 'all',
  382. label: '清空回收站',
  383. class: 'danger',
  384. },
  385. ]
  386. })
  387. function onChangeSelection(val) {
  388. batchHandle.data = val
  389. }
  390. function onBatchHandle(type) {
  391. let ids = []
  392. batchHandle.data.forEach((item) => {
  393. ids.push(item.id)
  394. })
  395. switch (type) {
  396. case 'restore':
  397. onRestore(ids.join(','))
  398. break;
  399. case 'destroy':
  400. ElMessageBox.confirm('此操作将销毁, 是否继续?', '提示', {
  401. confirmButtonText: '确定',
  402. cancelButtonText: '取消',
  403. type: 'warning',
  404. }).then(() => {
  405. onDestroy(ids.join(','))
  406. });
  407. break;
  408. case 'all':
  409. ElMessageBox.confirm('此操作将清空回收站, 是否继续?', '提示', {
  410. confirmButtonText: '确定',
  411. cancelButtonText: '取消',
  412. type: 'warning',
  413. }).then(() => {
  414. onDestroy('all')
  415. });
  416. break;
  417. }
  418. }
  419. function onRestore(id) {
  420. Fast.api.ajax({
  421. url: `shopro/goods/comment/restore/id/${id}`,
  422. type: 'POST',
  423. }, function (ret, res) {
  424. getData()
  425. }, function (ret, res) { })
  426. }
  427. function onDestroy(id) {
  428. Fast.api.ajax({
  429. url: `shopro/goods/comment/destroy/id/${id}`,
  430. type: 'POST',
  431. }, function (ret, res) {
  432. getData()
  433. }, function (ret, res) { })
  434. }
  435. onMounted(() => {
  436. getData()
  437. })
  438. return {
  439. state,
  440. getData,
  441. onChangeSort,
  442. pagination,
  443. batchHandle,
  444. onChangeSelection,
  445. onBatchHandle,
  446. onRestore,
  447. onDestroy,
  448. }
  449. }
  450. }
  451. createApp('recyclebin', recyclebin);
  452. },
  453. reply: () => {
  454. const { reactive, getCurrentInstance } = Vue
  455. const reply = {
  456. setup() {
  457. const { proxy } = getCurrentInstance();
  458. const state = reactive({
  459. id: new URLSearchParams(location.search).get('id'),
  460. })
  461. const form = reactive({
  462. model: {
  463. content: '',
  464. },
  465. rules: {
  466. content: [{ required: true, message: '请输入回复内容', trigger: 'change' }],
  467. },
  468. })
  469. function onConfirm() {
  470. proxy.$refs['formRef'].validate((valid) => {
  471. if (valid) {
  472. Fast.api.ajax({
  473. url: `shopro/goods/comment/reply/id/${state.id}`,
  474. type: 'POST',
  475. data: form.model,
  476. }, function (ret, res) {
  477. Fast.api.close()
  478. }, function (ret, res) { })
  479. }
  480. });
  481. }
  482. return {
  483. form,
  484. onConfirm
  485. }
  486. }
  487. }
  488. createApp('reply', reply);
  489. },
  490. };
  491. return Controller;
  492. });