123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529 |
- import { TickSystem } from 'XrFrame/systems'
- import DiyApi from '../../services/diy'
- import GoodApi from '../../services/good'
- import { share } from '../../utils/http'
- import Navi from '../../utils/navi'
- import { backPage, getUser } from '../../utils/util'
- const bag: any = []
- for (var i = 0; i < 20; i++) {
- bag.push({
- label: '',
- value: i,
- url: i % 2 === 0 ? '/assets/navbar/p1.png' : '/assets/navbar/p2.png',
- })
- }
- interface itemdto extends Record<string, any> {
- id: number
- imageUrl: string
- checked: boolean
- }
- // pages/diy/index.ts
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- ani: '',
- bag,
- wait: false,
- loading: false,
- loadingDiy: false,
- isManage: false,
- status: 0,
- userInfo: undefined,
- totalPage: 0,
- items: [] as itemdto[],
- pageparams: {
- mode: 'fangan',
- skipCount: 0,
- maxResultCount: 12,
- },
- showIndex: true,
- visible: false,
- closeBtn: true,
- deleteBtn: true,
- initIndex: 0,
- images: [] as string[],
- showSingle: false,
- deleteIds: [] as number[],
- show: false,
- authing: true,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad() {},
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- if (!this.data.authing) {
- console.log(this.data.pageparams.mode, this.data)
- this.load()
- this.setData({ ani: this.data.pageparams.mode === 'fangan' ? ' ani' : '' })
- } else {
- this.getTabBar().init(() => {
- this.setData({
- authing: true,
- })
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- this.setData({
- ani: '',
- authing: false,
- })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {},
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- let pages = getCurrentPages() //获取所有页面栈实例列表
- let nowPage = pages[pages.length - 1] //当前页页面实例
- return {
- title: share.title,
- path: `/${nowPage.route}`,
- imageUrl: share.imageUrl,
- success(res: any) {
- console.log('success(res)==', res)
- },
- fail(res: any) {
- console.log('fail(res)==', res)
- },
- }
- },
- handleAuthDisagree() {
- backPage()
- },
- handleAuthOK() {
- this.setData({
- authing: false,
- })
- this.init()
- },
- init() {
- this.getUserInfo()
- if (this.data.pageparams.skipCount > 0) {
- return
- }
- this.load()
- },
- getUserInfo() {
- const info = getUser()
- const self = this
- if (info != null) {
- self.setData({
- userInfo: info as any,
- ani: ' ani',
- })
- } else {
- self.gotoLogin()
- }
- },
- gotoLogin() {
- Navi.navigateTo({
- url: '/pages/login/index',
- })
- },
- load() {
- this.setData({
- status: 1,
- loading: true,
- })
- DiyApi.GetDiyList({
- ...this.data.pageparams,
- skipCount: this.data.pageparams.skipCount * this.data.pageparams.maxResultCount,
- })
- .then((rsp) => {
- const { result } = rsp
- const total = Math.ceil(result.totalCount / this.data.pageparams.maxResultCount)
- const newItems = this.data.isManage
- ? result.items.map((o: itemdto) => {
- o.checked = false
- return o
- })
- : result.items
- this.setData({
- status: total > this.data.pageparams.skipCount + 1 ? 0 : 2,
- totalPage: Math.ceil(result.totalCount / this.data.pageparams.maxResultCount),
- items:
- this.data.pageparams.skipCount === 0
- ? newItems
- : (this.data.items || []).concat(newItems),
- })
- })
- .catch(() => {
- this.setData({
- loading: false,
- })
- })
- .finally(() => {
- this.setData({
- loading: false,
- })
- })
- },
- remove() {
- const ids = this.data.deleteIds as number[]
- return new Promise<void>((resolve, reject) => {
- this.setData({
- loading: true,
- })
- DiyApi.RemoveDiy({
- mode: this.data.pageparams.mode,
- ids,
- })
- .then((rsp) => {
- if (rsp.result === 'ok') {
- this.setData({
- loading: false,
- deleteIds: [],
- items: this.data.items.filter((o: itemdto) => ids.indexOf(o.id) < 0),
- })
- resolve()
- } else {
- this.setData({
- loading: false,
- })
- reject()
- }
- })
- .catch(() => {
- this.setData({
- loading: false,
- })
- reject()
- })
- })
- },
- handleManage() {
- this.setData({
- isManage: true,
- deleteIds: [],
- items: this.data.items.map((o) => {
- o.checked = false
- return o
- }),
- })
- },
- handleManageBack() {
- this.setData({
- isManage: false,
- })
- },
- changeTab(e: WechatMiniprogram.CustomEvent<{}, {}, { tab: string }>) {
- this.setData(
- {
- status: 0,
- isManage: false,
- items: [],
- pageparams: {
- ...this.data.pageparams,
- mode: e.currentTarget.dataset.tab,
- skipCount: 0,
- },
- },
- () => {
- this.load()
- },
- )
- },
- pagetolower() {
- if (!this.data.loading) {
- if (this.data.totalPage > this.data.pageparams.skipCount + 1) {
- this.setData(
- {
- pageparams: {
- ...this.data.pageparams,
- skipCount: this.data.pageparams.skipCount + 1,
- },
- },
- this.load,
- )
- } else {
- this.setData({
- status: 2,
- })
- }
- console.log('lower')
- }
- },
- showPreview(e: WechatMiniprogram.CustomEvent<{}, {}, { idx: number }>) {
- const idx = e.currentTarget.dataset.idx
- if (this.data.isManage) {
- const newitems = this.data.items
- newitems[idx].checked = !newitems[idx].checked
- this.setData({
- items: newitems,
- deleteIds: newitems
- .filter((o) => o.checked)
- .map((o) => o.id)
- .filter((o) => o != null),
- })
- return
- }
- if (this.data.pageparams.mode === 'shoucang') {
- const item = this.data.items[idx]
- Navi.navigateTo({
- url: '/pages/goods/detail/index?id=' + item.id + '&cateid=' + item.cateId,
- })
- return
- }
- this.setData(
- {
- initIndex: idx,
- images: this.data.items.map((o) => o.imageUrl),
- ani: '',
- },
- () =>
- setTimeout(() => {
- this.setData({
- visible: true,
- })
- }, 100),
- )
- },
- handleUncheck() {
- this.setData({
- items: this.data.items.map((o) => {
- o.checked = false
- return o
- }),
- })
- },
- onClose() {
- this.setData({
- visible: false,
- images: [],
- initIndex: 0,
- ani: this.data.pageparams.mode === 'fangan' ? ' ani' : '',
- })
- },
- handleDelete() {
- if (this.data.deleteIds.length > 0) {
- this.setData({
- showSingle: true,
- })
- }
- },
- onDelete() {
- const item = this.data.items[this.data.initIndex] as any
- this.setData({
- showSingle: true,
- deleteIds: [item.id],
- })
- },
- showGood(e: WechatMiniprogram.CustomEvent<{}, {}, { good: string; cate: string }>) {
- const { good, cate } = e.currentTarget.dataset
- Navi.navigateTo({
- url: '/pages/goods/detail/index?id=' + good + '&cateid=' + cate,
- })
- },
- closeSingleConfirm() {
- if (this.data.loading) {
- return
- }
- this.remove().then(() => {
- this.closeSignleCancel()
- this.onClose()
- })
- },
- closeSignleCancel() {
- this.setData({
- showSingle: false,
- })
- },
- showdiy() {
- this.setData({
- show: true,
- })
- },
- goflatdiy() {
- this.setData({
- loadingDiy: true,
- show: false,
- })
- DiyApi.GetDiy({
- type: 'flat',
- })
- .then((rsp) => {
- console.log(rsp, rsp.result)
- if (rsp.result && rsp.result.length > 0) {
- this.setData(
- {
- loadingDiy: false,
- },
- () => {
- Navi.navigateTo({
- url: '/pages/outlink/index?url=' + encodeURIComponent(rsp.result),
- })
- },
- )
- return
- }
- this.setData({
- loadingDiy: false,
- })
- })
- .catch(() => {
- this.setData({
- loadingDiy: false,
- })
- })
- },
- gospacediy() {
- this.setData({
- loadingDiy: true,
- show: false,
- })
- DiyApi.GetDiy({
- type: 'space',
- })
- .then((rsp) => {
- console.log(rsp, rsp.result)
- if (rsp.result && rsp.result.length > 0) {
- this.setData(
- {
- loadingDiy: false,
- },
- () => {
- Navi.navigateTo({
- url: '/pages/outlink/index?url=' + encodeURIComponent(rsp.result),
- })
- },
- )
- return
- }
- this.setData({
- loadingDiy: false,
- })
- })
- .catch(() => {
- this.setData({
- loadingDiy: false,
- })
- })
- },
- getLink(e: WechatMiniprogram.CustomEvent<{}, {}, { id: string; type: string }>) {
- const id = e.currentTarget.dataset.id
- const type = e.currentTarget.dataset.type
- if (Number(id) > 0) {
- this.setData({
- wait: true,
- })
- GoodApi.GetInspireLink({
- id: Number(id),
- type: type,
- })
- .then((rsp) => {
- if (rsp.result && rsp.result.length > 0) {
- console.log(rsp.result)
- Navi.navigateTo({
- url: '/pages/outlink/index?url=' + encodeURIComponent(rsp.result),
- })
- }
- })
- .finally(() => {
- this.setData({
- wait: false,
- })
- })
- }
- },
- handlePopupHide() {
- this.setData({
- show: false,
- })
- },
- onUploadBackground() {
- const self = this
- wx.chooseMedia({
- count: 9,
- mediaType: ['image'],
- sourceType: ['album', 'camera'],
- maxDuration: 30,
- camera: 'back',
- success(res) {
- const filePath = res.tempFiles[0].tempFilePath
- wx.getFileSystemManager().readFile({
- filePath,
- encoding: 'base64',
- success(res) {
- self.setData({
- wait: true,
- })
- DiyApi.Transbase({
- base64: res.data,
- mode: 'Background',
- })
- .then(() => {
- self.setData(
- {
- wait: false,
- pageparams: {
- ...self.data.pageparams,
- skipCount: 0,
- },
- },
- () => {
- self.load()
- },
- )
- })
- .catch(() => {
- self.setData({
- wait: false,
- })
- })
- },
- })
- },
- })
- },
- })
|