comment_manage_home_page.dart 30.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:one_key/models/comments_label_model.dart';
import 'package:one_key/models/comments_model.dart';
import 'package:one_key/pages/my/comment_manage/input_buttom_widget.dart';
import 'package:one_key/pages/my/comment_manage/pop_route.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/dialog_util.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';

import '../../../constant/state.dart';
import '../../../provider/comment_manage_provider.dart';
import '../../../utils/event_bus.dart';
import '../../../utils/screen_util.dart';
import '../../../utils/utils.dart';
import '../../../widgets/page_exception.dart';
import '../../online_check/photo_view_wiget.dart';
import 'package:sliding_up_panel2/sliding_up_panel2.dart';

/**
 * 评价管理
 */

class CommentManageHomePage extends StatefulWidget {
  @override
  _CommentManageHomePageState createState() => _CommentManageHomePageState();
}

class _CommentManageHomePageState extends State<CommentManageHomePage> {
  CommentManageProvider commentManageProvider;
  ScrollController controller = ScrollController();
  Map<String, String> starTextMap = {};
  bool allSelect = true;
  String label = '';

  TextEditingController replyController = TextEditingController();
  @override
  void initState() {
    super.initState();

    starTextMap = {'1': '差', '2': '有点差', '3': '一般', '4': '满意', '5': '非常满意'};

    WidgetsBinding.instance.addPostFrameCallback((_) {
      _getSellerComments(isShowLoading: false);
      _getCountCommentLabel(isShowLoading: false);
    });
  }

  @override
  void dispose() {
    bus.emit('changeStatusColor');

    super.dispose();
  }

  ///评价标签
  _getCountCommentLabel({bool isShowLoading = true}) async {
    Map<String, String> pramas = {
      'sid': Provider.of<UserModel>(context, listen: false).user.sellerid,
    };
    // label
    await commentManageProvider.getCountCommentLabel(context, pramas,
        isShowLoading: isShowLoading);
  }

  ///评价列表
  _getSellerComments({bool isShowLoading = true}) async {
    Map<String, String> pramas = {
      'sid': Provider.of<UserModel>(context, listen: false).user.sellerid,
      'scene': '3',
      'status': '1'
    };
    if (label != '') {
      pramas['label'] = label;
    }

    await commentManageProvider.getSellerComments(context, pramas,
        isShowLoading: isShowLoading);
  }

  _setComment(String pid, String rid, String text,
      {bool isShowLoading = true}) async {
    Map<String, String> pramas = {
      'sid': Provider.of<UserModel>(context, listen: false).user.sellerid,
      'identity': '0',
      'pid': pid,
      'rid': rid,
      'text': text,
    };

    bool success = await commentManageProvider.setComment(context, pramas,
        isShowLoading: isShowLoading);
    if (success) {
      //成功  刷新列表
      _getSellerComments(isShowLoading: false);
    }
  }

