/**
 * 录音文件查询
 */
$(function(){

    AppCallRecord = {
        Events : {'click .btn': function (e, value, row, index) {
			var event = $(e.target).data('event');
			if(event == 'download'){
                AppCallRecord.download(row);
			}else if(event == 'thaw'){
                AppCallRecord.thaw(row);
			}
		}},
        download : function(row){
            var recordUrl = row['recordUrl'];
            if(!recordUrl) {
                App.MsgBox.msg("文件URL为空");
                return;
            }
            window.open(recordUrl);
		},
        thaw: function(row){
            var recordUrl = row['recordUrl'];
            recordUrl = recordUrl.replace("http://ydl-recording.oss-cn-hangzhou.aliyuncs.com/", "");
            var key = recordUrl.replace("https://ydl-recording.oss-cn-hangzhou.aliyuncs.com/", "");

            var oss_url = 'https://oss.console.aliyun.com/bucket/oss-cn-hangzhou/ydl-recording/object?keyword=' + encodeURI(key);
            window.open(oss_url);
		},
        search: function () {
            $table.search({
                'page'	: 1
            });
        }
	};
	
	
	//初始化表格
    var $table = new App.Table({
        url: Config.ROOT + '/call/call_record/list',
        search: false,
        searchParamName: '',
        searchPlaceholder: '',
        columns	:[
            {checkbox: true},
            {field:'id', title:'操作', width: 120, toolbar: 'tableRowToolbar', events: AppCallRecord.Events},
            {field:'', title:'通话记录ID', formatter: function (value, row, index) {
                    return row['id'];
                }},
            {field:'relationId', title:'订单', formatter: function (value, row, index) {
                    return row['orderId'] + '_' + value;
                }},
            {field:'recordUrl', title:'音频'}
        ],
        getQueryParam: function () {
            var search_orderId = $('#search_orderId').val() || '';
            var search_relationId = $('#search_relationId').val() || '';
            var search_callRecordId = $('#search_callRecordId').val() || '';
            var postData = {
                'orderId'	: search_orderId,
                'relationId'	: search_relationId,
                'id' : search_callRecordId
            };
            return postData;
        }
    });

});