123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <template>
- <mobile-frame>
- <view class="info">
- <view class="one">
- <uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
- <uni-forms-item label="评论内容" name="content">
- <uni-easyinput maxlength=-1 type="textarea" v-model="form.content" placeholder="请输入评论内容" />
- </uni-forms-item>
- <uni-forms-item label="上传评论图片" name="file">
- <upload :list="file" name="file" :count="6" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
- </uni-forms-item>
- <uni-forms-item label="商品评分" name="goods_score">
- <uni-rate :readonly="readonly" size="18" v-model="form.goods_score" />
- </uni-forms-item>
- <uni-forms-item label="发货评分" name="transport_score">
- <uni-rate :readonly="readonly" size="18" v-model="form.transport_score" />
- </uni-forms-item>
- <uni-forms-item label="店铺评分" name="shop_score">
- <uni-rate :readonly="readonly" size="18" v-model="form.shop_score" />
- </uni-forms-item>
- </uni-forms>
- <view class="btn">
- <button type="primary" @click="onSubmit('form')" size="small">提交</button>
- </view>
- </view>
- </view>
- </mobile-frame>
- </template>
- <script>
- import moment from 'moment';
- import upload from '@/components/upload/index.vue';
- export default {
- components: {
- upload
- },
- data() {
- return {
- id: '',
- // 追加
- rate_id: '',
- user: {},
- form: {},
- info: {},
- file: [],
- rules: {
- content: {
- rules: [{
- required: true,
- errorMessage: '请输入评论内容',
- }]
- },
- grade: {
- rules: [{
- required: true,
- errorMessage: '请输入评论等级',
- }]
- }
- },
- readonly: false,
- };
- },
- onLoad: function(e) {
- const that = this;
- that.$set(that, `id`, e.id || '');
- that.$set(that, `rate_id`, e.rate_id || '');
- // 监听用户是否登录
- that.watchLogin();
- },
- methods: {
- // 监听用户是否登录
- watchLogin() {
- const that = this;
- uni.getStorage({
- key: 'token',
- success: function(res) {
- let user = that.$jwt(res.data);
- if (user) that.$set(that, `user`, user);
- that.search();
- },
- fail: function(err) {
- uni.navigateTo({
- url: `/pages/login/index`
- })
- }
- });
- },
- // 查询列表
- async search() {
- const that = this;
- let user = that.user;
- let res;
- if (that.id) {
- res = await that.$api(`/orderDetail/${that.id}`);
- if (res.errcode == '0') {
- that.$set(that, `info`, res.data.order);
- uni.hideLoading();
- }
- }
- if (that.rate_id) {
- res = await that.$api(`/goodsRate/${that.rate_id}`);
- if (res.errcode == '0') {
- that.$set(that, `form`, res.data);
- that.$set(that, `readonly`, true)
- }
- }
- },
- // 图片上传
- uplSuc(e) {
- const that = this;
- that.$set(that, `${e.name}`, [...that[e.name], e.data]);
- },
- // 图片删除
- uplDel(e) {
- const that = this;
- let data = that[e.name];
- let arr = data.filter((i, index) => index != e.data.index);
- that.$set(that, `${e.name}`, arr)
- },
- // 提交保存
- async onSubmit(ref) {
- const that = this;
- that.$refs[ref].validate().then(async params => {
- if (that.rate_id) {
- let reply = that.form;
- let obj = {
- file: that.file,
- content: params.content,
- time: moment().format('YYYY-MM-DD HH:mm:ss')
- }
- reply.reply.push(obj)
- const arr = await that.$api(`/goodsRate/${that.rate_id}`, 'POST', reply)
- if (arr.errcode == '0') {
- uni.showToast({
- title: `追加成功`,
- icon: 'success',
- });
- uni.navigateBack({
- detail: 1
- })
- } else {
- uni.showToast({
- title: arr.errmsg,
- icon: 'none',
- })
- }
- } else {
- let reply = [{
- file: that.file,
- content: params.content,
- time: moment().format('YYYY-MM-DD HH:mm:ss')
- }];
- params.orderDetail = that.id
- params.reply = reply;
- params.customer = that.user?._id;
- params.shop = that.info?.goods[0]?.shop;
- params.goods = that.info?.goods[0]?.goods[0]?.goods?._id;
- params.goodsSpec = that.info?.goods[0]?.goods[0]?._id;
- const arr = await that.$api(`/goodsRate`, 'POST', params);
- if (arr.errcode == '0') {
- uni.showToast({
- title: `评论成功`,
- icon: 'success',
- });
- uni.navigateBack({
- detail: 1
- })
- } else {
- uni.showToast({
- title: arr.errmsg,
- icon: 'none',
- })
- }
- }
- })
- }
- }
- }
- </script>
- <style lang="scss">
- .info {
- display: flex;
- flex-direction: column;
- width: 100vw;
- height: 100vh;
- .one {
- padding: 2vw;
- .uni-input {
- border: #f1f1ff 1px solid;
- padding: 2vw 2vw;
- border-radius: 1vw;
- }
- .btn {
- text-align: center;
- button {
- margin: 0 2vw 2vw 2vw;
- background-color: var(--ff0Color);
- color: var(--fffColor);
- }
- .name {
- color: var(--f85Color);
- font-size: var(--font14Size);
- }
- }
- }
- }
- .uni-forms-item {
- margin-bottom: 6vw !important;
- display: flex;
- flex-direction: row;
- }
- .uni-forms-item__content {
- display: flex;
- align-items: center;
- }
- </style>
|