  List<Widget> _labelWidget() {
    List<Widget> data = [];
    data.add(InkWell(
        onTap: () {
          allSelect = true;
          commentManageProvider.commentsLabeldata.forEach((element) {
            element.select = false;
          });
          setState(() {});
          label = '';
          _getSellerComments(isShowLoading: true);
        },
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: w(8), vertical: w(3)),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(r(10)),
              color: allSelect
                  ? MyColours.color_33438E93
                  : MyColours.color_F8F7F3),
          child: Text(
            '全部',
            style: TextStyle(
                fontSize: font(14),
                color: allSelect
                    ? MyColours.color_438E93
                    : MyColours.color_515151),
          ),
        )));
    for (int i = 0; i < commentManageProvider.commentsLabeldata.length; i++) {
      CommentsLabelSunModel sunModel =
          commentManageProvider.commentsLabeldata[i];
      data.add(InkWell(
          onTap: () {
            commentManageProvider.commentsLabeldata.forEach((element) {
              element.select = false;
            });
            allSelect = false;
            sunModel.select = true;
            setState(() {});
            label = sunModel.name;
            _getSellerComments(isShowLoading: true);
          },
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: w(8), vertical: w(3)),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(r(10)),
                color: sunModel.select
                    ? MyColours.color_33438E93
                    : MyColours.color_F8F7F3),
            child: Text(
              sunModel.name,
              style: TextStyle(
                  fontSize: font(14),
                  color: sunModel.select
                      ? MyColours.color_438E93
                      : MyColours.color_515151),
            ),
          )));
    }
    return data;
  }

  /// 九宫格
  Widget _getGridImg(List<CommentsImageModel> imags) {
    imags.removeWhere((element) => element.url == null || element.url == '');
    return GridView.builder(
        controller: controller,
        padding: EdgeInsets.symmetric(vertical: w(7)),
        shrinkWrap: true,
        itemCount: imags.length,

        //SliverGridDelegateWithFixedCrossAxisCount 构建一个横轴固定数量Widget
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            //横轴元素个数
            crossAxisCount: 3,
            //纵轴间距
            mainAxisSpacing: w(7),
            //横轴间距
            crossAxisSpacing: w(7),
            //子组件宽高长度比例
            childAspectRatio: 1.0),
        itemBuilder: (BuildContext context, int index) {
          return InkWell(
              onTap: () {
                List<String> images = imags.map((e) => e.url).toList();
                _showPhotoView(context, index, images);
              },
              child: ClipRRect(
                borderRadius: BorderRadius.circular(r(8)),
                child: CachedNetworkImage(
                  imageUrl: imags[index].url,
                  fit: BoxFit.cover,

                  // width: w(),
                  // height: ScreenUtil().setWidth(100 * 2),
                ),
              ));
        });
  }

  //查看大图
  _showPhotoView(BuildContext context, int index, List imgs,
      {isShow = false, List dashName}) async {
    // if (imgs.length == 1 &&
    //     imgs[0] ==
    //         'http://nosqn.colorcun.com/custom/lite-online/image/def-banner.png') {
    //   imgs[0] = 'http://nosqn.colorcun.com/app/seller-hj-empty.png';
    // }
    Utils.setBarStatus(false, color: Colors.black);
    dynamic result = await showGeneralDialog(
        context: context,
        barrierDismissible: false,
        // barrierColor: Colors.red,
        barrierLabel:
            MaterialLocalizations.of(context).modalBarrierDismissLabel,
        transitionDuration: const Duration(milliseconds: 150),
        pageBuilder: (BuildContext context, Animation animation,
            Animation secondaryAnimation) {
          Widget child = Stack(
            children: <Widget>[
              PhotoPreview(
                  initialIndex: index,
                  photoList: imgs,
                  isShow: isShow,
                  dashName: dashName)
            ],
          );
          return child;
        });
    Utils.setBarStatus(true, color: Colors.white);
  }

  @override
  Widget build(BuildContext context) {
    commentManageProvider =
        Provider.of<CommentManageProvider>(context, listen: true);
    return Scaffold(
        backgroundColor: MyColours.color_ffffff,
        appBar: SystemAppBar('评价管理'),
        body: Consumer<CommentManageProvider>(builder: (context1, model, _) {
          if (model.pageState != PageState.Success) {
            return ExceptionPage(
              pageState: model.pageState,
              callback: () async {
                _getCountCommentLabel();
                _getSellerComments();
              },
              emptyMsg: "暂时没有评论列表信息哦",
              emptyImg: "empty_search",
              showMsg: "加载中,请稍后...",
            );
          } else {
            return Container(
                color: MyColours.color_ffffff,
                padding: EdgeInsets.symmetric(horizontal: w(20)),
                child: Column(
                  children: [
                    Container(
                      child: Wrap(
                          runSpacing: w(10),
                          spacing: w(10),
                          children: _labelWidget()),
                    ),
                    VEmptyView(10),
                    Expanded(
                        child: ListView.builder(
                            itemCount:
                                commentManageProvider.commentsData.length,
                            shrinkWrap: true,
                            controller: controller,
                            itemBuilder: (context, index) {
                              CommentsSunModel sunModel =
                                  commentManageProvider.commentsData[index];
                              return Stack(children: [
                                Container(
                                  margin: EdgeInsets.only(top: w(10)),
                                  decoration: BoxDecoration(
                                      border: Border(
                                          bottom: BorderSide(
                                              width: w(0.5),
                                              color: MyColours.color_DBDBDB))),
                                  child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Container(
                                          width: w(50),
                                          height: w(50),
                                          margin: EdgeInsets.only(
                                              left: w(8),
                                              right: w(8),
                                              top: w(20)),
                                          child: ClipRRect(
                                              borderRadius:
                                                  BorderRadius.circular(w(50)),
                                              child: sunModel.authorImage !=
                                                          null &&
                                                      sunModel.authorImage !=
                                                          '' &&
                                                      !sunModel.authorImage
                                                          .endsWith('.mp4')
                                                  ? CachedNetworkImage(
                                                      imageUrl:
                                                          sunModel.authorImage,
                                                      width: w(50),
                                                      height: w(50),
                                                    )
                                                  : Container(
                                                      width: w(50),
                                                      height: w(50),
                                                      decoration: BoxDecoration(
                                                          color: MyColours
                                                              .color_d9d9d9,
                                                          borderRadius:
                                                              BorderRadius
                                                                  .circular(
                                                                      r(50))),
                                                    ))),
                                      HEmptyView(34),
                                      Expanded(
                                          child: Padding(
                                              padding: EdgeInsets.symmetric(
                                                  vertical: w(4)),
                                              child: Column(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.start,
                                                  children: [
                                                    Row(
                                                      children: [
                                                        Container(
                                                            padding: EdgeInsets
                                                                .symmetric(
                                                                    vertical:
                                                                        w(4)),
                                                            constraints:
                                                                BoxConstraints(
                                                                    maxWidth:
                                                                        w(120)),
                                                            child: Text(
                                                              sunModel.author ??
                                                                  '',
                                                              maxLines: 10,
                                                              overflow:
                                                                  TextOverflow
                                                                      .ellipsis,
                                                              style: TextStyle(
                                                                  fontSize:
                                                                      font(14),
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .bold,
                                                                  color: MyColours
                                                                      .color_515151),
                                                            )),
                                                        Spacer(),
                                                        Container(
                                                            width: w(75),
                                                            height: w(24),
                                                            child: ListView
                                                                .builder(
                                                                    itemCount:
                                                                        5,
                                                                    shrinkWrap:
                                                                        true,
                                                                    scrollDirection:
                                                                        Axis
                                                                            .horizontal,
                                                                    itemBuilder:
                                                                        (context,
                                                                            index) {
                                                                      return CachedNetworkImage(
                                                                        imageUrl: index <=
                                                                                int.parse(sunModel.grade) - 1
                                                                            ? 'http://nosqn.colorcun.com/pinglun/p%20%283%29.png'
                                                                            : 'http://nosqn.colorcun.com/pinglun/p%20%284%29.png',
                                                                        width: w(
                                                                            15),
                                                                      );
                                                                    })),
                                                        HEmptyView(3),
                                                        Container(
                                                            padding: EdgeInsets
                                                                .symmetric(
                                                                    vertical:
                                                                        w(4)),
                                                            child: Text(
                                                              starTextMap[
                                                                      '${sunModel.grade}'] ??
                                                                  '',
                                                              maxLines: 2,
                                                              overflow:
                                                                  TextOverflow
                                                                      .ellipsis,
                                                              style: TextStyle(
                                                                  fontSize:
                                                                      font(12),
                                                                  color: MyColours
                                                                      .color_999999),
                                                            )),
                                                      ],
                                                    ),
                                                    VEmptyView(8),
                                                    Container(
                                                        padding: EdgeInsets
                                                            .symmetric(
                                                                vertical: w(4)),
                                                        child: Text(
                                                          '就餐于 ${sunModel.ddate} ${sunModel.ddateSolt} ${sunModel.tableinfo}',
                                                          maxLines: 10,
                                                          overflow: TextOverflow
                                                              .ellipsis,
                                                          style: TextStyle(
                                                              fontSize:
                                                                  font(12),
                                                              color: MyColours
                                                                  .color_999999),
                                                        )),
                                                    Container(
                                                        padding: EdgeInsets
                                                            .symmetric(
                                                                vertical: w(4)),
                                                        child: Text(
                                                          '发表于 ${sunModel.createTimeStr}',
                                                          maxLines: 10,
                                                          overflow: TextOverflow
                                                              .ellipsis,
                                                          style: TextStyle(
                                                              fontSize:
                                                                  font(12),
                                                              color: MyColours
                                                                  .color_999999),
                                                        )),
                                                    VEmptyView(8),
                                                    if (sunModel.text != null &&
                                                        sunModel.text.length >
                                                            0)
                                                      Container(
                                                          padding: EdgeInsets
                                                              .symmetric(
                                                                  vertical:
                                                                      w(4)),
                                                          child: Text(
                                                            sunModel.text ?? '',
                                                            style: TextStyle(
                                                                height: 1.8,
                                                                fontSize:
                                                                    font(12),
                                                                color: MyColours
                                                                    .color_515151),
                                                          )),
                                                    Container(
                                                        padding: EdgeInsets
                                                            .symmetric(
                                                                vertical: w(4)),
                                                        child: Text(
                                                          '#${sunModel.evalLabel ?? ''}',
                                                          style: TextStyle(
                                                              height: 1.8,
                                                              fontSize:
                                                                  font(12),
                                                              color: MyColours
                                                                  .color_438E93),
                                                        )),
                                                    if (sunModel
                                                            .enclosure.length >
                                                        0)
                                                      _getGridImg(
                                                          sunModel.enclosure),
                                                    VEmptyView(8),
                                                    sunModel.reply != null
                                                        ? Container(
                                                            width:
                                                                double.infinity,
                                                            padding:
                                                                EdgeInsets.all(
                                                                    w(4)),
                                                            decoration: BoxDecoration(
                                                                color: MyColours
                                                                    .color_33438E93,
                                                                borderRadius:
                                                                    BorderRadius
                                                                        .circular(
                                                                            r(8))),
                                                            child: Column(
                                                              crossAxisAlignment:
                                                                  CrossAxisAlignment
                                                                      .start,
                                                              children: [
                                                                Text(
                                                                  '回复内容',
                                                                  style: TextStyle(
                                                                      color: MyColours
                                                                          .color_515151,
                                                                      fontWeight:
                                                                          FontWeight
                                                                              .bold,
                                                                      fontSize:
                                                                          font(
                                                                              12)),
                                                                ),
                                                                VEmptyView(6),
                                                                Container(
                                                                    padding: EdgeInsets.symmetric(
                                                                        vertical:
                                                                            w(4)),
                                                                    child: Text(
                                                                      sunModel.reply
                                                                              .text ??
                                                                          "",
                                                                      style: TextStyle(
                                                                          height:
                                                                              1.8,
                                                                          fontSize: font(
                                                                              12),
                                                                          color:
                                                                              MyColours.color_515151),
                                                                    )),
                                                              ],
                                                            ),
                                                          )
                                                        : Align(
                                                            alignment: Alignment
                                                                .centerRight,
                                                            child: RoundButton(
                                                              text: '回复',
                                                              width: w(54),
                                                              height: w(24),
                                                              gradientStart:
                                                                  MyColours
                                                                      .color_ffffff,
                                                              gradientEnd: MyColours
                                                                  .color_ffffff,
                                                              textColor: MyColours
                                                                  .color_000000,
                                                              fontSize: 24,
                                                              borderColor: MyColours
                                                                  .color_999999,
                                                              radius: r(15),
                                                              onPressed: () {
                                                                Navigator.push(
                                                                    context,
                                                                    PopRoute(child:
                                                                        InputButtomWidget(
                                                                  onEditingCompleteText:
                                                                      (text) {
                                                                    print(
                                                                        '点击发送 ---$text');
                                                                    _setComment(
                                                                      sunModel
                                                                          .id,
                                                                      sunModel
                                                                          .rid,
                                                                      text,
                                                                    );
                                                                  },
                                                                )));
                                                              },
                                                            ),
                                                          ),
                                                    VEmptyView(26),
                                                  ]))),
                                    ],
                                  ),
                                ),
                              ]);
                            }))
                  ],
                ));
          }
        }));
  }
}