zhangjiaqing
8 天以前 1cef3adee31c6934c0da4b4f0b8a6f5ac03b364f
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
(function (vc) {
    vc.extends({
        data: {
            constrainFinishRepairInfo: {
                repairId: '',
                repairType: '',
                context: '',
                feeFlag: '200',
                repairObjType: '',
                publicArea: '',
                repairChannel: '',
                maintenanceTypes: [],
                maintenanceType: '',
                totalPrice: 0,
                choosedGoodsList: [],
                payTypes: [],
                mark: 1,
                sign: 1,
                payType: ''
            }
        },
        _initMethod: function () {
            //与字典表支付方式关联
            vc.getDict('r_repair_pool', "pay_type", function (_data) {
                vc.component.constrainFinishRepairInfo.payTypes = _data;
            });
            $that.constrainFinishRepairInfo.repairType = vc.getParam('repairType');
            $that.constrainFinishRepairInfo.repairId = vc.getParam('repairId');
            $that.constrainFinishRepairInfo.repairObjType = vc.getParam('repairObjType');
            $that.constrainFinishRepairInfo.publicArea = vc.getParam('publicArea');
            $that.constrainFinishRepairInfo.repairChannel = vc.getParam('repairChannel');
            $that._loadMaintenanceType();
        },
        _initEvent: function () {
            vc.on('constrainFinishRepairInfo', 'chooseSingleResource', function (_data) {
                $that.constrainFinishRepairInfo.choosedGoodsList.push(_data);
                $that._updateTotalPrice();
            });
        },
        methods: {
            _loadMaintenanceType() {
                vc.getDict('r_repair_pool', "maintenance_type", function (_data) {
                    vc.component.constrainFinishRepairInfo.maintenanceTypes = _data;
                });
            },
            finishRepairValidate() {
                return vc.validate.validate({
                    constrainFinishRepairInfo: vc.component.constrainFinishRepairInfo
                }, {
                    'constrainFinishRepairInfo.repairId': [{
                        limit: "required",
                        param: "",
                        errInfo: "报修单不能为空"
                    }],
                    'constrainFinishRepairInfo.maintenanceType': [{
                        limit: "required",
                        param: "",
                        errInfo: "维修类型不能为空"
                    }],
                    'constrainFinishRepairInfo.context': [{
                        limit: "required",
                        param: "",
                        errInfo: "处理意见不能为空"
                    }]
                });
            },
            _constrainFinishRepairInfo: function () {
                if (!vc.component.finishRepairValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                if (vc.component.constrainFinishRepairInfo.maintenanceType == '1001' || vc.component.constrainFinishRepairInfo.maintenanceType == '1003') {
                    if (vc.component.constrainFinishRepairInfo.choosedGoodsList.length < 1) {
                        vc.toast('请选择商品');
                        return;
                    }
                }
                if (vc.component.constrainFinishRepairInfo.maintenanceType == '1001' && vc.component.constrainFinishRepairInfo.payType == '') {
                    vc.toast('请选择支付方式');
                    return;
                }
                vc.component.constrainFinishRepairInfo.communityId = vc.getCurrentCommunity().communityId;
                vc.http.apiPost(
                    'ownerRepair.repairForceFinish',
                    JSON.stringify(vc.component.constrainFinishRepairInfo), {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            vc.component.clearConstrainFinishRepairInfo();
                            $that._back();
                            vc.toast("操作成功");
                            return;
                        } else {
                            vc.toast(_json.msg);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    }
                );
            },
            // 选择商品
            _openChooseSingleResourceModel: function () {
                vc.emit('chooseSingleResource', 'openChooseSingleResourceModel', {
                    maintenanceType: vc.component.constrainFinishRepairInfo.maintenanceType,
                    repairId: vc.component.constrainFinishRepairInfo.repairId,
                    sign: 1
                });
            },
            // 移除商品
            _removeChoosedGoodsItem: function (index) {
                vc.component.constrainFinishRepairInfo.choosedGoodsList.splice(index, 1);
                $that._updateTotalPrice();
            },
            // 商品数量减少
            _useNumberDec: function (index) {
                if (vc.component.constrainFinishRepairInfo.choosedGoodsList[index].useNumber <= 1) {
                    vc.toast("不能再减少了");
                    return;
                }
                vc.component.constrainFinishRepairInfo.choosedGoodsList[index].useNumber -= 1;
                this.$forceUpdate();
                $that._updateTotalPrice();
            },
            // 商品数量增加
            _useNumberInc: function (index) {
                vc.component.constrainFinishRepairInfo.choosedGoodsList[index].useNumber += 1;
                this.$forceUpdate();
                $that._updateTotalPrice();
            },
            // 更新总金额
            _updateTotalPrice: function () {
                let totalPrice = 0;
                vc.component.constrainFinishRepairInfo.choosedGoodsList.forEach((item) => {
                    totalPrice += item.price * item.useNumber;
                });
                vc.component.constrainFinishRepairInfo.totalPrice = totalPrice.toFixed(2);
            },
            // 返回
            _back: function () {
                vc.jumpToPage('/#/pages/property/repairForceFinishManage');
            },
            clearConstrainFinishRepairInfo: function () {
                vc.component.constrainFinishRepairInfo = {
                    repairId: '',
                    repairType: '',
                    context: '',
                    feeFlag: '200',
                    repairObjType: '',
                    publicArea: '',
                    repairChannel: '',
                    maintenanceTypes: [],
                    maintenanceType: '',
                    totalPrice: 0,
                    mark: 1,
                    sign: 1,
                    choosedGoodsList: []
                };
            }
        }
    });
})(window.vc);